java.lang.Object
net.i2p.router.tunnel.pool.RequestThrottler.BurstWindowCounter
- Enclosing class:
RequestThrottler
Sliding window counter for burst detection. Tracks per-peer request counts using 1-second buckets in a 10-second window.
Constructor Summary
ConstructorsConstructorDescriptionBurstWindowCounter(long windowSizeMs, int bucketCount) Divide the window into equal time buckets.Method Summary
All MethodsModifier and TypeMethodDescription(package private) voidcleanup(long now) Drop peers whose current and previous buckets are both zero.(package private) intWindow total for the peer without recording a request.(package private) intCount in the current bucket only, not the whole window.(package private) intRecord one request from the peer and return the fresh window total.(package private) booleanisBursting(Hash h, int normalLimit) Whether the peer's window total exceeds a burst limit derived from its normal limit (clamped between the min and max).
Constructor Details
BurstWindowCounter
BurstWindowCounter(long windowSizeMs, int bucketCount) Divide the window into equal time buckets.- Parameters:
windowSizeMs- total window length in msbucketCount- equal time buckets covering the window
Method Details
increment
Record one request from the peer and return the fresh window total. Sweeps aged-out peers when the last sweep is over a minute old.- Parameters:
h- the requesting peer's hash- Returns:
- requests within the window, including this one
getCount
Window total for the peer without recording a request.- Parameters:
h- the peer's hash- Returns:
- requests within the window, 0 if never seen
getCurrentBucketCount
Count in the current bucket only, not the whole window.- Parameters:
h- the peer's hash- Returns:
- this bucket's count, 0 if never seen
isBursting
Whether the peer's window total exceeds a burst limit derived from its normal limit (clamped between the min and max).- Parameters:
h- the peer's hashnormalLimit- the peer's normal request limit- Returns:
- true if the window total is above the derived burst limit
cleanup
void cleanup(long now) Drop peers whose current and previous buckets are both zero. CAS-claimed so concurrent callers mostly skip the sweep.- Parameters:
now- current time in ms