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
This commit is contained in:
zzz
2022-12-09 09:23:45 -05:00
parent 944dff0aa7
commit 75e23fd1e3
2 changed files with 13 additions and 3 deletions

View File

@@ -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;
}
}

View File

@@ -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);