java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.networkdb.kademlia.SearchJob
net.i2p.router.networkdb.kademlia.ExploreJob
- All Implemented Interfaces:
Job
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.
Nested Class Summary
Nested classes/interfaces inherited from class SearchJob
SearchJob.FailedJobModifier and TypeClassDescriptionprotected classCalled when a particular peer failed to respond before the timeout was reached, or if the peer could not be contacted at all.Field Summary
Modifier and TypeFieldDescriptionprivate final intCached concurrency level (bredth) for this exploratory search instance.private final booleanFalse for a search that only keeps the router active.private HashThe peer that answered the last explore.private final FloodfillPeerSelectorChooses the floodfills to explore through.private static intTuned exploratory breadth, or -1 when no tuned value has been applied.static final intDefault number of concurrent exploratory searches, adjusted for slower systems.(package private) static final intMaximum number of closest peers to exclude in queries.private static final longMaximum duration for each exploration in milliseconds.(package private) static final intTimeout per floodfill peer in milliseconds; shorter to avoid delays with unresponsive peers.static final StringConfiguration property key for controlling the maximum concurrent exploratory searches.Fields inherited from class SearchJob
_facade, _log, MIN_TIMEOUTModifier and TypeFieldDescriptionprotected final KademliaNetworkDatabaseFacadeNetwork database facade for peer lookups and storage.protected final LogClass logger.(package private) static final longMinimum timeout in ms.Constructor Summary
ConstructorsConstructorDescriptionExploreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, boolean isRealExplore, long msgIDBloomXor) New exploratory search with the given parameters and calculated concurrency level.Method Summary
Modifier and TypeMethodDescription(package private) booleanThis is called fromSearchReplyJob.protected I2NPMessagebuildMessage(TunnelId replyTunnelId, Hash replyGateway, long expiration, RouterInfo peer) Builds the database lookup message to send to a peer.private intComputes the concurrency level (bredth) for exploratory searches based on configured property, network size, and system speed.protected intReturns the maximum number of concurrent exploratory searches to run.static intThe tuned exploratory breadth, or -1 when no tuned value has been applied.getName()Descriptive name of the task.protected voidnewPeersFound(int numNewPeers) Called when the search has returned new peers that were previously unknown.(package private) voidreplyFound(DatabaseSearchReplyMessage message, Hash peer) Process a reply listing routers that hold the key.static voidsetExploreBredth(int bredth) Set the exploratory search breadth (called by Tuner).Methods inherited from class SearchJob
addDeferred, continueSearch, decrementOutstandingFloodfillSearches, fail, getExpiration, getFacade, getLeaseResendCount, getPerPeerTimeoutMs, getPerPeerTimeoutMs, getResendTimeout, getState, getTimeoutMs, onlyQueryFloodfillPeers, runJob, searchNext, sendLeaseSearch, sendRouterSearch, sendSearch, setLeaseResendCount, setResendTimeout, timeoutMs, toString, wasAttemptedModifier and TypeMethodDescriptionintaddDeferred(Job onFind, Job onFail, long expiration, boolean isLease) Add a deferred search to run on completion of this search.protected voidSend 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) voidDecrement the count of outstanding floodfill searches.protected voidfail()Search totally failed.longWhen this search gives up if no peer has answered.protected KademliaNetworkDatabaseFacadeGet the netdb that started this search.static intThe current max peers that get a lease republish after a search.protected intLet each peer take up to the average successful search RTT.protected intgetPerPeerTimeoutMs(Hash peer) Per-peer timeout adjusted for floodfill and remaining time.static longThe current lease republish message window.protected SearchStategetState()Get the per-search record of which peers have been tried.longHow long the search is allowed to run before it is abandoned.(package private) static booleanThis is now misnamed, as it is only used to determine whether to return floodfill peers only.voidrunJob()Execute the next step of the iterative search.protected voidSend the next search, or stop if its completed.protected voidsendLeaseSearch(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 voidsendRouterSearch(RouterInfo router) We're searching for a router, so we can just send direct.protected voidsendSearch(RouterInfo router) Send a search to the given peer.static voidsetLeaseResendCount(int val) Max peers that get a lease republish after a search.static voidsetResendTimeout(int val) Lease republish message window.(package private) longThe timeout this search was created with, for other netdb classes.toString()Describe the search, and how long it has been running, for the logs.(package private) booleanwasAttempted(Hash peer) Whether the peer was already queried.Methods inherited from class JobImpl
dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeueModifier and TypeMethodDescriptionvoiddropped()Default implementation does nothing.final RouterContextThe router context that this job belongs to.longgetJobId()The unique job ID for this job.longThe timestamp when this job was last made ready for execution.The timing object for this job.voidmadeReady(long now) For JobQueue only, not for external use.protected voidrequeue(long delayMs) Requeue this job to run after the specified delay.
Field Details
_peerSelector
Chooses the floodfills to explore through._isRealExplore
private final boolean _isRealExploreFalse for a search that only keeps the router active._lastReplyFrom
The peer that answered the last explore.MAX_EXPLORE_TIME
private static final long MAX_EXPLORE_TIMEMaximum 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
Configuration property key for controlling the maximum concurrent exploratory searches.- See Also:
EXPLORE_BREDTH
public static final int EXPLORE_BREDTHDefault number of concurrent exploratory searches, adjusted for slower systems._tunedExploreBredth
private static volatile int _tunedExploreBredthTuned exploratory breadth, or -1 when no tuned value has been applied. Set viasetExploreBredth(int)by the Tuner; takes priority over therouter.exploreBredthconfig read incalculateBredth().MAX_CLOSEST
static final int MAX_CLOSESTMaximum 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_TIMEOUTTimeout per floodfill peer in milliseconds; shorter to avoid delays with unresponsive peers.- See Also:
_bredth
private final int _bredthCached 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 accessfacade- Facade handling the Kademlia network database operationskey- Target key to explore/search forisRealExplore- 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
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:
buildMessagein classSearchJob- Parameters:
replyTunnelId- Tunnel ID for receiving replies, or null to send direct (no encryption)replyGateway- Gateway for the reply tunnel, or null for direct sendingexpiration- Absolute time when the message expirespeer- 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
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:
newPeersFoundin classSearchJob- Parameters:
numNewPeers- number of newly discovered peers
replyFound
Process a reply listing routers that hold the key.- Overrides:
replyFoundin classSearchJob- Parameters:
message- search reply received from the peerpeer- router hash that sent it, which is cleared from the pending set and recorded as having replied
add
This is called fromSearchReplyJob.getName