- All Implemented Interfaces:
Job
- Direct Known Subclasses:
FloodfillStoreJob
Handles the process of storing database entries (RouterInfo or LeaseSet) to floodfill peers with configurable parallelization, redundancy, and timeout handling. Supports both direct and tunnel-based delivery with garlic encryption for client data.
All store operations through this class request a reply to confirm successful delivery. Unused directly - see FloodfillStoreJob for the concrete implementation.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classJob to handle failed store attempts.private static classCompare leases by XOR distance to a target hash.private classJob to verify successful store delivery and trigger next steps.private classA job that waits briefly before continuing to send store messages.Field Summary
Modifier and TypeFieldDescriptionprivate final ConnectCheckerChecks if we can connect to a peer directly.private final intBitmask for connection types we can use (IPv4, IPv6, etc.).private final longExpiration time for the store operation.private final KademliaNetworkDatabaseFacadeReference to the network database facade.protected final LogLogger for this class.private final JobJob to run on failed store.private final JobJob to run on successful store.private final PeerSelectorPeer selector for choosing floodfill participants.protected final StoreStateCurrent state of the store operation.private final longTimeout in milliseconds for the store operation.private static final intLimit expiration for direct sends.private static final intMost peers one store job sends to in total.static final StringWas supported in 38, but they're now sigtype 11 which wasn't added until 39.static final StringMinimum version for LS2 stores.static final StringShort ECIES tunnel build messages (1.5.0).private static final intLookups sent at a time.private static final intPeers the data should end up stored on.private static final intPause before the next batch of sends: 1 second.private static final intPriority of this router's own netdb store.Constructor Summary
ConstructorsConstructorDescriptionStoreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, DatabaseEntry data, Job onSuccess, Job onFailure, long timeoutMs) Send a data structure to the floodfills.StoreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, DatabaseEntry data, Job onSuccess, Job onFailure, long timeoutMs, Set<Hash> toSkip) Send a data structure to the floodfills, skipping certain peers.Method Summary
Modifier and TypeMethodDescriptionprivate voidSend a series of searches to the next available peers as selected by the routing table, but making sure no more than PARALLELIZATION are outstanding at any timeprotected voidfail()Handle failed completion of the store operation.getClosestFloodfillRouters(Hash key, int numClosest, Set<Hash> alreadyChecked) Find the closest floodfill routers to a given key.getName()Name of this job for logging and debugging.protected intMaximum number of parallel store operations.protected intRequired redundancy level for successful store.private booleanCheck if the store operation has expired.private LeasepickReplyTunnel(LeaseSet ls, int attempts, Hash to) Pick a reply tunnel from a LeaseSet for the store response.voidrunJob()Execute the job to start sending to the next batch of peers.private voidsendDirect(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send a store message directly to a peer with direct reply.private voidsendNext()Send the key to the next batch of peers.private voidsendStore(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send a store message to a peer via the appropriate delivery method.private voidsendStore(RouterInfo router, int responseTime) Send a store message directly to a peer.private voidsendStoreThroughClient(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send a leaseset store message out the client tunnel, with the reply to come back through a client tunnel.private voidsendStoreThroughExploratory(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send it out through an exploratory tunnel, with the reply to come back through an exploratory tunnel.private voidsendWrappedStoreThroughExploratory(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send a leaseset store message out an exploratory tunnel, with the reply to come back through a exploratory tunnel.(package private) static booleanIs it new enough?(package private) static booleanIs it new enough?(package private) static booleanIs it new enough?protected voidsucceed()Handle successful completion of the store operation.Methods inherited from class JobImpl
dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toStringModifier 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.toString()
Field Details
_log
Logger for this class._facade
Reference to the network database facade._state
Current state of the store operation._onSuccess
Job to run on successful store._onFailure
Job to run on failed store._timeoutMs
private final long _timeoutMsTimeout in milliseconds for the store operation._expiration
private final long _expirationExpiration time for the store operation._peerSelector
Peer selector for choosing floodfill participants._connectChecker
Checks if we can connect to a peer directly._connectMask
private final int _connectMaskBitmask for connection types we can use (IPv4, IPv6, etc.).PARALLELIZATION
REDUNDANCY
private static final int REDUNDANCYPeers the data should end up stored on.- See Also:
STORE_PRIORITY
private static final int STORE_PRIORITYPriority of this router's own netdb store.- See Also:
MAX_PEERS_SENT
private static final int MAX_PEERS_SENTMost peers one store job sends to in total.- See Also:
RESEND_DELAY
private static final int RESEND_DELAYPause before the next batch of sends: 1 second.- See Also:
MAX_DIRECT_EXPIRATION
private static final int MAX_DIRECT_EXPIRATIONLimit expiration for direct sends.- See Also:
MIN_STORE_VERSION
Short ECIES tunnel build messages (1.5.0).- See Also:
MIN_STORE_LS2_VERSION
Minimum version for LS2 stores.- See Also:
MIN_STORE_ENCLS2_VERSION
Was supported in 38, but they're now sigtype 11 which wasn't added until 39.- See Also:
Constructor Details
StoreJob
public StoreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, DatabaseEntry data, Job onSuccess, Job onFailure, long timeoutMs) Send a data structure to the floodfills.- Parameters:
context- the router contextfacade- the network database facadekey- the hash the data is to be stored underdata- the data to storeonSuccess- job to run on successonFailure- job to run on failuretimeoutMs- timeout in milliseconds
StoreJob
public StoreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key, DatabaseEntry data, Job onSuccess, Job onFailure, long timeoutMs, Set<Hash> toSkip) Send a data structure to the floodfills, skipping certain peers.- Parameters:
context- the router contextfacade- the network database facadekey- the hash the data is to be stored underdata- the data to storeonSuccess- job to run on successonFailure- job to run on failuretimeoutMs- timeout in millisecondstoSkip- set of peer hashes of people we don't want to send the data to (e.g. we already know they have it). This can be null.
Method Details
getName
runJob
public void runJob()Execute the job to start sending to the next batch of peers.isExpired
private boolean isExpired()Check if the store operation has expired.- Returns:
- true if the operation has timed out
sendNext
private void sendNext()Send the key to the next batch of peers.Synchronized to enforce parallelization limits and prevent dups.
getParallelization
protected int getParallelization()Maximum number of parallel store operations. Note: Overridden in Floodfill Search Job.- Returns:
- number of messages to send simultaneously
getRedundancy
protected int getRedundancy()Required redundancy level for successful store. Note: Overridden in Floodfill Search Job.- Returns:
- number of peers that must receive the data
continueSending
private void continueSending()Send a series of searches to the next available peers as selected by the routing table, but making sure no more than PARALLELIZATION are outstanding at any timeCaller should synchronize to enforce parallelization limits and prevent dups.
getClosestFloodfillRouters
Find the closest floodfill routers to a given key.- Parameters:
key- the target hash to find routers nearnumClosest- how many routers to returnalreadyChecked- set of router hashes to skip- Returns:
- list of closest floodfill router hashes, empty if there are no KBuckets
sendStore
Send a store message directly to a peer.- Parameters:
router- the floodfill to send the store message toresponseTime- timeout for the response in milliseconds
sendStore
Send a store message to a peer via the appropriate delivery method.- Parameters:
msg- the database store message to sendpeer- the router to send toexpiration- when the message expires
sendDirect
Send a store message directly to a peer with direct reply.- Parameters:
msg- the database store message to sendpeer- the router to send toexpiration- when the message expires
sendStoreThroughExploratory
private void sendStoreThroughExploratory(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send it out through an exploratory tunnel, with the reply to come back through an exploratory tunnel. There is no garlic encryption added.- Parameters:
msg- the store message to sendpeer- the remote peer to store atexpiration- when the message expires
sendStoreThroughClient
Send a leaseset store message out the client tunnel, with the reply to come back through a client tunnel. Stores are garlic encrypted to hide the identity from the OBEP.This makes it harder for an exploratory OBEP or IBGW to correlate it with one or more destinations. Since we are publishing the leaseset, it's easy to find out that an IB tunnel belongs to this dest, and it isn't much harder to do the same for an OB tunnel.
As a side benefit, client tunnels should be faster and more reliable than exploratory tunnels.
- Parameters:
msg- must contain a leasesetpeer- the remote peer to store atexpiration- when the message expires
pickReplyTunnel
Pick a reply tunnel from a LeaseSet for the store response.- Parameters:
ls- the LeaseSet containing available tunnelsattempts- number of previous attempts madeto- the target hash for closest selection- Returns:
- the selected lease
- Throws:
IllegalStateException- if no leases are available
sendWrappedStoreThroughExploratory
private void sendWrappedStoreThroughExploratory(DatabaseStoreMessage msg, RouterInfo peer, long expiration) Send a leaseset store message out an exploratory tunnel, with the reply to come back through a exploratory tunnel. Stores are garlic encrypted to hide the identity from the OBEP.Only for Meta LS2, for now.
- Parameters:
msg- must contain a leasesetpeer- the remote peer to store atexpiration- when the message expires
shouldStoreTo
Is it new enough?- Parameters:
ri- the router info to check- Returns:
- true if the router is new enough
shouldStoreLS2To
Is it new enough?- Parameters:
ri- the router info to check- Returns:
- true if the router supports LS2
shouldStoreEncLS2To
Is it new enough?- Parameters:
ri- the router info to check- Returns:
- true if the router supports encrypted LS2
succeed
protected void succeed()Handle successful completion of the store operation.Called when the required redundancy level is reached.
fail
protected void fail()Handle failed completion of the store operation.Called when the store operation has exhausted all options.