java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.networkdb.kademlia.RefreshRoutersJob
- All Implemented Interfaces:
Job
RefreshRoutersJob performs router info refresh operations periodically.
After startup, refetches router infos, prioritizing floodfill routers, to keep the network database fresh and healthy. This class tries to balance load and avoid overload by controlling timing and refresh intervals.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classDisconnects a router whose refresh has stalled.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FloodfillNetworkDatabaseFacadeThe facade whose routers are refreshed.private final LogLogger for this class.private static final RandomShared instance, for the jitter and delays below.private longHow long to wait before restarting a stalled refresh - 1 minute.The routers still to visit this cycle, highest-value first.Constructor Summary
ConstructorsConstructorDescriptionRefreshRoutersJob(RouterContext ctx, FloodfillNetworkDatabaseFacade facade) Stores the network database and the log the refresh runs under.Method Summary
Modifier and TypeMethodDescriptionprivate voidAdjust _restartDelayMs based on known router count and uptime.getName()Name of this job.private intgetRouterAgeThreshold(boolean uninteresting, boolean refreshUninteresting, int netDbCount, long _uptime, boolean isFloodfill) Returns the router age threshold in milliseconds for refresh decision.private voidInitializes the router list with floodfill routers sorted first, then all other routers sorted by performance score.private voidLogs completion message when refresh cycle finishes.private voidLogs job suspension reasons if not running.private voidperformRouterRefresh(Hash routerHash, RouterInfo ri) Performs the router refresh operation by calling the facade search with proper timeout.private voidProcesses the next router(s) in the list to determine whether to refresh their info.voidrunJob()Entry point for the job execution.private voidSchedules the next run of the job with randomized delay.private intScore a peer for refresh priority.private booleanshouldRefreshRouter(RouterInfo ri, Hash _routerHash) Determines whether to refresh the given router info.private booleanChecks if conditions are suitable for running the refresh job.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
The facade whose routers are refreshed._routers
_restartDelayMs
private long _restartDelayMsHow long to wait before restarting a stalled refresh - 1 minute._random
Shared instance, for the jitter and delays below.
Constructor Details
RefreshRoutersJob
Stores the network database and the log the refresh runs under.- Parameters:
ctx- the router contextfacade- the network database the job refetches router infos through
Method Details
getName
Name of this job.- Returns:
- the name this job is listed under in the job queue and the logs, "Refresh NetDb Routers"
runJob
public void runJob()Entry point for the job execution. Performs checks and delegates detailed router refresh logic.shouldRunJob
private boolean shouldRunJob()Checks if conditions are suitable for running the refresh job.- Returns:
- whether run job
logSuspendedReason
private void logSuspendedReason()Logs job suspension reasons if not running.scorePeer
Score a peer for refresh priority. Higher score = refresh sooner (high-value peers first).- Parameters:
peer- the router to score from its RouterInfo in the local NetDb- Returns:
- the score, 0 when the router is not cached locally or has no valuable capability
initializeRouterListIfNeeded
private void initializeRouterListIfNeeded()Initializes the router list with floodfill routers sorted first, then all other routers sorted by performance score.adjustRestartDelayBasedOnNetDbCount
private void adjustRestartDelayBasedOnNetDbCount()Adjust _restartDelayMs based on known router count and uptime.logRefreshCompletion
private void logRefreshCompletion()Logs completion message when refresh cycle finishes.processNextRouterForRefresh
private void processNextRouterForRefresh()Processes the next router(s) in the list to determine whether to refresh their info. Processes up torouter.refreshBatchSizerouters (default 5) per invocation for faster coverage.shouldRefreshRouter
Determines whether to refresh the given router info. Includes checks for age, version, capabilities, and context properties.- Parameters:
ri- the router info whose age and capabilities are examined_routerHash- unused, the hash is taken from ri instead- Returns:
- true if the router has been published longer than its age threshold
getRouterAgeThreshold
private int getRouterAgeThreshold(boolean uninteresting, boolean refreshUninteresting, int netDbCount, long _uptime, boolean isFloodfill) Returns the router age threshold in milliseconds for refresh decision.- Parameters:
uninteresting- true for a router flagged unreachable, low bandwidth, or old versionrefreshUninteresting- the router.refreshUninteresting property, true to refresh those routers on the normal schedulenetDbCount- the routers we know, a larger NetDb gets a longer threshold_uptime- unused, the caller has already applied the uptime gateisFloodfill- true if we are a floodfill, which uses the longer thresholds- Returns:
- the age in milliseconds a router must exceed before it is refreshed again
performRouterRefresh
Performs the router refresh operation by calling the facade search with proper timeout.- Parameters:
routerHash- the router to look up againri- its current router info, used for the reverse DNS lookup and the log line
scheduleNextRunRandom
private void scheduleNextRunRandom()Schedules the next run of the job with randomized delay. Delay depends on router count, system load, and configured properties.