public class TunnelPoolManager extends Object implements TunnelManagerFacade
| Modifier and Type | Field and Description |
|---|---|
(package private) static String | PROP_OUTBOUND_STARTUP_RETRIESProperty: outbound tunnel startup retries. |
| Constructor and Description |
|---|
TunnelPoolManager(RouterContext ctx)Manage tunnel pools for the given router context. |
| Modifier and Type | Method and Description |
|---|---|
boolean | addAlias(Destination dest,
ClientTunnelSettings settings,
Destination existingClient)Add another destination to the same tunnels. |
void | adjustBuildHandlerThreads(int target)Dynamically adjust BuildHandler thread count to match target. |
(package private) void | buildComplete(PooledTunnelCreatorConfig cfg)Queue a recurring test job if appropriate. |
void | buildTunnels(Destination client,
ClientTunnelSettings settings)Used only at session startup. |
int | checkAndRecoverPools()Emergency pool recovery: Check all registered clients have valid tunnel pools. |
boolean | disableTunnelTesting()Tunnel testing status. |
void | fail(Hash peer)Fail all outbound tunnels with this peer as first hop,
and all inbound tunnels with this peer as the last hop,
baecause we can't contact it any more. |
void | forceRemoveTunnels(Hash destination)Force immediate removal of a pool - used for router shutdown. |
int | getBuildHandlerThreadCount()Actual number of running BuildHandler threads. |
static int | getBuildHandlerThreads()Tuned by Tuner — min 2, max 8 |
(package private) BuildExecutor | getExecutor()The build executor. |
int | getFreeTunnelCount()Number of valid (non-failed, non-expired) inbound exploratory tunnels. |
GhostPeerManager | getGhostPeerManager()The ghost peer manager for tracking unresponsive peers. |
int | getInboundBuildQueueSize()Size of the inbound build queue. |
Map<Hash,TunnelPool> | getInboundClientPools()For TunnelRenderer in router console. |
int | getInboundClientTunnelCount()Number of GOOD (tested+passed, non-failed, non-expired) inbound client tunnels across all destinations. |
int | getInboundClientTunnelCount(Hash destination)Use to verify a tunnel pool is alive. |
TunnelPool | getInboundExploratoryPool()For TunnelRenderer in router console |
TunnelPool | getInboundPool(Hash client)Inbound tunnel pool for the given client, or null if none. |
TunnelPoolSettings | getInboundSettings()The inbound exploratory tunnel pool settings. |
TunnelPoolSettings | getInboundSettings(Hash client)Get settings for a client's inbound tunnel pool. |
long | getLastParticipatingExpiration()The expiration time of the last participating tunnel. |
Map<Hash,TunnelPool> | getOutboundClientPools()For TunnelRenderer in router console. |
int | getOutboundClientTunnelCount()Number of GOOD (tested+passed, non-failed, non-expired) outbound client tunnels across all destinations. |
int | getOutboundClientTunnelCount(Hash destination)Use to verify a tunnel pool is alive. |
TunnelPool | getOutboundExploratoryPool()For TunnelRenderer in router console |
TunnelPool | getOutboundPool(Hash client)Outbound tunnel pool for the given client, or null if none. |
TunnelPoolSettings | getOutboundSettings()The outbound exploratory tunnel pool settings. |
TunnelPoolSettings | getOutboundSettings(Hash client)Get settings for a client's outbound tunnel pool. |
int | getOutboundTunnelCount()Number of valid (non-failed, non-expired) outbound exploratory tunnels. |
int | getParticipatingCount()The number of tunnels we're participating in as a gateway or endpoint. |
double | getShareRatio()Get the share ratio of participating tunnels. |
int | getUsableInboundClientTunnelCount(Hash destination)Get USABLE inbound client tunnel count for a specific destination. |
int | getUsableOutboundClientTunnelCount(Hash destination)Get USABLE outbound client tunnel count for a specific destination. |
boolean | isFirewalled()Firewall status. |
(package private) boolean | isShutdown()Whether the manager has been shut down. |
boolean | isValidTunnel(Hash client,
TunnelInfo tunnel)Check if a tunnel is valid and belongs to the client's pool. |
void | listPools(List<TunnelPool> out)List of TunnelPool instances currently in play. |
void | logPoolHealth()Log pool health summary for monitoring. |
void | pruneAllPools()Prune excess tunnels from all pools to stay within budget. |
void | removeAlias(Destination dest)Remove a destination for the same tunnels as another. |
(package private) void | removeFromExpiration(PooledTunnelCreatorConfig cfg)Remove a tunnel from the expiration queue to prevent memory leak |
void | removeTunnels(Destination dest)Must be called AFTER deregistration by the client manager. |
void | removeTunnels(Hash destination)This will be called twice, once by the inbound and once by the outbound pool. |
void | renderStatusHTML(Writer out)Required by Service; status rendering moved to routerconsole. |
boolean | replaceSlowTunnels()Find and remove tunnels exceeding the latency threshold. |
void | restart()Restart all tunnel handlers and rebuild all tunnels |
TunnelInfo | selectAnyInboundTunnel()Pick a random inbound tunnel from any pool — client pools first,
then exploratory. |
TunnelInfo | selectAnyOutboundTunnel()Pick a random outbound tunnel from any pool — client pools first,
then exploratory. |
TunnelInfo | selectInboundExploratoryTunnel(Hash closestTo)Pick the inbound exploratory tunnel with the gateway closest to the given hash. |
TunnelInfo | selectInboundTunnel()Pick a random inbound exploratory tunnel. |
TunnelInfo | selectInboundTunnel(Hash destination)Pick a random inbound tunnel from the given destination's pool. |
TunnelInfo | selectInboundTunnel(Hash destination,
Hash closestTo)Pick the inbound tunnel with the gateway closest to the given hash
from the given destination's pool. |
TunnelInfo | selectOutboundExploratoryTunnel(Hash closestTo)Pick the outbound exploratory tunnel with the endpoint closest to the given hash. |
TunnelInfo | selectOutboundTunnel()Pick a random outbound exploratory tunnel. |
TunnelInfo | selectOutboundTunnel(Hash destination)Pick a random outbound tunnel from the given destination's pool. |
TunnelInfo | selectOutboundTunnel(Hash destination,
Hash closestTo)Pick the outbound tunnel with the endpoint closest to the given hash
from the given destination's pool. |
Set<Hash> | selectPeersInTooManyTunnels()For reliability reasons, don't allow a peer in more than x% of
client and exploratory tunnels. |
static void | setBuildHandlerThreads(int val)The number of build handler threads. |
void | setInboundSettings(Hash client,
TunnelPoolSettings settings)Set settings for a client's inbound tunnel pool. |
void | setInboundSettings(TunnelPoolSettings settings)The inbound exploratory tunnel pool settings. |
void | setOutboundSettings(Hash client,
TunnelPoolSettings settings)Set settings for a client's outbound tunnel pool. |
void | setOutboundSettings(TunnelPoolSettings settings)The outbound exploratory tunnel pool settings. |
void | shutdown()Cannot be restarted |
void | startup()Start the tunnel pool manager and build initial tunnels |
(package private) void | tunnelFailed()Poke the build executor to build more tunnels. |
static final String PROP_OUTBOUND_STARTUP_RETRIES
public TunnelPoolManager(RouterContext ctx)
ctx - the router contextpublic boolean addAlias(Destination dest, ClientTunnelSettings settings, Destination existingClient)
addAlias in interface TunnelManagerFacadeIllegalArgumentException - if notpublic void adjustBuildHandlerThreads(int target)
target - desired thread countvoid buildComplete(PooledTunnelCreatorConfig cfg)
public void buildTunnels(Destination client, ClientTunnelSettings settings)
buildTunnels in interface TunnelManagerFacadepublic int checkAndRecoverPools()
public boolean disableTunnelTesting()
public void fail(Hash peer)
fail in interface TunnelManagerFacadepublic void forceRemoveTunnels(Hash destination)
destination - the destinationpublic int getBuildHandlerThreadCount()
getBuildHandlerThreads() if threads
were interrupted or failed to start.public static int getBuildHandlerThreads()
BuildExecutor getExecutor()
public int getFreeTunnelCount()
getFreeTunnelCount in interface TunnelManagerFacadepublic GhostPeerManager getGhostPeerManager()
getGhostPeerManager in interface TunnelManagerFacadepublic int getInboundBuildQueueSize()
getInboundBuildQueueSize in interface TunnelManagerFacadepublic Map<Hash,TunnelPool> getInboundClientPools()
getInboundClientPools in interface TunnelManagerFacadepublic int getInboundClientTunnelCount()
getInboundClientTunnelCount in interface TunnelManagerFacadepublic int getInboundClientTunnelCount(Hash destination)
getInboundClientTunnelCount in interface TunnelManagerFacadepublic TunnelPool getInboundExploratoryPool()
getInboundExploratoryPool in interface TunnelManagerFacadepublic TunnelPool getInboundPool(Hash client)
TunnelManagerFacadegetInboundPool in interface TunnelManagerFacadepublic TunnelPoolSettings getInboundSettings()
getInboundSettings in interface TunnelManagerFacadepublic TunnelPoolSettings getInboundSettings(Hash client)
getInboundSettings in interface TunnelManagerFacadeclient - destination hashpublic long getLastParticipatingExpiration()
getLastParticipatingExpiration in interface TunnelManagerFacadepublic Map<Hash,TunnelPool> getOutboundClientPools()
getOutboundClientPools in interface TunnelManagerFacadepublic int getOutboundClientTunnelCount()
getOutboundClientTunnelCount in interface TunnelManagerFacadepublic int getOutboundClientTunnelCount(Hash destination)
getOutboundClientTunnelCount in interface TunnelManagerFacadepublic TunnelPool getOutboundExploratoryPool()
getOutboundExploratoryPool in interface TunnelManagerFacadepublic TunnelPool getOutboundPool(Hash client)
TunnelManagerFacadegetOutboundPool in interface TunnelManagerFacadepublic TunnelPoolSettings getOutboundSettings()
getOutboundSettings in interface TunnelManagerFacadepublic TunnelPoolSettings getOutboundSettings(Hash client)
getOutboundSettings in interface TunnelManagerFacadeclient - destination hashpublic int getOutboundTunnelCount()
getOutboundTunnelCount in interface TunnelManagerFacadepublic int getParticipatingCount()
getParticipatingCount in interface TunnelManagerFacadepublic double getShareRatio()
getShareRatio in interface TunnelManagerFacadepublic int getUsableInboundClientTunnelCount(Hash destination)
destination - the client hashpublic int getUsableOutboundClientTunnelCount(Hash destination)
destination - the client hashpublic boolean isFirewalled()
boolean isShutdown()
public boolean isValidTunnel(Hash client, TunnelInfo tunnel)
isValidTunnel in interface TunnelManagerFacadeclient - destination hashtunnel - tunnel to validatepublic void listPools(List<TunnelPool> out)
listPools in interface TunnelManagerFacadepublic void logPoolHealth()
public void pruneAllPools()
public void removeAlias(Destination dest)
removeAlias in interface TunnelManagerFacadevoid removeFromExpiration(PooledTunnelCreatorConfig cfg)
public void removeTunnels(Destination dest)
removeTunnels in interface TunnelManagerFacadepublic void removeTunnels(Hash destination)
destination - the destinationpublic void renderStatusHTML(Writer out) throws IOException
Service; status rendering moved to routerconsole.renderStatusHTML in interface Serviceout - the writer to write toIOException - if an error occurs writingpublic boolean replaceSlowTunnels()
public void restart()
public TunnelInfo selectAnyInboundTunnel()
selectAnyInboundTunnel in interface TunnelManagerFacadepublic TunnelInfo selectAnyOutboundTunnel()
selectAnyOutboundTunnel in interface TunnelManagerFacadepublic TunnelInfo selectInboundExploratoryTunnel(Hash closestTo)
selectInboundExploratoryTunnel in interface TunnelManagerFacadeclosestTo - non-nullpublic TunnelInfo selectInboundTunnel()
selectInboundTunnel in interface TunnelManagerFacadepublic TunnelInfo selectInboundTunnel(Hash destination)
selectInboundTunnel in interface TunnelManagerFacadedestination - if null, returns inbound exploratory tunnelpublic TunnelInfo selectInboundTunnel(Hash destination, Hash closestTo)
selectInboundTunnel in interface TunnelManagerFacadedestination - if null, returns inbound exploratory tunnelclosestTo - non-nullpublic TunnelInfo selectOutboundExploratoryTunnel(Hash closestTo)
selectOutboundExploratoryTunnel in interface TunnelManagerFacadeclosestTo - non-nullpublic TunnelInfo selectOutboundTunnel()
selectOutboundTunnel in interface TunnelManagerFacadepublic TunnelInfo selectOutboundTunnel(Hash destination)
selectOutboundTunnel in interface TunnelManagerFacadedestination - if null, returns outbound exploratory tunnelpublic TunnelInfo selectOutboundTunnel(Hash destination, Hash closestTo)
selectOutboundTunnel in interface TunnelManagerFacadedestination - if null, returns outbound exploratory tunnelclosestTo - non-nullpublic Set<Hash> selectPeersInTooManyTunnels()
selectPeersInTooManyTunnels in interface TunnelManagerFacadepublic static void setBuildHandlerThreads(int val)
val - thread count (clamped 2-8)public void setInboundSettings(Hash client, TunnelPoolSettings settings)
setInboundSettings in interface TunnelManagerFacadeclient - destination hashsettings - the inbound settingspublic void setInboundSettings(TunnelPoolSettings settings)
setInboundSettings in interface TunnelManagerFacadesettings - the inbound settingspublic void setOutboundSettings(Hash client, TunnelPoolSettings settings)
setOutboundSettings in interface TunnelManagerFacadeclient - destination hashsettings - the outbound settingspublic void setOutboundSettings(TunnelPoolSettings settings)
setOutboundSettings in interface TunnelManagerFacadesettings - the outbound settingspublic void startup()
void tunnelFailed()