java.lang.Object
net.i2p.router.networkdb.kademlia.SearchMessageSelector
All Implemented Interfaces:
MessageSelector

class SearchMessageSelectorextends Object implements MessageSelector
Message selector for matching search operation responses from specific peers.

Filters incoming DatabaseStoreMessage and DatabaseSearchReplyMessage to identify responses corresponding to ongoing search operations. Tracks match status, expiration times, and coordinates with SearchState to manage pending peer queries.

Provides unique identification for each selector instance and implements continuation logic based on search progress and timeout conditions. Ensures proper response correlation between sent queries and received replies.

  • Field Details

    • _log

      private final Log _log
      The log for the selector.
    • _context

      private final RouterContext _context
      The router context.
    • __searchSelectorId

      private static final AtomicInteger __searchSelectorId
      The next selector id.
    • _peer

      private final Hash _peer
      The peer being searched for.
    • _found

      private volatile boolean _found
      True once a matching message was found.
    • _id

      private final int _id
      The id of this selector.
    • _exp

      private final long _exp
      When the selector expires.
    • _state

      private final SearchState _state
      The state of the search.
  • Constructor Details

    • SearchMessageSelector

      public SearchMessageSelector(RouterContext context, RouterInfo peer, long expiration, SearchState state)
      Claims a selector id and records the peer, deadline and search state.
      Parameters:
      context - the router context supplying the log and the search state
      peer - the router the search replies are expected from
      expiration - the time in milliseconds after which the reply is no longer waited for
      state - the search being run, holding the target key and the remaining peers
  • Method Details

    • toString

      public String toString()
      Debug description of this selector.
      Overrides:
      toString in class Object
    • continueMatching

      public boolean continueMatching()
      Continue matching until the search expires or the value is found.
      Specified by:
      continueMatching in interface MessageSelector
      Returns:
      true to keep searching for further matches, false to stop searching
    • getExpiration

      public long getExpiration()
      Absolute time when this selector stops matching.
      Specified by:
      getExpiration in interface MessageSelector
      Returns:
      the time in milliseconds after the epoch at which matching stops, taken from the expiration passed to the constructor
    • isMatch

      public boolean isMatch(I2NPMessage message)
      Whether the message is a store for the searched key.
      Specified by:
      isMatch in interface MessageSelector
      Parameters:
      message - the received message to test against this selector
      Returns:
      true for a DatabaseStoreMessage carrying the searched key, or a DatabaseSearchReplyMessage from the queried peer for that key; either match records the hit in _found