java.lang.Object
net.i2p.client.streaming.impl.ConnThrottler

class ConnThrottlerextends Object
Count how often we have received an incoming connection This offers basic DOS protection but is not a complete solution.
  • Field Details

    • counter

      private final ObjectCounter<Hash> counter
      Open connections counted per peer.
    • _max

      private volatile int _max
      Most connections allowed from one peer.
    • _totalMax

      private volatile int _totalMax
      Most connections allowed from all peers together.
    • _currentTotal

      private final AtomicInteger _currentTotal
      Connections open right now.
    • _cleaner

      private final ConnThrottler.Cleaner _cleaner
      Timer decaying the counts periodically.
  • Constructor Details

    • ConnThrottler

      ConnThrottler(int max, int totalMax, long period, SimpleTimer2 timer)
      Connection throttle for incoming connection rates.
      Parameters:
      max - per-peer, 0 for unlimited
      totalMax - for all peers, 0 for unlimited
      period - how often the counters are reset, in ms
      timer - the timer pool the periodic counter reset is scheduled on
  • Method Details

    • updateLimits

      public void updateLimits(int max, int totalMax)
      Update the connection limits.
      Parameters:
      max - per-peer, 0 for unlimited
      totalMax - for all peers, 0 for unlimited
    • shouldThrottle

      boolean shouldThrottle(Hash h)
      Checks both individual and total. Increments before checking.
      Parameters:
      h - the destination hash of the peer asking to connect
      Returns:
      true if the connection must be refused because a per-peer or overall limit was already exceeded
    • isThrottled

      boolean isThrottled(Hash h)
      Check if throttled without incrementing.
      Parameters:
      h - the destination hash to test against the per-peer limit
      Returns:
      true if this peer has already opened more connections than its limit allows
    • isOverBy

      boolean isOverBy(Hash h, int over)
      Checks if individual count is over the limit by this much. Does not increment.
      Parameters:
      h - the destination hash to test against the per-peer limit
      over - the number of extra connections to allow beyond that limit
      Returns:
      true if this peer's connection count exceeds its limit by more than over