cleanup the shitlist code

logging
This commit is contained in:
jrandom
2004-08-15 09:04:56 +00:00
committed by zzz
parent 190a2147cc
commit a295d0ad1e

View File

@ -124,7 +124,11 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
boolean isShitlisted(Hash key) { boolean isShitlisted(Hash key) {
synchronized (_badKeys) { synchronized (_badKeys) {
locked_cleanupShitlist(); locked_cleanupShitlist();
return !_badKeys.contains(key); boolean isShitlisted = _badKeys.contains(key);
if (!isShitlisted) return false;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Key " + key.toBase64() + " is shitlisted");
return true;
} }
} }
/** /**
@ -136,11 +140,16 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
void shitlist(Hash key) { void shitlist(Hash key) {
synchronized (_badKeys) { synchronized (_badKeys) {
locked_cleanupShitlist(); locked_cleanupShitlist();
_badKeys.add(key); boolean wasNew = _badKeys.add(key);
if (wasNew) {
long when = _context.clock().now(); long when = _context.clock().now();
while (_badKeyDates.containsKey(new Long(when))) while (_badKeyDates.containsKey(new Long(when)))
when++; when++;
_badKeyDates.put(new Long(when), key); _badKeyDates.put(new Long(when), key);
_log.info("Shitlist " + key.toBase64() + " - new shitlist");
} else {
_log.info("Shitlist " + key.toBase64() + " - already shitlisted");
}
} }
} }
private void locked_cleanupShitlist() { private void locked_cleanupShitlist() {
@ -166,12 +175,11 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
} }
} }
if (_badKeys.size() > 0) {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Cleaning up shitlist: " + _badKeys.size() + " remain after removing " _log.debug("Cleaning up shitlist: " + _badKeys.size() + " remain after removing "
+ (old != null ? old.size() : 0)); + (old != null ? old.size() : 0));
} }
}
KBucketSet getKBuckets() { return _kb; } KBucketSet getKBuckets() { return _kb; }
DataStore getDataStore() { return _ds; } DataStore getDataStore() { return _ds; }