java.lang.Object
net.i2p.router.transport.udp.IPThrottler
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 ClassesModifier and TypeClassDescriptionprivate classDecays the per-IP counts on a schedule.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longHow often the counts are decayed, in ms.private ObjectCounter<Integer> Recent messages counted per IP address.private final intMost messages allowed from one IP in a window.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static IntegerhashCode(byte[] ip) Hash an IP address for throttling.booleanshouldThrottle(byte[] ip) Increments before checking.private static IntegertoInt(byte[] ip) Reduces an IP address to a map key.
Field Details
_counter
Recent messages counted per IP address._max
private final int _maxMost messages allowed from one IP in a window._cleanTime
private final long _cleanTimeHow 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 throttlingtime- 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
Reduces an IP address to a map key.- Parameters:
ip- the address bytes- Returns:
- the key for that address
hashCode
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