forked from I2P_Developers/i2p.i2p
Tunnels: Drop request if hop throttle exceeded by 50%
Revert banning peer in throttles
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
2021-11-23 zzz
|
||||
* Tunnels:
|
||||
- Drop request if hop throttle exceeded by 50%
|
||||
- Revert banning peer in throttles
|
||||
|
||||
2021-11-21 zzz
|
||||
* Console: Drop peer when manually banned
|
||||
* Tunnels:
|
||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Git";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 6;
|
||||
public final static long BUILD = 7;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "-rc";
|
||||
|
@ -867,22 +867,37 @@ class BuildHandler implements Runnable {
|
||||
// Check participating throttle counters for previous and next hops
|
||||
// This is at the end as it compares to a percentage of created tunnels.
|
||||
// We may need another counter above for requests.
|
||||
if (response == 0 && !isInGW && _throttler != null) {
|
||||
if (from != null && _throttler.shouldThrottle(from)) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
if (response == 0 && !isInGW && _throttler != null && from != null) {
|
||||
ParticipatingThrottler.Result result = _throttler.shouldThrottle(from);
|
||||
if (result == ParticipatingThrottler.Result.DROP) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Dropping request (hop throttle), previous hop: " + from + ": " + req);
|
||||
_context.statManager().addRateData("tunnel.rejectHopThrottle", 1);
|
||||
_context.commSystem().mayDisconnect(from);
|
||||
return;
|
||||
}
|
||||
if (result == ParticipatingThrottler.Result.REJECT) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Rejecting tunnel (hop throttle), previous hop: " + from + ": " + req);
|
||||
// no setTunnelStatus() indication
|
||||
_context.statManager().addRateData("tunnel.rejectHopThrottle", 1);
|
||||
response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH;
|
||||
}
|
||||
}
|
||||
if (response == 0 && (!isOutEnd) &&
|
||||
_throttler != null && _throttler.shouldThrottle(nextPeer)) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Rejecting tunnel (hop throttle), next hop: " + req);
|
||||
_context.statManager().addRateData("tunnel.rejectHopThrottle", 1);
|
||||
// no setTunnelStatus() indication
|
||||
response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH;
|
||||
if (response == 0 && (!isOutEnd) && _throttler != null) {
|
||||
ParticipatingThrottler.Result result = _throttler.shouldThrottle(nextPeer);
|
||||
if (result == ParticipatingThrottler.Result.DROP) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Dropping request (hop throttle), next hop: " + nextPeer + ": " + req);
|
||||
_context.statManager().addRateData("tunnel.rejectHopThrottle", 1);
|
||||
_context.commSystem().mayDisconnect(from);
|
||||
return;
|
||||
}
|
||||
if (result == ParticipatingThrottler.Result.REJECT) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Rejecting tunnel (hop throttle), next hop: " + nextPeer + ": " + req);
|
||||
_context.statManager().addRateData("tunnel.rejectHopThrottle", 1);
|
||||
response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
HopConfig cfg = null;
|
||||
|
@ -40,6 +40,8 @@ class ParticipatingThrottler {
|
||||
private static final int PERCENT_LIMIT = 12 / LIFETIME_PORTION;
|
||||
private static final long CLEAN_TIME = 11*60*1000 / LIFETIME_PORTION;
|
||||
|
||||
public enum Result { ACCEPT, REJECT, DROP }
|
||||
|
||||
ParticipatingThrottler(RouterContext ctx) {
|
||||
this.context = ctx;
|
||||
this.counter = new ObjectCounter<Hash>();
|
||||
@ -48,17 +50,24 @@ class ParticipatingThrottler {
|
||||
}
|
||||
|
||||
/** increments before checking */
|
||||
boolean shouldThrottle(Hash h) {
|
||||
Result shouldThrottle(Hash h) {
|
||||
int numTunnels = this.context.tunnelManager().getParticipatingCount();
|
||||
int limit = Math.max(MIN_LIMIT, Math.min(MAX_LIMIT, numTunnels * PERCENT_LIMIT / 100));
|
||||
int count = counter.increment(h);
|
||||
boolean rv = count > limit;
|
||||
if (rv && count == 2 * limit) {
|
||||
context.banlist().banlistRouter(h, "Excess participating tunnels", null, null, context.clock().now() + 30*60*1000);
|
||||
// drop after any accepted tunnels have expired
|
||||
context.simpleTimer2().addEvent(new Disconnector(h), 11*60*1000);
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Banning router for excess part. tunnels, limit: " + limit + " count: " + count + ' ' + h.toBase64());
|
||||
Result rv;
|
||||
if (count > limit) {
|
||||
if (count > limit * 3 / 2) {
|
||||
//context.banlist().banlistRouter(h, "Excess participating tunnels", null, null, context.clock().now() + 30*60*1000);
|
||||
// drop after any accepted tunnels have expired
|
||||
//context.simpleTimer2().addEvent(new Disconnector(h), 11*60*1000);
|
||||
//if (_log.shouldWarn())
|
||||
// _log.warn("Banning router for excess part. tunnels, limit: " + limit + " count: " + count + ' ' + h.toBase64());
|
||||
rv = Result.DROP;
|
||||
} else {
|
||||
rv = Result.REJECT;
|
||||
}
|
||||
} else {
|
||||
rv = Result.ACCEPT;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@ -72,6 +81,7 @@ class ParticipatingThrottler {
|
||||
/**
|
||||
* @since 0.9.52
|
||||
*/
|
||||
/*
|
||||
private class Disconnector implements SimpleTimer.TimedEvent {
|
||||
private final Hash h;
|
||||
public Disconnector(Hash h) { this.h = h; }
|
||||
@ -79,4 +89,5 @@ class ParticipatingThrottler {
|
||||
context.commSystem().forceDisconnect(h);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ class RequestThrottler {
|
||||
int limit = Math.max(MIN_LIMIT, Math.min(MAX_LIMIT, numTunnels * PERCENT_LIMIT / 100));
|
||||
int count = counter.increment(h);
|
||||
boolean rv = count > limit;
|
||||
/*
|
||||
if (rv && count == 2 * limit) {
|
||||
context.banlist().banlistRouter(h, "Excess tunnel requests", null, null, context.clock().now() + 30*60*1000);
|
||||
// drop after any accepted tunnels have expired
|
||||
@ -45,6 +46,7 @@ class RequestThrottler {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Banning router for excess tunnel requests, limit: " + limit + " count: " + count + ' ' + h.toBase64());
|
||||
}
|
||||
*/
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -57,6 +59,7 @@ class RequestThrottler {
|
||||
/**
|
||||
* @since 0.9.52
|
||||
*/
|
||||
/*
|
||||
private class Disconnector implements SimpleTimer.TimedEvent {
|
||||
private final Hash h;
|
||||
public Disconnector(Hash h) { this.h = h; }
|
||||
@ -64,4 +67,5 @@ class RequestThrottler {
|
||||
context.commSystem().forceDisconnect(h);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user