forked from I2P_Developers/i2p.i2p
Streaming: Move throttler from context timer to streaming timer
This commit is contained in:
@@ -25,7 +25,7 @@ class ConnThrottler {
|
||||
* @param totalMax for all peers, 0 for unlimited
|
||||
* @param period ms
|
||||
*/
|
||||
ConnThrottler(int max, int totalMax, long period) {
|
||||
ConnThrottler(int max, int totalMax, long period, SimpleTimer2 timer) {
|
||||
_max = max;
|
||||
_totalMax = totalMax;
|
||||
this.counter = new ObjectCounter<Hash>();
|
||||
@@ -33,9 +33,9 @@ class ConnThrottler {
|
||||
// shorten the initial period by a random amount
|
||||
// to prevent correlation across destinations
|
||||
// and identification of router startup time
|
||||
SimpleTimer2.getInstance().addPeriodicEvent(new Cleaner(),
|
||||
(period / 2) + RandomSource.getInstance().nextLong(period / 2),
|
||||
period);
|
||||
timer.addPeriodicEvent(new Cleaner(),
|
||||
(period / 2) + RandomSource.getInstance().nextLong(period / 2),
|
||||
period);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -178,21 +178,24 @@ class ConnectionManager {
|
||||
if ((_defaultOptions.getMaxConnsPerMinute() > 0 || _defaultOptions.getMaxTotalConnsPerMinute() > 0) &&
|
||||
_minuteThrottler == null) {
|
||||
_context.statManager().createRateStat("stream.con.throttledMinute", "Dropped for conn limit", "Stream", new long[] { 5*60*1000 });
|
||||
_minuteThrottler = new ConnThrottler(_defaultOptions.getMaxConnsPerMinute(), _defaultOptions.getMaxTotalConnsPerMinute(), 60*1000);
|
||||
_minuteThrottler = new ConnThrottler(_defaultOptions.getMaxConnsPerMinute(), _defaultOptions.getMaxTotalConnsPerMinute(),
|
||||
60*1000, _timer);
|
||||
} else if (_minuteThrottler != null) {
|
||||
_minuteThrottler.updateLimits(_defaultOptions.getMaxConnsPerMinute(), _defaultOptions.getMaxTotalConnsPerMinute());
|
||||
}
|
||||
if ((_defaultOptions.getMaxConnsPerHour() > 0 || _defaultOptions.getMaxTotalConnsPerHour() > 0) &&
|
||||
_hourThrottler == null) {
|
||||
_context.statManager().createRateStat("stream.con.throttledHour", "Dropped for conn limit", "Stream", new long[] { 5*60*1000 });
|
||||
_hourThrottler = new ConnThrottler(_defaultOptions.getMaxConnsPerHour(), _defaultOptions.getMaxTotalConnsPerHour(), 60*60*1000);
|
||||
_hourThrottler = new ConnThrottler(_defaultOptions.getMaxConnsPerHour(), _defaultOptions.getMaxTotalConnsPerHour(),
|
||||
60*60*1000, _timer);
|
||||
} else if (_hourThrottler != null) {
|
||||
_hourThrottler.updateLimits(_defaultOptions.getMaxConnsPerHour(), _defaultOptions.getMaxTotalConnsPerHour());
|
||||
}
|
||||
if ((_defaultOptions.getMaxConnsPerDay() > 0 || _defaultOptions.getMaxTotalConnsPerDay() > 0) &&
|
||||
_dayThrottler == null) {
|
||||
_context.statManager().createRateStat("stream.con.throttledDay", "Dropped for conn limit", "Stream", new long[] { 5*60*1000 });
|
||||
_dayThrottler = new ConnThrottler(_defaultOptions.getMaxConnsPerDay(), _defaultOptions.getMaxTotalConnsPerDay(), 24*60*60*1000);
|
||||
_dayThrottler = new ConnThrottler(_defaultOptions.getMaxConnsPerDay(), _defaultOptions.getMaxTotalConnsPerDay(),
|
||||
24*60*60*1000, _timer);
|
||||
} else if (_dayThrottler != null) {
|
||||
_dayThrottler.updateLimits(_defaultOptions.getMaxConnsPerDay(), _defaultOptions.getMaxTotalConnsPerDay());
|
||||
}
|
||||
|
Reference in New Issue
Block a user