public class BuildExecutor extends Object implements Runnable
| Modifier and Type | Class and Description |
|---|---|
(package private) static class | BuildExecutor.ExpiryBucketsImmutable result of countExpiryBuckets(List, long, boolean). |
(package private) static class | BuildExecutor.ResultBuild result enumeration. |
| Constructor and Description |
|---|
BuildExecutor(RouterContext ctx,
TunnelPoolManager mgr,
GhostPeerManager ghostMgr)Create a new BuildExecutor. |
| Modifier and Type | Method and Description |
|---|---|
void | buildComplete(PooledTunnelCreatorConfig cfg,
BuildExecutor.Result result)Handle a completed tunnel build. |
void | buildComplete(PooledTunnelCreatorConfig cfg,
BuildExecutor.Result result,
String detail)Handle a completed tunnel build with additional detail. |
(package private) void | buildTunnel(PooledTunnelCreatorConfig cfg)Build a tunnel with the given configuration. |
(package private) static Map<Hash,int[]> | collectPairTargets(List<TunnelPool> pools)Collect per-direction build quantity targets for paired destinations,
used by the proportional per-direction cap in calculatePairedBuilds(). |
(package private) static int | computeUrgencyScore(int usableCount,
int target)Urgency score used to sort pools before build allocation, so a
collapsed or near-collapse pool earlier in the list cannot consume
build slots (or trigger the proportional cap) before an urgent pool
later in the list gets any. |
(package private) void | cooldownFailedPeers(PooledTunnelCreatorConfig cfg)Cool down every non-self hop of a failed build so the immediate retry
selects different peers. |
(package private) static BuildExecutor.ExpiryBuckets | countExpiryBuckets(List<TunnelInfo> tunnels,
long now,
boolean allowZeroHop)Count a pool's tunnels into cumulative expiry-window buckets. |
(package private) static boolean | countsAsPoolFailure(BuildExecutor.Result result)Pool-backoff counting excludes results that are not peer failures:
SUCCESS, DUP_ID (already handled), REJECT (peer said no),
NO_TUNNELS (local resource condition), NO_NETDB (local netdb miss),
and SKIPPED (local policy, no build dispatched). |
boolean | fullStats()Check if full statistics are enabled. |
static long | getGoodDeficitThrottle(RouterContext ctx)The GOOD deficit throttle interval from config or default (30s). |
static int | getMaxConcurrentBuilds()The maximum number of concurrent builds allowed. |
static long | getPoolBackoffMs()The pool backoff time in milliseconds. |
static int | getPoolFailureThreshold()The pool failure threshold. |
(package private) static int | getTunnelLifetime(RouterContext ctx)The tunnel lifetime from config, delegated to TunnelPool. |
(package private) static int | getTunnelTargetBuffer(RouterContext ctx)The target build buffer from config or default (0). |
(package private) boolean | isPoolInBackoff(TunnelPool pool)Check if a pool is in backoff due to consecutive build failures. |
boolean | isRunning()Check if the executor is currently running. |
(package private) void | penalizeTimeout(PooledTunnelCreatorConfig cfg)Penalize the peers of an expired build. |
(package private) PooledTunnelCreatorConfig | removeFromBuilding(long id)This returns the PTCC up to a minute after it 'expired', thus allowing us to
still use a tunnel if it was accepted, and to update peer stats. |
(package private) void | removePoolState(TunnelPool pool)Remove failure state for a pool that is being removed. |
void | repoll()Signal the executor to repoll for tunnel building opportunities. |
void | restart()Restart the build executor, clearing recent build state. |
void | run()Starts the tunnel building process in a loop and takes care of error handling. |
static void | setMaxConcurrentBuilds(int val)The maximum number of concurrent builds allowed. |
static void | setPoolBackoffMs(long val)The pool backoff time in milliseconds. |
static void | setPoolFailureThreshold(int val)The pool failure threshold. |
void | shutdown()Cannot be restarted. |
(package private) static long | spacingDelay(long lastPassTime,
long now)Remaining build-pass spacing in ms: 0 when the spacing floor since the
last pass is satisfied, otherwise the time still left to wait. |
(package private) static void | trimFifo(Set<Long> ids,
int max)Trim a FIFO id set to at most max entries, dropping the oldest
(head) entries first. |
boolean | wasRecentlyBuilding(long replyId)Check if a tunnel build was recently attempted. |
public BuildExecutor(RouterContext ctx, TunnelPoolManager mgr, GhostPeerManager ghostMgr)
ctx - the router contextmgr - the tunnel pool managerghostMgr - the ghost peer manager for tracking timeoutspublic void buildComplete(PooledTunnelCreatorConfig cfg, BuildExecutor.Result result)
cfg - the tunnel configuration that completedresult - the build result (success, failure, etc.)public void buildComplete(PooledTunnelCreatorConfig cfg, BuildExecutor.Result result, String detail)
cfg - the tunnel configuration that completedresult - the build result (success, failure, etc.)detail - additional detail on the resultvoid buildTunnel(PooledTunnelCreatorConfig cfg)
cfg - the tunnel configuration to buildstatic Map<Hash,int[]> collectPairTargets(List<TunnelPool> pools)
pools - pools to scan; dead pools and pools without a destination
are skippedstatic int computeUrgencyScore(int usableCount,
int target)usableCount - current usable tunnel count of the pooltarget - minimum desired tunnel count (already clamped to >= 2)void cooldownFailedPeers(PooledTunnelCreatorConfig cfg)
TunnelPeerSelector.PEER_SELECTION_COOLDOWN_MS and both peer
selectors consult this map; profile penalties are separate and, for
timeouts, go to the contacted hop only via
penalizeTimeout(PooledTunnelCreatorConfig).cfg - the failed build configstatic BuildExecutor.ExpiryBuckets countExpiryBuckets(List<TunnelInfo> tunnels, long now, boolean allowZeroHop)
tunnels - tunnels of one pool, never nullnow - current time, used to compute time-to-expiryallowZeroHop - if false, length-1 tunnels are counted as
fallbackCount and skipped; if true they are
counted normallystatic boolean countsAsPoolFailure(BuildExecutor.Result result)
result - the build resultpublic boolean fullStats()
public static long getGoodDeficitThrottle(RouterContext ctx)
ctx - the router contextpublic static int getMaxConcurrentBuilds()
public static long getPoolBackoffMs()
public static int getPoolFailureThreshold()
static int getTunnelLifetime(RouterContext ctx)
ctx - the router contextstatic int getTunnelTargetBuffer(RouterContext ctx)
ctx - the router contextboolean isPoolInBackoff(TunnelPool pool)
pool - the tunnel pool to checkpublic boolean isRunning()
void penalizeTimeout(PooledTunnelCreatorConfig cfg)
BuildRequestor.getBuildRequestPeer(PooledTunnelCreatorConfig) —
failed to deliver a reply; the other hops may never have received
the request, or may be waiting downstream of a silent peer. Blaming
them all shrinks the pool on innocent peers during network-wide
no-reply events, so the profile penalty and ghost mark go to the
contacted hop only. The per-tier expire stat and the didNotReply
debug log stay per-hop for accounting and triage.
Every non-self hop is additionally cooled down out of the immediate
retry selection (cooldownFailedPeers(PooledTunnelCreatorConfig)),
since any of them may have been the silent one.cfg - the expired build config, non-nullPooledTunnelCreatorConfig removeFromBuilding(long id)
id - the build message IDvoid removePoolState(TunnelPool pool)
pool - the pool to remove state forpublic void repoll()
public void restart()
public void run()
public static void setMaxConcurrentBuilds(int val)
val - the maximum concurrent buildspublic static void setPoolBackoffMs(long val)
val - the backoff in ms (1000-60000)public static void setPoolFailureThreshold(int val)
val - the threshold value (1-20)public void shutdown()
static long spacingDelay(long lastPassTime,
long now)lastPassTime - the end of the last build pass in msnow - the current time in msstatic void trimFifo(Set<Long> ids, int max)
max entries, dropping the oldest
(head) entries first. Insertion order is preserved by the caller.ids - the id set, held by the caller's monitormax - the maximum size to keeppublic boolean wasRecentlyBuilding(long replyId)
replyId - the reply message ID to check