java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.tunnel.pool.ExpireJob
All Implemented Interfaces:
Job

class ExpireJobextends JobImpl
Handles tunnel expiration in two phases for graceful shutdown. Uses batch processing to reduce job queue overhead. First run removes tunnel from LeaseSet and triggers refresh. Second run stops accepting data for the tunnel entirely. Uses randomized early expiration with different timing for inbound vs outbound tunnels.
  • Field Details

    • _expirations

      private static final ConcurrentHashMap<Long, ExpireJob.TunnelExpiration> _expirations
      The tunnels being expired, by tunnel key.
    • _isScheduled

      private static volatile boolean _isScheduled
      True while the job is scheduled.
    • BATCH_WINDOW

      private static final long BATCH_WINDOW
      Expiration window handled per run.
      See Also:
    • OB_EARLY_EXPIRE

      private static final long OB_EARLY_EXPIRE
      How early outbound tunnels are replaced.
      See Also:
    • IB_EARLY_EXPIRE

      private static final long IB_EARLY_EXPIRE
      How early inbound tunnels are replaced.
      See Also:
    • LEASESET_GRACE_PERIOD

      private static final long LEASESET_GRACE_PERIOD
      Keep tunnels alive for 10 minutes after LeaseSet refresh so clients with cached (stale) LeaseSets can still connect using old tunnel IDs.
      See Also:
    • MAX_ENTRY_LIFETIME

      private static final long MAX_ENTRY_LIFETIME
      Longest an entry may stay in the map. With early expiration the entries live about 21 minutes; the extra time covers clock skew and slow job execution.
      See Also:
    • MAX_ITERATE_PER_RUN

      private static final int MAX_ITERATE_PER_RUN
      Entries examined per normal run.
      See Also:
    • MAX_ITERATE_BACKED_UP

      private static final int MAX_ITERATE_BACKED_UP
      Entries examined when pools are short.
      See Also:
    • BACKED_UP_THRESHOLD

      private static final int BACKED_UP_THRESHOLD
      Build failures counting as backed up.
      See Also:
    • MAX_UNTESTED_EXTENSIONS

      static final int MAX_UNTESTED_EXTENSIONS
      Maximum number of times an UNTESTED tunnel's expiry can be extended to give tests time to complete. Each extension is UNTESTED_EXTENSION_MS.
      See Also:
    • UNTESTED_EXTENSION_MS

      static final long UNTESTED_EXTENSION_MS
      How long to extend an UNTESTED tunnel's expiry each time. 30s gives the test pipeline enough time for one full test cycle.
      See Also:
  • Constructor Details

    • ExpireJob

      private ExpireJob(RouterContext ctx)
      Constructor for the batch job, with no tunnel config.
      Parameters:
      ctx - the router context
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Job
      Descriptive name of the task.
      Returns:
      the descriptive name of the task
    • scheduleExpiration

      public static void scheduleExpiration(RouterContext ctx, PooledTunnelCreatorConfig cfg)
      Schedule a tunnel for batched expiration. Applies randomized early expiration to reduce the chance of LeaseSet/tunnel mismatch during the transition period. If the tunnel is already scheduled with a later expiration (e.g. by BuildExecutor at build completion), an earlier expiration set by the caller on the config is merged in so early-expiry paths (slow-tunnel removal, budget pruning) actually take effect.
      Parameters:
      ctx - the router context
      cfg - the tunnel config to expire
    • expirationLine

      static String expirationLine(long key, long expire, long dropAt, long now)
      The entry recording when a tunnel expires and when it is dropped for good, as durations from now rather than raw epoch milliseconds.
      Parameters:
      key - the tunnel's id, as used in the expiration map
      expire - when phase 1 replaces the tunnel, in ms
      dropAt - when the tunnel is dropped, in ms
      now - the current time, in ms
      Returns:
      the log entry, never null
    • removeFromExpiration

      public static void removeFromExpiration(PooledTunnelCreatorConfig cfg)
      Remove a tunnel from the expiration queue. Called during pool shutdown to prevent memory leaks.
      Parameters:
      cfg - config to remove
    • getTunnelKey

      public static Long getTunnelKey(PooledTunnelCreatorConfig cfg)
      Get the unique key for this tunnel config. Uses tunnel IDs when available; falls back to identity hash for partially cleaned-up or zero-ID configs.
      Parameters:
      cfg - the tunnel config whose expiration key is wanted; may be null
      Returns:
      key or null
    • runJob

      public void runJob()
      Description copied from interface: Job
      Actually perform the task. This call blocks until the Job is complete.
    • runPhase

      private void runPhase(Log log, long now)
      Runs one expiration phase.
      Parameters:
      log - the logger for the phase
      now - the current time