forked from I2P_Developers/i2p.i2p
* Streaming: Improve conn limit log message
This commit is contained in:
@ -160,26 +160,22 @@ class ConnectionManager {
|
|||||||
_log.warn("Refusing connection since we have exceeded our max of "
|
_log.warn("Refusing connection since we have exceeded our max of "
|
||||||
+ _maxConcurrentStreams + " connections");
|
+ _maxConcurrentStreams + " connections");
|
||||||
reject = true;
|
reject = true;
|
||||||
} else if (shouldRejectConnection(synPacket)) {
|
|
||||||
// this may not be right if more than one is enabled
|
|
||||||
String why;
|
|
||||||
if (_defaultOptions.isAccessListEnabled())
|
|
||||||
why = "not whitelisted: ";
|
|
||||||
else if (_defaultOptions.isBlacklistEnabled())
|
|
||||||
why = "blacklisted: ";
|
|
||||||
else
|
|
||||||
why = "throttled: ";
|
|
||||||
_log.error("Refusing connection since peer is " + why +
|
|
||||||
(synPacket.getOptionalFrom() == null ? "null from" : synPacket.getOptionalFrom().calculateHash().toBase64()));
|
|
||||||
reject = true;
|
|
||||||
} else {
|
} else {
|
||||||
while (true) {
|
// this may not be right if more than one is enabled
|
||||||
Connection oldCon = _connectionByInboundId.putIfAbsent(Long.valueOf(receiveId), con);
|
String why = shouldRejectConnection(synPacket);
|
||||||
if (oldCon == null) {
|
if (why != null) {
|
||||||
break;
|
_log.logAlways(Log.WARN, "Refusing connection since peer is " + why +
|
||||||
} else {
|
(synPacket.getOptionalFrom() == null ? "" : ": " + synPacket.getOptionalFrom().calculateHash().toBase64()));
|
||||||
// receiveId already taken, try another
|
reject = true;
|
||||||
receiveId = _context.random().nextLong(Packet.MAX_STREAM_ID-1)+1;
|
} else {
|
||||||
|
while (true) {
|
||||||
|
Connection oldCon = _connectionByInboundId.putIfAbsent(Long.valueOf(receiveId), con);
|
||||||
|
if (oldCon == null) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// receiveId already taken, try another
|
||||||
|
receiveId = _context.random().nextLong(Packet.MAX_STREAM_ID-1)+1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,35 +299,46 @@ class ConnectionManager {
|
|||||||
return (active >= _maxConcurrentStreams);
|
return (active >= _maxConcurrentStreams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldRejectConnection(Packet syn) {
|
/**
|
||||||
|
* @return reason string or null if not rejected
|
||||||
|
*/
|
||||||
|
private String shouldRejectConnection(Packet syn) {
|
||||||
// unfortunately we don't have access to the router client manager here,
|
// unfortunately we don't have access to the router client manager here,
|
||||||
// so we can't whitelist local access
|
// so we can't whitelist local access
|
||||||
Destination from = syn.getOptionalFrom();
|
Destination from = syn.getOptionalFrom();
|
||||||
if (from == null)
|
if (from == null)
|
||||||
return true;
|
return "null";
|
||||||
Hash h = from.calculateHash();
|
Hash h = from.calculateHash();
|
||||||
boolean throttled = false;
|
String throttled = null;
|
||||||
// always call all 3 to increment all counters
|
// always call all 3 to increment all counters
|
||||||
if (_minuteThrottler != null && _minuteThrottler.shouldThrottle(h)) {
|
if (_minuteThrottler != null && _minuteThrottler.shouldThrottle(h)) {
|
||||||
_context.statManager().addRateData("stream.con.throttledMinute", 1, 0);
|
_context.statManager().addRateData("stream.con.throttledMinute", 1, 0);
|
||||||
throttled = true;
|
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerMinute() +
|
||||||
|
" or total limit of " + _defaultOptions.getMaxTotalConnsPerMinute() +
|
||||||
|
" per minute";
|
||||||
}
|
}
|
||||||
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);
|
||||||
throttled = true;
|
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerHour() +
|
||||||
|
" or total limit of " + _defaultOptions.getMaxTotalConnsPerHour() +
|
||||||
|
" per hour";
|
||||||
}
|
}
|
||||||
if (_dayThrottler != null && _dayThrottler.shouldThrottle(h)) {
|
if (_dayThrottler != null && _dayThrottler.shouldThrottle(h)) {
|
||||||
_context.statManager().addRateData("stream.con.throttledDay", 1, 0);
|
_context.statManager().addRateData("stream.con.throttledDay", 1, 0);
|
||||||
throttled = true;
|
throttled = "throttled by per-peer limit of " + _defaultOptions.getMaxConnsPerDay() +
|
||||||
|
" or total limit of " + _defaultOptions.getMaxTotalConnsPerDay() +
|
||||||
|
" per day";
|
||||||
}
|
}
|
||||||
if (throttled)
|
if (throttled != null)
|
||||||
return true;
|
return throttled;
|
||||||
// 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())
|
if (_defaultOptions.isAccessListEnabled() &&
|
||||||
return !_defaultOptions.getAccessList().contains(h);
|
!_defaultOptions.getAccessList().contains(h))
|
||||||
if (_defaultOptions.isBlacklistEnabled())
|
return "not whitelisted";
|
||||||
return _defaultOptions.getBlacklist().contains(h);
|
if (_defaultOptions.isBlacklistEnabled() &&
|
||||||
return false;
|
_defaultOptions.getBlacklist().contains(h))
|
||||||
|
return "blacklisted";
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user