java.lang.Object
net.i2p.router.tunnel.pool.RequestThrottler.BurstWindowCounter
Enclosing class:
RequestThrottler

static class RequestThrottler.BurstWindowCounterextends Object
Sliding window counter for burst detection. Tracks per-peer request counts using 1-second buckets in a 10-second window.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BurstWindowCounter(long windowSizeMs, int bucketCount)
    Divide the window into equal time buckets.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    (package private) void
    cleanup(long now)
    Drop peers whose current and previous buckets are both zero.
    (package private) int
    Window total for the peer without recording a request.
    (package private) int
    Count in the current bucket only, not the whole window.
    (package private) int
    Record one request from the peer and return the fresh window total.
    (package private) boolean
    isBursting(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).

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BurstWindowCounter

      BurstWindowCounter(long windowSizeMs, int bucketCount)
      Divide the window into equal time buckets.
      Parameters:
      windowSizeMs - total window length in ms
      bucketCount - equal time buckets covering the window
  • Method Details

    • increment

      int increment(Hash h)
      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

      int getCount(Hash h)
      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

      int getCurrentBucketCount(Hash h)
      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

      boolean isBursting(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).
      Parameters:
      h - the peer's hash
      normalLimit - 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