class NegativeLookupCache extends Object
Caches failed lookup attempts to prevent repeated queries to unavailable or malicious peers. Implements time-based expiration and configurable failure thresholds to balance between cache effectiveness and resource usage.
Uses LRU eviction policy and periodic cleanup to maintain cache size. Provides DOS protection by rate-limiting repeated failed lookups for the same targets within configurable time windows.
Thread-safe implementation with atomic counters and scheduled cleanup operations for reliable concurrent access in multi-threaded environments.
| Modifier and Type | Field and Description |
|---|---|
(package private) static int | MAX_FAILSmaximum number of failures before caching |
| Constructor and Description |
|---|
NegativeLookupCache(RouterContext context)Creates a new NegativeLookupCache. |
| Modifier and Type | Method and Description |
|---|---|
void | cache(Hash h)Negative cache the hash until the next clean time. |
void | clear()Clears the negative cache and bad destinations. |
void | failPermanently(Destination dest)Negative cache the hash permanently until restart,
but cache the destination. |
Destination | getBadDest(Hash h)Get a cached bad destination. |
boolean | isCached(Hash h)Check if the hash is in the negative cache. |
void | lookupFailed(Hash h)Record a failed lookup for the given hash. |
void | stop()Stops the timer. |
static final int MAX_FAILS
public NegativeLookupCache(RouterContext context)
context - the router contextpublic void cache(Hash h)
h - the hash to cachepublic void clear()
public void failPermanently(Destination dest)
dest - the destination to permanently failpublic Destination getBadDest(Hash h)
h - the hash to look uppublic boolean isCached(Hash h)
h - the hash to checkpublic void lookupFailed(Hash h)
h - the hash that failed lookuppublic void stop()