- All Implemented Interfaces:
Service, TunnelManagerFacade
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classBuilds tunnels for a pool that never came up.private static classConditionally start the outbound pool after the inbound pool has at least one tunnel.private classDelayed cleanup task for pool removal.(package private) static classBackground reachability probe over the peers a client pool would provisionally use as a first hop.private static classJob to refresh LeaseSets after slow tunnel removal.private static classPeriodically drops tunnels that fail the latency test.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Hash, TunnelPool> Hash (destination) to TunnelPool.private final Map<Hash, TunnelPool> Hash (destination) to TunnelPool.private final TunnelPeerSelectorPeer selector shared by the client pools.private final RouterContextThe router context.private final intSteady-state share of tunnels allowed to clients.private final BuildExecutorRuns the tunnel build requests.private final GhostPeerManagerTracks peers that keep failing builds.private final BuildHandlerMatches build replies to the requests.private static final AtomicIntegerCounter naming the handler threads.private final CopyOnWriteArrayList<I2PThread> The running handler threads.private final TunnelPoolThe router's inbound exploratory pool.private booleanTrue once the manager has shut down.private longWall-clock ms at which some pool last published an incomplete LeaseSet, or 0 if never.private longWall-clock ms of the last participation-share log, for rate limiting.private final LogLogger for pool management.private static intThreads running the build handler.private final TunnelPoolThe router's outbound exploratory pool.private final Map<Hash, TunnelPoolManager.DelayedPoolCleanup> Pending delayed cleanups for pool removal.private final Map<Hash, TunnelPoolManager.ConditionalOutboundStartup> Pending delayed outbound pool startups, keyed by destination hash.private final intLarger share allowed while the router starts up.private static final intThe derived threshold never falls below 10 seconds.private static final intTries to bring up the outbound pool at startup.private static final intSlow tunnels are checked every 60 seconds.private static final intZero means derive the threshold from average latency.(package private) static final doubleRelief factor applied while any pool has published an incomplete LeaseSet.(package private) static final longHow long an incomplete-LeaseSet observation keeps relief active, in ms.private static final doubleLargest client share ratio accepted.private static final longDelay before removing pools after client disconnect.private static final StringConfig key turning tunnel testing off.(package private) static final StringProperty: outbound tunnel startup retries.private static final StringConfig key for how often slow tunnels are checked.private static final StringConfig key for the floor on the slow tunnel threshold.private static final StringConfig key for the slow tunnel latency threshold.private static final longReplacement tunnels get 15 seconds to build before a refresh.private static final longMinimum ms between participation-share limit log lines.(package private) static final doubleBuild success at or below which relief reaches its full factor of 2.(package private) static final doubleBuild success at or above which no build-success relief is applied.Constructor Summary
ConstructorsConstructorDescriptionManage tunnel pools for the given router context.Method Summary
Modifier and TypeMethodDescriptionbooleanaddAlias(Destination dest, ClientTunnelSettings settings, Destination existingClient) Add another destination to the same tunnels.voidadjustBuildHandlerThreads(int target) Dynamically adjust BuildHandler thread count to match target.(package private) voidQueue a recurring test job if appropriate.(package private) static doublebuildSuccessRelief(double buildSuccess) Graded relief factor for the per-peer participation share, from tunnel build success.voidbuildTunnels(Destination client, ClientTunnelSettings settings) Used only at session startup.private voidcancelPendingOutboundStartup(Hash destination) Cancel any pending outbound startup event for the destination.intEmergency pool recovery: Check all registered clients have valid tunnel pools.private intcountTunnelsPerPeer(ObjectCounterUnsafe<Hash> lc, boolean exploratory) Count tunnels and peers separately for exploratory or client pools.booleanReport whether periodic tunnel testing is switched off.private voiddoRemoveTunnels(Hash destination) Actually perform pool removal.intensurePoolsFor(Hash client) Nudge both of a local client's pools to run their ensure logic.(package private) static booleanexceedsShareLimit(int count, int total, int maxPct) Whether a peer's share of tunnel participation exceeds the limit.voidFail all outbound tunnels with this peer as first hop, and all inbound tunnels with this peer as the last hop, because we can't contact it any more.private voidfailTunnelsWithFirstHop(TunnelPool pool, Hash peer) Fail all (outbound) tunnels with this peer as first hop (not counting us).private voidfailTunnelsWithLastHop(TunnelPool pool, Hash peer) Fail all (inbound) tunnels with this peer as last hop (not counting us).voidforceRemoveTunnels(Hash destination) Force immediate removal of a pool - used for router shutdown.voidforceTunnelFailure(TunnelInfo tunnel) Force a tunnel to fail immediately and trigger a replacement build.intActual number of running BuildHandler threads.static intTuned by Tuner — min 2, max 8.(package private) BuildExecutorReturn the shared thread pool that runs tunnel builds.intNumber of valid (non-failed, non-expired) inbound exploratory tunnels.The ghost peer manager for tracking unresponsive peers.intSize of the inbound build queue.For TunnelRenderer in router console.intNumber of GOOD (tested+passed, non-failed, non-expired) inbound client tunnels across all destinations.intgetInboundClientTunnelCount(Hash destination) Use to verify a tunnel pool is alive.For TunnelRenderer in router console.getInboundPool(Hash client) The client's inbound pool, creating it if needed.The inbound exploratory tunnel pool settings.getInboundSettings(Hash client) Get settings for a client's inbound tunnel pool.longThe expiration time of the last participating tunnel.For TunnelRenderer in router console.intNumber of GOOD (tested+passed, non-failed, non-expired) outbound client tunnels across all destinations.intgetOutboundClientTunnelCount(Hash destination) Use to verify a tunnel pool is alive.For TunnelRenderer in router console.getOutboundPool(Hash client) The client's outbound pool, creating it if needed.The outbound exploratory tunnel pool settings.getOutboundSettings(Hash client) Get settings for a client's outbound tunnel pool.intNumber of valid (non-failed, non-expired) outbound exploratory tunnels.intThe number of tunnels we're participating in as a gateway or endpoint.doubleGet the share ratio of participating tunnels.intgetUsableInboundClientTunnelCount(Hash destination) Get USABLE inbound client tunnel count for a specific destination.intgetUsableOutboundClientTunnelCount(Hash destination) Get USABLE outbound client tunnel count for a specific destination.(package private) booleanhasRecentIncompleteLeaseSet(long now) Whether an incomplete-LeaseSet observation is recent enough to still justify relaxing the participation share.booleanReport whether the router is firewalled on either address family.(package private) booleanWhether the manager has been shut down.booleanisValidTunnel(Hash client, TunnelInfo tunnel) Check if a tunnel is valid and belongs to the client's pool.voidlistPools(List<TunnelPool> out) List of TunnelPool instances currently in play.voidLog pool health summary for monitoring.private voidlogShareLimit(long now, int basePct, int max, double buildSuccess, boolean firewalled, boolean incompleteLeaseSet, int excluded) Rate-limited log of the participation share limit actually in force, so a surprising exclusion count can be read against the reason for it instead of guessed at.(package private) static StringnoPoolLine(boolean inbound, Hash destination) The entry for a destination with no client pool of the given direction, so a null return from the selector carries a reason in the log.(package private) voidnoteIncompleteLeaseSet(long now) Note that some pool published an incomplete LeaseSet, which is a direct signal that first-hop supply is too narrow to fill one.(package private) static doubleparticipationRelief(boolean firewalled, double buildSuccess, boolean incompleteLeaseSet) The relief factor actually applied to the participation share, combining the three inputs.(package private) static intparticipationShareLimit(int basePct, double relief) Apply a relief factor to a participation share percentage, never returning less than the un-relieved base.voidPrune excess tunnels from all pools to stay within budget.voidremoveAlias(Destination dest) Remove a destination for the same tunnels as another.(package private) voidRemove a tunnel from the expiration queue to prevent memory leak.voidremoveTunnels(Destination dest) Must be called AFTER deregistration by the client manager.voidremoveTunnels(Hash destination) This will be called twice, once by the inbound and once by the outbound pool.voidrenderStatusHTML(Writer out) Required byService; status rendering moved to routerconsole.booleanFind and remove tunnels exceeding the latency threshold.voidreportSendFailure(TunnelInfo tunnel, int status) Report a data-phase send failure for a specific outbound tunnel.voidrestart()Restart all tunnel handlers and rebuild all tunnels.private voidschedulePeerTests(List<Hash> peers) Schedule peers for priority testing.Pick a random inbound tunnel from any pool — client pools first, then exploratory.Pick a random outbound tunnel from any pool — client pools first, then exploratory.selectInboundExploratoryTunnel(Hash closestTo) Pick the inbound exploratory tunnel with the gateway closest to the given hash.Pick a random inbound exploratory tunnel.selectInboundTunnel(Hash destination) Pick a random inbound tunnel from the given destination's pool.selectInboundTunnel(Hash destination, Hash closestTo) Pick the inbound tunnel with the gateway closest to the given hash from the given destination's pool.selectInboundTunnelForTest(Hash destination) Pick a tunnel from a destination's inbound pool to carry a test round's reply, preferring partners that have demonstrated they work.selectOutboundExploratoryTunnel(Hash closestTo) Pick the outbound exploratory tunnel with the endpoint closest to the given hash.Pick a random outbound exploratory tunnel.selectOutboundTunnel(Hash destination) Pick a random outbound tunnel from the given destination's pool.selectOutboundTunnel(Hash destination, Hash closestTo) Pick the outbound tunnel with the endpoint closest to the given hash from the given destination's pool.selectOutboundTunnelForTest(Hash destination) Pick a tunnel from a destination's outbound pool to carry a test round's outbound leg, preferring partners that have demonstrated they work.For reliability reasons, don't allow a peer in more than x% of client and exploratory tunnels.static voidsetBuildHandlerThreads(int val) The number of build handler threads.voidsetInboundSettings(Hash client, TunnelPoolSettings settings) Set settings for a client's inbound tunnel pool.voidsetInboundSettings(TunnelPoolSettings settings) The inbound exploratory tunnel pool settings.voidsetOutboundSettings(Hash client, TunnelPoolSettings settings) Set settings for a client's outbound tunnel pool.voidsetOutboundSettings(TunnelPoolSettings settings) The outbound exploratory tunnel pool settings.private static voidsetSettings(Map<Hash, TunnelPool> pools, Hash client, TunnelPoolSettings settings) Applies settings to one client's pools.voidshutdown()Shut the pool manager down.private voidShuts down the two exploratory pools.voidstartup()Start the tunnel pool manager and build initial tunnels.(package private) voidPoke the build executor to build more tunnels.
Field Details
_context
The router context._log
Logger for pool management._clientInboundPools
Hash (destination) to TunnelPool._clientOutboundPools
Hash (destination) to TunnelPool._inboundExploratory
The router's inbound exploratory pool._outboundExploratory
The router's outbound exploratory pool._executor
Runs the tunnel build requests._handler
Matches build replies to the requests._clientPeerSelector
Peer selector shared by the client pools._ghostPeerManager
Tracks peers that keep failing builds._isShutdown
private volatile boolean _isShutdownTrue once the manager has shut down._numHandlerThreads
private static volatile int _numHandlerThreadsThreads running the build handler._handlerThreadId
Counter naming the handler threads._handlerThreads
The running handler threads._defaultMaxPctTunnels
private final int _defaultMaxPctTunnelsSteady-state share of tunnels allowed to clients._startupMaxPctTunnels
private final int _startupMaxPctTunnelsLarger share allowed while the router starts up._lastIncompleteLeaseSet
private volatile long _lastIncompleteLeaseSetWall-clock ms at which some pool last published an incomplete LeaseSet, or 0 if never. Used as a decaying signal rather than a live counter so a pool destroyed while incomplete cannot leave the relief stuck on.SHARE_RELIEF_TOP
static final double SHARE_RELIEF_TOPBuild success at or above which no build-success relief is applied.- See Also:
SHARE_RELIEF_BOTTOM
static final double SHARE_RELIEF_BOTTOMBuild success at or below which relief reaches its full factor of 2.- See Also:
INCOMPLETE_LEASESET_RELIEF
static final double INCOMPLETE_LEASESET_RELIEFRelief factor applied while any pool has published an incomplete LeaseSet.- See Also:
INCOMPLETE_LEASESET_WINDOW_MS
static final long INCOMPLETE_LEASESET_WINDOW_MSHow long an incomplete-LeaseSet observation keeps relief active, in ms.- See Also:
SHARE_LIMIT_LOG_INTERVAL_MS
private static final long SHARE_LIMIT_LOG_INTERVAL_MSMinimum ms between participation-share limit log lines.- See Also:
PROP_DISABLE_TUNNEL_TESTING
Config key turning tunnel testing off.- See Also:
PROP_SLOW_TUNNEL_THRESHOLD
Config key for the slow tunnel latency threshold.- See Also:
PROP_SLOW_TUNNEL_MIN
Config key for the floor on the slow tunnel threshold.- See Also:
PROP_SLOW_TUNNEL_INTERVAL
Config key for how often slow tunnels are checked.- See Also:
DEFAULT_SLOW_THRESHOLD_MS
private static final int DEFAULT_SLOW_THRESHOLD_MSZero means derive the threshold from average latency.- See Also:
DEFAULT_MIN_SLOW_THRESHOLD
private static final int DEFAULT_MIN_SLOW_THRESHOLDThe derived threshold never falls below 10 seconds.- See Also:
DEFAULT_RUN_INTERVAL_MS
private static final int DEFAULT_RUN_INTERVAL_MSSlow tunnels are checked every 60 seconds.- See Also:
REFRESH_DELAY_AFTER_REMOVAL
private static final long REFRESH_DELAY_AFTER_REMOVALReplacement tunnels get 15 seconds to build before a refresh.- See Also:
MAX_SHARE_RATIO
private static final double MAX_SHARE_RATIOLargest client share ratio accepted.- See Also:
POOL_CLEANUP_DELAY_MS
private static final long POOL_CLEANUP_DELAY_MSDelay before removing pools after client disconnect. Allows tunnels to naturally expire rather than collapsing.- See Also:
_pendingCleanups
Pending delayed cleanups for pool removal. Key: destination hash, Value: cleanup task._pendingOutboundStartups
Pending delayed outbound pool startups, keyed by destination hash. Cancelled when the pool is actually removed.PROP_OUTBOUND_STARTUP_RETRIES
Property: outbound tunnel startup retries.- See Also:
DEFAULT_OUTBOUND_STARTUP_RETRIES
private static final int DEFAULT_OUTBOUND_STARTUP_RETRIESTries to bring up the outbound pool at startup.- See Also:
Constructor Details
TunnelPoolManager
Manage tunnel pools for the given router context.- Parameters:
ctx- the router context
Method Details
selectInboundTunnel
Pick a random inbound exploratory tunnel. Warning - selectInboundExploratoryTunnel(Hash) is preferred.- Specified by:
selectInboundTunnelin interfaceTunnelManagerFacade- Returns:
- null if none
selectInboundTunnel
Pick a random inbound tunnel from the given destination's pool. Warning - selectInboundTunnel(Hash, Hash) is preferred.- Specified by:
selectInboundTunnelin interfaceTunnelManagerFacade- Parameters:
destination- if null, returns inbound exploratory tunnel- Returns:
- null if none
selectOutboundTunnel
Pick a random outbound exploratory tunnel. Warning - selectOutboundExploratoryTunnel(Hash) is preferred.- Specified by:
selectOutboundTunnelin interfaceTunnelManagerFacade- Returns:
- null if none
selectInboundTunnelForTest
Pick a tunnel from a destination's inbound pool to carry a test round's reply, preferring partners that have demonstrated they work. Used only by the test cycle; the live data path keeps using the uniform-randomselectInboundTunnel(Hash).- Parameters:
destination- if null, an exploratory tunnel is used- Returns:
- null if none
selectOutboundTunnelForTest
Pick a tunnel from a destination's outbound pool to carry a test round's outbound leg, preferring partners that have demonstrated they work. Test cycle only.- Parameters:
destination- if null, an exploratory tunnel is used- Returns:
- null if none
selectOutboundTunnel
Pick a random outbound tunnel from the given destination's pool. Warning - selectOutboundTunnel(Hash, Hash) is preferred.- Specified by:
selectOutboundTunnelin interfaceTunnelManagerFacade- Parameters:
destination- if null, returns outbound exploratory tunnel- Returns:
- null if none
selectAnyOutboundTunnel
Pick a random outbound tunnel from any pool — client pools first, then exploratory. Used byBuildRequestorfor cross-pool build replies when the requesting pool's own tunnels are unavailable. Client tunnels provide a lower-latency reply path than exploratory.- Specified by:
selectAnyOutboundTunnelin interfaceTunnelManagerFacade- Returns:
- null if none
selectAnyInboundTunnel
Pick a random inbound tunnel from any pool — client pools first, then exploratory. Used by BuildRequestor for cross-pool build replies when the requesting pool's own tunnels are unavailable.- Specified by:
selectAnyInboundTunnelin interfaceTunnelManagerFacade- Returns:
- null if none
selectInboundExploratoryTunnel
Pick the inbound exploratory tunnel with the gateway closest to the given hash. By using this instead of the random selectTunnel(), we force some locality in OBEP-IBGW connections to minimize those connections network-wide.- Specified by:
selectInboundExploratoryTunnelin interfaceTunnelManagerFacade- Parameters:
closestTo- the hash whose closest gateway the returned tunnel should reach- Returns:
- null if none
selectInboundTunnel
Pick the inbound tunnel with the gateway closest to the given hash from the given destination's pool. By using this instead of the random selectTunnel(), we force some locality in OBEP-IBGW connections to minimize those connections network-wide.- Specified by:
selectInboundTunnelin interfaceTunnelManagerFacade- Parameters:
destination- if null, returns inbound exploratory tunnelclosestTo- the hash whose closest gateway the returned tunnel should reach- Returns:
- null if none
selectOutboundExploratoryTunnel
Pick the outbound exploratory tunnel with the endpoint closest to the given hash. By using this instead of the random selectTunnel(), we force some locality in OBEP-IBGW connections to minimize those connections network-wide.- Specified by:
selectOutboundExploratoryTunnelin interfaceTunnelManagerFacade- Parameters:
closestTo- the hash whose closest gateway the returned tunnel should reach- Returns:
- null if none
selectOutboundTunnel
Pick the outbound tunnel with the endpoint closest to the given hash from the given destination's pool. By using this instead of the random selectTunnel(), we force some locality in OBEP-IBGW connections to minimize those connections network-wide.- Specified by:
selectOutboundTunnelin interfaceTunnelManagerFacade- Parameters:
destination- if null, returns outbound exploratory tunnelclosestTo- the hash whose closest gateway the returned tunnel should reach- Returns:
- null if none
getFreeTunnelCount
public int getFreeTunnelCount()Number of valid (non-failed, non-expired) inbound exploratory tunnels.- Specified by:
getFreeTunnelCountin interfaceTunnelManagerFacade- Returns:
- the count of usable inbound exploratory tunnels
getOutboundTunnelCount
public int getOutboundTunnelCount()Number of valid (non-failed, non-expired) outbound exploratory tunnels.- Specified by:
getOutboundTunnelCountin interfaceTunnelManagerFacade- Returns:
- the count of usable outbound exploratory tunnels
getInboundClientTunnelCount
public int getInboundClientTunnelCount()Number of GOOD (tested+passed, non-failed, non-expired) inbound client tunnels across all destinations.- Specified by:
getInboundClientTunnelCountin interfaceTunnelManagerFacade- Returns:
- the count of good inbound client tunnels over all clients
getOutboundClientTunnelCount
public int getOutboundClientTunnelCount()Number of GOOD (tested+passed, non-failed, non-expired) outbound client tunnels across all destinations.- Specified by:
getOutboundClientTunnelCountin interfaceTunnelManagerFacade- Returns:
- the count of good outbound client tunnels over all clients
getOutboundClientTunnelCount
Use to verify a tunnel pool is alive. During bootstrap (no GOOD tunnels yet), counts any valid tunnel (including UNTESTED) so the sidebar shows ok immediately after the first build. Once the pool has established GOOD tunnels, enforces a strict GOOD-only count — UNTESTED tunnels alone don't keep the indicator green.- Specified by:
getOutboundClientTunnelCountin interfaceTunnelManagerFacade- Parameters:
destination- hash of the destination owning the outbound pool- Returns:
- number of outbound client tunnels for the given destination
getInboundClientTunnelCount
Use to verify a tunnel pool is alive. During bootstrap (no GOOD tunnels yet), counts any valid tunnel (including UNTESTED) so the sidebar shows ok immediately after the first build. Once the pool has established GOOD tunnels, enforces a strict GOOD-only count.- Specified by:
getInboundClientTunnelCountin interfaceTunnelManagerFacade- Parameters:
destination- hash of the destination owning the inbound pool- Returns:
- number of inbound client tunnels for the given destination
getUsableInboundClientTunnelCount
Get USABLE inbound client tunnel count for a specific destination.- Parameters:
destination- the client hash- Returns:
- number of GOOD (tested+passed, non-failed, non-expired) tunnels
getUsableOutboundClientTunnelCount
Get USABLE outbound client tunnel count for a specific destination.- Parameters:
destination- the client hash- Returns:
- number of GOOD (tested+passed, non-failed, non-expired) tunnels
getParticipatingCount
public int getParticipatingCount()The number of tunnels we're participating in as a gateway or endpoint.- Specified by:
getParticipatingCountin interfaceTunnelManagerFacade- Returns:
- number of tunnels where we are a gateway or an endpoint
getLastParticipatingExpiration
public long getLastParticipatingExpiration()The expiration time of the last participating tunnel.- Specified by:
getLastParticipatingExpirationin interfaceTunnelManagerFacade- Returns:
- expiration of the latest-expiring participating tunnel in milliseconds since the epoch, or -1 if we participate in none
isValidTunnel
Check if a tunnel is valid and belongs to the client's pool.- Specified by:
isValidTunnelin interfaceTunnelManagerFacade- Parameters:
client- the destination hash identifying the client's pooltunnel- tunnel to validate- Returns:
- true if the tunnel is valid and belongs to the client's pool
getInboundSettings
The inbound exploratory tunnel pool settings.- Specified by:
getInboundSettingsin interfaceTunnelManagerFacade- Returns:
- the inbound settings
getOutboundSettings
The outbound exploratory tunnel pool settings.- Specified by:
getOutboundSettingsin interfaceTunnelManagerFacade- Returns:
- the outbound settings
setInboundSettings
The inbound exploratory tunnel pool settings.- Specified by:
setInboundSettingsin interfaceTunnelManagerFacade- Parameters:
settings- the inbound settings
setOutboundSettings
The outbound exploratory tunnel pool settings.- Specified by:
setOutboundSettingsin interfaceTunnelManagerFacade- Parameters:
settings- the outbound settings
getInboundSettings
Get settings for a client's inbound tunnel pool.- Specified by:
getInboundSettingsin interfaceTunnelManagerFacade- Parameters:
client- the destination hash identifying the client's pool- Returns:
- settings or null if not found
getOutboundSettings
Get settings for a client's outbound tunnel pool.- Specified by:
getOutboundSettingsin interfaceTunnelManagerFacade- Parameters:
client- the destination hash identifying the client's pool- Returns:
- settings or null if not found
setInboundSettings
Set settings for a client's inbound tunnel pool.- Specified by:
setInboundSettingsin interfaceTunnelManagerFacade- Parameters:
client- the destination hash identifying the client's poolsettings- the inbound settings
setOutboundSettings
Set settings for a client's outbound tunnel pool.- Specified by:
setOutboundSettingsin interfaceTunnelManagerFacade- Parameters:
client- the destination hash identifying the client's poolsettings- the outbound settings
setSettings
private static void setSettings(Map<Hash, TunnelPool> pools, Hash client, TunnelPoolSettings settings) Applies settings to one client's pools.- Parameters:
pools- the client pools by destinationclient- the client's destinationsettings- the settings to apply
restart
buildTunnels
Used only at session startup. Do not use to change settings. Do not use for aliased destinations; useaddAlias(Destination, ClientTunnelSettings, Destination).- Specified by:
buildTunnelsin interfaceTunnelManagerFacade- Parameters:
client- connecting destination, whose hash keys the pools created heresettings- per-destination inbound and outbound pool settings, which replace those of any pools that already exist
addAlias
public boolean addAlias(Destination dest, ClientTunnelSettings settings, Destination existingClient) Add another destination to the same tunnels. Must have same encryption key and a different signing key.- Specified by:
addAliasin interfaceTunnelManagerFacade- Parameters:
dest- alias destination, which gets its own pools flagged as aliasedsettings- settings for the alias pools, retained under the primary hashexistingClient- primary destination whose tunnels are being shared- Returns:
- true if the destination was added, false if it already had a pool
- Throws:
IllegalArgumentException- if the signing keys match or the encryption keys differ
removeAlias
Remove a destination for the same tunnels as another.- Specified by:
removeAliasin interfaceTunnelManagerFacade- Parameters:
dest- alias destination to drop from the primary's alias set
removeTunnels
Must be called AFTER deregistration by the client manager.- Specified by:
removeTunnelsin interfaceTunnelManagerFacade- Parameters:
dest- destination whose pools are scheduled for removal, deferred so its tunnels keep operating until they expire
removeTunnels
This will be called twice, once by the inbound and once by the outbound pool. Synched withbuildTunnels(Destination, ClientTunnelSettings)above.Must be called AFTER deregistration by the client manager.
Uses delayed cleanup to allow tunnels to continue operating until they naturally expire. Prevents pool collapse when client disconnects.
- Parameters:
destination- the hash of the client whose pools are scheduled for removal; anullhash is ignored
forceRemoveTunnels
Force immediate removal of a pool - used for router shutdown.- Parameters:
destination- the hash of the client whose pools are dropped immediately; anullhash is ignored
doRemoveTunnels
Actually perform pool removal.- Parameters:
destination- the hash of the client whose inbound and outbound pools are shut down here
buildComplete
Queue a recurring test job if appropriate.- Parameters:
cfg- the configuration of the tunnel that just built, whose pool the test job queues against
disableTunnelTesting
public boolean disableTunnelTesting()Report whether periodic tunnel testing is switched off.- Returns:
- true if tunnel testing is disabled by property, false if it is enabled
startup
getBuildHandlerThreads
public static int getBuildHandlerThreads()Tuned by Tuner — min 2, max 8.- Returns:
- number of build handler threads
setBuildHandlerThreads
public static void setBuildHandlerThreads(int val) The number of build handler threads.- Parameters:
val- thread count (clamped 2-8)
getBuildHandlerThreadCount
public int getBuildHandlerThreadCount()Actual number of running BuildHandler threads. May differ fromgetBuildHandlerThreads()if threads were interrupted or failed to start.- Returns:
- current build handler thread count
adjustBuildHandlerThreads
public void adjustBuildHandlerThreads(int target) Dynamically adjust BuildHandler thread count to match target.- Parameters:
target- desired thread count
replaceSlowTunnels
public boolean replaceSlowTunnels()Find and remove tunnels exceeding the latency threshold. Does not blame peers for the removal. Removes all such tunnels per pool if pool has more tunnels than configured quantity, but won't go below the configured quantity. Threshold is either the configured property (in ms), orMath.max(int, int)avg latency, DEFAULT_MIN_SLOW_THRESHOLD), whichever is larger.- Returns:
- true if any tunnels were removed
pruneAllPools
public void pruneAllPools()Prune excess tunnels from all pools to stay within budget. Called periodically from RemoveSlowTunnelsJob to ensure we don't exceed the configured tunnel quantity for any pool.shutdown
schedulePeerTests
cancelPendingOutboundStartup
Cancel any pending outbound startup event for the destination. Called when the pool is actually removed.- Parameters:
destination- the destination hash
shutdownExploratory
private void shutdownExploratory()Shuts down the two exploratory pools.listPools
List of TunnelPool instances currently in play.- Specified by:
listPoolsin interfaceTunnelManagerFacade- Parameters:
out- list that the client inbound, client outbound and both exploratory pools are appended to
tunnelFailed
void tunnelFailed()Poke the build executor to build more tunnels.reportSendFailure
Report a data-phase send failure for a specific outbound tunnel. Routes to the correct pool (client or exploratory) based on the tunnel's destination, so the pool can increment the failure counter and trigger replacement builds immediately.- Specified by:
reportSendFailurein interfaceTunnelManagerFacade- Parameters:
tunnel- the outbound tunnel that carried the failed messagestatus- the I2CP MessageStatusMessage failure code
forceTunnelFailure
Force a tunnel to fail immediately and trigger a replacement build. Used when rotation is saturated and the pool has no viable alternative tunnels.- Specified by:
forceTunnelFailurein interfaceTunnelManagerFacade- Parameters:
tunnel- the outbound tunnel to force-fail
getExecutor
BuildExecutor getExecutor()Return the shared thread pool that runs tunnel builds.- Returns:
- the build executor
removeFromExpiration
Remove a tunnel from the expiration queue to prevent memory leak.- Parameters:
cfg- the tunnel configuration to drop from the expiration queue
getGhostPeerManager
The ghost peer manager for tracking unresponsive peers.- Specified by:
getGhostPeerManagerin interfaceTunnelManagerFacade- Returns:
- the manager of peers excluded after build failures
isShutdown
boolean isShutdown()Whether the manager has been shut down.- Returns:
- true if the manager has been shut down
getInboundBuildQueueSize
public int getInboundBuildQueueSize()Size of the inbound build queue.- Specified by:
getInboundBuildQueueSizein interfaceTunnelManagerFacade- Returns:
- current number of queued inbound builds
renderStatusHTML
Required byService; status rendering moved to routerconsole.- Specified by:
renderStatusHTMLin interfaceService- Parameters:
out- the writer to write to- Throws:
IOException- if an error occurs writing
countTunnelsPerPeer
Count tunnels and peers separately for exploratory or client pools.- Parameters:
lc- object counter to store peer countsexploratory- if true, count exploratory tunnels; if false, count client tunnels- Returns:
- total number of tunnels counted
selectPeersInTooManyTunnels
For reliability reasons, don't allow a peer in more than x% of client and exploratory tunnels.This also will prevent a single huge-capacity (or malicious) peer from taking all the tunnels in the network (although it would be nice to limit the % of total network tunnels to 10% or so, but that appears to be too low to set as a default here... much lower than 33% will push client tunnels out of the fast tier into high cap or beyond...)
Possible improvement - restrict based on count per IP, or IP block, to slightly increase costs of collusion.
- Specified by:
selectPeersInTooManyTunnelsin interfaceTunnelManagerFacade- Returns:
- Set of peers that should not be allowed in another tunnel
participationRelief
static double participationRelief(boolean firewalled, double buildSuccess, boolean incompleteLeaseSet) The relief factor actually applied to the participation share, combining the three inputs. Pure, so the precedence between them is testable without a router.Firewalled and incomplete-LeaseSet are both hard signals that the first hop pool is too narrow, and either one takes full relief regardless of what aggregate build success says. Build success is the weakest signal and only applies when neither of the others fires.
- Parameters:
firewalled- whether the router is firewalledbuildSuccess- build success ratio, or 1.0 when unknownincompleteLeaseSet- whether a pool published an incomplete LeaseSet recently- Returns:
- the multiplier to apply
buildSuccessRelief
static double buildSuccessRelief(double buildSuccess) Graded relief factor for the per-peer participation share, from tunnel build success. Pure: no state, no clock, no logging.Returns 1.0 (no relief) at or above
SHARE_RELIEF_TOPand 2.0 (the pre-existing full relief) at or belowSHARE_RELIEF_BOTTOM, interpolating linearly between. A build success of 1.0 is passed in when no data exists yet, which yields no relief and so leaves the startup thresholds to govern.- Parameters:
buildSuccess- build success ratio in [0,1], or 1.0 when unknown- Returns:
- the multiplier to apply to the participation share percentage
noteIncompleteLeaseSet
void noteIncompleteLeaseSet(long now) Note that some pool published an incomplete LeaseSet, which is a direct signal that first-hop supply is too narrow to fill one.- Parameters:
now- current time in ms
hasRecentIncompleteLeaseSet
boolean hasRecentIncompleteLeaseSet(long now) Whether an incomplete-LeaseSet observation is recent enough to still justify relaxing the participation share. Decays on its own, so it cannot be left stuck on by a pool that was destroyed mid-renewal.- Parameters:
now- current time in ms- Returns:
- whether relief applies
isFirewalled
public boolean isFirewalled()Report whether the router is firewalled on either address family.- Returns:
- true if the router is firewalled
getInboundClientPools
For TunnelRenderer in router console.- Specified by:
getInboundClientPoolsin interfaceTunnelManagerFacade- Returns:
- snapshot of the inbound pools, keyed by destination hash
getOutboundClientPools
For TunnelRenderer in router console.- Specified by:
getOutboundClientPoolsin interfaceTunnelManagerFacade- Returns:
- snapshot of the outbound pools, keyed by destination hash
getInboundExploratoryPool
For TunnelRenderer in router console.- Specified by:
getInboundExploratoryPoolin interfaceTunnelManagerFacade- Returns:
- the inbound exploratory pool, never null
getOutboundExploratoryPool
For TunnelRenderer in router console.- Specified by:
getOutboundExploratoryPoolin interfaceTunnelManagerFacade- Returns:
- the outbound exploratory pool, never null
getInboundPool
The client's inbound pool, creating it if needed.- Specified by:
getInboundPoolin interfaceTunnelManagerFacade- Parameters:
client- hash of the destination that owns the pool- Returns:
- pool or null
getOutboundPool
The client's outbound pool, creating it if needed.- Specified by:
getOutboundPoolin interfaceTunnelManagerFacade- Parameters:
client- hash of the destination that owns the pool- Returns:
- pool or null
ensurePoolsFor
Nudge both of a local client's pools to run their ensure logic. Throttled inside each pool, so failure floods stay cheap.- Specified by:
ensurePoolsForin interfaceTunnelManagerFacade- Parameters:
client- the LOCAL client hash (the pool-map key)- Returns:
- how many pools were nudged; 0 when none are registered
checkAndRecoverPools
public int checkAndRecoverPools()Emergency pool recovery: Check all registered clients have valid tunnel pools. Recreates missing pools to prevent service interruption. Called periodically byBuildExecutor.- Returns:
- number of pools recovered
logPoolHealth
public void logPoolHealth()Log pool health summary for monitoring.fail
Fail all outbound tunnels with this peer as first hop, and all inbound tunnels with this peer as the last hop, because we can't contact it any more. This is most likely to be triggered by an outbound tunnel.- Specified by:
failin interfaceTunnelManagerFacade- Parameters:
peer- hash of the unreachable peer
failTunnelsWithFirstHop
Fail all (outbound) tunnels with this peer as first hop (not counting us).- Parameters:
pool- the pool whose tunnels are scannedpeer- the banlisted peer looked for at the first hop
failTunnelsWithLastHop
Fail all (inbound) tunnels with this peer as last hop (not counting us).- Parameters:
pool- the pool whose tunnels are scannedpeer- the banlisted peer looked for at the last hop
noPoolLine
The entry for a destination with no client pool of the given direction, so a null return from the selector carries a reason in the log.- Parameters:
inbound- true to name an inbound pool, false for an outbound onedestination- the destination whose pool is missing- Returns:
- the log entry, never null