DHTPluginStorageManager.java

Index Score
com.aelitis.azureus.plugins.dht.impl
Azureus

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
WHITESPACENumber of whitespace lines
BLOCKSNumber of blocks
LOCLines of code
JAVA0145JAVA0145 Tab character used in source file
LINESNumber of lines in the source file
ELOCEffective lines of code
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
LOGICAL_LINESNumber of statements
COMPARISONSNumber of comparison operators
CYCLOMATICCyclomatic complexity
OPERANDSNumber of operands
EXEC_COMMENTSComments in executable code
LOOPSNumber of loops
LINE_COMMENTNumber of line comments
INTERFACE_COMPLEXITYInterface complexity
JAVA0117JAVA0117 Missing javadoc: method 'method'
PARAMSNumber of formal parameter declarations
SIZESize of the file in bytes
UNIQUE_OPERANDSNumber of unique operands
FUNCTIONSNumber of function declarations
EXITSProcedure exits
PROGRAM_VOCABHalstead program vocabulary
RETURNSNumber of return points from functions
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0166JAVA0166 Generic exception caught
JAVA0170JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0076JAVA0076 Use of magic number
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0034JAVA0034 Missing braces in if statement
JAVA0077JAVA0077 Private field not used in declaring class
UNIQUE_OPERATORSNumber of unique operators
JAVA0264JAVA0264 Integer math in long context - check for overflow
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0174JAVA0174 Assigned local variable never used
JAVA0256JAVA0256 Assignment of external collection/array to field
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0171JAVA0171 Unused local variable
JAVA0173JAVA0173 Unused method parameter
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
/* * Created on 12-Mar-2005 * Created by Paul Gardner * Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * AELITIS, SAS au capital de 46,603.30 euros * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France. * */ package com.aelitis.azureus.plugins.dht.impl; import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.math.BigInteger; import java.security.KeyFactory; import java.security.Signature; import java.security.interfaces.RSAPublicKey; import java.security.spec.RSAPublicKeySpec; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.gudy.azureus2.core3.util.*; import com.aelitis.azureus.core.dht.DHT; import com.aelitis.azureus.core.dht.DHTLogger; import com.aelitis.azureus.core.dht.DHTStorageAdapter; import com.aelitis.azureus.core.dht.DHTStorageBlock; import com.aelitis.azureus.core.dht.DHTStorageKey; import com.aelitis.azureus.core.dht.DHTStorageKeyStats; import com.aelitis.azureus.core.dht.impl.DHTLog; import com.aelitis.azureus.core.dht.transport.DHTTransportContact; import com.aelitis.azureus.core.dht.transport.DHTTransportValue; import com.aelitis.azureus.core.util.bloom.BloomFilter; import com.aelitis.azureus.core.util.bloom.BloomFilterFactory; /** * @author parg * */ public class DHTPluginStorageManager implements DHTStorageAdapter { private static final String pub_exp = "10001"; private static final String modulus = "b8a440c76405b2175a24c86d70f2c71929673a31045791d8bd84220a48729998900d227b560e88357074fa534ccccc6944729bfdda5413622f068e7926176a8afc8b75d4ba6cde760096624415b544f73677e8093ddba46723cb973b4d55f61c2003b73f52582894c018e141e8d010bb615cdbbfaeb97a7af6ce1a5a20a62994da81bde6487e8a39e66c8df0cfd9d763c2da4729cbf54278ea4912169edb0a33"; private static final long ADDRESS_EXPIRY = 7*24*60*60*1000L; private static final int DIV_WIDTH = 10; private static final int DIV_FRAG_GET_SIZE = 2; private static final long DIV_EXPIRY_MIN = 2*24*60*60*1000L; private static final long DIV_EXPIRY_RAND = 1*24*60*60*1000L; private static final long KEY_BLOCK_TIMEOUT_SECS = 7*24*60*60; public static final int LOCAL_DIVERSIFICATION_SIZE_LIMIT = 4096; public static final int LOCAL_DIVERSIFICATION_ENTRIES_LIMIT = 512; public static final int LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES = 3; public static final int LOCAL_DIVERSIFICATION_READS_PER_MIN = 30; public static final int MAX_STORAGE_KEYS = 65536; private int network; private DHTLogger log; private File data_dir; private AEMonitor address_mon = new AEMonitor( "DHTPluginStorageManager:address" ); private AEMonitor contact_mon = new AEMonitor( "DHTPluginStorageManager:contact" ); private AEMonitor storage_mon = new AEMonitor( "DHTPluginStorageManager:storage" ); private AEMonitor version_mon = new AEMonitor( "DHTPluginStorageManager:version" ); private AEMonitor key_block_mon = new AEMonitor( "DHTPluginStorageManager:block" ); private Map version_map = new HashMap(); private Map recent_addresses = new HashMap(); private Map remote_diversifications = new HashMap(); private Map local_storage_keys = new HashMap(); private volatile ByteArrayHashMap key_block_map_cow = new ByteArrayHashMap(); private volatile DHTStorageBlock[] key_blocks_direct_cow = new DHTStorageBlock[0]; private BloomFilter kb_verify_fail_bloom; private long kb_verify_fail_bloom_create_time; private static RSAPublicKey key_block_public_key; static{ try{ KeyFactory key_factory = KeyFactory.getInstance("RSA"); RSAPublicKeySpec public_key_spec = new RSAPublicKeySpec( new BigInteger(modulus,16), new BigInteger(pub_exp,16)); key_block_public_key = (RSAPublicKey)key_factory.generatePublic( public_key_spec ); }catch( Throwable e ){ Debug.printStackTrace(e); } } public DHTPluginStorageManager( int _network, DHTLogger _log, File _data_dir ) { network = _network; log = _log; data_dir = _data_dir; FileUtil.mkdirs(data_dir); readRecentAddresses(); readDiversifications(); readVersionData(); readKeyBlocks(); } protected void importContacts( DHT dht ) { try{ contact_mon.enter(); File target = new File( data_dir, "contacts.dat" ); if ( !target.exists()){ target = new File( data_dir, "contacts.saving" ); } if ( target.exists()){ DataInputStream dis = new DataInputStream( new FileInputStream( target )); try{ dht.importState( dis ); }finally{ dis.close(); } } }catch( Throwable e ){ Debug.printStackTrace( e ); }finally{ contact_mon.exit(); } } protected void exportContacts( DHT dht ) { try{ contact_mon.enter(); File saving = new File( data_dir, "contacts.saving" ); File target = new File( data_dir, "contacts.dat" ); saving.delete(); DataOutputStream dos = null; boolean ok = false; try{ FileOutputStream fos = new FileOutputStream( saving ); dos = new DataOutputStream(fos); dht.exportState( dos, 32 ); dos.flush(); fos.getFD().sync(); ok = true; }finally{ if ( dos != null ){ dos.close(); if ( ok ){ target.delete(); saving.renameTo( target ); } } } }catch( Throwable e ){ Debug.printStackTrace( e ); }finally{ contact_mon.exit(); } // this is a good point to save diversifications - useful when they've expired // as writing isn't triggered at expiry time writeDiversifications(); } protected void readRecentAddresses() { try{ address_mon.enter(); recent_addresses = readMapFromFile( "addresses" ); }finally{ address_mon.exit(); } } protected void writeRecentAddresses() { try{ address_mon.enter(); // remove any old crud Iterator it = recent_addresses.keySet().iterator(); while( it.hasNext()){ String key = (String)it.next(); if ( !key.equals( "most_recent" )){ Long time = (Long)recent_addresses.get(key); if ( SystemTime.getCurrentTime() - time.longValue() > ADDRESS_EXPIRY ){ it.remove(); } } } writeMapToFile( recent_addresses, "addresses" ); }catch( Throwable e ){ Debug.printStackTrace(e); }finally{ address_mon.exit(); } } protected void recordCurrentAddress( String address ) { try{ address_mon.enter(); recent_addresses.put( address, new Long( SystemTime.getCurrentTime())); recent_addresses.put( "most_recent", address.getBytes()); writeRecentAddresses(); }finally{ address_mon.exit(); } } protected String getMostRecentAddress() { byte[] addr = (byte[])recent_addresses.get( "most_recent" ); if ( addr == null ){ return( null ); } return( new String( addr )); } protected boolean isRecentAddress( String address ) { try{ address_mon.enter(); if ( recent_addresses.containsKey( address )){ return( true ); } String most_recent = getMostRecentAddress(); return( most_recent != null && most_recent.equals( address )); }finally{ address_mon.exit(); } } protected void localContactChanged( DHTTransportContact contact ) { purgeDirectKeyBlocks(); } protected Map readMapFromFile( String file_prefix ) { try{ File target = new File( data_dir, file_prefix + ".dat" ); if ( !target.exists()){ target = new File( data_dir, file_prefix + ".saving" ); } if ( target.exists()){ BufferedInputStream is = new BufferedInputStream( new FileInputStream( target )); try{ return( BDecoder.decode( is )); }finally{ is.close(); } } }catch( Throwable e ){ Debug.printStackTrace( e ); } return( new HashMap()); } protected void writeMapToFile( Map map, String file_prefix ) { try{ File saving = new File( data_dir, file_prefix + ".saving" ); File target = new File( data_dir, file_prefix + ".dat" ); saving.delete(); if ( map.size() == 0 ){ target.delete(); }else{ FileOutputStream os = null; boolean ok = false; try{ byte[] data = BEncoder.encode( map ); os = new FileOutputStream( saving ); os.write( data ); os.flush(); os.getFD().sync(); os.close(); ok = true; }finally{ if ( os != null ){ os.close(); if ( ok ){ target.delete(); saving.renameTo( target ); } } } } }catch( Throwable e ){ Debug.printStackTrace(e); } } protected void readVersionData() { try{ version_mon.enter(); version_map = readMapFromFile( "version" ); }finally{ version_mon.exit(); } } protected void writeVersionData() { try{ version_mon.enter(); writeMapToFile( version_map, "version" ); }finally{ version_mon.exit(); } } public int getNextValueVersions( int num ) { try{ version_mon.enter(); Long l_next = (Long)version_map.get( "next" ); int now = (int)(SystemTime.getCurrentTime()/1000); int next; if ( l_next == null ){ next = now; }else{ next = l_next.intValue(); // if "next" is in the future then we live with it to try and ensure increasing // values (system clock must have changed) if ( next < now ){ next = now; } } version_map.put( "next", new Long( next+num )); writeVersionData(); return( next ); }finally{ version_mon.exit(); } } // key storage public DHTStorageKey keyCreated( HashWrapper key, boolean local ) { //System.out.println( "DHT key created"); try{ storage_mon.enter(); return( getStorageKey( key )); }finally{ storage_mon.exit(); } } public void keyDeleted( DHTStorageKey key ) { //System.out.println( "DHT key deleted" ); try{ storage_mon.enter(); deleteStorageKey((storageKey)key ); }finally{ storage_mon.exit(); } } public void keyRead( DHTStorageKey key, DHTTransportContact contact ) { //System.out.println( "DHT value read" ); try{ storage_mon.enter(); ((storageKey)key).read( contact ); }finally{ storage_mon.exit(); } } public void serialiseStats( storageKey key, DataOutputStream dos ) throws IOException { dos.writeByte( (byte)0 ); // version dos.writeInt( key.getEntryCount()); dos.writeInt( key.getSize()); dos.writeInt( key.getReadsPerMinute()); dos.writeByte( key.getDiversificationType()); } public DHTStorageKeyStats deserialiseStats( DataInputStream is ) throws IOException { byte version = is.readByte(); final int entry_count = is.readInt(); final int size = is.readInt(); final int reads = is.readInt(); final byte div = is.readByte(); return( new DHTStorageKeyStats() { public int getEntryCount() { return( entry_count ); } public int getSize() { return( size ); } public int getReadsPerMinute() { return( reads ); } public byte getDiversification() { return( div ); } public String getString() { return( "entries=" + getEntryCount() + ",size=" + getSize() + ",rpm=" + getReadsPerMinute() + ",div=" + getDiversification()); } }); } public void valueAdded( DHTStorageKey key, DHTTransportValue value ) { // System.out.println( network + ": DHT value added: " + DHTLog.getString2( ((storageKey)key).getKey().getBytes()) + " -> " + value.getString()); try{ storage_mon.enter(); ((storageKey)key).valueChanged( 1, value.getValue().length); }finally{ storage_mon.exit(); } } public void valueUpdated( DHTStorageKey key, DHTTransportValue old_value, DHTTransportValue new_value ) { //System.out.println( "DHT value updated" ); try{ storage_mon.enter(); ((storageKey)key).valueChanged( 0, new_value.getValue().length - old_value.getValue().length); }finally{ storage_mon.exit(); } } public void valueDeleted( DHTStorageKey key, DHTTransportValue value ) { //System.out.println( "DHT value deleted" ); try{ storage_mon.enter(); ((storageKey)key).valueChanged( -1, -value.getValue().length); }finally{ storage_mon.exit(); } } public boolean isDiversified( byte[] key ) { HashWrapper wrapper = new HashWrapper( key ); try{ storage_mon.enter(); return( lookupDiversification( wrapper ) != null ); }finally{ storage_mon.exit(); } } // get diversifications for put operations must deterministically return the same end points // but gets for gets should be randomised to load balance public byte[][] getExistingDiversification( byte[] key, boolean put_operation, boolean exhaustive ) { //System.out.println( "DHT get existing diversification: put = " + put_operation ); HashWrapper wrapper = new HashWrapper( key ); // must always return a value - original if no diversification exists try{ storage_mon.enter(); byte[][] res = followDivChain( wrapper, put_operation, exhaustive ); if ( !Arrays.equals( res[0], key )){ String trace = ""; for (int i=0;i<res.length;i++){ trace += (i==0?"":",") + DHTLog.getString2( res[i] ); } log.log( "SM: get div: " + DHTLog.getString2(key) + ", put = " + put_operation + ", exh = " + exhaustive + " -> " + trace ); } return( res ); }finally{ storage_mon.exit(); } } public byte[][] createNewDiversification( DHTTransportContact cause, byte[] key, boolean put_operation, byte diversification_type, boolean exhaustive ) { //System.out.println( "DHT create new diversification: put = " + put_operation +", type = " + diversification_type ); HashWrapper wrapper = new HashWrapper( key ); try{ storage_mon.enter(); diversification div = lookupDiversification( wrapper ); boolean created = false; if ( div == null ){ div = createDiversification( wrapper, diversification_type ); created = true; } byte[][] res = followDivChain( wrapper, put_operation, exhaustive ); String trace = ""; for (int i=0;i<res.length;i++){ trace += (i==0?"":",") + DHTLog.getString2( res[i] ); } log.log( "SM: create div: " + DHTLog.getString2(key) + ", new = " + created + ", put = " + put_operation + ", exh = " + exhaustive + ", type = " + DHT.DT_STRINGS[diversification_type] + " -> " + trace + ", cause = " + (cause==null?"<unknown>":cause.getString())); return( res ); }finally{ storage_mon.exit(); } } protected byte[][] followDivChain( HashWrapper wrapper, boolean put_operation, boolean exhaustive ) { List list = new ArrayList(); list.add( wrapper ); list = followDivChain( list, put_operation, 0, exhaustive, new ArrayList()); byte[][] res = new byte[list.size()][]; for (int i=0;i<list.size();i++){ res[i] = ((HashWrapper)list.get(i)).getBytes(); } return( res ); } protected List followDivChain( List list_in, boolean put_operation, int depth, boolean exhaustive, List keys_done ) { List list_out = new ArrayList(); /* String indent = ""; for(int i=0;i<depth;i++){ indent+= " "; } System.out.println( indent + "->" ); */ // for each entry, if there are no diversifications then we just return the value // for those with divs we replace their entry with the diversified set (which can // include the entry itself under some circumstances ) for (int i=0;i<list_in.size();i++){ HashWrapper wrapper = (HashWrapper)list_in.get(i); diversification div = lookupDiversification( wrapper ); if ( div == null ){ if ( !list_out.contains( wrapper )){ list_out.add(wrapper); } }else{ if ( keys_done.contains( wrapper )){ // we've recursed on the key, this means that a prior diversification wanted // the key included, so include it now if ( !list_out.contains( wrapper )){ list_out.add(wrapper); } continue; } keys_done.add( wrapper ); // replace this entry with the diversified keys List new_list = followDivChain( div.getKeys( put_operation, exhaustive ), put_operation, depth+1, exhaustive, keys_done ); for (int j=0;j<new_list.size();j++){ Object entry = new_list.get(j); if ( !list_out.contains( entry )){ list_out.add(entry); } } } } // System.out.println( indent + "<-" ); return( list_out ); } protected storageKey getStorageKey( HashWrapper key ) { storageKey res = (storageKey)local_storage_keys.get( key ); if ( res == null ){ // someout could be spamming us with crap, prevent things from getting // out of control if ( local_storage_keys.size() >= MAX_STORAGE_KEYS ){ res = new storageKey( this, DHT.DT_SIZE, key ); Debug.out( "DHTStorageManager: max key limit exceeded" ); log.log( "SM: max storage key limit exceeded - " + DHTLog.getString2( key.getBytes())); }else{ res = new storageKey( this, DHT.DT_NONE, key ); local_storage_keys.put( key, res ); } } return( res ); } protected void deleteStorageKey( storageKey key ) { if ( local_storage_keys.remove( key ) != null ){ if ( key.getDiversificationType() != DHT.DT_NONE ){ writeDiversifications(); } } } protected void readDiversifications() { try{ storage_mon.enter(); Map map = readMapFromFile( "diverse" ); List keys = (List)map.get("local"); if ( keys != null ){ long now = SystemTime.getCurrentTime(); for (int i=0;i<keys.size();i++){ storageKey d = storageKey.deserialise(this, (Map)keys.get(i)); long time_left = d.getExpiry() - now; if ( time_left > 0 ){ local_storage_keys.put( d.getKey(), d ); }else{ log.log( "SM: serialised sk: " + DHTLog.getString2( d.getKey().getBytes()) + " expired" ); } } } List divs = (List)map.get("remote"); if ( divs != null ){ long now = SystemTime.getCurrentTime(); for (int i=0;i<divs.size();i++){ diversification d = diversification.deserialise( this, (Map)divs.get(i)); long time_left = d.getExpiry() - now; if ( time_left > 0 ){ remote_diversifications.put( d.getKey(), d ); }else{ log.log( "SM: serialised div: " + DHTLog.getString2( d.getKey().getBytes()) + " expired" ); } } } }finally{ storage_mon.exit(); } } protected void writeDiversifications() { try{ storage_mon.enter(); Map map = new HashMap(); List keys = new ArrayList(); map.put( "local", keys ); Iterator it = local_storage_keys.values().iterator(); while( it.hasNext()){ storageKey key = (storageKey)it.next(); if ( key.getDiversificationType() != DHT.DT_NONE ){ keys.add(key.serialise()); } } List divs = new ArrayList(); map.put( "remote", divs ); it = remote_diversifications.values().iterator(); while( it.hasNext()){ divs.add(((diversification)it.next()).serialise()); } writeMapToFile( map, "diverse" ); }catch( Throwable e ){ Debug.printStackTrace(e); }finally{ storage_mon.exit(); } } protected diversification lookupDiversification( HashWrapper wrapper ) { diversification div = (diversification)remote_diversifications.get(wrapper); if ( div != null ){ if ( div.getExpiry() < SystemTime.getCurrentTime()){ log.log( "SM: div: " + DHTLog.getString2( div.getKey().getBytes()) + " expired" ); remote_diversifications.remove( wrapper ); div = null; } } return( div ); } protected diversification createDiversification( HashWrapper wrapper, byte type ) { diversification div = new diversification( this, wrapper, type ); remote_diversifications.put( wrapper, div ); writeDiversifications(); return( div ); } protected static String formatExpiry( long l ) { long diff = l - SystemTime.getCurrentTime(); return( (diff<0?"-":"") + DisplayFormatters.formatTime(Math.abs(diff))); } // key blocks protected void readKeyBlocks() { try{ key_block_mon.enter(); Map map = readMapFromFile( "block" ); List entries = (List)map.get( "entries" ); int now_secs = (int)(SystemTime.getCurrentTime()/1000); ByteArrayHashMap new_map = new ByteArrayHashMap(); if ( entries != null ){ for (int i=0;i<entries.size();i++){ try{ Map m = (Map)entries.get(i); byte[] request = (byte[])m.get( "req" ); byte[] cert = (byte[])m.get( "cert" ); int recv = ((Long)m.get( "received" )).intValue(); boolean direct = ((Long)m.get( "direct" )).longValue()==1; if ( recv > now_secs ){ recv = now_secs; } keyBlock kb = new keyBlock( request, cert, recv, direct ); // direct "add" values never timeout, however direct "removals" do, as do // indirect values if ( ( direct && kb.isAdd()) || now_secs - recv < KEY_BLOCK_TIMEOUT_SECS ){ if ( verifyKeyBlock( request, cert )){ log.log( "KB: deserialised " + DHTLog.getString2( kb.getKey()) + ",add=" + kb.isAdd() + ",dir=" + kb.isDirect()); new_map.put( kb.getKey(), kb ); } } }catch( Throwable e ){ Debug.printStackTrace(e); } } } key_block_map_cow = new_map; key_blocks_direct_cow = buildKeyBlockDetails( new_map ); }finally{ key_block_mon.exit(); } } protected DHTStorageBlock[] buildKeyBlockDetails( ByteArrayHashMap map ) { List kbs = map.values(); Iterator it = kbs.iterator(); while( it.hasNext()){ keyBlock kb = (keyBlock)it.next(); if ( !kb.isDirect()){ it.remove(); } } DHTStorageBlock[] new_blocks = new DHTStorageBlock[kbs.size()]; kbs.toArray( new_blocks ); return( new_blocks ); } protected void writeKeyBlocks() { try{ key_block_mon.enter(); Map map = new HashMap(); List entries = new ArrayList(); map.put( "entries", entries ); List kbs = key_block_map_cow.values(); for (int i=0;i<kbs.size();i++){ keyBlock kb = (keyBlock)kbs.get(i); Map m = new HashMap(); m.put( "req", kb.getRequest()); m.put( "cert", kb.getCertificate()); m.put( "received", new Long(kb.getReceived())); m.put( "direct", new Long(kb.isDirect()?1:0)); entries.add( m ); } writeMapToFile( map, "block" ); }catch( Throwable e ){ Debug.printStackTrace(e); }finally{ key_block_mon.exit(); } } public DHTStorageBlock keyBlockRequest( DHTTransportContact originating_contact, byte[] request, byte[] signature ) { // request is 4 bytes flags, 4 byte time, K byte key // flag: MSB 00 -> unblock, 01 ->block if ( request.length <= 8 ){ return( null ); } keyBlock kb = new keyBlock(request, signature, (int)(SystemTime.getCurrentTime()/1000), originating_contact != null ); try{ key_block_mon.enter(); boolean add_it = false; try{ keyBlock old = (keyBlock)key_block_map_cow.get( kb.getKey()); if ( old != null ){ // never override a direct value with an indirect one as direct = first hand knowledge // whereas indirect is hearsay if ( old.isDirect() && !kb.isDirect()){ return( null ); } // don't let older instructions override newer ones if ( old.getCreated() > kb.getCreated()){ return( null ); } } if ( kb.isAdd()){ if ( old == null || !old.isAdd()){ if ( !verifyKeyBlock( kb, originating_contact )){ return( null ); } add_it = true; } return( kb ); }else{ // only direct operations can "remove" blocks if ( kb.isDirect() && ( old == null || old.isAdd())){ if ( !verifyKeyBlock( kb, originating_contact )){ return( null ); } add_it = true; } return( null ); } }finally{ if ( add_it ){ ByteArrayHashMap new_map = key_block_map_cow.duplicate(); new_map.put( kb.getKey(), kb ); // seeing as we've received this from someone there's no point in replicating it // back to them later - mark them to prevent this if ( originating_contact != null ){ kb.sentTo( originating_contact ); } key_block_map_cow = new_map; key_blocks_direct_cow = buildKeyBlockDetails( key_block_map_cow ); writeKeyBlocks(); } } }finally{ key_block_mon.exit(); } } protected boolean verifyKeyBlock( keyBlock kb, DHTTransportContact originator ) { byte[] id = originator==null?new byte[20]:originator.getID(); BloomFilter filter = kb_verify_fail_bloom; long now = SystemTime.getCurrentTime(); if ( filter == null || kb_verify_fail_bloom_create_time > now || now - kb_verify_fail_bloom_create_time > 30*60*1000 ){ kb_verify_fail_bloom_create_time = now; filter = BloomFilterFactory.createAddOnly(4000); kb_verify_fail_bloom = filter; } if ( filter.contains( id )){ log.log( "KB: request verify denied" ); return( false ); } try{ Signature verifier = Signature.getInstance("MD5withRSA" ); verifier.initVerify( key_block_public_key ); verifier.update( kb.getRequest() ); if ( !verifier.verify( kb.getCertificate())){ log.log( "KB: request verify failed for " + DHTLog.getString2( kb.getKey())); filter.add( id ); return( false ); } log.log( "KB: request verify ok " + DHTLog.getString2( kb.getKey()) + ", add = " + kb.isAdd() + ", direct = " + kb.isDirect()); return( true ); }catch( Throwable e ){ return( false ); } } public static boolean verifyKeyBlock( byte[] request, byte[] signature ) { try{ Signature verifier = Signature.getInstance("MD5withRSA" ); verifier.initVerify( key_block_public_key ); verifier.update( request ); if ( !verifier.verify( signature )){ return( false ); } return( true ); }catch( Throwable e ){ return( false ); } } public DHTStorageBlock getKeyBlockDetails( byte[] key ) { keyBlock kb = (keyBlock)key_block_map_cow.get( key ); if ( kb == null || !kb.isAdd()){ return( null ); } if ( !kb.getLogged()){ kb.setLogged(); log.log( "KB: Access to key '" + DHTLog.getFullString( kb.getKey()) + "' denied as it is blocked" ); } return( kb ); } public DHTStorageBlock[] getDirectKeyBlocks() { return( key_blocks_direct_cow ); } public byte[] getKeyForKeyBlock( byte[] request ) { if ( request.length <= 8 ){ return( new byte[0] ); } byte[] key = new byte[ request.length - 8 ]; System.arraycopy( request, 8, key, 0, key.length ); return( key ); } protected void purgeDirectKeyBlocks() { try{ key_block_mon.enter(); ByteArrayHashMap new_map = new ByteArrayHashMap(); Iterator it = key_block_map_cow.values().iterator(); boolean changed = false; while( it.hasNext()){ keyBlock kb = (keyBlock)it.next(); if ( kb.isDirect()){ changed = true; }else{ new_map.put( kb.getKey(), kb ); } } if ( changed ){ log.log( "KB: Purged direct entries on ID change" ); key_block_map_cow = new_map; key_blocks_direct_cow = buildKeyBlockDetails( key_block_map_cow ); writeKeyBlocks(); } }finally{ key_block_mon.exit(); } } public void setStorageForKey( String key, byte[] data ) { try{ storage_mon.enter(); Map map = readMapFromFile( "general" ); map.put( key, data ); writeMapToFile( map, "general" ); }finally{ storage_mon.exit(); } } public byte[] getStorageForKey( String key ) { try{ storage_mon.enter(); Map map = readMapFromFile( "general" ); return((byte[])map.get( key )); }finally{ storage_mon.exit(); } } protected static class keyBlock implements DHTStorageBlock { private byte[] request; private byte[] cert; private int received; private boolean direct; private BloomFilter sent_to_bloom; private boolean logged; protected keyBlock( byte[] _request, byte[] _cert, int _received, boolean _direct ) { request = _request; cert = _cert; received = _received; direct = _direct; } public byte[] getRequest() { return( request ); } public byte[] getCertificate() { return( cert ); } public byte[] getKey() { byte[] key = new byte[ request.length - 8 ]; System.arraycopy( request, 8, key, 0, key.length ); return( key ); } protected boolean isAdd() { return( request[0] == 0x01 ); } protected boolean getLogged() { return( logged ); } protected void setLogged() { logged = true; } protected int getCreated() { int created = (request[4]<<24)&0xff000000 | (request[5]<<16)&0x00ff0000 | (request[6]<< 8)&0x0000ff00 | request[7] &0x000000ff; return( created ); } protected int getReceived() { return( received ); } protected boolean isDirect() { return( direct ); } public boolean hasBeenSentTo( DHTTransportContact contact ) { BloomFilter filter = sent_to_bloom; if ( filter == null ){ return( false ); } return( filter.contains( contact.getID())); } public void sentTo( DHTTransportContact contact ) { BloomFilter filter = sent_to_bloom; if ( filter == null || filter.getEntryCount() > 100 ){ filter = BloomFilterFactory.createAddOnly(500); sent_to_bloom = filter; } filter.add( contact.getID()); } } protected static class diversification { private DHTPluginStorageManager manager; private HashWrapper key; private byte type; private long expiry; private int[] fixed_put_offsets; protected diversification( DHTPluginStorageManager _manager, HashWrapper _key, byte _type ) { manager = _manager; key = _key; type = _type; expiry = SystemTime.getCurrentTime() + DIV_EXPIRY_MIN + (long)(Math.random() * DIV_EXPIRY_RAND ); fixed_put_offsets = new int[DIV_FRAG_GET_SIZE]; int pos = 0; while( pos < DIV_FRAG_GET_SIZE ){ int i = (int)(Math.random()*DIV_WIDTH); boolean found = false; for (int j=0;j<pos;j++){ if( i == fixed_put_offsets[j] ){ found = true; break; } } if ( !found ){ fixed_put_offsets[pos++] = i; } } } protected diversification( DHTPluginStorageManager _manager, HashWrapper _key, byte _type, long _expiry, int[] _fixed_put_offsets ) { manager = _manager; key = _key; type = _type; expiry = _expiry; fixed_put_offsets = _fixed_put_offsets; } protected Map serialise() { Map map = new HashMap(); map.put( "key", key.getBytes()); map.put( "type", new Long(type)); map.put( "exp", new Long(expiry)); List offsets = new ArrayList(); for (int i=0;i<fixed_put_offsets.length;i++){ offsets.add( new Long( fixed_put_offsets[i])); } map.put( "fpo", offsets ); if ( Constants.isCVSVersion()){ manager.log.log( "SM: serialised div: " + DHTLog.getString2( key.getBytes()) + ", " + DHT.DT_STRINGS[type] + ", " + formatExpiry(expiry)); } return( map ); } protected static diversification deserialise( DHTPluginStorageManager _manager, Map _map ) { HashWrapper key = new HashWrapper((byte[])_map.get("key")); int type = ((Long)_map.get("type")).intValue(); long exp = ((Long)_map.get("exp")).longValue(); List offsets = (List)_map.get("fpo"); int[] fops = new int[offsets.size()]; for (int i=0;i<fops.length;i++){ fops[i] = ((Long)offsets.get(i)).intValue(); } _manager.log.log( "SM: deserialised div: " + DHTLog.getString2( key.getBytes()) + ", " + DHT.DT_STRINGS[type] + ", " + formatExpiry(exp)); return( new diversification( _manager, key, (byte)type, exp, fops )); } protected HashWrapper getKey() { return( key ); } protected long getExpiry() { return( expiry ); } protected List getKeys( boolean put, boolean exhaustive ) { List keys = new ArrayList(); if ( put ){ if ( type == DHT.DT_FREQUENCY ){ // put to all keys for (int i=0;i<DIV_WIDTH;i++){ keys.add( diversifyKey( key, i )); } if ( exhaustive ){ // include original key // System.out.println( "followDivs:put:freq adding original" ); keys.add( key ); } }else{ // put to a fixed subset. has to be fixed else over time we'll put to // all the fragmented locations and nullify the point of this. gets are // randomised to we don't loose out by fixing the puts for (int i=0;i<fixed_put_offsets.length;i++){ keys.add( diversifyKey( key, fixed_put_offsets[i])); } if ( exhaustive ){ // include original key // System.out.println( "followDivs:put:size adding original" ); keys.add( key ); } } }else{ // get always returns a randomised selection if ( type == DHT.DT_FREQUENCY ){ // diversification has lead to caching at all 'n' places keys.add( diversifyKey( key,(int)(Math.random()*DIV_WIDTH))); }else{ // diversification has fragmented across 'n' places // select 2 to search or all if exhaustive if ( exhaustive ){ for (int i=0;i<DIV_WIDTH;i++){ keys.add( diversifyKey( key, i )); } // System.out.println( "followDivs:get:size adding all" ); }else{ List randoms = new ArrayList(); while( randoms.size() < DIV_FRAG_GET_SIZE ){ Integer i = new Integer((int)(Math.random()*DIV_WIDTH)); if ( !randoms.contains(i)){ randoms.add( i ); } } for (int i=0;i<DIV_FRAG_GET_SIZE;i++){ keys.add( diversifyKey( key, ((Integer) randoms.get(i)).intValue())); } } } } return( keys ); } } public static HashWrapper diversifyKey( HashWrapper key_in, int offset ) { return( new HashWrapper( diversifyKey( key_in.getBytes(), offset ))); } public static byte[] diversifyKey( byte[] key_in, int offset ) { return(new SHA1Simple().calculateHash( diversifyKeyLocal( key_in, offset ))); } public static byte[] diversifyKeyLocal( byte[] key_in, int offset ) { byte[] key_out = new byte[key_in.length+1]; System.arraycopy( key_in, 0, key_out, 0, key_in.length ); key_out[key_in.length] = (byte)offset; return( key_out ); } protected static class storageKey implements DHTStorageKey { private DHTPluginStorageManager manager; private HashWrapper key; private byte type; private int size; private int entries; private long expiry; private long read_count_start; private short reads_per_min; private BloomFilter ip_bloom_filter; protected storageKey( DHTPluginStorageManager _manager, byte _type, HashWrapper _key ) { manager = _manager; type = _type; key = _key; expiry = SystemTime.getCurrentTime() + DIV_EXPIRY_MIN + (long)(Math.random() * DIV_EXPIRY_RAND ); } protected storageKey( DHTPluginStorageManager _manager, byte _type, HashWrapper _key, long _expiry ) { manager = _manager; type = _type; key = _key; expiry = _expiry; } protected Map serialise() { Map map = new HashMap(); map.put( "key", key.getBytes()); map.put( "type", new Long(type)); map.put( "exp", new Long(expiry)); manager.log.log( "SM: serialised sk: " + DHTLog.getString2( key.getBytes()) + ", " + DHT.DT_STRINGS[type] + ", " + formatExpiry(expiry) ); return( map ); } protected static storageKey deserialise( DHTPluginStorageManager _manager, Map map ) { HashWrapper key = new HashWrapper((byte[])map.get("key")); int type = ((Long)map.get("type")).intValue(); long exp = ((Long)map.get("exp")).longValue(); _manager.log.log( "SM: deserialised sk: " + DHTLog.getString2( key.getBytes()) + ", " + DHT.DT_STRINGS[type] + ", " + formatExpiry(exp)); return( new storageKey( _manager, (byte)type, key, exp )); } public void serialiseStats( DataOutputStream dos ) throws IOException { manager.serialiseStats( this, dos ); } protected HashWrapper getKey() { return( key ); } protected long getExpiry() { return( expiry ); } public byte getDiversificationType() { if ( type != DHT.DT_NONE ){ // trigger timeouts here if ( expiry < SystemTime.getCurrentTime()){ type = DHT.DT_NONE; manager.log.log( "SM: sk: " + DHTLog.getString2( getKey().getBytes()) + " expired" ); manager.writeDiversifications(); } } return( type ); } public int getReadsPerMinute() { return( reads_per_min ); } public int getSize() { return( size ); } public int getEntryCount() { return( entries ); } protected void read( DHTTransportContact contact ) { // System.out.println( "read: " + DHTLog.getString2( key.getBytes())); if ( type == DHT.DT_NONE ){ long now = SystemTime.getCurrentTime(); long diff = now - read_count_start; if ( diff > LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES*60*1000 ){ if ( ip_bloom_filter != null ){ int ip_entries = ip_bloom_filter.getEntryCount(); reads_per_min = (short)( ip_entries / LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES ); if ( reads_per_min == 0 && ip_entries > 0 ){ // show at least some activity! reads_per_min = 1; } if ( ip_entries > LOCAL_DIVERSIFICATION_READS_PER_MIN * LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES ){ type = DHT.DT_FREQUENCY; manager.log.log( "SM: sk freq created (" + ip_entries + "reads ) - " + DHTLog.getString2( key.getBytes())); manager.writeDiversifications(); } } read_count_start = now; ip_bloom_filter = null; // just null it and drop this read, doesn't matter // and means that we don't bother creating a filter for // infrequently accessed data }else{ if ( ip_bloom_filter == null ){ // we want to hold enough IPs to detect a hit rate of reads_per_min*min // with a reasonable accuracy (sized to 10/3 to save space - this gives // an average of 100 adds required to detect 90 unique) ip_bloom_filter = BloomFilterFactory.createAddOnly( ( LOCAL_DIVERSIFICATION_READS_PER_MIN * LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES *10 ) / 3 ); } byte[] address_bytes = contact.getAddress().getAddress().getAddress(); ip_bloom_filter.add( address_bytes ); } } } protected void valueChanged( int entries_diff, int size_diff ) { entries += entries_diff; size += size_diff; if ( entries < 0 ){ Debug.out( "entries negative" ); entries = 0; } if ( size < 0 ){ Debug.out( "size negative" ); size = 0; } if ( type == DHT.DT_NONE ){ if ( size > LOCAL_DIVERSIFICATION_SIZE_LIMIT ){ type = DHT.DT_SIZE; manager.log.log( "SM: sk size total created (size " + size + ") - " + DHTLog.getString2( key.getBytes())); manager.writeDiversifications(); }else if ( entries > LOCAL_DIVERSIFICATION_ENTRIES_LIMIT ){ type = DHT.DT_SIZE; manager.log.log( "SM: sk size entries created (" + entries + " entries) - " + DHTLog.getString2( key.getBytes())); manager.writeDiversifications(); } } // System.out.println( "value changed: entries = " + entries + "(" + entries_diff + "), size = " + size + "(" + size_diff + ")"); } } }

The table below shows all metrics for DHTPluginStorageManager.java.

MetricValueDescription
BLOCKS285.00Number of blocks
BLOCK_COMMENT28.00Number of block comment lines
COMMENTS91.00Comment lines
COMMENT_DENSITY 0.09Comment density
COMPARISONS169.00Number of comparison operators
CYCLOMATIC221.00Cyclomatic complexity
DECL_COMMENTS 5.00Comments in declarations
DOC_COMMENT 4.00Number of javadoc comment lines
ELOC1053.00Effective lines of code
EXEC_COMMENTS40.00Comments in executable code
EXITS135.00Procedure exits
FUNCTIONS86.00Number of function declarations
HALSTEAD_DIFFICULTY117.83Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY214.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 6.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA007621.00JAVA0076 Use of magic number
JAVA0077 2.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 2.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 5.00JAVA0116 Missing javadoc: field 'field'
JAVA011757.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA014413.00JAVA0144 Line exceeds maximum M characters
JAVA01456751.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA016611.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA017011.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 1.00JAVA0171 Unused local variable
JAVA0173 1.00JAVA0173 Unused method parameter
JAVA0174 1.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 1.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 3.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 2.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 2.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES2118.00Number of lines in the source file
LINE_COMMENT59.00Number of line comments
LOC1377.00Lines of code
LOGICAL_LINES584.00Number of statements
LOOPS23.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2501.00Number of operands
OPERATORS5241.00Number of operators
PARAMS100.00Number of formal parameter declarations
PROGRAM_LENGTH7742.00Halstead program length
PROGRAM_VOCAB720.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS114.00Number of return points from functions
SIZE42797.00Size of the file in bytes
UNIQUE_OPERANDS658.00Number of unique operands
UNIQUE_OPERATORS62.00Number of unique operators
WHITESPACE650.00Number of whitespace lines