java.lang.Object
net.i2p.router.networkdb.kademlia.FloodfillDatabaseLookupMessageHandler
- All Implemented Interfaces:
HandlerJobBuilder
Handler for DatabaseLookupMessage received on floodfills.
This class verifies incoming lookup messages, applies throttling and banning policies, and builds appropriate jobs for accepted lookups. Unacceptable lookups are logged and dropped.
It tracks lookup statistics such as received, dropped, handled, and matched lookups via the statManager.
Supports floodfill and non-floodfill router modes, with special handling for floodfill peers and exploratory lookups.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BanLoggerRecords peers that send bad lookups.private RouterContextThe router answering lookups.private FloodfillNetworkDatabaseFacadeThe facade holding the keys being looked up.private LogLogger for this class.private final longXor mask for this router's lookup message ids.private static final long[]Rate windows kept for the lookup statistics.Constructor Summary
ConstructorsConstructorDescriptionHandler for floodfill DatabaseLookupMessages.Method Summary
Modifier and TypeMethodDescriptioncreateJob(I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) Creates a job to handle an incoming DatabaseLookupMessage, or returns null if the lookup should be dropped.private StringExtract IP:port fromRouterInfofor a peer hash.private voidlogDroppedLookup(String searchType, String fromBase64, String searchKeyBase64, int keyLength, boolean isFF, boolean floodfillMode, boolean isDirect, boolean isBanned, int maxLookups) Logs warning messages when a lookup is dropped due to throttling, banning, or mode restrictions.private DatabaseLookupMessagepreProcessDatabaseLookup(DatabaseLookupMessage dlm, Hash fromHash) Handle special cases: - Fix loopback DLM bug (pre-0.9.67) where from was set to self - Reject direct floodfill-to-floodfill lookups of type EXPL or ANY.private booleanshouldAcceptLookup(boolean isSenderUs, boolean shouldThrottle, boolean shouldBan, boolean ourRI, boolean floodfillMode, boolean isFF, DatabaseLookupMessage.Type type) Determines whether a lookup request should be accepted based on sender identity, throttling and banning status, router participation mode, and type of lookup.private static StringConverts a DatabaseLookupMessage.Type enum to a human-readable string.
Field Details
_context
The router answering lookups._facade
The facade holding the keys being looked up._log
Logger for this class._banLogger
Records peers that send bad lookups._msgIDBloomXor
private final long _msgIDBloomXorXor mask for this router's lookup message ids.RATES
private static final long[] RATESRate windows kept for the lookup statistics.
Constructor Details
FloodfillDatabaseLookupMessageHandler
public FloodfillDatabaseLookupMessageHandler(RouterContext context, FloodfillNetworkDatabaseFacade facade) Handler for floodfill DatabaseLookupMessages.- Parameters:
context- the router context providing system state and utilitiesfacade- the network database facade used for lookup management and throttling
Method Details
createJob
Creates a job to handle an incoming DatabaseLookupMessage, or returns null if the lookup should be dropped.This method performs several checks, including: floodfill participation, sender identity, whether the lookup is for this router, throttling, banning, and lookup type compatibility. Logs details about accepted or dropped lookups and updates statistics.
- Specified by:
createJobin interfaceHandlerJobBuilder- Parameters:
receivedMessage- the incoming message, expected to be a DatabaseLookupMessagefrom- the identity of the sender routerfromHash- the hash of the sender router- Returns:
- a Job to handle the lookup if accepted, or null if dropped
- Throws:
ClassCastException- if receivedMessage is not a DatabaseLookupMessage
preProcessDatabaseLookup
Handle special cases: - Fix loopback DLM bug (pre-0.9.67) where from was set to self - Reject direct floodfill-to-floodfill lookups of type EXPL or ANY.- Parameters:
dlm- the received lookup message, never modified - corrections return a copyfromHash- the peer the message actually arrived from, or null if unknown- Returns:
- the corrected DLM, or null to drop the message
logDroppedLookup
private void logDroppedLookup(String searchType, String fromBase64, String searchKeyBase64, int keyLength, boolean isFF, boolean floodfillMode, boolean isDirect, boolean isBanned, int maxLookups) Logs warning messages when a lookup is dropped due to throttling, banning, or mode restrictions. Does nothing if warning logs are disabled or the sender is already banned.- Parameters:
searchType- the type string of the lookup (e.g. "Exploratory", "RouterInfo")fromBase64- the base64 representation of the sender router hash (truncated to 6 chars)searchKeyBase64- the base64 representation of the lookup search key (truncated)keyLength- the length of key substring to log (6 if RouterInfo or 8 chars otherwise)isFF- true if the sender router is a floodfillfloodfillMode- true if the local router is participating as floodfillisDirect- true if the lookup is being sent directly (no tunnel)isBanned- true if the sender router is bannedmaxLookups- max allowed lookups in time window for floodfill or non-floodfill
shouldAcceptLookup
private boolean shouldAcceptLookup(boolean isSenderUs, boolean shouldThrottle, boolean shouldBan, boolean ourRI, boolean floodfillMode, boolean isFF, DatabaseLookupMessage.Type type) Determines whether a lookup request should be accepted based on sender identity, throttling and banning status, router participation mode, and type of lookup.- Parameters:
isSenderUs- true if the sender is the local router itself (loopback)shouldThrottle- true if the lookup request should be throttled (rate limited)shouldBan- true if the lookup request should be banned (blocked)ourRI- true if the lookup is for this router's identityfloodfillMode- true if the local router participates as floodfillisFF- true if the sender router is a floodfilltype- the lookup message type, where exploratory and any lookups are rejected- Returns:
- true if the lookup is accepted, false if dropped
typeToString
Converts a DatabaseLookupMessage.Type enum to a human-readable string.- Parameters:
type- the lookup message type- Returns:
- a descriptive string representation of the type
getIPFromHash
Extract IP:port fromRouterInfofor a peer hash.- Parameters:
h- the peer hash whose RouterInfo is looked up locally- Returns:
- the IP from hash