public void insertOrRefresh(final KBucketEntry newEntry){
  if (newEntry == null)   return;
  List<KBucketEntry> entriesRef=entries;
  for (  KBucketEntry existing : entriesRef) {
    if (existing.equals(newEntry)) {
      existing.mergeInTimestamps(newEntry);
      return;
    }
    if (existing.matchIPorID(newEntry)) {
      DHT.logInfo("new node " + newEntry + " claims same ID or IP as "+ existing+ ", might be impersonation attack or IP change. ignoring until old entry times out");
      return;
    }
  }
  if (newEntry.verifiedReachable()) {
    if (entriesRef.size() < DHTConstants.MAX_ENTRIES_PER_BUCKET) {
      modifyMainBucket(null,newEntry);
      return;
    }
    if (replaceBadEntry(newEntry))     return;
    KBucketEntry youngest=entriesRef.get(entriesRef.size() - 1);
    if (youngest.getCreationTime() > newEntry.getCreationTime() || newEntry.getRTT() * 2.5 < youngest.getRTT()) {
      modifyMainBucket(youngest,newEntry);
      insertInReplacementBucket(youngest);
      return;
    }
  }
  insertInReplacementBucket(newEntry);
}

public void insertOrRefresh ( final KBucketEntry newEntry ) { if ( newEntry == null ) return ; List < KBucketEntry > entriesRef = entries ; for ( KBucketEntry existing : entriesRef ) { if ( existing . equals ( newEntry ) ) { existing . mergeInTimestamps ( newEntry ) ; return ; } if ( existing . matchIPorID ( newEntry ) ) { DHT . logInfo ( "new node " + newEntry + " claims same ID or IP as " + existing + ", might be impersonation attack or IP change. ignoring until old entry times out" ) ; return ; } } if ( newEntry . verifiedReachable ( ) ) { if ( entriesRef . size ( ) < DHTConstants . MAX_ENTRIES_PER_BUCKET ) { modifyMainBucket ( null , newEntry ) ; return ; } if ( replaceBadEntry ( newEntry ) ) return ; KBucketEntry youngest = entriesRef . get ( entriesRef . size ( ) - 1 ) ; if ( youngest . getCreationTime ( ) > newEntry . getCreationTime ( ) || newEntry . getRTT ( ) * 2.5 < youngest . getRTT ( ) ) { modifyMainBucket ( youngest , newEntry ) ; insertInReplacementBucket ( youngest ) ; return ; } } insertInReplacementBucket ( newEntry ) ; }
notify bucket of new incoming packet from a node , perform update or insert existing nodes where appropriate
