diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java index 35864c5543bf812cff27241db1869012e30302ea..794638708b2980e1acdbb6324114b38dae0c26a4 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java @@ -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(); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java b/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java index 1915caf4ee56d890e237ef9082061291c0aa23ab..d9164225d44a9f151b27f78a494b5e84bc63d360 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/NegativeLookupCache.java @@ -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;