- All Implemented Interfaces:
Runnable
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router context.private TunnelDispatcherThe dispatcher whose tunnels are checked.private booleanTrue once the monitor shut down.private final LogThe log for the idle monitor.protected static final doubleTransit usage fraction at or above which idle culling runs; below it, capacity is not under pressure and expiration alone handles lifecycle.private static final longDefault 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.private static final intFloor of 1 drops only zero-message tunnels; higher values re-enable low-traffic culling.private static final longDefault interval between the idle scans.private static final StringConfig key of the idle detection period, one of the only configurable settings.private static final StringConfig key of the most participating tunnels.private static final StringConfig key of the minimum messages for activity.private static final StringConfig key of the idle scan interval.Fields inherited from class SimpleTimer2.TimedEvent
_state, DEFAULT_FUZZModifier and TypeFieldDescriptionprotected SimpleTimer2.TimedEventStateState of the current event.protected static final intDefault fuzz threshold in milliseconds.Constructor Summary
ConstructorsConstructorDescriptionStarts the scan timer and registers the dropped-tunnel stat.Method Summary
Modifier and TypeMethodDescription(package private) voiddropTunnel(HopConfig tunnel) Drop an idle tunnel by removing it from the dispatcher.private TunnelDispatcherThe dispatcher, fetching from context if not yet initialized.private HashgetPeerHash(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).(package private) static booleannearCapacity(int participating, int maxParticipating) Whether the transit population is close enough to configured capacity that idle culling is worthwhile.private voidMain scan method - checks all participating tunnels.voidshutdown()Shut down the monitor and clean up resources.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
_context
The router context._log
The log for the idle monitor._dispatcher
The dispatcher whose tunnels are checked.DEFAULT_DETECTION_PERIOD
private static final long DEFAULT_DETECTION_PERIODDefault 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_MESSAGESFloor 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_INTERVALDefault interval between the idle scans.- See Also:
PROP_DETECTION_PERIOD
Config key of the idle detection period, one of the only configurable settings.- See Also:
PROP_MIN_MESSAGES
Config key of the minimum messages for activity.- See Also:
PROP_SCAN_INTERVAL
Config key of the idle scan interval.- See Also:
CULL_CAPACITY_FRACTION
protected static final double CULL_CAPACITY_FRACTIONTransit 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
Config key of the most participating tunnels.- See Also:
_isShutdown
private volatile boolean _isShutdownTrue 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
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.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
scanAndCleanup
private void scanAndCleanup()Main scan method - checks all participating tunnels.getPeerHash
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 countmaxParticipating- 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
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