java.lang.Object
net.i2p.router.networkdb.kademlia.StoreState
Manages state for network database store operations.
Tracks peer interaction status, timing information, and operation progress for store operations. Maintains separate sets for pending, attempted, and successful operations to coordinate concurrent store operations and prevent duplicate queries.
Thread-safe implementation using synchronized collections and atomic counters for safe concurrent access from multiple store jobs.
Provides comprehensive state management for reliable data persistence with validation, timeout handling, and operation completion tracking.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intPeers contacted so far.The peers contacted so far.private intReplies received so far.private longWhen the store finished, zero while running.private final RouterContextThe router context.private final DatabaseEntryThe entry being stored.private final HashThe key being stored.private final Map<Hash, MessageWrapper.WrappedMessage> The sent messages awaiting a reply.The peers not yet replied.When each pending peer was contacted.private longWhen the store started.The peers that stored the entry.Constructor Summary
ConstructorsConstructorDescriptionStoreState(RouterContext ctx, Hash key, DatabaseEntry data) Starts a store tracking no skipped peers.StoreState(RouterContext ctx, Hash key, DatabaseEntry data, Set<Hash> toSkip) New store state tracking pending, attempted, and successful peers.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidaddPending(Hash peer) Increments attempted count.voidaddPending(Hash peer, MessageWrapper.WrappedMessage msg) Adds a pending message for tracking.voidaddSkipped(Hash peer) We aren't even going to try to contact this peer.voidcomplete(boolean completed) Mark the store as completed at the current time, if not already.booleanWhether the store has completed.longMark the peer as confirmed and return the response time.The peers attempted OR skipped.intThe number of peers attempted.intNumber of peers that confirmed the store.getData()The data being stored.intNumber of pending peers.getPendingMessage(Hash peer) Returns the pending message for the specified peer.Return a successful peer (a random one if more than one was successful) or null.The DatabaseEntry hash target.longTime the store completed, or -1 if not yet completed.longTime the store started.voidreplyTimeout(Hash peer) Remove the peer from pending on timeout.toString()Debug string for this store state.
Field Details
_context
The router context._key
The key being stored._data
The entry being stored._pendingPeers
_pendingPeerTimes
_pendingMessages
The sent messages awaiting a reply._successfulPeers
_attemptedPeers
_completeCount
private int _completeCountReplies received so far._attempted
private int _attemptedPeers contacted so far._completed
private volatile long _completedWhen the store finished, zero while running._started
private volatile long _startedWhen the store started.
Constructor Details
StoreState
Starts a store tracking no skipped peers.- Parameters:
ctx- the router context supplying the clock used to time the storekey- the DatabaseEntry hash being storeddata- the entry that will be sent to each peer that stores it
StoreState
New store state tracking pending, attempted, and successful peers.- Parameters:
ctx- the router context supplying the clock used to time the storekey- the DatabaseEntry hashdata- the entry that will be sent to each peer that stores ittoSkip- may be null, if non-null, all attempted and skipped targets will be added as of 0.9.53
Method Details
getTarget
getData
The data being stored.- Returns:
- the DatabaseEntry to be sent to each peer that stores the target
getPendingCount
public int getPendingCount()Number of pending peers.- Returns:
- the pending count
getAttempted
getAttemptedCount
public int getAttemptedCount()The number of peers attempted. Does not include skipped peers. Do not usegetAttempted().size() as that does include skipped peers.- Returns:
- the attempted count
getSuccessful
Return a successful peer (a random one if more than one was successful) or null.- Returns:
- one of the peers that stored the entry, chosen at random when more than one did, or null if none has yet
completed
public boolean completed()Whether the store has completed.- Returns:
- true once complete(true) has recorded a completion time
complete
public void complete(boolean completed) Mark the store as completed at the current time, if not already.- Parameters:
completed- whether to mark the store as completed
getCompleteCount
public int getCompleteCount()Number of peers that confirmed the store.- Returns:
- the complete count
getWhenStarted
public long getWhenStarted()Time the store started.- Returns:
- the when started
getWhenCompleted
public long getWhenCompleted()Time the store completed, or -1 if not yet completed.- Returns:
- the when completed
addPending
Adds a pending message for tracking.- Parameters:
peer- the peer the message is queued to, which is also counted as attemptedmsg- the wrapped message to hand back fromgetPendingMessage(Hash)
getPendingMessage
Returns the pending message for the specified peer.- Parameters:
peer- the peer whose pending message should be taken- Returns:
- the message or null; will only return the message once, so tags are only acked or failed once.
addPending
Increments attempted count.- Parameters:
peer- the peer now pending a store reply, and counted as attempted
addSkipped
We aren't even going to try to contact this peer.- Parameters:
peer- the peer to count as attempted without being contacted
confirmed
Mark the peer as confirmed and return the response time.- Parameters:
peer- the peer that confirmed- Returns:
- the response time in ms, or -1 if unknown
replyTimeout
Remove the peer from pending on timeout.- Parameters:
peer- the peer that timed out
toString