java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.networkdb.kademlia.StartExplorersJob
- All Implemented Interfaces:
Job
This job initiates exploration of the network database by selecting keys to explore and queuing ExploreJobs up to a maximum per run. It adjusts the exploration frequency and intensity based on network conditions such as number of known routers, floodfills, system load, and message delays.
For hidden routers, this job helps maintain integration in the network by aggressively exploring when known peers are few and reducing load otherwise. The job is scheduled to run repeatedly with delays adapted to system load and network state.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final KademliaNetworkDatabaseFacadeThe facade the explorers serve.private final LogLogger for the explorer startup.private final longRandom mask for the message id bloom filter.private static final longA bucket untouched for this long gets a targeted explore key even if reasonably full.private static final longBase spread of the rerun delays.private static final longRandom extra spread of the rerun delays.private static final longRerun delay while the router is lagged.(package private) static final intLow floodfills threshold.private static final intRouter count treated as a thin network.private static final intExplore jobs queued at once.private static final longJob queue lag that counts as behind.private static final longMessage delay that counts as behind.private static final intExplorations started in one run.private static final intLongest delay before the job runs again.private static final intRouter count treated as a full network.private static final intFloodfills we want in the network database.private static final intShortest delay before the job runs again.private static final intRouter count below which we explore more.(package private) static final StringProperty to configure number of buckets to explore.(package private) static final StringProperty to configure exploration delay.(package private) static final StringProperty to force exploration even when floodfill.private static final intStartup time treated as a cold network database.Constructor Summary
ConstructorsConstructorDescriptionStartExplorersJob(RouterContext context, KademliaNetworkDatabaseFacade facade) Job to manage peer exploration scheduling.Method Summary
Modifier and TypeMethodDescriptionprivate intdetermineNumExplorations(RouterContext ctx, int datastoreSize, long lag, long msgDelay, boolean highLoad) Dynamically determines the number of explorations to run based on system state.getName()Name of this job.private longCalculates the delay until the next peer exploration job run based on router state and uptime.voidrunJob()Runs the job, determines if exploration should occur, how many explorations to run, selects keys to explore, creates and queues ExploreJobs, and schedules the next run.private voidscheduleNextRun(RouterContext ctx, long lag, long msgDelay, boolean highLoad) Schedules the next job run based on current load and configured delay properties.selectKeysToExplore(int num) Selects a set of keys from the exploration pool, supplementing with bucket-targeted keys (classic Kademlia bucket refresh) and then random keys if needed.private booleanshouldExplore(long lag, long msgDelay, CommSystemFacade.Status commStatus) Determines if conditions allow for exploration based on lag, message delay, and comm status.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
MAX_PER_RUN
MAX_EXPLORE_JOBS
MIN_RERUN_DELAY_MS
private static final int MIN_RERUN_DELAY_MSShortest delay before the job runs again.- See Also:
MAX_RERUN_DELAY_MS
private static final int MAX_RERUN_DELAY_MSLongest delay before the job runs again.- See Also:
STARTUP_TIME
private static final int STARTUP_TIMEStartup time treated as a cold network database.- See Also:
MIN_ROUTERS
private static final int MIN_ROUTERSRouter count below which we explore more.- See Also:
LOW_ROUTERS
private static final int LOW_ROUTERSRouter count treated as a thin network.- See Also:
MAX_ROUTERS
private static final int MAX_ROUTERSRouter count treated as a full network.- See Also:
MIN_FFS
private static final int MIN_FFSFloodfills we want in the network database.- See Also:
LOW_FFS
MAX_LAG
MAX_MSG_DELAY
private static final long MAX_MSG_DELAYMessage delay that counts as behind.- See Also:
DELAY_SPREAD_BASE
private static final long DELAY_SPREAD_BASEBase spread of the rerun delays.- See Also:
DELAY_SPREAD_VARIANCE
private static final long DELAY_SPREAD_VARIANCERandom extra spread of the rerun delays.- See Also:
LAGGED_DELAY_MS
private static final long LAGGED_DELAY_MSRerun delay while the router is lagged.- See Also:
PROP_EXPLORE_DELAY
Property to configure exploration delay.- See Also:
PROP_EXPLORE_BUCKETS
Property to configure number of buckets to explore.- See Also:
PROP_FORCE_EXPLORE
Property to force exploration even when floodfill.- See Also:
_log
Logger for the explorer startup._facade
The facade the explorers serve._msgIDBloomXor
private final long _msgIDBloomXorRandom mask for the message id bloom filter.BUCKET_REFRESH_AGE
private static final long BUCKET_REFRESH_AGEA bucket untouched for this long gets a targeted explore key even if reasonably full. Two full explore-job rerun periods.- See Also:
Constructor Details
StartExplorersJob
Job to manage peer exploration scheduling.- Parameters:
context- the router contextfacade- the network database facade to interact with peer data
Method Details
getName
Name of this job.- Returns:
- the name this job is listed under in the job queue and the logs, "Start NetDb Explorers"
runJob
public void runJob()Runs the job, determines if exploration should occur, how many explorations to run, selects keys to explore, creates and queues ExploreJobs, and schedules the next run.shouldExplore
Determines if conditions allow for exploration based on lag, message delay, and comm status.- Parameters:
lag- the current maximum job queue lag in msmsgDelay- the current message delay in mscommStatus- current communication system status- Returns:
- true if exploration should proceed
determineNumExplorations
private int determineNumExplorations(RouterContext ctx, int datastoreSize, long lag, long msgDelay, boolean highLoad) Dynamically determines the number of explorations to run based on system state. Also respects configured overrides from context properties.- Parameters:
ctx- router context, read for the exploreBuckets property overridedatastoreSize- number of known peers in the data storelag- maximum lag of job queue, in msmsgDelay- current message delay, in mshighLoad- whether the system is deemed under high load- Returns:
- number of explorations to run this cycle
scheduleNextRun
Schedules the next job run based on current load and configured delay properties.- Parameters:
ctx- router context, read for the exploreDelay property overridelag- current max lag in msmsgDelay- current message delay in mshighLoad- whether the system is under high load
getNextRunDelay
private long getNextRunDelay()Calculates the delay until the next peer exploration job run based on router state and uptime.- Returns:
- delay in milliseconds before the next exploration run
selectKeysToExplore