java.lang.Object
net.i2p.router.networkdb.kademlia.LookupThrottler
Provides denial-of-service protection for network database lookup operations.
Tracks the frequency of recent lookup requests targeting specific reply peer/tunnel pairs to prevent abuse. Implements burst detection over sliding time windows and configurable request limits.
Note this is basic DOS protection and does not prevent spoofed reply identifiers or multiple reply tunnels from malicious requestors.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classPeriodically clears throttle counters to prevent unbounded growth.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LookupThrottler.CleanerPeriodic cleanup task for stale throttle entries.private final FloodfillNetworkDatabaseFacadeFloodfill network database facade for capability checks.private intMax value.private static final intMax requests allowed per peer per burst window.private static final longLength of the burst detection window in ms.Map of peer hashes to sets of reply tunnel IDs for throttling.private final longClean time.private final ConcurrentHashMap<Hash, ConcurrentHashMap<TunnelId, AtomicInteger>> Concurrent hash map.private static final longClean interval for expired throttle entries.private static final intThis seems like plenty.private static final intMax lookups per peer when not floodfill.private static final TunnelIdThe id of this is -1.private static final intHard cap on unique (from, tunnel) pairs tracked to prevent memory leaks.private final intMax lookups limit.private final intMax non-FF lookups limit.Constructor Summary
ConstructorsConstructorDescriptionThrottle for the given floodfill facade.LookupThrottler(FloodfillNetworkDatabaseFacade facade, int maxlookups, int maxnonfflookups, long cleanTime) Throttle with configurable lookup limits.Method Summary
All MethodsModifier and TypeMethodDescription(package private) voidcancel()Stop the periodic cleaner.(package private) booleanshouldThrottle(Hash key, TunnelId id) Increment and check throttling for the given peer and tunnel.
Field Details
counter
Concurrent hash map.burstTimestamps
DUMMY_ID
The id of this is -1.DEFAULT_MAX_LOOKUPS
DEFAULT_MAX_NON_FF_LOOKUPS
private static final int DEFAULT_MAX_NON_FF_LOOKUPSMax lookups per peer when not floodfill.- See Also:
DEFAULT_CLEAN_TIME
private static final long DEFAULT_CLEAN_TIMEClean interval for expired throttle entries.- See Also:
BURST_THRESHOLD
private static final int BURST_THRESHOLDMax requests allowed per peer per burst window.- See Also:
BURST_WINDOW_MS
private static final long BURST_WINDOW_MSLength of the burst detection window in ms.- See Also:
MAX_ENTRIES
private static final int MAX_ENTRIESHard cap on unique (from, tunnel) pairs tracked to prevent memory leaks. At ~25 peak lookups/sec with a 3-min clean window, ~4,500 keys is sufficient. 10,000 gives ~7 min headroom at peak. The clean runs every 3 min so this cap is only hit during sustained attack.- See Also:
MAX_LOOKUPS
private final int MAX_LOOKUPSMax lookups limit.MAX_NON_FF_LOOKUPS
private final int MAX_NON_FF_LOOKUPSMax non-FF lookups limit.CLEAN_TIME
private final long CLEAN_TIMEClean time._facade
Floodfill network database facade for capability checks._max
private volatile int _maxMax value._cleaner
Periodic cleanup task for stale throttle entries.
Constructor Details
LookupThrottler
LookupThrottler(FloodfillNetworkDatabaseFacade facade) Throttle for the given floodfill facade.- Parameters:
facade- floodfill network database facade
LookupThrottler
LookupThrottler(FloodfillNetworkDatabaseFacade facade, int maxlookups, int maxnonfflookups, long cleanTime) Throttle with configurable lookup limits.- Parameters:
facade- floodfill network database facademaxlookups- the concurrent lookup limit while floodfillmaxnonfflookups- when not floodfillcleanTime- milliseconds between throttling table cleanups
Method Details
cancel
void cancel()Stop the periodic cleaner. Call on facade shutdown.shouldThrottle