public abstract class TunnelPeerSelector extends ConnectChecker
| Modifier and Type | Class and Description |
|---|---|
protected class | TunnelPeerSelector.ExcluderExcluder that automatically adds peers to the set when they should be excluded. |
| Modifier and Type | Field and Description |
|---|---|
protected static Object | _cooldownLockLock for atomic cooldown check+record across peer selectors |
protected static Map<Hash,Long> | _firstHopFailsTracks when a peer last failed as first hop |
protected static Map<Hash,Long> | _peerCooldownsShared cooldown map across all peer selectors |
protected static double | ATTACK_THRESHOLDThreshold for detecting tunnel build attacks |
protected static double | DEGRADED_BUILD_THRESHOLDBuild success at or below this widens the activity window to counter the
purgatory band (40-79% success) where the recency gate prunes good peers
faster than they can be re-tested, tightening the eligible pool in a
self-reinforcing loop. |
protected static long | FIRST_HOP_FAIL_COOLDOWN_MSPeers that failed as first hop (first hop unreachable) excluded for this long |
protected static long | PEER_SELECTION_COOLDOWN_MSPeers selected within this window are excluded from further selection to ensure diversity |
protected static long | STARTUP_WARNING_SUPPRESS_MSDuration in ms to suppress startup warnings |
ANY_V4, ctx, log| Modifier | Constructor and Description |
|---|---|
protected | TunnelPeerSelector(RouterContext context)TunnelPeerSelector. |
| Modifier and Type | Method and Description |
|---|---|
protected boolean | allowAsIBGW(Hash h)Should we allow as IBGW?
This just checks for the "R" capability and IPv4 support. |
protected boolean | allowAsOBEP(Hash h)Should we allow as OBEP?
This just checks for IPv4 support. |
protected boolean | checkTunnel(boolean isInbound,
boolean isExploratory,
List<Hash> tunnel)Connectivity check. |
protected boolean | filterSlow(boolean isInbound,
boolean isExploratory)do we want to skip peers that are slow? |
static long | getActivityWindow(RouterContext ctx)Compute the activity window for peer selection based on current network
visibility. |
protected Set<Hash> | getClosestHopExclude(boolean isInbound,
Set<Hash> toAdd)Pick peers that we want to avoid for the first OB hop or last IB hop. |
protected Set<Hash> | getExclude(boolean isInbound,
boolean isExploratory)As of 0.9.58, this returns a set populated only by TunnelManager.selectPeersInTooManyTunnels(),
for passing to ProfileOrganizer. |
protected int | getLength(TunnelPoolSettings settings)Determine the tunnel length (number of hops). |
protected static Set<Hash> | getPeersInPool(RouterContext ctx,
TunnelPool pool)Get all non-self peers in active tunnels of the given pool. |
static int | getWindowMultiplier()Get the current Tuner-controlled activity-window multiplier. |
protected static boolean | hasRecoveredFromFailure(RouterContext ctx,
Hash peer)Check if a peer has recovered from failure and can be reconsidered. |
protected static boolean | hasValidTransportAddress(RouterContext ctx,
Hash peer)Check if a peer's RouterInfo has at least one reachable SSU or NTCP address. |
protected boolean | isDuplicateSequence(TunnelPoolSettings settings,
List<Hash> newPeers)Check if the selected peer sequence matches an existing tunnel in the pool. |
static boolean | isFirstHopFailing(RouterContext ctx,
Hash peer)Check if a peer recently failed as first hop and should be excluded. |
protected boolean | isInStartupGracePeriod()Convenience instance method wrapping the static helper. |
protected static boolean | isInStartupGracePeriod(RouterContext ctx)Is the router in the startup grace period?
During startup, peers haven't accumulated test history yet, so
quality filters (pre-qualification, tier capping) should be relaxed
to allow tunnels to build. |
protected boolean | isIPv6Only()Are we IPv6 only? |
protected static boolean | isLowAcceptanceRatio(RouterContext ctx,
Hash peer)Check if a peer has a history of rejecting tunnel build requests. |
(package private) static boolean | isStalePeer(RouterContext ctx,
Hash peer)Check if a peer is stale — no contact (heard from or heard about) within
the dynamic activity window. |
static void | keepAlive(RouterContext ctx,
boolean aggressive)Periodically called to keep transport sessions alive for top-tier peers and
proactively establish connections to Fast/HighCap peers before builds need them. |
protected void | orderPeers(List<Hash> rv,
SessionKey key)Order peers using the given key. |
protected static void | preConnectTo(RouterContext ctx,
Hash peer)Trigger an outbound connection establishment to a peer. |
protected static void | prunePeerMaps(RouterContext ctx)Prune expired entries from static peer maps. |
protected static void | recordFirstHopFail(RouterContext ctx,
Hash peer)Record that a peer failed as first hop (first hop unreachable). |
protected static void | recordPeerFailure(RouterContext ctx,
Hash peer)Record that a peer failed during peer selection (first-hop or adjacent). |
protected List<Hash> | regeneratePeers(TunnelPoolSettings settings,
List<Hash> peers)Regenerate tunnel peers to avoid duplicate sequence. |
protected List<Hash> | selectExplicit(TunnelPoolSettings settings,
int length)For debugging, also possibly for restricted routes. |
abstract List<Hash> | selectPeers(TunnelPoolSettings settings)Which peers should go into the next tunnel for the given settings? |
static void | setWindowMultiplier(int mult)Set the Tuner-controlled activity-window multiplier. |
static boolean | shouldExclude(RouterContext ctx,
RouterInfo peer)Should the peer be excluded based on its published caps, crypto, and version? |
protected boolean | shouldSelectExplicit(TunnelPoolSettings settings)For debugging, also possibly for restricted routes?
Needs analysis and testing |
protected static boolean | supportsNTCP2(RouterContext ctx,
Hash peer)Check if a peer supports NTCP2 transport. |
canConnect, canConnect, canConnect, getInboundMask, getOutboundMask, isNTCPDisabled, isSSUDisabledprotected static final Object _cooldownLock
protected static final Map<Hash,Long> _firstHopFails
protected static final Map<Hash,Long> _peerCooldowns
protected static final double ATTACK_THRESHOLD
protected static final double DEGRADED_BUILD_THRESHOLD
ATTACK_THRESHOLD because
relaxing recency is far safer than relaxing capability exclusions.protected static final long FIRST_HOP_FAIL_COOLDOWN_MS
protected static final long PEER_SELECTION_COOLDOWN_MS
protected static final long STARTUP_WARNING_SUPPRESS_MS
protected TunnelPeerSelector(RouterContext context)
protected boolean allowAsIBGW(Hash h)
h - the peer hashprotected boolean allowAsOBEP(Hash h)
h - the peer hashprotected boolean checkTunnel(boolean isInbound,
boolean isExploratory,
List<Hash> tunnel)isInbound - true for inbound tunnelsisExploratory - true for exploratory tunnelstunnel - ENDPOINT FIRST, GATEWAY LAST!!!!, length 2 or greaterprotected boolean filterSlow(boolean isInbound,
boolean isExploratory)isInbound - true for inbound tunnelsisExploratory - true for exploratory tunnelspublic static long getActivityWindow(RouterContext ctx)
setWindowMultiplier(int)) and floored to at least 4 hours
when build success is in the degraded/purgatory band, so good peers whose
last successful test has aged out are re-admitted instead of pruned in a
self-reinforcing loop.ctx - the router contextprotected Set<Hash> getClosestHopExclude(boolean isInbound, Set<Hash> toAdd)
isInbound - true for inbound tunnelstoAdd - set of peers to initially populate the exclusion setprotected Set<Hash> getExclude(boolean isInbound, boolean isExploratory)
isInbound - true for inbound tunnelsisExploratory - true for exploratory tunnelsprotected int getLength(TunnelPoolSettings settings)
settings - the tunnel pool settingsprotected static Set<Hash> getPeersInPool(RouterContext ctx, TunnelPool pool)
ctx - the router contextpool - the tunnel pool to scanpublic static int getWindowMultiplier()
protected static boolean hasRecoveredFromFailure(RouterContext ctx, Hash peer)
ctx - the router contextpeer - the peerprotected static boolean hasValidTransportAddress(RouterContext ctx, Hash peer)
ctx - the router contextpeer - hash of the peer to checkprotected boolean isDuplicateSequence(TunnelPoolSettings settings, List<Hash> newPeers)
settings - the tunnel pool settingsnewPeers - the newly selected peers (excluding self)public static boolean isFirstHopFailing(RouterContext ctx, Hash peer)
ctx - the router contextpeer - the peerprotected boolean isInStartupGracePeriod()
protected static boolean isInStartupGracePeriod(RouterContext ctx)
ctx - the router contextprotected boolean isIPv6Only()
protected static boolean isLowAcceptanceRatio(RouterContext ctx, Hash peer)
ctx - the router contextpeer - hash of the peer to checkstatic boolean isStalePeer(RouterContext ctx, Hash peer)
ctx - the router contextpeer - hash of the peer to checkpublic static void keepAlive(RouterContext ctx, boolean aggressive)
ctx - the router contextaggressive - if true, also pre-connect to non-established eligible peers
(used when any pool has 0 tunnels)protected void orderPeers(List<Hash> rv, SessionKey key)
rv - the list to orderkey - the session key for orderingprotected static void preConnectTo(RouterContext ctx, Hash peer)
ctx - the router contextpeer - hash of the peer to connect toprotected static void prunePeerMaps(RouterContext ctx)
ctx - the router contextprotected static void recordFirstHopFail(RouterContext ctx, Hash peer)
ctx - the router contextpeer - the peerprotected static void recordPeerFailure(RouterContext ctx, Hash peer)
ctx - the router contextpeer - the peerprotected List<Hash> regeneratePeers(TunnelPoolSettings settings, List<Hash> peers)
settings - the tunnel pool settingspeers - the peers to regenerateprotected List<Hash> selectExplicit(TunnelPoolSettings settings, int length)
settings - the tunnel pool settingslength - the desired length of the tunnelpublic abstract List<Hash> selectPeers(TunnelPoolSettings settings)
settings - the tunnel pool settingspublic static void setWindowMultiplier(int mult)
mult - the multiplier applied to the base activity windowpublic static boolean shouldExclude(RouterContext ctx, RouterInfo peer)
ctx - Router context for peer count checkspeer - The peer to evaluateprotected boolean shouldSelectExplicit(TunnelPoolSettings settings)
settings - the tunnel pool settingsprotected static boolean supportsNTCP2(RouterContext ctx, Hash peer)
ctx - the router contextpeer - hash of the peer to check