java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.networkdb.kademlia.RefreshRoutersJob
All Implemented Interfaces:
Job

class RefreshRoutersJobextends JobImpl
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.

  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _facade

      private final FloodfillNetworkDatabaseFacade _facade
      The facade whose routers are refreshed.
    • _routers

      private Deque<Hash> _routers
      The routers still to visit this cycle, highest-value first. A deque, not an ArrayList: the job drains from the head a few at a time, and ArrayList.remove(0) shifts every remaining element - up to the whole netdb - on each visit.
    • _restartDelayMs

      private long _restartDelayMs
      How long to wait before restarting a stalled refresh - 1 minute.
    • _random

      private static final Random _random
      Shared instance, for the jitter and delays below.
  • Constructor Details

    • RefreshRoutersJob

      public RefreshRoutersJob(RouterContext ctx, FloodfillNetworkDatabaseFacade facade)
      Stores the network database and the log the refresh runs under.
      Parameters:
      ctx - the router context
      facade - the network database the job refetches router infos through
  • Method Details

    • getName

      public String 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

      private int scorePeer(Hash peer)
      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 to router.refreshBatchSize routers (default 5) per invocation for faster coverage.
    • shouldRefreshRouter

      private boolean shouldRefreshRouter(RouterInfo ri, Hash _routerHash)
      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 version
      refreshUninteresting - the router.refreshUninteresting property, true to refresh those routers on the normal schedule
      netDbCount - the routers we know, a larger NetDb gets a longer threshold
      _uptime - unused, the caller has already applied the uptime gate
      isFloodfill - 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

      private void performRouterRefresh(Hash routerHash, RouterInfo ri)
      Performs the router refresh operation by calling the facade search with proper timeout.
      Parameters:
      routerHash - the router to look up again
      ri - 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.