All Implemented Interfaces:
Job

public class ExploreJobextends SearchJob
Represents an exploratory search job for a particular key in the Kademlia network database. <p> This job performs an exploratory search until it gets a Database Search Reply Message (DSRM). It selects peers to send queries to based on floodfill capabilities and excludes peers already queried or close to the target key to avoid redundancy. <p> The concurrency level ("bredth") for this search is calculated once during construction based on system and network conditions, and does not change during the lifetime of the job.
  • Field Details

    • _peerSelector

      private final FloodfillPeerSelector _peerSelector
      Chooses the floodfills to explore through.
    • _isRealExplore

      private final boolean _isRealExplore
      False for a search that only keeps the router active.
    • _lastReplyFrom

      private volatile Hash _lastReplyFrom
      The peer that answered the last explore.
    • MAX_EXPLORE_TIME

      private static final long MAX_EXPLORE_TIME
      Maximum duration for each exploration in milliseconds. Explorations run relatively long since they seek multiple peers without expecting a quick success.
      See Also:
    • PROP_EXPLORE_BREDTH

      public static final String PROP_EXPLORE_BREDTH
      Configuration property key for controlling the maximum concurrent exploratory searches.
      See Also:
    • EXPLORE_BREDTH

      public static final int EXPLORE_BREDTH
      Default number of concurrent exploratory searches, adjusted for slower systems.
    • _tunedExploreBredth

      private static volatile int _tunedExploreBredth
      Tuned exploratory breadth, or -1 when no tuned value has been applied. Set via setExploreBredth(int) by the Tuner; takes priority over the router.exploreBredth config read in calculateBredth().
    • MAX_CLOSEST

      static final int MAX_CLOSEST
      Maximum number of closest peers to exclude in queries. This is intentionally larger to include floodfill and previously queried peers.
      See Also:
    • PER_FLOODFILL_PEER_TIMEOUT

      static final int PER_FLOODFILL_PEER_TIMEOUT
      Timeout per floodfill peer in milliseconds; shorter to avoid delays with unresponsive peers.
      See Also:
    • _bredth

      private final int _bredth
      Cached concurrency level (bredth) for this exploratory search instance.
  • Constructor Details

    • ExploreJob

      public ExploreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, boolean isRealExplore, long msgIDBloomXor)
      New exploratory search with the given parameters and calculated concurrency level.
      Parameters:
      context - Router context providing environment and config access
      facade - Facade handling the Kademlia network database operations
      key - Target key to explore/search for
      isRealExplore - True if this is a standard exploration (no floodfills returned), false if a standard lookup (floodfills returned, useful when floodfill count is low)
      msgIDBloomXor - XOR value for message ID Bloom filter (used internally)
  • Method Details

    • setExploreBredth

      public static void setExploreBredth(int bredth)
      Set the exploratory search breadth (called by Tuner).
      Parameters:
      bredth - the concurrent search count
    • getExploreBredth

      public static int getExploreBredth(RouterContext ctx)
      The tuned exploratory breadth, or -1 when no tuned value has been applied.
      Parameters:
      ctx - the router context (unused, kept for symmetry with other Tuner bridges)
      Returns:
      the tuned concurrent search count, or -1 if none
    • buildMessage

      protected I2NPMessage buildMessage(TunnelId replyTunnelId, Hash replyGateway, long expiration, RouterInfo peer)
      Builds the database lookup message to send to a peer. <p> Unlike normal searches, this method explicitly excludes certain peers: those previously queried, and those close to the target key in routing space, to avoid repeatedly querying the same nodes. The floodfill peers are also handled specially.
      Overrides:
      buildMessage in class SearchJob
      Parameters:
      replyTunnelId - Tunnel ID for receiving replies, or null to send direct (no encryption)
      replyGateway - Gateway for the reply tunnel, or null for direct sending
      expiration - Absolute time when the message expires
      peer - RouterInfo object representing the peer to which the message will be sent
      Returns:
      an encrypted or plain DatabaseLookupMessage wrapped as an I2NPMessage, or null on error
    • getBredth

      protected int getBredth()
      Returns the maximum number of concurrent exploratory searches to run. <p> This value is computed once at construction based on configuration and network state.
      Overrides:
      getBredth in class SearchJob
      Returns:
      maximum concurrent exploratory searches (bredth)
    • calculateBredth

      private int calculateBredth()
      Computes the concurrency level (bredth) for exploratory searches based on configured property, network size, and system speed. <p> If the "router.exploreBredth" property is defined and parseable, it is used. Otherwise, network size and system speed heuristics determine the bredth.
      Returns:
      computed maximum concurrency level for exploration
    • newPeersFound

      protected void newPeersFound(int numNewPeers)
      Called when the search has returned new peers that were previously unknown. <p> Logs the number of newly discovered peers and updates the last explore timestamp.
      Overrides:
      newPeersFound in class SearchJob
      Parameters:
      numNewPeers - number of newly discovered peers
    • replyFound

      void replyFound(DatabaseSearchReplyMessage message, Hash peer)
      Process a reply listing routers that hold the key.
      Overrides:
      replyFound in class SearchJob
      Parameters:
      message - search reply received from the peer
      peer - router hash that sent it, which is cleared from the pending set and recorded as having replied
    • add

      boolean add(Hash peer)
      This is called from SearchReplyJob.
      Overrides:
      add in class SearchJob
      Parameters:
      peer - router hash to add to the kbuckets, and to queue for exploration if it was not already there
      Returns:
      true if peer was new
    • getName

      public String getName()
      Description copied from interface: Job
      Descriptive name of the task.
      Specified by:
      getName in interface Job
      Overrides:
      getName in class SearchJob
      Returns:
      the descriptive name of the task