All Implemented Interfaces:
Runnable

class IdleCheckerextends SimpleTimer2.TimedEvent
Periodically ramp the tunnel count with connected peers, and reduce it once nothing is running. We can't use the I2CP idle detector because it's based on traffic, so DHT and announces would keep it non-idle.

The floor is keyed on whether a torrent is *running*, not on the peer count: a started torrent with no peers yet is still announcing, still DHT-serving and still holding a LeaseSet, and dropping its tunnels out from under it would stall every one of those. Peers only ever raise a count above its floor.

Each session is floored independently at MIN_TUNNEL_QTY in each direction. In single-destination mode that is one shared session, which also carries the trackers, the DHT and the announces, so it is floored whenever any torrent runs at all. Under multi-dest the shared session is joined by one destination per pool (or per torrent), and each of those keeps its own floor for as long as it still has torrents assigned - a pool is never dragged below 2/2 because a sibling pool is busy, nor raised because one is.

Reducing is hysteretic and one-directional per check: growth applies immediately, while a reduction has to be wanted for SHRINK_HYSTERESIS consecutive checks. BitTorrent peer counts swing across any threshold within a few seconds, so recomputing a target from peerCount / 2 every CHECK_TIME ms and pushing it at the router made the pool oscillate, and every oscillation is a ReconfigureSessionMessage that destroys the surplus tunnels outright rather than letting them expire.

  • Field Details

  • Constructor Details

    • IdleChecker

      public IdleChecker(SnarkManager mgr, PeerCoordinatorSet pcs)
      Caller must schedule.
      Parameters:
      mgr - the SnarkManager providing the util and owning this timer
      pcs - the peer set whose connectivity state decides whether tunnels may be released
  • Method Details

    • 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
    • desiredQuantity

      static int desiredQuantity(int peerCount)
      The tunnel count to hold in each direction given the connected peers, never below the floor.
      Parameters:
      peerCount - total connected peers across all running torrents
      Returns:
      the desired quantity in each direction, at least MIN_TUNNEL_QTY
    • decideQuantity

      static int decideQuantity(int peerCount, int currentQuantity, int noRunningConsec)
      Decide whether to reconfigure the session's tunnel quantity.

      Pure decision logic, split out so it can be exercised without a router. The quantity currently applied is taken as a parameter rather than read from the configured options: I2PSnarkUtil caps the session at MIN_TUNNEL_QTY when it is created, while the configured options still read the operator's larger figure. Comparing against the configured value made every check believe the pool was oversized and reissue a reconfiguration, so the applied quantity is passed in.

      Parameters:
      peerCount - total connected peers across all running torrents
      currentQuantity - quantity most recently applied to the session
      noRunningConsec - consecutive checks that have found no running torrent
      Returns:
      the new quantity to apply in each direction, or NO_CHANGE to leave the session alone
    • getActiveInboundCount

      public int getActiveInboundCount()
      The inbound tunnel count currently applied to the shared session.
      Returns:
      the active inbound count, never below MIN_TUNNEL_QTY
    • getActiveOutboundCount

      public int getActiveOutboundCount()
      The outbound tunnel count currently applied to the shared session. Inbound and outbound are always pushed together, so this matches getActiveInboundCount().
      Returns:
      the active outbound count, never below MIN_TUNNEL_QTY