Compare commits

...

2 Commits

View File

@ -282,8 +282,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
if (_ds != null) if (_ds != null)
_ds.stop(); _ds.stop();
_exploreKeys.clear(); _exploreKeys.clear();
if (_negativeCache != null) negativeCache().clear();
_negativeCache.clear();
if (isMainDb()) if (isMainDb())
blindCache().shutdown(); blindCache().shutdown();
} }
@ -386,9 +385,10 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
} catch (IOException ioe) { } catch (IOException ioe) {
throw new RuntimeException("Unable to initialize netdb storage", ioe); throw new RuntimeException("Unable to initialize netdb storage", ioe);
} }
_negativeCache = new NegativeLookupCache(_context); if (isMainDb()) {
if (isMainDb()) _negativeCache = new NegativeLookupCache(_context);
blindCache().startup(); blindCache().startup();
}
createHandlers(); createHandlers();
@ -802,7 +802,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
return ls.getDestination(); return ls.getDestination();
} }
} else { } else {
return _negativeCache.getBadDest(key); return negativeCache().getBadDest(key);
} }
return null; return null;
} }
@ -1514,7 +1514,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
*/ */
void dropAfterLookupFailed(Hash peer) { void dropAfterLookupFailed(Hash peer) {
_context.peerManager().removeCapabilities(peer); _context.peerManager().removeCapabilities(peer);
_negativeCache.cache(peer); negativeCache().cache(peer);
_kb.remove(peer); _kb.remove(peer);
//if (removed) { //if (removed) {
// if (_log.shouldLog(Log.INFO)) // if (_log.shouldLog(Log.INFO))
@ -1656,7 +1656,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
* @since 0.9.4 moved from FNDF to KNDF in 0.9.16 * @since 0.9.4 moved from FNDF to KNDF in 0.9.16
*/ */
void lookupFailed(Hash key) { void lookupFailed(Hash key) {
_negativeCache.lookupFailed(key); negativeCache().lookupFailed(key);
} }
/** /**
@ -1666,7 +1666,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
* @since 0.9.4 moved from FNDF to KNDF in 0.9.16 * @since 0.9.4 moved from FNDF to KNDF in 0.9.16
*/ */
boolean isNegativeCached(Hash key) { boolean isNegativeCached(Hash key) {
boolean rv = _negativeCache.isCached(key); boolean rv = negativeCache().isCached(key);
if (rv) if (rv)
_context.statManager().addRateData("netDb.negativeCache", 1); _context.statManager().addRateData("netDb.negativeCache", 1);
return rv; return rv;
@ -1677,7 +1677,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
* @since 0.9.16 * @since 0.9.16
*/ */
void failPermanently(Destination dest) { void failPermanently(Destination dest) {
_negativeCache.failPermanently(dest); negativeCache().failPermanently(dest);
} }
/** /**
@ -1687,7 +1687,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
* @since 0.9.16 * @since 0.9.16
*/ */
public boolean isNegativeCachedForever(Hash key) { public boolean isNegativeCachedForever(Hash key) {
return _negativeCache.getBadDest(key) != null; return negativeCache().getBadDest(key) != null;
} }
/** /**
@ -1698,4 +1698,11 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
public void renderStatusHTML(Writer out) throws IOException { public void renderStatusHTML(Writer out) throws IOException {
out.write(_kb.toString().replace("\n", "<br>\n")); out.write(_kb.toString().replace("\n", "<br>\n"));
} }
private NegativeLookupCache negativeCache() {
if (_negativeCache != null)
return _negativeCache;
KademliaNetworkDatabaseFacade kndf = (KademliaNetworkDatabaseFacade) _context.netDb();
return kndf.negativeCache();
}
} }