java.lang.Object
net.i2p.router.networkdb.kademlia.FloodfillDatabaseLookupMessageHandler
All Implemented Interfaces:
HandlerJobBuilder

public class FloodfillDatabaseLookupMessageHandlerextends Object implements 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 Details

    • _context

      private RouterContext _context
      The router answering lookups.
    • _facade

      The facade holding the keys being looked up.
    • _log

      private Log _log
      Logger for this class.
    • _banLogger

      private BanLogger _banLogger
      Records peers that send bad lookups.
    • _msgIDBloomXor

      private final long _msgIDBloomXor
      Xor mask for this router's lookup message ids.
    • RATES

      private static final long[] RATES
      Rate 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 utilities
      facade - the network database facade used for lookup management and throttling
  • Method Details

    • createJob

      public Job createJob(I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash)
      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:
      createJob in interface HandlerJobBuilder
      Parameters:
      receivedMessage - the incoming message, expected to be a DatabaseLookupMessage
      from - the identity of the sender router
      fromHash - 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

      private DatabaseLookupMessage preProcessDatabaseLookup(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.
      Parameters:
      dlm - the received lookup message, never modified - corrections return a copy
      fromHash - 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 floodfill
      floodfillMode - true if the local router is participating as floodfill
      isDirect - true if the lookup is being sent directly (no tunnel)
      isBanned - true if the sender router is banned
      maxLookups - 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 identity
      floodfillMode - true if the local router participates as floodfill
      isFF - true if the sender router is a floodfill
      type - the lookup message type, where exploratory and any lookups are rejected
      Returns:
      true if the lookup is accepted, false if dropped
    • typeToString

      private static String typeToString(DatabaseLookupMessage.Type type)
      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

      private String getIPFromHash(Hash h)
      Extract IP:port from RouterInfo for a peer hash.
      Parameters:
      h - the peer hash whose RouterInfo is looked up locally
      Returns:
      the IP from hash