class SearchState extends Object
Tracks peer interaction status, timing information, and search progress for iterative Kademlia searches. Maintains separate sets for pending, attempted, failed, successful, and replied peers to coordinate concurrent search operations and prevent duplicate queries.
Thread-safe implementation using synchronized collections and atomic counters for safe concurrent access from multiple search jobs.
| Constructor and Description |
|---|
SearchState(RouterContext context,
Hash key)SearchState. |
| Modifier and Type | Method and Description |
|---|---|
void | abort()Aborts this search state. |
void | addInitialLeaseSetResponse(Hash peer,
LeaseSet ls)Record the peer's LeaseSet response from the initial phase. |
void | addLeaseSetResponse(Hash peer,
LeaseSet ls)Record the peer's LeaseSet response. |
void | addPending(Collection<Hash> pending)Add the peers to the pending and attempted sets. |
void | addPending(Hash peer)Add the peer to the pending and attempted sets. |
void | clearInitialTracking()Clear the initial response tracking state. |
void | complete()Mark the search as completed at the current time. |
boolean | completed()Whether the search has completed. |
long | dataFound(Hash peer)How long it took to get the reply, or -1 if we don't know. |
Set<Hash> | getAttempted()Copy of the attempted peers. |
int | getAttemptedSize()Number of attempted peers. |
LeaseSet | getBestInitialLeaseSet()LeaseSet with the newest lease date among the initial responses. |
Set<Hash> | getClosestAttempted(int max)Up to max attempted peers closest to the target. |
Set<Hash> | getFailed()Copy of the failed peers. |
int | getFailedSize()Number of failed peers. |
LeaseSet | getNewestLeaseSet()LeaseSet with the newest lease date among the responses. |
Set<Hash> | getPending()Copy of the pending peers. |
int | getPendingSize()Number of pending peers. |
Set<Hash> | getRepliedPeers()Copy of the peers that replied. |
long | getStoredLeaseDate()Stored lease date of the last accepted LeaseSet. |
Set<Hash> | getSuccessful()Copy of the successful peers. |
int | getSuccessfulSize()Number of successful peers. |
Hash | getTarget()The search target. |
long | getWhenCompleted()Time the search completed, or -1 if not yet completed. |
long | getWhenStarted()Time the search started. |
boolean | isAborted()Checks if this search state has been aborted. |
void | removePending(Hash peer)We didn't actually want to add this peer as part of the pending list... |
long | replyFound(Hash peer)How long it took to get the reply, or -1 if we don't know. |
void | replyTimeout(Hash peer)Move the peer from pending to failed on timeout. |
void | setStoredLeaseDate(long date)Record the stored lease date. |
boolean | shouldStoreInitial()Whether enough initial responses have been received to store. |
boolean | shouldUpdateStored(LeaseSet ls)Whether the given LeaseSet is newer than the stored one. |
String | toString()Debug string for this search state. |
boolean | wasAttempted(Hash peer)Whether the peer was attempted. |
public SearchState(RouterContext context, Hash key)
public void abort()
public void addInitialLeaseSetResponse(Hash peer, LeaseSet ls)
peer - the peer that respondedls - the received LeaseSetpublic void addLeaseSetResponse(Hash peer, LeaseSet ls)
peer - the peer that respondedls - the received LeaseSetpublic void addPending(Collection<Hash> pending)
pending - the peers to addpublic void addPending(Hash peer)
peer - the peer to addpublic void clearInitialTracking()
public void complete()
public boolean completed()
public long dataFound(Hash peer)
public int getAttemptedSize()
public LeaseSet getBestInitialLeaseSet()
public Set<Hash> getClosestAttempted(int max)
public int getFailedSize()
public LeaseSet getNewestLeaseSet()
public int getPendingSize()
public Set<Hash> getRepliedPeers()
public long getStoredLeaseDate()
public int getSuccessfulSize()
public Hash getTarget()
public long getWhenCompleted()
public long getWhenStarted()
public boolean isAborted()
public void removePending(Hash peer)
public long replyFound(Hash peer)
public void replyTimeout(Hash peer)
peer - the peer that timed outpublic void setStoredLeaseDate(long date)
date - the new stored lease datepublic boolean shouldStoreInitial()
public boolean shouldUpdateStored(LeaseSet ls)
ls - the LeaseSet to comparepublic String toString()
public boolean wasAttempted(Hash peer)