From dae8b253746b375d1884c5333c4582657df42a77 Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 31 Oct 2013 21:27:26 +0000 Subject: [PATCH] Transports: - Increase threshold for idle timeout reduction from 33% to 60%. This was reduced from 75% to 33% in -10 and it caused significant tunnel build problems, for reasons that aren't entirely clear. - Don't change the SSU idle timeout quicker when firewalled. - log tweaks --- history.txt | 5 ++ .../src/net/i2p/router/RouterVersion.java | 2 +- .../router/transport/ntcp/EventPumper.java | 2 +- .../router/transport/udp/UDPTransport.java | 50 ++++++++++++++----- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/history.txt b/history.txt index 33c632ab5..0c4f8587e 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,8 @@ +2013-10-31 zzz + * i2psnark: Always verify file lengths at startup (ticket #1099) + * Transports: Increase threshold for idle timeout reduction + (partially back out change from -10) + 2013-10-29 dg * i2psnark: Start torrents by default (ticket #1072) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 8ab24107c..80cfb9c84 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 17; + public final static long BUILD = 18; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java index d4fd7521a..063d5f1d4 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java +++ b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java @@ -211,7 +211,7 @@ class EventPumper implements Runnable { int failsafeInvalid = 0; // Increase allowed idle time if we are well under allowed connections, otherwise decrease - if (_transport.haveCapacity(33)) + if (_transport.haveCapacity(60)) _expireIdleWriteTime = Math.min(_expireIdleWriteTime + 1000, MAX_EXPIRE_IDLE_TIME); else _expireIdleWriteTime = Math.max(_expireIdleWriteTime - 3000, MIN_EXPIRE_IDLE_TIME); diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index bf616c3e4..298eb2daf 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -102,7 +102,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority */ private final Set _dropList; - private int _expireTimeout; + private volatile long _expireTimeout; /** last report from a peer of our IP */ private Hash _lastFrom; @@ -1217,11 +1217,11 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority return; } else { if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) { - if (_log.shouldLog(Log.INFO)) - _log.info("Received an RI from the same net"); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Received an RI from the same net"); } else { - if (_log.shouldLog(Log.INFO)) - _log.info("Received a leaseSet: " + dsm); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Received a leaseSet: " + dsm); } } } else { @@ -2826,6 +2826,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority private final List _expireBuffer; private volatile boolean _alive; private int _runCount; + private boolean _lastLoopShort; // we've seen firewalls change ports after 40 seconds private static final long PING_FIREWALL_TIME = 30*1000; private static final long PING_FIREWALL_CUTOFF = PING_FIREWALL_TIME / 2; @@ -2833,6 +2834,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority private static final int SLICES = 4; private static final long SHORT_LOOP_TIME = PING_FIREWALL_CUTOFF / (SLICES + 1); private static final long LONG_LOOP_TIME = 25*1000; + private static final long EXPIRE_INCREMENT = 15*1000; + private static final long EXPIRE_DECREMENT = 45*1000; public ExpirePeerEvent() { super(_context.simpleTimer2()); @@ -2842,10 +2845,22 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority public void timeReached() { // Increase allowed idle time if we are well under allowed connections, otherwise decrease - if (haveCapacity(33)) - _expireTimeout = Math.min(_expireTimeout + 15*1000, EXPIRE_TIMEOUT); - else - _expireTimeout = Math.max(_expireTimeout - 45*1000, MIN_EXPIRE_TIMEOUT); + if (haveCapacity(60)) { + long inc; + // don't adjust too quickly if we are looping fast + if (_lastLoopShort) + inc = EXPIRE_INCREMENT * SHORT_LOOP_TIME / LONG_LOOP_TIME; + else + inc = EXPIRE_INCREMENT; + _expireTimeout = Math.min(_expireTimeout + inc, EXPIRE_TIMEOUT); + } else { + long dec; + if (_lastLoopShort) + dec = EXPIRE_DECREMENT * SHORT_LOOP_TIME / LONG_LOOP_TIME; + else + dec = EXPIRE_DECREMENT; + _expireTimeout = Math.max(_expireTimeout - dec, MIN_EXPIRE_TIMEOUT); + } long now = _context.clock().now(); long shortInactivityCutoff = now - _expireTimeout; long longInactivityCutoff = now - EXPIRE_TIMEOUT; @@ -2855,6 +2870,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority int currentListenPort = getListenPort(false); boolean pingOneOnly = shouldPingFirewall && getExternalPort(false) == currentListenPort; boolean shortLoop = shouldPingFirewall; + _lastLoopShort = shortLoop; _expireBuffer.clear(); _runCount++; @@ -2890,11 +2906,19 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority } } - for (PeerState peer : _expireBuffer) { - sendDestroy(peer); - dropPeer(peer, false, "idle too long"); + if (!_expireBuffer.isEmpty()) { + if (_log.shouldLog(Log.WARN)) + _log.warn("Expiring " + _expireBuffer.size() + " peers"); + for (PeerState peer : _expireBuffer) { + sendDestroy(peer); + dropPeer(peer, false, "idle too long"); + // TODO sleep to limit burst like in destroyAll() ?? + // but we are on the timer thread... + // hopefully this isn't too many at once + // ... or only send a max of x, then requeue + } + _expireBuffer.clear(); } - _expireBuffer.clear(); if (_alive) schedule(shortLoop ? SHORT_LOOP_TIME : LONG_LOOP_TIME);