From 75e23fd1e3d3fb5c1e5c433d2de9938e6beac930 Mon Sep 17 00:00:00 2001 From: zzz Date: Fri, 9 Dec 2022 09:23:45 -0500 Subject: [PATCH] Tunnels: Tighten the hop throttle drop sooner when over limit to better protect the network penalize throttled peers in profile to discourage use in our tunnels --- .../src/net/i2p/router/tunnel/pool/BuildHandler.java | 10 ++++++++++ .../i2p/router/tunnel/pool/ParticipatingThrottler.java | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java index 2d5c725e8..fcf4ed858 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java @@ -870,6 +870,8 @@ class BuildHandler implements Runnable { _log.warn("Dropping request (hop throttle), previous hop: " + from + ": " + req); _context.statManager().addRateData("tunnel.rejectHopThrottle", 1); _context.commSystem().mayDisconnect(from); + // fake failed so we won't use him for our tunnels + _context.profileManager().tunnelFailed(from, 400); return; } if (result == ParticipatingThrottler.Result.REJECT) { @@ -877,6 +879,8 @@ class BuildHandler implements Runnable { _log.warn("Rejecting tunnel (hop throttle), previous hop: " + from + ": " + req); _context.statManager().addRateData("tunnel.rejectHopThrottle", 1); response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH; + // fake failed so we won't use him for our tunnels + _context.profileManager().tunnelFailed(from, 200); } } if (response == 0 && (!isOutEnd) && _throttler != null) { @@ -887,6 +891,8 @@ class BuildHandler implements Runnable { _context.statManager().addRateData("tunnel.rejectHopThrottle", 1); if (from != null) _context.commSystem().mayDisconnect(from); + // fake failed so we won't use him for our tunnels + _context.profileManager().tunnelFailed(nextPeer, 400); return; } if (result == ParticipatingThrottler.Result.REJECT) { @@ -894,6 +900,8 @@ class BuildHandler implements Runnable { _log.warn("Rejecting tunnel (hop throttle), next hop: " + nextPeer + ": " + req); _context.statManager().addRateData("tunnel.rejectHopThrottle", 1); response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH; + // fake failed so we won't use him for our tunnels + _context.profileManager().tunnelFailed(nextPeer, 200); } } @@ -1129,6 +1137,8 @@ class BuildHandler implements Runnable { if (_log.shouldLog(Log.WARN)) _log.warn("Dropping tunnel request (from throttle) id " + reqId + ", previous hop: " + fh); _context.statManager().addRateData("tunnel.dropReqThrottle", 1); + // fake failed so we won't use him for our tunnels + _context.profileManager().tunnelFailed(fh, 400); accept = false; } } diff --git a/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java b/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java index 0e56d42a7..765492de7 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/ParticipatingThrottler.java @@ -35,9 +35,9 @@ class ParticipatingThrottler { /** portion of the tunnel lifetime */ private static final int LIFETIME_PORTION = 3; - private static final int MIN_LIMIT = 18 / LIFETIME_PORTION; + private static final int MIN_LIMIT = 12 / LIFETIME_PORTION; private static final int MAX_LIMIT = 66 / LIFETIME_PORTION; - private static final int PERCENT_LIMIT = 12 / LIFETIME_PORTION; + private static final int PERCENT_LIMIT = 9 / LIFETIME_PORTION; private static final long CLEAN_TIME = 11*60*1000 / LIFETIME_PORTION; public enum Result { ACCEPT, REJECT, DROP } @@ -56,7 +56,7 @@ class ParticipatingThrottler { int count = counter.increment(h); Result rv; if (count > limit) { - if (count > limit * 3 / 2) { + if (count > limit * 9 / 8) { //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);