java.lang.Object
net.i2p.router.networkdb.kademlia.SearchMessageSelector
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicIntegerThe next selector id.private final RouterContextThe router context.private final longWhen the selector expires.private booleanTrue once a matching message was found.private final intThe id of this selector.private final LogThe log for the selector.private final HashThe peer being searched for.private final SearchStateThe state of the search.Constructor Summary
ConstructorsConstructorDescriptionSearchMessageSelector(RouterContext context, RouterInfo peer, long expiration, SearchState state) Claims a selector id and records the peer, deadline and search state.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanContinue matching until the search expires or the value is found.longAbsolute time when this selector stops matching.booleanisMatch(I2NPMessage message) Whether the message is a store for the searched key.toString()Debug description of this selector.
Field Details
_log
The log for the selector._context
The router context.__searchSelectorId
The next selector id._peer
The peer being searched for._found
private volatile boolean _foundTrue once a matching message was found._id
private final int _idThe id of this selector._exp
private final long _expWhen the selector expires._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 statepeer- the router the search replies are expected fromexpiration- the time in milliseconds after which the reply is no longer waited forstate- the search being run, holding the target key and the remaining peers
Method Details
toString
continueMatching
public boolean continueMatching()Continue matching until the search expires or the value is found.- Specified by:
continueMatchingin interfaceMessageSelector- 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:
getExpirationin interfaceMessageSelector- Returns:
- the time in milliseconds after the epoch at which matching stops, taken from the expiration passed to the constructor
isMatch
Whether the message is a store for the searched key.- Specified by:
isMatchin interfaceMessageSelector- 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