* Streaming:

- Ensure minimum randomized initial conn throttle period
   - Change order of throttle checks again
   - Don't continue throttle checks if throttled
This commit is contained in:
zzz
2013-10-28 17:59:50 +00:00
parent f0f363e8c3
commit a92913da4c
2 changed files with 36 additions and 37 deletions

View File

@ -34,7 +34,7 @@ class ConnThrottler {
// to prevent correlation across destinations // to prevent correlation across destinations
// and identification of router startup time // and identification of router startup time
SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(), SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(),
RandomSource.getInstance().nextLong(period), (period / 2) + RandomSource.getInstance().nextLong(period / 2),
period); period);
} }

View File

@ -401,12 +401,6 @@ class ConnectionManager {
// possibly trigger total-counter blocks for others. // possibly trigger total-counter blocks for others.
// if the sig is absent or bad it will be caught later (in CPH) // if the sig is absent or bad it will be caught later (in CPH)
if (_defaultOptions.isAccessListEnabled() &&
!_defaultOptions.getAccessList().contains(h))
return "not whitelisted";
if (_defaultOptions.isBlacklistEnabled() &&
_defaultOptions.getBlacklist().contains(h))
return "blacklisted";
String hashes = _context.getProperty(PROP_BLACKLIST, ""); String hashes = _context.getProperty(PROP_BLACKLIST, "");
if (!_currentBlacklist.equals(hashes)) { if (!_currentBlacklist.equals(hashes)) {
// rebuild _globalBlacklist when property changes // rebuild _globalBlacklist when property changes
@ -434,53 +428,58 @@ class ConnectionManager {
if (hashes.length() > 0 && _globalBlacklist.contains(h)) if (hashes.length() > 0 && _globalBlacklist.contains(h))
return "blacklisted globally"; return "blacklisted globally";
if (_defaultOptions.isAccessListEnabled() &&
!_defaultOptions.getAccessList().contains(h))
return "not whitelisted";
if (_defaultOptions.isBlacklistEnabled() &&
_defaultOptions.getBlacklist().contains(h))
return "blacklisted";
String throttled = null;
// always call all 3 to increment all counters if (_dayThrottler != null && _dayThrottler.shouldThrottle(h)) {
if (_minuteThrottler != null && _minuteThrottler.shouldThrottle(h)) { _context.statManager().addRateData("stream.con.throttledDay", 1, 0);
_context.statManager().addRateData("stream.con.throttledMinute", 1, 0); if (_defaultOptions.getMaxConnsPerDay() <= 0)
if (_defaultOptions.getMaxConnsPerMinute() <= 0) return "throttled by" +
throttled = "throttled by" + " total limit of " + _defaultOptions.getMaxTotalConnsPerDay() +
" total limit of " + _defaultOptions.getMaxTotalConnsPerMinute() + " per day";
" per minute"; else if (_defaultOptions.getMaxTotalConnsPerDay() <= 0)
else if (_defaultOptions.getMaxTotalConnsPerMinute() <= 0) return "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerDay() +
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerMinute() + " per day";
" per minute";
else else
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerMinute() + return "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerDay() +
" or total limit of " + _defaultOptions.getMaxTotalConnsPerMinute() + " or total limit of " + _defaultOptions.getMaxTotalConnsPerDay() +
" per minute"; " per day";
} }
if (_hourThrottler != null && _hourThrottler.shouldThrottle(h)) { if (_hourThrottler != null && _hourThrottler.shouldThrottle(h)) {
_context.statManager().addRateData("stream.con.throttledHour", 1, 0); _context.statManager().addRateData("stream.con.throttledHour", 1, 0);
if (_defaultOptions.getMaxConnsPerHour() <= 0) if (_defaultOptions.getMaxConnsPerHour() <= 0)
throttled = "throttled by" + return "throttled by" +
" total limit of " + _defaultOptions.getMaxTotalConnsPerHour() + " total limit of " + _defaultOptions.getMaxTotalConnsPerHour() +
" per hour"; " per hour";
else if (_defaultOptions.getMaxTotalConnsPerHour() <= 0) else if (_defaultOptions.getMaxTotalConnsPerHour() <= 0)
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerHour() + return "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerHour() +
" per hour"; " per hour";
else else
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerHour() + return "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerHour() +
" or total limit of " + _defaultOptions.getMaxTotalConnsPerHour() + " or total limit of " + _defaultOptions.getMaxTotalConnsPerHour() +
" per hour"; " per hour";
} }
if (_dayThrottler != null && _dayThrottler.shouldThrottle(h)) { if (_minuteThrottler != null && _minuteThrottler.shouldThrottle(h)) {
_context.statManager().addRateData("stream.con.throttledDay", 1, 0); _context.statManager().addRateData("stream.con.throttledMinute", 1, 0);
if (_defaultOptions.getMaxConnsPerDay() <= 0) if (_defaultOptions.getMaxConnsPerMinute() <= 0)
throttled = "throttled by" + return "throttled by" +
" total limit of " + _defaultOptions.getMaxTotalConnsPerDay() + " total limit of " + _defaultOptions.getMaxTotalConnsPerMinute() +
" per day"; " per minute";
else if (_defaultOptions.getMaxTotalConnsPerDay() <= 0) else if (_defaultOptions.getMaxTotalConnsPerMinute() <= 0)
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerDay() + return "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerMinute() +
" per day"; " per minute";
else else
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerDay() + return "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerMinute() +
" or total limit of " + _defaultOptions.getMaxTotalConnsPerDay() + " or total limit of " + _defaultOptions.getMaxTotalConnsPerMinute() +
" per day"; " per minute";
} }
return throttled; return null;
} }