java.lang.Object
net.i2p.client.streaming.impl.ConnThrottler
Count how often we have received an incoming connection This offers basic DOS protection but is not a complete solution.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classDecays the per-peer counts on a schedule.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConnThrottler.CleanerTimer decaying the counts periodically.private final AtomicIntegerConnections open right now.private intMost connections allowed from one peer.private intMost connections allowed from all peers together.private final ObjectCounter<Hash> Open connections counted per peer.Constructor Summary
ConstructorsConstructorDescriptionConnThrottler(int max, int totalMax, long period, SimpleTimer2 timer) Connection throttle for incoming connection rates.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) booleanChecks if individual count is over the limit by this much.(package private) booleanisThrottled(Hash h) Check if throttled without incrementing.(package private) booleanChecks both individual and total.voidupdateLimits(int max, int totalMax) Update the connection limits.
Field Details
counter
Open connections counted per peer._max
private volatile int _maxMost connections allowed from one peer._totalMax
private volatile int _totalMaxMost connections allowed from all peers together._currentTotal
Connections open right now._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 unlimitedtotalMax- for all peers, 0 for unlimitedperiod- how often the counters are reset, in mstimer- 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 unlimitedtotalMax- for all peers, 0 for unlimited
shouldThrottle
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
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
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 limitover- 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