java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
net.i2p.router.tunnel.pool.IdleTunnelMonitor
All Implemented Interfaces:
Runnable

class IdleTunnelMonitorextends SimpleTimer2.TimedEvent
Monitors transit tunnels for idle behavior.

This class periodically scans participating tunnels and drops those that have carried no traffic at all since joining — but only as a pressure valve: culling is skipped unless the transit population is near the configured capacity, because every dropped tunnel looks like a failed tunnel to its originator. With defaults, quiet-but-alive tunnels live out their full lifetime. Expiration handles normal lifecycle.

Configurable properties: - router.idleTunnelDetectionPeriod: Time before checking for idle (default: 300000ms) - router.idleTunnelMinMessages: Minimum messages to not be considered idle (default: 1) - router.idleTunnelScanInterval: How often to scan (default: 60000ms).

  • Field Details

    • _context

      private final RouterContext _context
      The router context.
    • _log

      private final Log _log
      The log for the idle monitor.
    • _dispatcher

      private TunnelDispatcher _dispatcher
      The dispatcher whose tunnels are checked.
    • DEFAULT_DETECTION_PERIOD

      private static final long DEFAULT_DETECTION_PERIOD
      Default value of the router.idleTunnelDetectionPeriod property: five minutes, half of a tunnel's typical lifetime, so genuinely dead tunnels are still reaped well before expiry.
      See Also:
    • DEFAULT_MIN_MESSAGES

      private static final int DEFAULT_MIN_MESSAGES
      Floor of 1 drops only zero-message tunnels; higher values re-enable low-traffic culling.
      See Also:
    • DEFAULT_SCAN_INTERVAL

      private static final long DEFAULT_SCAN_INTERVAL
      Default interval between the idle scans.
      See Also:
    • PROP_DETECTION_PERIOD

      private static final String PROP_DETECTION_PERIOD
      Config key of the idle detection period, one of the only configurable settings.
      See Also:
    • PROP_MIN_MESSAGES

      private static final String PROP_MIN_MESSAGES
      Config key of the minimum messages for activity.
      See Also:
    • PROP_SCAN_INTERVAL

      private static final String PROP_SCAN_INTERVAL
      Config key of the idle scan interval.
      See Also:
    • CULL_CAPACITY_FRACTION

      protected static final double CULL_CAPACITY_FRACTION
      Transit usage fraction at or above which idle culling runs; below it, capacity is not under pressure and expiration alone handles lifecycle.
      See Also:
    • PROP_MAX_PARTICIPATING

      private static final String PROP_MAX_PARTICIPATING
      Config key of the most participating tunnels.
      See Also:
    • _isShutdown

      private volatile boolean _isShutdown
      True once the monitor shut down.
  • Constructor Details

    • IdleTunnelMonitor

      IdleTunnelMonitor(RouterContext ctx)
      Starts the scan timer and registers the dropped-tunnel stat.
      Parameters:
      ctx - the context supplying the timers, dispatcher, log and stat manager
  • Method Details

    • getDispatcher

      private TunnelDispatcher getDispatcher()
      The dispatcher, fetching from context if not yet initialized.
      Returns:
      the transit tunnel dispatcher, cached here after the first lookup
    • shutdown

      public void shutdown()
      Shut down the monitor and clean up resources.
    • timeReached

      public void timeReached()
      Description copied from class: SimpleTimer2.TimedEvent
      Called when this event's scheduled time arrives. Must NOT block. For periodic events, call schedule(period) at the end to self-reschedule.
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent
    • scanAndCleanup

      private void scanAndCleanup()
      Main scan method - checks all participating tunnels.
    • getPeerHash

      private Hash getPeerHash(HopConfig tunnel)
      The peer hash for a tunnel - this is the "entry point" peer who first introduced this tunnel to us (IBGW or closest hop to IBGW).
      Parameters:
      tunnel - the tunnel to find the entry point peer of
      Returns:
      the peer hash
    • nearCapacity

      static boolean nearCapacity(int participating, int maxParticipating)
      Whether the transit population is close enough to configured capacity that idle culling is worthwhile. Pure decision helper, package visible for tests.
      Parameters:
      participating - current transit tunnel count
      maxParticipating - the configured participating-tunnel capacity
      Returns:
      true if usage is at or above CULL_CAPACITY_FRACTION; false when capacity is unknown or usage is below it
    • dropTunnel

      void dropTunnel(HopConfig tunnel)
      Drop an idle tunnel by removing it from the dispatcher.

      Package-visible so a test can drive a single drop against a dispatcher it controls and check the bandwidth accounting exactly.

      Parameters:
      tunnel - the idle tunnel to drop