public class TunnelPool extends Object
| Modifier and Type | Field and Description |
|---|---|
protected boolean | _aliveWhether this pool is running |
protected RouterContext | _contextThe router context |
protected Log | _logThe log |
(package private) static long | DEFAULT_PRUNE_EARLY_EXPIRYDefault early expiration time for pruned tunnels (30 seconds) |
| Constructor and Description |
|---|
TunnelPool(RouterContext ctx,
TunnelPoolManager mgr,
TunnelPoolSettings settings,
TunnelPeerSelector sel)Tunnel pool |
| Modifier and Type | Method and Description |
|---|---|
protected void | addTunnel(TunnelInfo info)Add a tunnel to the pool. |
(package private) void | buildComplete(PooledTunnelCreatorConfig cfg,
BuildExecutor.Result result)Remove from the _inprogress list and call addTunnel() if result is SUCCESS. |
(package private) boolean | buildFallback()This will build a fallback (zero-hop) tunnel ONLY if
this pool is exploratory, or the settings allow it. |
List<PooledTunnelCreatorConfig> | cancelExcessInProgress(int maxAllowed)Cancel excess in-progress tunnel builds to stay within budget. |
(package private) PooledTunnelCreatorConfig | configureNewTunnel()This only sets the peers and creation/expiration times in the configuration. |
(package private) void | ensureSufficientTunnels()Ensure the pool has at least target valid tunnels, building replacements
proactively when the count drops below target. |
static String | formatPoolIdentity(TunnelPoolSettings settings)Format a pool identity for log messages, combining nickname and truncated hash. |
int | getActiveTunnelCount()Count GOOD and TESTING (non-failed, not expired) tunnels in the pool. |
int | getAvgBWPerTunnel()Average bandwidth per tunnel in the pool. |
(package private) static int | getBuildTriesQuantityOverride(RouterContext ctx)Quantity override threshold from config or default (12). |
(package private) int | getConsecutiveBuildTimeouts()Count of consecutive tunnel build timeouts. |
(package private) LeaseSet | getInboundTunnelsAsLeaseSet()Build and return current LeaseSet from our tunnels. |
int | getInProgressCount()Count tunnels currently being built. |
(package private) static long | getLeaseMaxDuration(RouterContext ctx)Maximum lease set lease duration from config or auto-computed default. |
(package private) static long | getLeaseSetBuildMinInterval(RouterContext ctx)LeaseSet build minimum interval from config or default (2 minutes). |
long | getLifetimeProcessed()Total lifetime processed bytes for this pool. |
(package private) static int | getMaxConcurrentBuildsPerDirection(RouterContext ctx)Max concurrent builds per direction from config or default (6). |
(package private) TunnelPool | getPairedPool()Paired pool (inbound <-> outbound for same destination). |
(package private) long | getPruneEarlyExpiry()Early expiry time for pruned tunnels. |
String | getRateName()RateStat name for the bandwidth graph |
(package private) static long | getRefreshThrottle(RouterContext ctx)Refresh throttle interval from config or default (2 minutes). |
TunnelPoolSettings | getSettings()Pool settings. |
(package private) static long | getStartupTime(RouterContext ctx)Startup suppression period from config or default (5 minutes). |
int | getTestingTunnelCount()Count tunnels that have been built but not yet passed their first test. |
TunnelInfo | getTunnel(TunnelId gatewayId)tunnel by its gateway tunnel ID. |
(package private) static int | getTunnelAvgLatency(TunnelInfo t)Average test latency for a tunnel. |
(package private) int | getTunnelCount()duplicate of size(), let's pick one |
(package private) static int | getTunnelLifetime(RouterContext ctx)Tunnel lifetime from config or default (10 minutes). |
TunnelPoolManager | getTunnelPoolManager()TunnelPoolManager that owns this pool. |
(package private) int | getUsableTunnelCount()Count tunnels that are usable for routing — not failed, not expired,
not expiring within 5 minutes. |
int | getValidTunnelCount()Count valid (non-failed, not expired) tunnels in the pool. |
(package private) void | incrementBuildTimeout()Increment consecutive build timeout counter. |
boolean | isAlive()Is this pool running AND either exploratory, or tracked by the client manager?
A pool will be alive but not tracked after the client manager removes it
but before all the tunnels have expired. |
(package private) boolean | isExpiringSoon(long now)Check if the LeaseSet is expiring soon (within 1 minute). |
boolean | isStruggling()Whether this pool is struggling to meet its tunnel targets. |
List<PooledTunnelCreatorConfig> | listPending()list of tunnelInfo instances of tunnels currently being built |
List<TunnelInfo> | listTunnels()Return a list of tunnels in the pool |
protected LeaseSet | locked_buildNewLeaseSet()Build a leaseSet with the required tunnels that aren't about to expire. |
(package private) boolean | needFallback()Do we really need more fallbacks?
Used to prevent a zillion of them. |
(package private) void | notifyServerPoolTestFailed()Called by TestJob when a server pool tunnel fails a test but is retained. |
(package private) void | proactiveRepublishIfHealthy()Proactively republish the LeaseSet when all tunnels are healthy (all > 5 min expiry). |
int | pruneExcessTunnels()Prune excess tunnels from the pool to stay within budget. |
(package private) void | refreshLeaseSet()noop for outbound and exploratory |
(package private) void | refreshLeaseSet(boolean force)Refresh the LeaseSet, throttled to prevent flooding but not on initial creation. |
(package private) void | removeTunnel(TunnelInfo info)Remove a tunnel from the pool. |
(package private) boolean | removeTunnelSynchronous(TunnelInfo info)Synchronous tunnel removal for use during recovery or critical situations. |
(package private) TunnelInfo | selectTunnel()Pull a random tunnel out of the pool. |
(package private) TunnelInfo | selectTunnel(Hash closestTo)Return the tunnel from the pool that is XOR-closest to the target. |
(package private) void | setPairedPool(TunnelPool pool)Paired pool (inbound <-> outbound for same destination). |
(package private) void | setSettings(TunnelPoolSettings settings)Update the settings for this pool |
(package private) void | shutdown()Shut down the pool and clean up resources. |
int | size()duplicate of getTunnelCount(), let's pick one |
(package private) void | startup()Warning, this may be called more than once
(without an intervening shutdown()) if the
tunnel is stopped and then restarted by the client manager with the same
Destination (i.e. |
String | toString()toString. |
(package private) void | tunnelFailed(TunnelInfo cfg)Remove tunnel and blame all peers (not necessarily equally). |
(package private) void | tunnelFailed(TunnelInfo cfg,
Hash blamePeer)Remove the tunnel and blame only one peer. |
protected volatile boolean _alive
protected final RouterContext _context
protected final Log _log
static final long DEFAULT_PRUNE_EARLY_EXPIRY
TunnelPool(RouterContext ctx, TunnelPoolManager mgr, TunnelPoolSettings settings, TunnelPeerSelector sel)
protected void addTunnel(TunnelInfo info)
info - the tunnel to addvoid buildComplete(PooledTunnelCreatorConfig cfg, BuildExecutor.Result result)
cfg - the completed tunnel configurationresult - the build resultboolean buildFallback()
public List<PooledTunnelCreatorConfig> cancelExcessInProgress(int maxAllowed)
maxAllowed - the maximum number of in-progress builds allowedPooledTunnelCreatorConfig configureNewTunnel()
void ensureSufficientTunnels()
public static String formatPoolIdentity(TunnelPoolSettings settings)
settings - the pool settingspublic int getActiveTunnelCount()
public int getAvgBWPerTunnel()
static int getBuildTriesQuantityOverride(RouterContext ctx)
ctx - the router contextint getConsecutiveBuildTimeouts()
LeaseSet getInboundTunnelsAsLeaseSet()
public int getInProgressCount()
static long getLeaseMaxDuration(RouterContext ctx)
ctx - the router contextstatic long getLeaseSetBuildMinInterval(RouterContext ctx)
ctx - the router contextpublic long getLifetimeProcessed()
static int getMaxConcurrentBuildsPerDirection(RouterContext ctx)
ctx - the router contextTunnelPool getPairedPool()
long getPruneEarlyExpiry()
public String getRateName()
static long getRefreshThrottle(RouterContext ctx)
ctx - the router contextpublic TunnelPoolSettings getSettings()
static long getStartupTime(RouterContext ctx)
ctx - the router contextpublic int getTestingTunnelCount()
public TunnelInfo getTunnel(TunnelId gatewayId)
gatewayId - for inbound, the GW rcv tunnel ID; for outbound, the GW send tunnel ID.static int getTunnelAvgLatency(TunnelInfo t)
t - the tunnel to queryint getTunnelCount()
static int getTunnelLifetime(RouterContext ctx)
ctx - the router contextpublic TunnelPoolManager getTunnelPoolManager()
int getUsableTunnelCount()
public int getValidTunnelCount()
void incrementBuildTimeout()
public boolean isAlive()
boolean isExpiringSoon(long now)
now - current timepublic boolean isStruggling()
public List<PooledTunnelCreatorConfig> listPending()
public List<TunnelInfo> listTunnels()
protected LeaseSet locked_buildNewLeaseSet()
boolean needFallback()
void notifyServerPoolTestFailed()
void proactiveRepublishIfHealthy()
public int pruneExcessTunnels()
void refreshLeaseSet()
void refreshLeaseSet(boolean force)
force - if true, bypass throttle (for critical refresh when below minimum or near expiry)void removeTunnel(TunnelInfo info)
info - the tunnel to removeboolean removeTunnelSynchronous(TunnelInfo info)
info - tunnel to removeTunnelInfo selectTunnel()
TunnelInfo selectTunnel(Hash closestTo)
closestTo - the hash to find the closest tunnel tovoid setPairedPool(TunnelPool pool)
pool - the paired poolvoid setSettings(TunnelPoolSettings settings)
settings - the new settings, may be nullvoid shutdown()
public int size()
void startup()
void tunnelFailed(TunnelInfo cfg)
cfg - the tunnel that failedvoid tunnelFailed(TunnelInfo cfg, Hash blamePeer)
cfg - the tunnel that failedblamePeer - the peer to blame