class SearchJob extends JobImpl
Searches for a specific key by querying peers iteratively until either the value is found or all available peers are exhausted. Manages search state, timeout handling, and peer selection with configurable concurrency levels.
Note that this is rarely used directly and primarily serves as a base for ExploreJob. FloodOnlySearchJob and FloodSearchJob do not extend this class. Does not update peer profile statistics.
| Modifier and Type | Class and Description |
|---|---|
protected class | SearchJob.FailedJobCalled when a particular peer failed to respond before the timeout was
reached, or if the peer could not be contacted at all. |
| Modifier and Type | Field and Description |
|---|---|
protected KademliaNetworkDatabaseFacade | _facadeNetwork database facade for peer lookups and storage. |
protected Log | _logClass logger. |
(package private) static int | MAX_CLOSESTOnly send the 10 closest "don't tell me about" refs |
(package private) static long | MIN_TIMEOUTMinimum timeout in ms |
(package private) static int | PER_FLOODFILL_PEER_TIMEOUTTimeout per floodfill peer in ms |
| Constructor and Description |
|---|
SearchJob(RouterContext context,
KademliaNetworkDatabaseFacade facade,
Hash key,
Job onSuccess,
Job onFailure,
long timeoutMs,
boolean keepStats,
boolean isLease,
long msgIDBloomXor)Create a new search for the routingKey specified |
| Modifier and Type | Method and Description |
|---|---|
(package private) boolean | add(Hash peer)Adds a peer to the search. |
int | addDeferred(Job onFind,
Job onFail,
long expiration,
boolean isLease)Add a deferred search to run on completion of this search. |
protected I2NPMessage | buildMessage(TunnelId replyTunnelId,
Hash replyGateway,
long expiration,
RouterInfo peer)Build the database search message |
protected void | continueSearch()Send a series of searches to the next available peers as selected by
the routing table, but making sure no more than SEARCH_BREDTH are outstanding
at any time |
(package private) void | decrementOutstandingFloodfillSearches()Decrement the count of outstanding floodfill searches |
protected void | fail()Search totally failed |
protected int | getBredth()Max # of concurrent searches |
long | getExpiration() |
protected KademliaNetworkDatabaseFacade | getFacade() |
String | getName()Descriptive name of the task |
protected int | getPerPeerTimeoutMs()Let each peer take up to the average successful search RTT |
protected int | getPerPeerTimeoutMs(Hash peer)Per-peer timeout adjusted for floodfill and remaining time. |
protected SearchState | getState() |
long | getTimeoutMs() |
protected void | newPeersFound(int numNewPeers)We've gotten a search reply that contained the specified
number of peers that we didn't know about before. |
(package private) static boolean | onlyQueryFloodfillPeers(RouterContext ctx)This is now misnamed, as it is only used to determine whether to return floodfill peers only |
(package private) void | replyFound(DatabaseSearchReplyMessage message,
Hash peer)Found a reply |
void | runJob()Execute the next step of the iterative search. |
protected void | searchNext()Send the next search, or stop if its completed |
protected void | sendLeaseSearch(RouterInfo router)we're (probably) searching for a LeaseSet, so to be (overly) cautious, we're sending
the request out through a tunnel w/ reply back through another tunnel. |
protected void | sendRouterSearch(RouterInfo router)We're searching for a router, so we can just send direct |
protected void | sendSearch(RouterInfo router)Send a search to the given peer |
(package private) long | timeoutMs() |
String | toString() |
(package private) boolean | wasAttempted(Hash peer) |
dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeueprotected final KademliaNetworkDatabaseFacade _facade
protected final Log _log
static final int MAX_CLOSEST
static final long MIN_TIMEOUT
static final int PER_FLOODFILL_PEER_TIMEOUT
public SearchJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, Job onSuccess, Job onFailure, long timeoutMs, boolean keepStats, boolean isLease, long msgIDBloomXor)
boolean add(Hash peer)
public int addDeferred(Job onFind, Job onFail, long expiration, boolean isLease)
protected I2NPMessage buildMessage(TunnelId replyTunnelId, Hash replyGateway, long expiration, RouterInfo peer)
replyTunnelId - tunnel to receive replies throughreplyGateway - gateway for the reply tunnelexpiration - when the search should stoppeer - unused here; see ExploreJob extensionprotected void continueSearch()
void decrementOutstandingFloodfillSearches()
protected void fail()
protected int getBredth()
public long getExpiration()
protected KademliaNetworkDatabaseFacade getFacade()
public String getName()
Jobprotected int getPerPeerTimeoutMs()
protected int getPerPeerTimeoutMs(Hash peer)
protected SearchState getState()
public long getTimeoutMs()
protected void newPeersFound(int numNewPeers)
static boolean onlyQueryFloodfillPeers(RouterContext ctx)
void replyFound(DatabaseSearchReplyMessage message, Hash peer)
public void runJob()
protected void searchNext()
protected void sendLeaseSearch(RouterInfo router)
protected void sendRouterSearch(RouterInfo router)
protected void sendSearch(RouterInfo router)
long timeoutMs()
boolean wasAttempted(Hash peer)