forked from I2P_Developers/i2p.i2p
Make parameters of NegativeLookupCache configurable
This commit is contained in:
@@ -274,7 +274,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
//_ds = new TransientDataStore();
|
||||
// _exploreKeys = new HashSet(64);
|
||||
_dbDir = dbDir;
|
||||
_negativeCache = new NegativeLookupCache();
|
||||
_negativeCache = new NegativeLookupCache(_context);
|
||||
|
||||
createHandlers();
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import java.util.Map;
|
||||
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.LHMCache;
|
||||
import net.i2p.util.ObjectCounter;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
@@ -17,15 +18,18 @@ import net.i2p.util.SimpleTimer2;
|
||||
class NegativeLookupCache {
|
||||
private final ObjectCounter<Hash> counter;
|
||||
private final Map<Hash, Destination> badDests;
|
||||
|
||||
private final int _maxFails;
|
||||
|
||||
private static final int MAX_FAILS = 3;
|
||||
private static final int MAX_BAD_DESTS = 128;
|
||||
private static final long CLEAN_TIME = 2*60*1000;
|
||||
|
||||
public NegativeLookupCache() {
|
||||
public NegativeLookupCache(RouterContext context) {
|
||||
this.counter = new ObjectCounter<Hash>();
|
||||
this.badDests = new LHMCache<Hash, Destination>(MAX_BAD_DESTS);
|
||||
SimpleTimer2.getInstance().addPeriodicEvent(new Cleaner(), CLEAN_TIME);
|
||||
this._maxFails = context.getProperty("netdb.negativeCache.maxFails",MAX_FAILS);
|
||||
final long cleanTime = context.getProperty("netdb.negativeCache.cleanupInterval", CLEAN_TIME);
|
||||
SimpleTimer2.getInstance().addPeriodicEvent(new Cleaner(), cleanTime);
|
||||
}
|
||||
|
||||
public void lookupFailed(Hash h) {
|
||||
@@ -33,7 +37,7 @@ class NegativeLookupCache {
|
||||
}
|
||||
|
||||
public boolean isCached(Hash h) {
|
||||
if (counter.count(h) >= MAX_FAILS)
|
||||
if (counter.count(h) >= _maxFails)
|
||||
return true;
|
||||
synchronized(badDests) {
|
||||
return badDests.get(h) != null;
|
||||
|
Reference in New Issue
Block a user