I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit c901010d authored by zab2's avatar zab2
Browse files

Make parameters of NegativeLookupCache configurable

parent 9f0f1f5e
No related branches found
No related tags found
No related merge requests found
...@@ -274,7 +274,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade { ...@@ -274,7 +274,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
//_ds = new TransientDataStore(); //_ds = new TransientDataStore();
// _exploreKeys = new HashSet(64); // _exploreKeys = new HashSet(64);
_dbDir = dbDir; _dbDir = dbDir;
_negativeCache = new NegativeLookupCache(); _negativeCache = new NegativeLookupCache(_context);
createHandlers(); createHandlers();
......
...@@ -4,6 +4,7 @@ import java.util.Map; ...@@ -4,6 +4,7 @@ import java.util.Map;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.router.RouterContext;
import net.i2p.util.LHMCache; import net.i2p.util.LHMCache;
import net.i2p.util.ObjectCounter; import net.i2p.util.ObjectCounter;
import net.i2p.util.SimpleTimer; import net.i2p.util.SimpleTimer;
...@@ -17,15 +18,18 @@ import net.i2p.util.SimpleTimer2; ...@@ -17,15 +18,18 @@ import net.i2p.util.SimpleTimer2;
class NegativeLookupCache { class NegativeLookupCache {
private final ObjectCounter<Hash> counter; private final ObjectCounter<Hash> counter;
private final Map<Hash, Destination> badDests; private final Map<Hash, Destination> badDests;
private final int _maxFails;
private static final int MAX_FAILS = 3; private static final int MAX_FAILS = 3;
private static final int MAX_BAD_DESTS = 128; private static final int MAX_BAD_DESTS = 128;
private static final long CLEAN_TIME = 2*60*1000; private static final long CLEAN_TIME = 2*60*1000;
public NegativeLookupCache() { public NegativeLookupCache(RouterContext context) {
this.counter = new ObjectCounter<Hash>(); this.counter = new ObjectCounter<Hash>();
this.badDests = new LHMCache<Hash, Destination>(MAX_BAD_DESTS); 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) { public void lookupFailed(Hash h) {
...@@ -33,7 +37,7 @@ class NegativeLookupCache { ...@@ -33,7 +37,7 @@ class NegativeLookupCache {
} }
public boolean isCached(Hash h) { public boolean isCached(Hash h) {
if (counter.count(h) >= MAX_FAILS) if (counter.count(h) >= _maxFails)
return true; return true;
synchronized(badDests) { synchronized(badDests) {
return badDests.get(h) != null; return badDests.get(h) != null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment