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

class StartExplorersJobextends JobImpl
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 Details

    • MAX_PER_RUN

      private static final int MAX_PER_RUN
      Explorations started in one run.
      See Also:
    • MAX_EXPLORE_JOBS

      private static final int MAX_EXPLORE_JOBS
      Explore jobs queued at once.
      See Also:
    • MIN_RERUN_DELAY_MS

      private static final int MIN_RERUN_DELAY_MS
      Shortest delay before the job runs again.
      See Also:
    • MAX_RERUN_DELAY_MS

      private static final int MAX_RERUN_DELAY_MS
      Longest delay before the job runs again.
      See Also:
    • STARTUP_TIME

      private static final int STARTUP_TIME
      Startup time treated as a cold network database.
      See Also:
    • MIN_ROUTERS

      private static final int MIN_ROUTERS
      Router count below which we explore more.
      See Also:
    • LOW_ROUTERS

      private static final int LOW_ROUTERS
      Router count treated as a thin network.
      See Also:
    • MAX_ROUTERS

      private static final int MAX_ROUTERS
      Router count treated as a full network.
      See Also:
    • MIN_FFS

      private static final int MIN_FFS
      Floodfills we want in the network database.
      See Also:
    • LOW_FFS

      static final int LOW_FFS
      Low floodfills threshold.
      See Also:
    • MAX_LAG

      private static final long MAX_LAG
      Job queue lag that counts as behind.
      See Also:
    • MAX_MSG_DELAY

      private static final long MAX_MSG_DELAY
      Message delay that counts as behind.
      See Also:
    • DELAY_SPREAD_BASE

      private static final long DELAY_SPREAD_BASE
      Base spread of the rerun delays.
      See Also:
    • DELAY_SPREAD_VARIANCE

      private static final long DELAY_SPREAD_VARIANCE
      Random extra spread of the rerun delays.
      See Also:
    • LAGGED_DELAY_MS

      private static final long LAGGED_DELAY_MS
      Rerun delay while the router is lagged.
      See Also:
    • PROP_EXPLORE_DELAY

      static final String PROP_EXPLORE_DELAY
      Property to configure exploration delay.
      See Also:
    • PROP_EXPLORE_BUCKETS

      static final String PROP_EXPLORE_BUCKETS
      Property to configure number of buckets to explore.
      See Also:
    • PROP_FORCE_EXPLORE

      static final String PROP_FORCE_EXPLORE
      Property to force exploration even when floodfill.
      See Also:
    • _log

      private final Log _log
      Logger for the explorer startup.
    • _facade

      private final KademliaNetworkDatabaseFacade _facade
      The facade the explorers serve.
    • _msgIDBloomXor

      private final long _msgIDBloomXor
      Random mask for the message id bloom filter.
    • BUCKET_REFRESH_AGE

      private static final long BUCKET_REFRESH_AGE
      A 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

      public StartExplorersJob(RouterContext context, KademliaNetworkDatabaseFacade facade)
      Job to manage peer exploration scheduling.
      Parameters:
      context - the router context
      facade - the network database facade to interact with peer data
  • 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, "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

      private boolean shouldExplore(long lag, long msgDelay, CommSystemFacade.Status commStatus)
      Determines if conditions allow for exploration based on lag, message delay, and comm status.
      Parameters:
      lag - the current maximum job queue lag in ms
      msgDelay - the current message delay in ms
      commStatus - 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 override
      datastoreSize - number of known peers in the data store
      lag - maximum lag of job queue, in ms
      msgDelay - current message delay, in ms
      highLoad - whether the system is deemed under high load
      Returns:
      number of explorations to run this cycle
    • scheduleNextRun

      private void scheduleNextRun(RouterContext ctx, long lag, long msgDelay, boolean highLoad)
      Schedules the next job run based on current load and configured delay properties.
      Parameters:
      ctx - router context, read for the exploreDelay property override
      lag - current max lag in ms
      msgDelay - current message delay in ms
      highLoad - 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

      private Set<Hash> 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.
      Parameters:
      num - number of keys to select
      Returns:
      a set of keys to explore of size 'num'