From c901010d96df0312ecdb293a596ecd745454d5bb Mon Sep 17 00:00:00 2001
From: zab2 <zab2@mail.i2p>
Date: Sat, 7 Nov 2015 02:56:59 +0000
Subject: [PATCH] Make parameters of NegativeLookupCache configurable

---
 .../kademlia/KademliaNetworkDatabaseFacade.java      |  2 +-
 .../networkdb/kademlia/NegativeLookupCache.java      | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

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 35864c5543..794638708b 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 1915caf4ee..d9164225d4 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;
-- 
GitLab