java.lang.Object
net.i2p.router.tunnel.pool.RequestThrottler
Throttles incoming tunnel requests earlier than ParticipatingThrottler, with higher limits and more frequent cleanup.
Checks various router characteristics and decides whether to throttle, ban, or disconnect routers based on request count, version, bandwidth, and system load.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classTracks burst offense history for escalation.(package private) static classSliding window counter for burst detection.private classPeriodic timer event that clears the request counts to reset throttling.private classTimer event that forces disconnection from a router after a delay.Field Summary
Modifier and TypeFieldDescriptionprivate BanLoggerRecords why routers were banned.private final RequestThrottler.BurstWindowCounterSliding window counter for burst detection.private final Map<Hash, RequestThrottler.BurstOffenseRecord> Burst offenses recorded per peer.static intHigh-load CPU threshold (percent)static intHigh-load job lag threshold (ms)static intHigh-load system load threshold (percent, normalized by cores)private final LogLogger for throttling decisions.static intModerate-load CPU threshold (percent)static intModerate-load job lag threshold (ms)private longWhen the request load first reached the moderate level.static intModerate-load system load threshold (percent, normalized by cores)static intBurst threshold for 1-second sliding window (requests per second).static intLoad weight: how much load inflates effective ratio (0-300%, default 100%).static intMaximum request limit per peer.static intMinimum request limit per peer.static intRequest limit as percentage of participating tunnel count.static intRejection steepness: 100=linear ramp, 200=quadratic.static intRejection threshold: start rejecting at count/limit ratio this high (30-100, default 70%).static longDuration (ms) moderate load must persist before disconnecting low-share peersprivate static final longBan length for the first banning burst offense, scaling with further offenses.private static final longCeiling for burst bans.private static final intBurst offenses before a ban issues; earlier offenses only throttle the request.private static final intBuckets in the burst window, one second each.private static final longIdle time before burst offenses are forgotten.private static final intHighest burst threshold allowed.private static final intLowest burst threshold allowed.private static final doubleShare of the 90 second limit used as the burst threshold.private static final longLength of the burst detection window.private booleanCached result of the firewall status check.private booleanCached flag for banning excessive requesters.private BooleanCached flag for rejecting old routers.private BooleanCached flag for disconnecting excessive requesters.private BooleanCached flag for whether to throttle at all.private static final longInterval between request count resets.private final RouterContextThe router context.private final ObjectCounter<Hash> Build requests counted per peer.private static final booleanBanning excessive requesters is off by default.private static final booleanRejecting old routers is on by default.(package private) static final booleanWhether a versionless peer is disconnected when the property is unset.(package private) static final booleanWhether count-based transit throttling applies when the property is unset.private static final longInterval between firewall status checks.private longWhen our firewall status was last checked.private longWhen the config values were last re-read.private static final longBan length for LU prev-hops under load.private static final StringConfig key turning the excessive request ban on or off.private static final StringConfig key for rejecting routers with old profiles.(package private) static final StringEnables scheduling a disconnect for a peer that joins with no version.(package private) static final StringEnables counting transit requests and rejecting or dropping over-limit peers.private static final longInterval between config re-reads.private static final long[]Rate stat periods for the throttle statistics.Constructor Summary
ConstructorsConstructorDescriptionCreates a new RequestThrottler bound to the given router context.Method Summary
Modifier and TypeMethodDescription(package private) static longburstBanDurationMs(int offenses) Ban length for a repeated burst offense: zero for the firstBURST_BAN_OFFENSES- 1 offenses (throttle-only), then five minutes growing by five minutes per further offense, capped at thirty minutes.(package private) static intburstThreshold(int configuredThreshold, int limit) Effective single-second burst threshold for a peer: the configured floor, raised so peers whose limit permits heavy traffic are not banned for bursts that limit allows (one tenth of the 90-second request limit as a per-second ceiling).private static intclamp(int val, int lo, int hi) Constrain a configured property to an allowed range.static intThe high-load CPU threshold percentage.static intThe high-load job lag threshold in milliseconds.static intThe high-load system load threshold percentage (normalized by cores).static intThe moderate-load CPU threshold percentage.static intThe moderate-load job lag threshold in milliseconds.static intThe moderate-load system load threshold percentage (normalized by cores).static intThe burst threshold for 1-second sliding window.static intThe load weight (how much load inflates effective ratio, 0-300%).static intThe maximum request limit per peer.static intThe minimum request limit per peer.static intThe request limit as percentage of participating tunnel count.static intThe rejection steepness (100=linear ramp, 200=quadratic).static intThe rejection threshold (30-100, default 70%).static longThe duration (ms) moderate load must persist before disconnecting low-share peers.private booleanisFast(RouterInfo ri) Checks if router has high bandwidth capabilities.private booleanChecks if we are firewalled, with caching to avoid repeated commSystem status checks.private booleanisLowShare(RouterInfo ri) Checks if router has low bandwidth sharing capabilities.private booleanChecks whether a router is known to be unreachable.(package private) static floatluEnforcementProbability(float loadScore) Probability of enforcing the LU prev-hop ban at a given load score: zero when idle, linear up to full enforcement at 50% load and beyond, so unloaded routers carry LU traffic while loaded ones shed it.static voidsetHighLoadCpuPct(int val) The high-load CPU threshold percentage.static voidsetHighLoadLagMs(int val) The high-load job lag threshold in milliseconds.static voidsetHighLoadSysLoadPct(int val) The high-load system load threshold percentage.static voidsetModerateLoadCpuPct(int val) The moderate-load CPU threshold percentage.static voidsetModerateLoadLagMs(int val) The moderate-load job lag threshold in milliseconds.static voidsetModerateLoadSysLoadPct(int val) The moderate-load system load threshold percentage.static voidsetRequestBurst1sThreshold(int val) The burst threshold for 1-second sliding window.static voidsetRequestLoadWeight(int val) The load weight percentage.static voidsetRequestMaxLimit(int val) The maximum request limit per peer.static voidsetRequestMinLimit(int val) The minimum request limit per peer.static voidsetRequestPctLimit(int val) The request limit as percentage of participating tunnel count.static voidsetRequestRejectSteepness(int val) The rejection steepness (100=linear, 500=max curve).static voidsetRequestRejectThreshold(int val) The rejection threshold percentage.static voidsetSustainedModerateLoadMs(long val) The duration (ms) moderate load must persist before disconnecting low-share peers.(package private) booleanChecks if the given router's tunnel requests should be throttled.private voidUpdates cached property values to avoid repeated property lookups.
Field Details
context
The router context.counter
Build requests counted per peer._log
Logger for throttling decisions._banLogger
Records why routers were banned.lastFirewallCheckTime
private volatile long lastFirewallCheckTimeWhen our firewall status was last checked.cachedFirewalledStatus
private volatile boolean cachedFirewalledStatusCached result of the firewall status check.FIREWALL_CHECK_INTERVAL
private static final long FIREWALL_CHECK_INTERVALInterval between firewall status checks.- See Also:
lastPropertyCheckTime
private volatile long lastPropertyCheckTimeWhen the config values were last re-read.cachedShouldThrottle
Cached flag for whether to throttle at all.cachedShouldDisconnect
Cached flag for disconnecting excessive requesters.cachedShouldBlockOldRouters
Cached flag for rejecting old routers.cachedShouldBanExcessive
private volatile boolean cachedShouldBanExcessiveCached flag for banning excessive requesters.PROPERTY_CHECK_INTERVAL
private static final long PROPERTY_CHECK_INTERVALInterval between config re-reads.- See Also:
_reqMinLimit
public static volatile int _reqMinLimitMinimum request limit per peer._reqMaxLimit
public static volatile int _reqMaxLimitMaximum request limit per peer._reqPercentLimit
public static volatile int _reqPercentLimitRequest limit as percentage of participating tunnel count._reqBurst1sThreshold
public static volatile int _reqBurst1sThresholdBurst threshold for 1-second sliding window (requests per second)._reqRejectThreshold
public static volatile int _reqRejectThresholdRejection threshold: start rejecting at count/limit ratio this high (30-100, default 70%)._reqRejectSteepness
public static volatile int _reqRejectSteepnessRejection steepness: 100=linear ramp, 200=quadratic._reqLoadWeight
public static volatile int _reqLoadWeightLoad weight: how much load inflates effective ratio (0-300%, default 100%)._highLoadLagMs
public static volatile int _highLoadLagMsHigh-load job lag threshold (ms)_highLoadCpuPct
public static volatile int _highLoadCpuPctHigh-load CPU threshold (percent)_highLoadSysLoadPct
public static volatile int _highLoadSysLoadPctHigh-load system load threshold (percent, normalized by cores)_moderateLoadLagMs
public static volatile int _moderateLoadLagMsModerate-load job lag threshold (ms)_moderateLoadCpuPct
public static volatile int _moderateLoadCpuPctModerate-load CPU threshold (percent)_moderateLoadSysLoadPct
public static volatile int _moderateLoadSysLoadPctModerate-load system load threshold (percent, normalized by cores)_sustainedModerateLoadMs
public static volatile long _sustainedModerateLoadMsDuration (ms) moderate load must persist before disconnecting low-share peersCLEAN_TIME
private static final long CLEAN_TIMEInterval between request count resets.- See Also:
LU_BAN_MS
private static final long LU_BAN_MSBan length for LU prev-hops under load.- See Also:
BURST_BAN_OFFENSES
private static final int BURST_BAN_OFFENSESBurst offenses before a ban issues; earlier offenses only throttle the request.- See Also:
BURST_BAN_BASE_MS
private static final long BURST_BAN_BASE_MSBan length for the first banning burst offense, scaling with further offenses.- See Also:
BURST_BAN_MAX_MS
RATES
private static final long[] RATESRate stat periods for the throttle statistics.BURST_WINDOW_MS
private static final long BURST_WINDOW_MSLength of the burst detection window.- See Also:
BURST_BUCKET_COUNT
private static final int BURST_BUCKET_COUNTBuckets in the burst window, one second each.- See Also:
BURST_THRESHOLD_MIN
private static final int BURST_THRESHOLD_MINLowest burst threshold allowed.- See Also:
BURST_THRESHOLD_MAX
private static final int BURST_THRESHOLD_MAXHighest burst threshold allowed.- See Also:
BURST_THRESHOLD_PERCENT
private static final double BURST_THRESHOLD_PERCENTShare of the 90 second limit used as the burst threshold.- See Also:
BURST_OFFENSE_RESET
private static final long BURST_OFFENSE_RESETIdle time before burst offenses are forgotten.- See Also:
_burstCounter
Sliding window counter for burst detection._burstOffenses
Burst offenses recorded per peer._moderateLoadStart
private volatile long _moderateLoadStartWhen the request load first reached the moderate level.DEFAULT_SHOULD_THROTTLE
static final boolean DEFAULT_SHOULD_THROTTLEWhether count-based transit throttling applies when the property is unset.- See Also:
PROP_SHOULD_THROTTLE
Enables counting transit requests and rejecting or dropping over-limit peers.- See Also:
DEFAULT_SHOULD_DISCONNECT
static final boolean DEFAULT_SHOULD_DISCONNECTWhether a versionless peer is disconnected when the property is unset.- See Also:
PROP_SHOULD_DISCONNECT
Enables scheduling a disconnect for a peer that joins with no version.- See Also:
DEFAULT_BLOCK_OLD_ROUTERS
private static final boolean DEFAULT_BLOCK_OLD_ROUTERSRejecting old routers is on by default.- See Also:
PROP_BLOCK_OLD_ROUTERS
Config key for rejecting routers with old profiles.- See Also:
DEFAULT_BAN_EXCESSIVE_REQUESTS
private static final boolean DEFAULT_BAN_EXCESSIVE_REQUESTSBanning excessive requesters is off by default.- See Also:
PROP_BAN_EXCESSIVE_REQUESTS
Config key turning the excessive request ban on or off.- See Also:
Constructor Details
RequestThrottler
RequestThrottler(RouterContext ctx) Creates a new RequestThrottler bound to the given router context. Initializes the request counter, burst detector, ban logger, and configures tunable parameters from router properties.- Parameters:
ctx- the router context
Method Details
getRequestMinLimit
public static int getRequestMinLimit()The minimum request limit per peer.- Returns:
- the minimum limit
setRequestMinLimit
public static void setRequestMinLimit(int val) The minimum request limit per peer.- Parameters:
val- the minimum limit (clamped to 1-100)
getRequestMaxLimit
public static int getRequestMaxLimit()The maximum request limit per peer.- Returns:
- the maximum limit
setRequestMaxLimit
public static void setRequestMaxLimit(int val) The maximum request limit per peer.- Parameters:
val- the maximum limit (clamped to 10-1000)
getRequestPctLimit
public static int getRequestPctLimit()The request limit as percentage of participating tunnel count.- Returns:
- the percentage limit
setRequestPctLimit
public static void setRequestPctLimit(int val) The request limit as percentage of participating tunnel count.- Parameters:
val- the percentage limit (clamped to 1-100)
getRequestBurst1sThreshold
public static int getRequestBurst1sThreshold()The burst threshold for 1-second sliding window.- Returns:
- the burst threshold (requests per second)
setRequestBurst1sThreshold
public static void setRequestBurst1sThreshold(int val) The burst threshold for 1-second sliding window.- Parameters:
val- the burst threshold (clamped to 1-100)
getRequestRejectThreshold
public static int getRequestRejectThreshold()The rejection threshold (30-100, default 70%).- Returns:
- the rejection threshold percentage
setRequestRejectThreshold
public static void setRequestRejectThreshold(int val) The rejection threshold percentage.- Parameters:
val- the rejection threshold (clamped to 30-100)
getRequestRejectSteepness
public static int getRequestRejectSteepness()The rejection steepness (100=linear ramp, 200=quadratic).- Returns:
- the rejection steepness value
setRequestRejectSteepness
public static void setRequestRejectSteepness(int val) The rejection steepness (100=linear, 500=max curve).- Parameters:
val- the steepness value (clamped to 100-500)
getRequestLoadWeight
public static int getRequestLoadWeight()The load weight (how much load inflates effective ratio, 0-300%).- Returns:
- the load weight percentage
setRequestLoadWeight
public static void setRequestLoadWeight(int val) The load weight percentage.- Parameters:
val- the load weight (clamped to 0-300)
getHighLoadLagMs
public static int getHighLoadLagMs()The high-load job lag threshold in milliseconds.- Returns:
- the high-load lag threshold (ms)
setHighLoadLagMs
public static void setHighLoadLagMs(int val) The high-load job lag threshold in milliseconds.- Parameters:
val- the high-load lag threshold (clamped to 200-5000)
getHighLoadCpuPct
public static int getHighLoadCpuPct()The high-load CPU threshold percentage.- Returns:
- the high-load CPU percentage
setHighLoadCpuPct
public static void setHighLoadCpuPct(int val) The high-load CPU threshold percentage.- Parameters:
val- the CPU percentage (clamped to 50-100)
getHighLoadSysLoadPct
public static int getHighLoadSysLoadPct()The high-load system load threshold percentage (normalized by cores).- Returns:
- the high-load system load percentage
setHighLoadSysLoadPct
public static void setHighLoadSysLoadPct(int val) The high-load system load threshold percentage.- Parameters:
val- the system load percentage (clamped to 50-100)
getModerateLoadLagMs
public static int getModerateLoadLagMs()The moderate-load job lag threshold in milliseconds.- Returns:
- the moderate-load lag threshold (ms)
setModerateLoadLagMs
public static void setModerateLoadLagMs(int val) The moderate-load job lag threshold in milliseconds.- Parameters:
val- the moderate-load lag threshold (clamped to 100-3000)
getModerateLoadCpuPct
public static int getModerateLoadCpuPct()The moderate-load CPU threshold percentage.- Returns:
- the moderate-load CPU percentage
setModerateLoadCpuPct
public static void setModerateLoadCpuPct(int val) The moderate-load CPU threshold percentage.- Parameters:
val- the CPU percentage (clamped to 40-100)
getModerateLoadSysLoadPct
public static int getModerateLoadSysLoadPct()The moderate-load system load threshold percentage (normalized by cores).- Returns:
- the moderate-load system load percentage
setModerateLoadSysLoadPct
public static void setModerateLoadSysLoadPct(int val) The moderate-load system load threshold percentage.- Parameters:
val- the system load percentage (clamped to 30-100)
getSustainedModerateLoadMs
public static long getSustainedModerateLoadMs()The duration (ms) moderate load must persist before disconnecting low-share peers.- Returns:
- the sustained moderate load duration (ms)
setSustainedModerateLoadMs
public static void setSustainedModerateLoadMs(long val) The duration (ms) moderate load must persist before disconnecting low-share peers.- Parameters:
val- the sustained moderate load duration (clamped to 10-300s)
luEnforcementProbability
static float luEnforcementProbability(float loadScore) Probability of enforcing the LU prev-hop ban at a given load score: zero when idle, linear up to full enforcement at 50% load and beyond, so unloaded routers carry LU traffic while loaded ones shed it.- Parameters:
loadScore- the 0.0-1.0 load score fromParticipatingThrottler.calculateLoadScore(RouterContext)- Returns:
- the enforcement probability, clamped to 0.0-1.0
burstThreshold
static int burstThreshold(int configuredThreshold, int limit) Effective single-second burst threshold for a peer: the configured floor, raised so peers whose limit permits heavy traffic are not banned for bursts that limit allows (one tenth of the 90-second request limit as a per-second ceiling).- Parameters:
configuredThreshold- thei2p.tunnel.requestThrottle.burst1sThresholdvaluelimit- the peer's request limit for the current window- Returns:
- the burst threshold in requests per second
burstBanDurationMs
static long burstBanDurationMs(int offenses) Ban length for a repeated burst offense: zero for the firstBURST_BAN_OFFENSES- 1 offenses (throttle-only), then five minutes growing by five minutes per further offense, capped at thirty minutes.- Parameters:
offenses- the consecutive offense count, 1-based- Returns:
- the ban duration in ms, 0 when only throttling applies
clamp
private static int clamp(int val, int lo, int hi) Constrain a configured property to an allowed range. Used so a single expression both reads the property and clamps it, rather than storing the raw value and overwriting it on the next line.- Parameters:
val- the value read from the propertieslo- the lowest permitted valuehi- the highest permitted value- Returns:
- val limited to [lo, hi]
shouldThrottle
Checks if the given router's tunnel requests should be throttled. Increments the request count and evaluates limits, router capabilities, blocking policies, version, and system load to decide throttling.- Parameters:
h- the router's hash- Returns:
- true if the request should be throttled (denied), false otherwise
isUnreachable
Checks whether a router is known to be unreachable.- Parameters:
ri- the router info- Returns:
- true if the router is unreachable
isFast
Checks if router has high bandwidth capabilities.- Parameters:
ri- the router to check, null returns false- Returns:
- true if the router advertises BW256, BW512 or unbounded bandwidth
updateCachedProperties
private void updateCachedProperties()Updates cached property values to avoid repeated property lookups.isFirewalled
private boolean isFirewalled()Checks if we are firewalled, with caching to avoid repeated commSystem status checks.- Returns:
- true if firewalled, false otherwise