java.lang.Object
net.i2p.router.transport.udp.IPThrottler

class IPThrottlerextends Object
Throttles connection attempts by IP address to prevent abuse. Counts and limits requests from individual IPs within a time window. Supports both IPv4 (direct IP) and IPv6 (hashed first 8 bytes) addresses.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
    Decays the per-IP counts on a schedule.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final long
    How often the counts are decayed, in ms.
    Recent messages counted per IP address.
    private final int
    Most messages allowed from one IP in a window.
  • Constructor Summary

    Constructors
    Constructor
    Description
    IPThrottler(int max, long time)
    Create an IP throttler.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static Integer
    hashCode(byte[] ip)
    Hash an IP address for throttling.
    boolean
    shouldThrottle(byte[] ip)
    Increments before checking.
    private static Integer
    toInt(byte[] ip)
    Reduces an IP address to a map key.

    Methods inherited from class Object

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

    • _counter

      private ObjectCounter<Integer> _counter
      Recent messages counted per IP address.
    • _max

      private final int _max
      Most messages allowed from one IP in a window.
    • _cleanTime

      private final long _cleanTime
      How often the counts are decayed, in ms.
  • Constructor Details

    • IPThrottler

      public IPThrottler(int max, long time)
      Create an IP throttler.
      Parameters:
      max - the maximum count before throttling
      time - the cleanup interval in ms
  • Method Details

    • shouldThrottle

      public boolean shouldThrottle(byte[] ip)
      Increments before checking.
      Parameters:
      ip - the IP address bytes
      Returns:
      true if the IP should be throttled
    • toInt

      private static Integer toInt(byte[] ip)
      Reduces an IP address to a map key.
      Parameters:
      ip - the address bytes
      Returns:
      the key for that address
    • hashCode

      private static Integer hashCode(byte[] ip)
      Hash an IP address for throttling.
      Parameters:
      ip - the raw address bytes, at least 8 bytes long
      Returns:
      the hash value used as the throttle map key