DHTDBImpl.java

Index Score
com.aelitis.azureus.core.dht.db.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
LOOPSNumber of loops
LINE_COMMENTNumber of line comments
WHITESPACENumber of whitespace lines
JAVA0145JAVA0145 Tab character used in source file
EXEC_COMMENTSComments in executable code
LINESNumber of lines in the source file
LOCLines of code
ELOCEffective lines of code
BLOCKSNumber of blocks
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
SIZESize of the file in bytes
COMPARISONSNumber of comparison operators
OPERANDSNumber of operands
LOGICAL_LINESNumber of statements
CYCLOMATICCyclomatic complexity
EXITSProcedure exits
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
PARAMSNumber of formal parameter declarations
INTERFACE_COMPLEXITYInterface complexity
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
FUNCTIONSNumber of function declarations
RETURNSNumber of return points from functions
JAVA0144JAVA0144 Line exceeds maximum M characters
BLOCK_COMMENTNumber of block comment lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0264JAVA0264 Integer math in long context - check for overflow
COMMENTSComment lines
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0034JAVA0034 Missing braces in if statement
UNIQUE_OPERATORSNumber of unique operators
NEST_DEPTHMaximum nesting depth
JAVA0076JAVA0076 Use of magic number
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0266JAVA0266 Use of System.out
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0173JAVA0173 Unused method parameter
JAVA0013JAVA0013 Non-blank final field is not static
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
/* * Created on 28-Jan-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.core.dht.db.impl; import java.io.DataInputStream; import java.io.IOException; import java.util.*; import org.gudy.azureus2.core3.ipfilter.IpFilter; import org.gudy.azureus2.core3.ipfilter.IpFilterManagerFactory; import org.gudy.azureus2.core3.util.AEMonitor; import org.gudy.azureus2.core3.util.AESemaphore; import org.gudy.azureus2.core3.util.AEThread2; import org.gudy.azureus2.core3.util.HashWrapper; import org.gudy.azureus2.core3.util.SimpleTimer; import org.gudy.azureus2.core3.util.SystemTime; import org.gudy.azureus2.core3.util.TimerEvent; import org.gudy.azureus2.core3.util.TimerEventPerformer; 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.db.*; import com.aelitis.azureus.core.dht.impl.DHTLog; import com.aelitis.azureus.core.dht.router.DHTRouter; import com.aelitis.azureus.core.dht.control.DHTControl; import com.aelitis.azureus.core.dht.transport.DHTTransportContact; import com.aelitis.azureus.core.dht.transport.DHTTransportReplyHandlerAdapter; import com.aelitis.azureus.core.dht.transport.DHTTransportValue; import com.aelitis.azureus.core.dht.transport.udp.DHTTransportUDP; import com.aelitis.azureus.core.util.bloom.BloomFilter; import com.aelitis.azureus.core.util.bloom.BloomFilterFactory; /** * @author parg * */ public class DHTDBImpl implements DHTDB, DHTDBStats { private int original_republish_interval; // the grace period gives the originator time to republish their data as this could involve // some work on their behalf to find closest nodes etc. There's no real urgency here anyway private int ORIGINAL_REPUBLISH_INTERVAL_GRACE = 60*60*1000; private final int PRECIOUS_CHECK_INTERVAL = 2*60*60*1000; private int cache_republish_interval; private long MIN_CACHE_EXPIRY_CHECK_INTERVAL = 60000; private long last_cache_expiry_check; private static final long IP_BLOOM_FILTER_REBUILD_PERIOD = 15*60*1000; private static final int IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK = 1000; private BloomFilter ip_count_bloom_filter = BloomFilterFactory.createAddRemove8Bit( IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK ); private static final int VALUE_VERSION_CHUNK = 128; private int next_value_version; private int next_value_version_left; private Map stored_values = new HashMap(); private DHTControl control; private DHTStorageAdapter adapter; private DHTRouter router; private DHTTransportContact local_contact; private DHTLogger logger; private static final long MAX_TOTAL_SIZE = 4*1024*1024; private long total_size; private long total_values; private long total_keys; private boolean force_original_republish; private IpFilter ip_filter = IpFilterManagerFactory.getSingleton().getIPFilter(); private AEMonitor this_mon = new AEMonitor( "DHTDB" ); public DHTDBImpl( DHTStorageAdapter _adapter, int _original_republish_interval, int _cache_republish_interval, DHTLogger _logger ) { adapter = _adapter==null?null:new adapterFacade( _adapter ); original_republish_interval = _original_republish_interval; cache_republish_interval = _cache_republish_interval; logger = _logger; SimpleTimer.addPeriodicEvent( "DHTDB:precious", PRECIOUS_CHECK_INTERVAL/4, true, // absolute, we don't want effective time changes (computer suspend/resume) to shift these new TimerEventPerformer() { public void perform( TimerEvent event ) { checkPreciousStuff(); } }); SimpleTimer.addPeriodicEvent( "DHTDB:op", original_republish_interval, true, // absolute, we don't want effective time changes (computer suspend/resume) to shift these new TimerEventPerformer() { public void perform( TimerEvent event ) { logger.log( "Republish of original mappings starts" ); long start = SystemTime.getCurrentTime(); int stats = republishOriginalMappings(); long end = SystemTime.getCurrentTime(); logger.log( "Republish of original mappings completed in " + (end-start) + ": " + "values = " + stats ); } }); // random skew here so that cache refresh isn't very synchronised, as the optimisations // regarding non-republising benefit from this SimpleTimer.addPeriodicEvent( "DHTDB:cp", cache_republish_interval + 10000 - (int)(Math.random()*20000), true, // absolute, we don't want effective time changes (computer suspend/resume) to shift these new TimerEventPerformer() { public void perform( TimerEvent event ) { logger.log( "Republish of cached mappings starts" ); long start = SystemTime.getCurrentTime(); int[] stats = republishCachedMappings(); long end = SystemTime.getCurrentTime(); logger.log( "Republish of cached mappings completed in " + (end-start) + ": " + "values = " + stats[0] + ", keys = " + stats[1] + ", ops = " + stats[2]); if ( force_original_republish ){ force_original_republish = false; logger.log( "Force republish of original mappings due to router change starts" ); start = SystemTime.getCurrentTime(); int stats2 = republishOriginalMappings(); end = SystemTime.getCurrentTime(); logger.log( "Force republish of original mappings due to router change completed in " + (end-start) + ": " + "values = " + stats2 ); } } }); SimpleTimer.addPeriodicEvent( "DHTDB:bloom", IP_BLOOM_FILTER_REBUILD_PERIOD, new TimerEventPerformer() { public void perform( TimerEvent event ) { try{ this_mon.enter(); rebuildIPBloomFilter( false ); }finally{ this_mon.exit(); } } }); } public void setControl( DHTControl _control ) { control = _control; // trigger an "original value republish" if router has changed force_original_republish = router != null; router = control.getRouter(); local_contact = control.getTransport().getLocalContact(); // our ID has changed - amend the originator of all our values try{ this_mon.enter(); Iterator it = stored_values.values().iterator(); while( it.hasNext()){ DHTDBMapping mapping = (DHTDBMapping)it.next(); mapping.updateLocalContact( local_contact ); } }finally{ this_mon.exit(); } } public DHTDBValue store( HashWrapper key, byte[] value, byte flags ) { // local store try{ this_mon.enter(); // don't police max check for locally stored data // only that received DHTDBMapping mapping = (DHTDBMapping)stored_values.get( key ); if ( mapping == null ){ mapping = new DHTDBMapping( this, key, true ); stored_values.put( key, mapping ); } DHTDBValueImpl res = new DHTDBValueImpl( SystemTime.getCurrentTime(), value, getNextValueVersion(), local_contact, local_contact, true, flags ); mapping.add( res ); return( res ); }finally{ this_mon.exit(); } } public byte store( DHTTransportContact sender, HashWrapper key, DHTTransportValue[] values ) { // allow 4 bytes per value entry to deal with overhead (prolly should be more but we're really // trying to deal with 0-length value stores) if ( total_size + ( total_values*4 ) > MAX_TOTAL_SIZE ){ DHTLog.log( "Not storing " + DHTLog.getString2(key.getHash()) + " as maximum storage limit exceeded" ); return( DHT.DT_SIZE ); } // remote store for cache values // Make sure that we only accept values for storing that are reasonable. // Assumption is that the caller has made a reasonable effort to ascertain // the correct place to store a value. Part of this will in general have // needed them to query us for example. Therefore, limit values to those // that are at least as close to us List closest_contacts = control.getClosestKContactsList( key.getHash(), true ); boolean store_it = false; for (int i=0;i<closest_contacts.size();i++){ if ( router.isID(((DHTTransportContact)closest_contacts.get(i)).getID())){ store_it = true; break; } } if ( !store_it ){ DHTLog.log( "Not storing " + DHTLog.getString2(key.getHash()) + " as key too far away" ); return( DHT.DT_NONE ); } // next, for cache forwards (rather then values coming directly from // originators) we ensure that the contact sending the values to us is // close enough. If any values are coming indirect then we can safely assume // that they all are boolean cache_forward = false; for (int i=0;i<values.length;i++){ if (!Arrays.equals( sender.getID(), values[i].getOriginator().getID())){ cache_forward = true; break; } } if ( cache_forward ){ // get the closest contacts to me byte[] my_id = local_contact.getID(); closest_contacts = control.getClosestKContactsList( my_id, true ); DHTTransportContact furthest = (DHTTransportContact)closest_contacts.get( closest_contacts.size()-1); if ( control.computeAndCompareDistances( furthest.getID(), sender.getID(), my_id ) < 0 ){ store_it = false; } } if ( !store_it ){ DHTLog.log( "Not storing " + DHTLog.getString2(key.getHash()) + " as cache forward and sender too far away" ); return( DHT.DT_NONE ); } try{ this_mon.enter(); checkCacheExpiration( false ); DHTDBMapping mapping = (DHTDBMapping)stored_values.get( key ); if ( mapping == null ){ mapping = new DHTDBMapping( this, key, false ); stored_values.put( key, mapping ); } boolean contact_checked = false; boolean contact_ok = false; // we carry on an update as its ok to replace existing entries // even if diversified for (int i=0;i<values.length;i++){ // last check, verify that the contact is who they say they are, only for non-forwards // as cache forwards are only accepted if they are "close enough" and we can't // rely on their identify due to the way that cache republish works (it doesn't // guarantee a "lookup_node" prior to "store". DHTTransportValue value = values[i]; boolean ok_to_store = false; boolean direct =Arrays.equals( sender.getID(), value.getOriginator().getID()); if ( !contact_checked ){ contact_ok = control.verifyContact( sender, direct ); if ( !contact_ok ){ logger.log( "DB: verification of contact '" + sender.getName() + "' failed for store operation" ); } contact_checked = true; } ok_to_store = contact_ok; if ( ok_to_store ){ DHTDBValueImpl mapping_value = new DHTDBValueImpl( sender, value, false ); mapping.add( mapping_value ); } } return( mapping.getDiversificationType()); }finally{ this_mon.exit(); } } public DHTDBLookupResult get( DHTTransportContact reader, HashWrapper key, int max_values, // 0 -> all byte flags, boolean external_request ) { try{ this_mon.enter(); checkCacheExpiration( false ); final DHTDBMapping mapping = (DHTDBMapping)stored_values.get(key); if ( mapping == null ){ return( null ); } if ( external_request ){ mapping.addHit(); } final DHTDBValue[] values = mapping.get( reader, max_values, flags ); return( new DHTDBLookupResult() { public DHTDBValue[] getValues() { return( values ); } public byte getDiversificationType() { return( mapping.getDiversificationType()); } }); }finally{ this_mon.exit(); } } public DHTDBValue get( HashWrapper key ) { // local remove try{ this_mon.enter(); DHTDBMapping mapping = (DHTDBMapping)stored_values.get( key ); if ( mapping != null ){ return( mapping.get( local_contact )); } return( null ); }finally{ this_mon.exit(); } } public DHTDBValue remove( DHTTransportContact originator, HashWrapper key ) { // local remove try{ this_mon.enter(); DHTDBMapping mapping = (DHTDBMapping)stored_values.get( key ); if ( mapping != null ){ DHTDBValueImpl res = mapping.remove( originator ); if ( res != null ){ return( res.getValueForDeletion( getNextValueVersion())); } return( null ); } return( null ); }finally{ this_mon.exit(); } } public DHTStorageBlock keyBlockRequest( DHTTransportContact direct_sender, byte[] request, byte[] signature ) { if ( adapter == null ){ return( null ); } // for block requests sent to us (as opposed to being returned from other operations) // make sure that the key is close enough to us if ( direct_sender != null ){ byte[] key = adapter.getKeyForKeyBlock( request ); List closest_contacts = control.getClosestKContactsList( key, true ); boolean process_it = false; for (int i=0;i<closest_contacts.size();i++){ if ( router.isID(((DHTTransportContact)closest_contacts.get(i)).getID())){ process_it = true; break; } } if ( !process_it ){ DHTLog.log( "Not processing key block for " + DHTLog.getString2(key) + " as key too far away" ); return( null ); } if ( ! control.verifyContact( direct_sender, true )){ DHTLog.log( "Not processing key block for " + DHTLog.getString2(key) + " as verification failed" ); return( null ); } } return( adapter.keyBlockRequest( direct_sender, request, signature )); } public DHTStorageBlock getKeyBlockDetails( byte[] key ) { if ( adapter == null ){ return( null ); } return( adapter.getKeyBlockDetails( key )); } public boolean isKeyBlocked( byte[] key ) { return( getKeyBlockDetails(key) != null ); } public DHTStorageBlock[] getDirectKeyBlocks() { if ( adapter == null ){ return( new DHTStorageBlock[0] ); } return( adapter.getDirectKeyBlocks()); } public boolean isEmpty() { return( total_keys == 0 ); } public int getKeyCount() { return( (int)total_keys ); } public int[] getValueDetails() { try{ this_mon.enter(); int[] res = new int[6]; Iterator it = stored_values.values().iterator(); while( it.hasNext()){ DHTDBMapping mapping = (DHTDBMapping)it.next(); res[DHTDBStats.VD_VALUE_COUNT] += mapping.getValueCount(); res[DHTDBStats.VD_LOCAL_SIZE] += mapping.getLocalSize(); res[DHTDBStats.VD_DIRECT_SIZE] += mapping.getDirectSize(); res[DHTDBStats.VD_INDIRECT_SIZE] += mapping.getIndirectSize(); int dt = mapping.getDiversificationType(); if ( dt == DHT.DT_FREQUENCY ){ res[DHTDBStats.VD_DIV_FREQ]++; }else if ( dt == DHT.DT_SIZE ){ res[DHTDBStats.VD_DIV_SIZE]++; } } return( res ); }finally{ this_mon.exit(); } } public int getKeyBlockCount() { if ( adapter == null ){ return( 0 ); } return( adapter.getDirectKeyBlocks().length ); } public Iterator getKeys() { try{ this_mon.enter(); return( new ArrayList( stored_values.keySet()).iterator()); }finally{ this_mon.exit(); } } protected int republishOriginalMappings() { int values_published = 0; Map republish = new HashMap(); try{ this_mon.enter(); Iterator it = stored_values.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper key = (HashWrapper)entry.getKey(); DHTDBMapping mapping = (DHTDBMapping)entry.getValue(); Iterator it2 = mapping.getValues(); List values = new ArrayList(); while( it2.hasNext()){ DHTDBValueImpl value = (DHTDBValueImpl)it2.next(); if ( value != null && value.isLocal()){ // we're republising the data, reset the creation time value.setCreationTime(); values.add( value ); } } if ( values.size() > 0 ){ republish.put( key, values ); } } }finally{ this_mon.exit(); } Iterator it = republish.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper key = (HashWrapper)entry.getKey(); List values = (List)entry.getValue(); // no point in worry about multi-value puts here as it is extremely unlikely that // > 1 value will locally stored, or > 1 value will go to the same contact for (int i=0;i<values.size();i++){ values_published++; control.putEncodedKey( key.getHash(), "Republish", (DHTDBValueImpl)values.get(i), 0, true ); } } return( values_published ); } protected int[] republishCachedMappings() { // first refresh any leaves that have not performed at least one lookup in the // last period router.refreshIdleLeaves( cache_republish_interval ); final Map republish = new HashMap(); long now = System.currentTimeMillis(); try{ this_mon.enter(); checkCacheExpiration( true ); Iterator it = stored_values.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper key = (HashWrapper)entry.getKey(); DHTDBMapping mapping = (DHTDBMapping)entry.getValue(); // assume that if we've diversified then the other k-1 locations are under similar // stress and will have done likewise - no point in republishing cache values to them // New nodes joining will have had stuff forwarded to them regardless of diversification // status if ( mapping.getDiversificationType() != DHT.DT_NONE ){ continue; } Iterator it2 = mapping.getValues(); List values = new ArrayList(); while( it2.hasNext()){ DHTDBValueImpl value = (DHTDBValueImpl)it2.next(); if ( !value.isLocal()){ // if this value was stored < period ago then we assume that it was // also stored to the other k-1 locations at the same time and therefore // we don't need to re-store it if ( now < value.getStoreTime()){ // deal with clock changes value.setStoreTime( now ); }else if ( now - value.getStoreTime() <= cache_republish_interval ){ // System.out.println( "skipping store" ); }else{ values.add( value ); } } } if ( values.size() > 0 ){ republish.put( key, values ); } } }finally{ this_mon.exit(); } final int[] values_published = {0}; final int[] keys_published = {0}; final int[] republish_ops = {0}; final HashSet anti_spoof_done = new HashSet(); if ( republish.size() > 0 ){ // System.out.println( "cache replublish" ); // The approach is to refresh all leaves in the smallest subtree, thus populating the tree with // sufficient information to directly know which nodes to republish the values // to. // However, I'm going to rely on the "refresh idle leaves" logic above // (that's required to keep the DHT alive in general) to ensure that all // k-buckets are reasonably up-to-date Iterator it = republish.entrySet().iterator(); List stop_caching = new ArrayList(); // build a map of contact -> list of keys to republish Map contact_map = new HashMap(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper key = (HashWrapper)entry.getKey(); byte[] lookup_id = key.getHash(); // just use the closest contacts - if some have failed then they'll // get flushed out by this operation. Grabbing just the live ones // is a bad idea as failures may rack up against the live ones due // to network problems and kill them, leaving the dead ones! List contacts = control.getClosestKContactsList( lookup_id, false ); // if we are no longer one of the K closest contacts then we shouldn't // cache the value boolean keep_caching = false; for (int j=0;j<contacts.size();j++){ if ( router.isID(((DHTTransportContact)contacts.get(j)).getID())){ keep_caching = true; break; } } if ( !keep_caching ){ DHTLog.log( "Dropping cache entry for " + DHTLog.getString( lookup_id ) + " as now too far away" ); stop_caching.add( key ); // we carry on and do one last publish } for (int j=0;j<contacts.size();j++){ DHTTransportContact contact = (DHTTransportContact)contacts.get(j); if ( router.isID( contact.getID())){ continue; // ignore ourselves } Object[] data = (Object[])contact_map.get( new HashWrapper(contact.getID())); if ( data == null ){ data = new Object[]{ contact, new ArrayList()}; contact_map.put( new HashWrapper(contact.getID()), data ); } ((List)data[1]).add( key ); } } it = contact_map.values().iterator(); while( it.hasNext()){ final Object[] data = (Object[])it.next(); final DHTTransportContact contact = (DHTTransportContact)data[0]; // move to anti-spoof on cache forwards - gotta do a find-node first // to get the random id final AESemaphore sem = new AESemaphore( "DHTDB:cacheForward" ); contact.sendFindNode( new DHTTransportReplyHandlerAdapter() { public void findNodeReply( DHTTransportContact _contact, DHTTransportContact[] _contacts ) { anti_spoof_done.add( _contact ); try{ // System.out.println( "cacheForward: pre-store findNode OK" ); List keys = (List)data[1]; byte[][] store_keys = new byte[keys.size()][]; DHTTransportValue[][] store_values = new DHTTransportValue[store_keys.length][]; keys_published[0] += store_keys.length; for (int i=0;i<store_keys.length;i++){ HashWrapper wrapper = (HashWrapper)keys.get(i); store_keys[i] = wrapper.getHash(); List values = (List)republish.get( wrapper ); store_values[i] = new DHTTransportValue[values.size()]; values_published[0] += store_values[i].length; for (int j=0;j<values.size();j++){ DHTDBValueImpl value = (DHTDBValueImpl)values.get(j); // we reduce the cache distance by 1 here as it is incremented by the // recipients store_values[i][j] = value.getValueForRelay(local_contact); } } List contacts = new ArrayList(); contacts.add( contact ); republish_ops[0]++; control.putDirectEncodedKeys( store_keys, "Republish cache", store_values, contacts ); }finally{ sem.release(); } } public void failed( DHTTransportContact _contact, Throwable _error ) { try{ // System.out.println( "cacheForward: pre-store findNode Failed" ); DHTLog.log( "cacheForward: pre-store findNode failed " + DHTLog.getString( _contact ) + " -> failed: " + _error.getMessage()); router.contactDead( _contact.getID(), false); }finally{ sem.release(); } } }, contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ANTI_SPOOF2?new byte[0]:new byte[20] ); sem.reserve(); } try{ this_mon.enter(); for (int i=0;i<stop_caching.size();i++){ DHTDBMapping mapping = (DHTDBMapping)stored_values.remove( stop_caching.get(i)); if ( mapping != null ){ mapping.destroy(); } } }finally{ this_mon.exit(); } } DHTStorageBlock[] direct_key_blocks = getDirectKeyBlocks(); if ( direct_key_blocks.length > 0 ){ for (int i=0;i<direct_key_blocks.length;i++){ final DHTStorageBlock key_block = direct_key_blocks[i]; List contacts = control.getClosestKContactsList( key_block.getKey(), false ); boolean forward_it = false; // ensure that the key is close enough to us for (int j=0;j<contacts.size();j++){ final DHTTransportContact contact = (DHTTransportContact)contacts.get(j); if ( router.isID( contact.getID())){ forward_it = true; break; } } for (int j=0; forward_it && j<contacts.size();j++){ final DHTTransportContact contact = (DHTTransportContact)contacts.get(j); if ( key_block.hasBeenSentTo( contact )){ continue; } if ( contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_BLOCK_KEYS ){ final Runnable task = new Runnable() { public void run() { contact.sendKeyBlock( new DHTTransportReplyHandlerAdapter() { public void keyBlockReply( DHTTransportContact _contact ) { DHTLog.log( "key block forward ok " + DHTLog.getString( _contact )); key_block.sentTo( _contact ); } public void failed( DHTTransportContact _contact, Throwable _error ) { DHTLog.log( "key block forward failed " + DHTLog.getString( _contact ) + " -> failed: " + _error.getMessage()); } }, key_block.getRequest(), key_block.getCertificate()); } }; if ( anti_spoof_done.contains( contact )){ task.run(); }else{ contact.sendFindNode( new DHTTransportReplyHandlerAdapter() { public void findNodeReply( DHTTransportContact contact, DHTTransportContact[] contacts ) { task.run(); } public void failed( DHTTransportContact _contact, Throwable _error ) { // System.out.println( "nodeAdded: pre-store findNode Failed" ); DHTLog.log( "pre-kb findNode failed " + DHTLog.getString( _contact ) + " -> failed: " + _error.getMessage()); router.contactDead( _contact.getID(), false); } }, contact.getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ANTI_SPOOF2?new byte[0]:new byte[20] ); } } } } } return( new int[]{ values_published[0], keys_published[0], republish_ops[0] }); } protected void checkCacheExpiration( boolean force ) { long now = SystemTime.getCurrentTime(); if ( !force ){ long elapsed = now - last_cache_expiry_check; if ( elapsed > 0 && elapsed < MIN_CACHE_EXPIRY_CHECK_INTERVAL ){ return; } } try{ this_mon.enter(); last_cache_expiry_check = now; Iterator it = stored_values.values().iterator(); while( it.hasNext()){ DHTDBMapping mapping = (DHTDBMapping)it.next(); if ( mapping.getValueCount() == 0 ){ mapping.destroy(); it.remove(); }else{ Iterator it2 = mapping.getValues(); while( it2.hasNext()){ DHTDBValueImpl value = (DHTDBValueImpl)it2.next(); if ( !value.isLocal()){ // distance 1 = initial store location. We use the initial creation date // when deciding whether or not to remove this, plus a bit, as the // original publisher is supposed to republish these if ( now - value.getCreationTime() > original_republish_interval + ORIGINAL_REPUBLISH_INTERVAL_GRACE ){ DHTLog.log( "removing cache entry (" + value.getString() + ")" ); it2.remove(); } } } } } }finally{ this_mon.exit(); } } protected void checkPreciousStuff() { long now = SystemTime.getCurrentTime(); Map republish = new HashMap(); try{ this_mon.enter(); Iterator it = stored_values.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper key = (HashWrapper)entry.getKey(); DHTDBMapping mapping = (DHTDBMapping)entry.getValue(); Iterator it2 = mapping.getValues(); List values = new ArrayList(); while( it2.hasNext()){ DHTDBValueImpl value = (DHTDBValueImpl)it2.next(); if ( value.isLocal()){ if (( value.getFlags() | DHT.FLAG_PRECIOUS ) != 0 ){ if ( now - value.getCreationTime() > PRECIOUS_CHECK_INTERVAL ){ value.setCreationTime(); values.add( value ); } } } } if ( values.size() > 0 ){ republish.put( key, values ); } } }finally{ this_mon.exit(); } Iterator it = republish.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper key = (HashWrapper)entry.getKey(); List values = (List)entry.getValue(); // no point in worry about multi-value puts here as it is extremely unlikely that // > 1 value will locally stored, or > 1 value will go to the same contact for (int i=0;i<values.size();i++){ control.putEncodedKey( key.getHash(), "Precious republish", (DHTDBValueImpl)values.get(i), 0, true ); } } } protected DHTTransportContact getLocalContact() { return( local_contact ); } protected DHTStorageAdapter getAdapter() { return( adapter ); } protected void log( String str ) { logger.log( str ); } public DHTDBStats getStats() { return( this ); } public void print() { Map count = new TreeMap(); try{ this_mon.enter(); logger.log( "Stored keys = " + stored_values.size() + ", values = " + getValueDetails()[DHTDBStats.VD_VALUE_COUNT]); Iterator it = stored_values.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper value_key = (HashWrapper)entry.getKey(); DHTDBMapping mapping = (DHTDBMapping)entry.getValue(); DHTDBValue[] values = mapping.get(null,0,(byte)0); for (int i=0;i<values.length;i++){ DHTDBValue value = values[i]; Integer key = new Integer( value.isLocal()?0:1); Object[] data = (Object[])count.get( key ); if ( data == null ){ data = new Object[2]; data[0] = new Integer(1); data[1] = ""; count.put( key, data ); }else{ data[0] = new Integer(((Integer)data[0]).intValue() + 1 ); } String s = (String)data[1]; s += (s.length()==0?"":", ") + "key=" + DHTLog.getString2(value_key.getHash()) + ",val=" + value.getString(); data[1] = s; } } it = count.keySet().iterator(); while( it.hasNext()){ Integer k = (Integer)it.next(); Object[] data = (Object[])count.get(k); logger.log( " " + k + " -> " + data[0] + " entries" ); // ": " + data[1]); } it = stored_values.entrySet().iterator(); String str = " "; int str_entries = 0; while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); HashWrapper value_key = (HashWrapper)entry.getKey(); DHTDBMapping mapping = (DHTDBMapping)entry.getValue(); if ( str_entries == 16 ){ logger.log( str ); str = " "; str_entries = 0; } str_entries++; str += (str_entries==1?"":", ") + DHTLog.getString2(value_key.getHash()) + " -> " + mapping.getValueCount() + "/" + mapping.getHits()+"["+mapping.getLocalSize()+","+mapping.getDirectSize()+","+mapping.getIndirectSize() + "]"; } if ( str_entries > 0 ){ logger.log( str ); } }finally{ this_mon.exit(); } } protected void banContact( final DHTTransportContact contact, final String reason ) { new AEThread2( "DHTDBImpl:delayed flood delete", true ) { public void run() { // delete their data on a separate thread so as not to // interfere with the current action try{ this_mon.enter(); Iterator it = stored_values.values().iterator(); while( it.hasNext()){ DHTDBMapping mapping = (DHTDBMapping)it.next(); Iterator it2 = mapping.getDirectValues(); while( it2.hasNext()){ DHTDBValueImpl val = (DHTDBValueImpl)it2.next(); if ( !val.isLocal()){ if ( Arrays.equals( val.getOriginator().getID(), contact.getID())){ it.remove(); } } } } }finally{ this_mon.exit(); } } }.start(); logger.log( "Banning " + contact.getString() + " due to store flooding (" + reason + ")" ); ip_filter.ban( contact.getAddress().getAddress().getHostAddress(), "DHT: Sender stored excessive entries at this node (" + reason + ")", false ); } protected void incrementValueAdds( DHTTransportContact contact ) { // assume a node stores 1000 values at 20 (K) locations -> 20,000 values // assume a DHT size of 100,000 nodes // that is, on average, 1 value per 5 nodes // assume NAT of up to 30 ports per address // this gives 6 values per address // with a factor of 10 error this is still only 60 per address int hit_count = ip_count_bloom_filter.add( contact.getAddress().getAddress().getAddress()); if ( DHTLog.GLOBAL_BLOOM_TRACE ){ System.out.println( "direct add from " + contact.getAddress() + ", hit count = " + hit_count ); } // allow up to 10% bloom filter utilisation if ( ip_count_bloom_filter.getSize() / ip_count_bloom_filter.getEntryCount() < 10 ){ rebuildIPBloomFilter( true ); } if ( hit_count > 64 ){ // obviously being spammed, drop all data originated by this IP and ban it banContact( contact, "global flood" ); } } protected void decrementValueAdds( DHTTransportContact contact ) { int hit_count = ip_count_bloom_filter.remove( contact.getAddress().getAddress().getAddress()); if ( DHTLog.GLOBAL_BLOOM_TRACE ){ System.out.println( "direct remove from " + contact.getAddress() + ", hit count = " + hit_count ); } } protected void rebuildIPBloomFilter( boolean increase_size ) { BloomFilter new_filter; if ( increase_size ){ new_filter = BloomFilterFactory.createAddRemove8Bit( ip_count_bloom_filter.getSize() + IP_COUNT_BLOOM_SIZE_INCREASE_CHUNK ); }else{ new_filter = BloomFilterFactory.createAddRemove8Bit( ip_count_bloom_filter.getSize()); } try{ //Map sender_map = new HashMap(); //List senders = new ArrayList(); Iterator it = stored_values.values().iterator(); int max_hits = 0; while( it.hasNext()){ DHTDBMapping mapping = (DHTDBMapping)it.next(); mapping.rebuildIPBloomFilter( false ); Iterator it2 = mapping.getDirectValues(); while( it2.hasNext()){ DHTDBValueImpl val = (DHTDBValueImpl)it2.next(); if ( !val.isLocal()){ // logger.log( " adding " + val.getOriginator().getAddress()); int hits = new_filter.add( val.getOriginator().getAddress().getAddress().getAddress()); if ( hits > max_hits ){ max_hits = hits; } } } // survey our neighbourhood /* * its is non-trivial to do anything about nodes that get "close" to us and then * spam us with crap. Ultimately, of course, to take a key out you "just" create * the 20 closest nodes to the key and then run nodes that swallow all registrations * and return nothing. * Protecting against one or two such nodes that flood crap requires crap to be * identified. Tracing shows a large disparity between number of values registered * per neighbour (factors of 100), so an approach based on number of registrations * is non-trivial (assuming future scaling of the DHT, what do we consider crap?) * A further approach would be to query the claimed originators of values (obviously * a low bandwith approach, e.g. query 3 values from the contact with highest number * of forwarded values). This requires originators to support long term knowledge of * what they've published (we don't want to blacklist a neighbour because an originator * has deleted a value/been restarted). We also then have to consider how to deal with * non-responses to queries (assuming an affirmative Yes -> value has been forwarded * correnctly, No -> probably crap). We can't treat non-replies as No. Thus a bad * neighbour only has to forward crap with originators that aren't AZ nodes (very * easy to do!) to break this aproach. * * it2 = mapping.getIndirectValues(); while( it2.hasNext()){ DHTDBValueImpl val = (DHTDBValueImpl)it2.next(); DHTTransportContact sender = val.getSender(); HashWrapper hw = new HashWrapper( sender.getID()); Integer sender_count = (Integer)sender_map.get( hw ); if ( sender_count == null ){ sender_count = new Integer(1); senders.add( sender ); }else{ sender_count = new Integer( sender_count.intValue() + 1 ); } sender_map.put( hw, sender_count ); } */ } logger.log( "Rebuilt global IP bloom filter, size = " + new_filter.getSize() + ", entries =" + new_filter.getEntryCount()+", max hits = " + max_hits ); /* senders = control.sortContactsByDistance( senders ); for (int i=0;i<senders.size();i++){ DHTTransportContact sender = (DHTTransportContact)senders.get(i); System.out.println( i + ":" + sender.getString() + " -> " + sender_map.get(new HashWrapper(sender.getID()))); } */ }finally{ ip_count_bloom_filter = new_filter; } } protected void reportSizes( String op ) { /* if ( !this_mon.isHeld()){ Debug.out( "Monitor not held" ); } int actual_keys = stored_values.size(); int actual_values = 0; int actual_size = 0; Iterator it = stored_values.values().iterator(); while( it.hasNext()){ DHTDBMapping mapping = (DHTDBMapping)it.next(); int reported_size = mapping.getLocalSize() + mapping.getDirectSize() + mapping.getIndirectSize(); actual_values += mapping.getValueCount(); Iterator it2 = mapping.getValues(); int sz = 0; while( it2.hasNext()){ DHTDBValue val = (DHTDBValue)it2.next(); sz += val.getValue().length; } if ( sz != reported_size ){ Debug.out( "Reported mapping size != actual: " + reported_size + "/" + sz ); } actual_size += sz; } if ( actual_keys != total_keys ){ Debug.out( "Actual keys != total: " + actual_keys + "/" + total_keys ); } if ( actual_values != total_values ){ Debug.out( "Actual values != total: " + actual_values + "/" + total_values ); } if ( actual_size != total_size ){ Debug.out( "Actual size != total: " + actual_size + "/" + total_size ); } System.out.println( "DHTDB: " + op + " - keys=" + total_keys + ", values=" + total_values + ", size=" + total_size ); */ } protected int getNextValueVersion() { try{ this_mon.enter(); if ( next_value_version_left == 0 ){ next_value_version_left = VALUE_VERSION_CHUNK; if ( adapter == null ){ // no persistent manager, just carry on incrementing }else{ next_value_version = adapter.getNextValueVersions( VALUE_VERSION_CHUNK ); } //System.out.println( "next chunk:" + next_value_version ); } next_value_version_left--; int res = next_value_version++; //System.out.println( "next value version = " + res ); return( res ); }finally{ this_mon.exit(); } } protected class adapterFacade implements DHTStorageAdapter { private DHTStorageAdapter delegate; protected adapterFacade( DHTStorageAdapter _delegate ) { delegate = _delegate; } public DHTStorageKey keyCreated( HashWrapper key, boolean local ) { // report *before* incrementing as this occurs before the key is locally added reportSizes( "keyAdded" ); total_keys++; return( delegate.keyCreated( key, local )); } public void keyDeleted( DHTStorageKey adapter_key ) { total_keys--; reportSizes( "keyDeleted" ); delegate.keyDeleted( adapter_key ); } public void keyRead( DHTStorageKey adapter_key, DHTTransportContact contact ) { reportSizes( "keyRead" ); delegate.keyRead( adapter_key, contact ); } public DHTStorageKeyStats deserialiseStats( DataInputStream is ) throws IOException { return( delegate.deserialiseStats( is )); } public void valueAdded( DHTStorageKey key, DHTTransportValue value ) { total_values++; total_size += value.getValue().length; reportSizes( "valueAdded"); if ( !value.isLocal() ){ DHTDBValueImpl val = (DHTDBValueImpl)value; boolean direct = Arrays.equals( value.getOriginator().getID(), val.getSender().getID()); if ( direct ){ incrementValueAdds( value.getOriginator()); } } delegate.valueAdded( key, value ); } public void valueUpdated( DHTStorageKey key, DHTTransportValue old_value, DHTTransportValue new_value ) { total_size += (new_value.getValue().length - old_value.getValue().length ); reportSizes("valueUpdated"); delegate.valueUpdated( key, old_value, new_value ); } public void valueDeleted( DHTStorageKey key, DHTTransportValue value ) { total_values--; total_size -= value.getValue().length; reportSizes("valueDeleted"); if ( !value.isLocal() ){ DHTDBValueImpl val = (DHTDBValueImpl)value; boolean direct = Arrays.equals( value.getOriginator().getID(), val.getSender().getID()); if ( direct ){ decrementValueAdds( value.getOriginator()); } } delegate.valueDeleted( key, value ); } // local lookup/put operations public boolean isDiversified( byte[] key ) { return( delegate.isDiversified( key )); } public byte[][] getExistingDiversification( byte[] key, boolean put_operation, boolean exhaustive_get ) { return( delegate.getExistingDiversification( key, put_operation, exhaustive_get )); } public byte[][] createNewDiversification( DHTTransportContact cause, byte[] key, boolean put_operation, byte diversification_type, boolean exhaustive_get ) { return( delegate.createNewDiversification( cause, key, put_operation, diversification_type, exhaustive_get )); } public int getNextValueVersions( int num ) { return( delegate.getNextValueVersions(num)); } public DHTStorageBlock keyBlockRequest( DHTTransportContact direct_sender, byte[] request, byte[] signature ) { return( delegate.keyBlockRequest( direct_sender, request, signature )); } public DHTStorageBlock getKeyBlockDetails( byte[] key ) { return( delegate.getKeyBlockDetails(key)); } public DHTStorageBlock[] getDirectKeyBlocks() { return( delegate.getDirectKeyBlocks()); } public byte[] getKeyForKeyBlock( byte[] request ) { return( delegate.getKeyForKeyBlock( request )); } public void setStorageForKey( String key, byte[] data ) { delegate.setStorageForKey( key, data ); } public byte[] getStorageForKey( String key ) { return( delegate.getStorageForKey(key)); } } }

The table below shows all metrics for DHTDBImpl.java.

MetricValueDescription
BLOCKS218.00Number of blocks
BLOCK_COMMENT133.00Number of block comment lines
COMMENTS230.00Comment lines
COMMENT_DENSITY 0.26Comment density
COMPARISONS143.00Number of comparison operators
CYCLOMATIC181.00Cyclomatic complexity
DECL_COMMENTS 4.00Comments in declarations
DOC_COMMENT 4.00Number of javadoc comment lines
ELOC868.00Effective lines of code
EXEC_COMMENTS51.00Comments in executable code
EXITS137.00Procedure exits
FUNCTIONS63.00Number of function declarations
HALSTEAD_DIFFICULTY105.32Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY157.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 1.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 1.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'
JAVA004911.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
JAVA0076 5.00JAVA0076 Use of magic number
JAVA0077 0.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 1.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 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011715.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
JAVA0144 8.00JAVA0144 Line exceeds maximum M characters
JAVA01457578.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
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 1.00JAVA0173 Unused method parameter
JAVA0174 0.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
JAVA025413.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 1.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 5.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 2.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 4.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
LINES1953.00Number of lines in the source file
LINE_COMMENT93.00Number of line comments
LOC1135.00Lines of code
LOGICAL_LINES480.00Number of statements
LOOPS36.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2259.00Number of operands
OPERATORS4593.00Number of operators
PARAMS79.00Number of formal parameter declarations
PROGRAM_LENGTH6852.00Halstead program length
PROGRAM_VOCAB680.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS78.00Number of return points from functions
SIZE46306.00Size of the file in bytes
UNIQUE_OPERANDS622.00Number of unique operands
UNIQUE_OPERATORS58.00Number of unique operators
WHITESPACE588.00Number of whitespace lines