- All Implemented Interfaces:
Runnable
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 Summary
FieldsModifier and TypeFieldDescription(package private) static final intdecideQuantity(int, int, int)return value meaning the session should be left alone.Fields inherited from class SimpleTimer2.TimedEvent
_state, DEFAULT_FUZZModifier and TypeFieldDescriptionprotected net.i2p.util.SimpleTimer2.TimedEventStateState of the current event.protected static final intDefault fuzz threshold in milliseconds.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescription(package private) static intdecideQuantity(int peerCount, int currentQuantity, int noRunningConsec) Decide whether to reconfigure the session's tunnel quantity.(package private) static intdesiredQuantity(int peerCount) The tunnel count to hold in each direction given the connected peers, never below the floor.intThe inbound tunnel count currently applied to the shared session.intThe outbound tunnel count currently applied to the shared session.voidCalled when this event's scheduled time arrives.Methods inherited from class SimpleTimer2.TimedEvent
cancel, forceReschedule, reschedule, reschedule, run, schedule, setFuzz, setPool, toStringModifier and TypeMethodDescriptionbooleancancel()Cancel the timed event.voidforceReschedule(long timeoutMs) Always use the new time - ignores fuzz.voidreschedule(long timeoutMs) Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there.voidreschedule(long timeoutMs, boolean useEarliestTime) May be called from within timeReached(), but schedule() is better there.voidrun()voidschedule(long timeoutMs) Schedule this event.voidsetFuzz(int fuzz) Reschedule threshold in ms.voidsetPool(SimpleTimer2 pool) Timer pool for this event.toString()Timer summary for log messages.
Field Details
NO_CHANGE
static final int NO_CHANGEdecideQuantity(int, int, int)return value meaning the session should be left alone.- See Also:
Constructor Details
IdleChecker
Caller must schedule.- Parameters:
mgr- the SnarkManager providing the util and owning this timerpcs- the peer set whose connectivity state decides whether tunnels may be released
Method Details
timeReached
public void timeReached()Description copied from class:SimpleTimer2.TimedEventCalled when this event's scheduled time arrives. Must NOT block. For periodic events, call schedule(period) at the end to self-reschedule.- Specified by:
timeReachedin classSimpleTimer2.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:
I2PSnarkUtilcaps the session atMIN_TUNNEL_QTYwhen 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 torrentscurrentQuantity- quantity most recently applied to the sessionnoRunningConsec- consecutive checks that have found no running torrent- Returns:
- the new quantity to apply in each direction, or
NO_CHANGEto 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 matchesgetActiveInboundCount().- Returns:
- the active outbound count, never below
MIN_TUNNEL_QTY