Skip to content

Commit

Permalink
Router: add getter for _negativeCache that always gets the right one
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Oct 18, 2023
1 parent 284bdcb commit 077eb99
Showing 1 changed file with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ public synchronized void shutdown() {
if (_ds != null)
_ds.stop();
_exploreKeys.clear();
if (_negativeCache != null)
_negativeCache.clear();
negativeCache().clear();
if (isMainDb())
blindCache().shutdown();
}
Expand Down Expand Up @@ -803,8 +802,7 @@ public Destination lookupDestinationLocally(Hash key) {
return ls.getDestination();
}
} else {
if (_negativeCache != null)
return _negativeCache.getBadDest(key);
return negativeCache().getBadDest(key);
}
return null;
}
Expand Down Expand Up @@ -1516,8 +1514,7 @@ protected void lookupBeforeDropping(Hash peer, RouterInfo info) {
*/
void dropAfterLookupFailed(Hash peer) {
_context.peerManager().removeCapabilities(peer);
if (_negativeCache != null)
_negativeCache.cache(peer);
negativeCache().cache(peer);
_kb.remove(peer);
//if (removed) {
// if (_log.shouldLog(Log.INFO))
Expand Down Expand Up @@ -1659,8 +1656,7 @@ else if (responseTime < MIN_PER_PEER_TIMEOUT)
* @since 0.9.4 moved from FNDF to KNDF in 0.9.16
*/
void lookupFailed(Hash key) {
if (_negativeCache != null)
_negativeCache.lookupFailed(key);
negativeCache().lookupFailed(key);
}

/**
Expand All @@ -1670,9 +1666,7 @@ void lookupFailed(Hash key) {
* @since 0.9.4 moved from FNDF to KNDF in 0.9.16
*/
boolean isNegativeCached(Hash key) {
if (_negativeCache == null)
return false;
boolean rv = _negativeCache.isCached(key);
boolean rv = negativeCache().isCached(key);
if (rv)
_context.statManager().addRateData("netDb.negativeCache", 1);
return rv;
Expand All @@ -1683,9 +1677,7 @@ boolean isNegativeCached(Hash key) {
* @since 0.9.16
*/
void failPermanently(Destination dest) {
if (_negativeCache != null)
return;
_negativeCache.failPermanently(dest);
negativeCache().failPermanently(dest);
}

/**
Expand All @@ -1695,9 +1687,7 @@ void failPermanently(Destination dest) {
* @since 0.9.16
*/
public boolean isNegativeCachedForever(Hash key) {
if (_negativeCache != null)
return false;
return _negativeCache.getBadDest(key) != null;
return negativeCache().getBadDest(key) != null;
}

/**
Expand All @@ -1708,4 +1698,11 @@ public boolean isNegativeCachedForever(Hash key) {
public void renderStatusHTML(Writer out) throws IOException {
out.write(_kb.toString().replace("\n", "<br>\n"));
}

private NegativeLookupCache negativeCache() {
if (_negativeCache != null)
return _negativeCache;
KademliaNetworkDatabaseFacade kndf = (KademliaNetworkDatabaseFacade) _context.netDb();
return kndf.negativeCache();
}
}

0 comments on commit 077eb99

Please sign in to comment.