diff --git a/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java b/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java index 85855b0395087c123bd7d15b79aec33771e04c0a..16225955967f565988e80674080b91e5c012514b 100644 --- a/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java +++ b/router/java/src/net/i2p/router/transport/udp/IntroductionManager.java @@ -144,11 +144,19 @@ class IntroductionManager { // FIXME failsafe if found == 0, relax inactivityCutoff and try again? + pingIntroducers(); + return found; + } + + /** + * Was part of pickInbound(), moved out so we can call it more often + * @since 0.8.11 + */ + public void pingIntroducers() { // Try to keep the connection up for two hours after we made anybody an introducer - long pingCutoff = _context.clock().now() - (2 * 60 * 60 * 1000); - inactivityCutoff = _context.clock().now() - (UDPTransport.EXPIRE_TIMEOUT / 4); - for (int i = 0; i < sz; i++) { - PeerState cur = peers.get(i); + long pingCutoff = _context.clock().now() - (105 * 60 * 1000); + long inactivityCutoff = _context.clock().now() - UDPTransport.MIN_EXPIRE_TIMEOUT; + for (PeerState cur : _inbound) { if (cur.getIntroducerTime() > pingCutoff && cur.getLastSendTime() < inactivityCutoff) { if (_log.shouldLog(Log.INFO)) @@ -157,8 +165,6 @@ class IntroductionManager { _transport.send(_builder.buildPing(cur)); } } - - return found; } /** 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 6a2ff74f6f012ffec565b2576a8dfed866a90a44..e99b185eab983ddc02a4cd57f9dd8746704c9be9 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -227,6 +227,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority _context.statManager().createRateStat("udp.dropPeerDroplist", "How many peers currently have their packets dropped outright when a new peer is added to the list?", "udp", RATES); _context.statManager().createRateStat("udp.dropPeerConsecutiveFailures", "How many consecutive failed sends to a peer did we attempt before giving up and reestablishing a new session (lifetime is inactivity perood)", "udp", RATES); __instance = this; + + SimpleScheduler.getInstance().addPeriodicEvent(new PingIntroducers(), MIN_EXPIRE_TIMEOUT * 3 / 4); } public void startup() { @@ -1154,9 +1156,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority // and lose the old introducer tags, causing introduction fails, // so we keep the max time long to give the introducer keepalive code // in the IntroductionManager a chance to work. - public static final int EXPIRE_TIMEOUT = 30*60*1000; + public static final int EXPIRE_TIMEOUT = 20*60*1000; private static final int MAX_IDLE_TIME = EXPIRE_TIMEOUT; - private static final int MIN_EXPIRE_TIMEOUT = 10*60*1000; + public static final int MIN_EXPIRE_TIMEOUT = 6*60*1000; public String getStyle() { return STYLE; } @@ -1253,8 +1255,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority return getCurrentAddress(); } - void rebuildExternalAddress() { rebuildExternalAddress(true); } - void rebuildExternalAddress(boolean allowRebuildRouterInfo) { + private void rebuildExternalAddress() { rebuildExternalAddress(true); } + + private void rebuildExternalAddress(boolean allowRebuildRouterInfo) { // if the external port is specified, we want to use that to bind to even // if we don't know the external host. _externalListenPort = _context.getProperty(PROP_EXTERNAL_PORT, -1); @@ -2459,6 +2462,18 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority } } + /** + * Periodically ping the introducers, split out since we need to + * do it faster than we rebuild our address. + * @since 0.8.11 + */ + private class PingIntroducers implements SimpleTimer.TimedEvent { + public void timeReached() { + if (introducersRequired()) + _introManager.pingIntroducers(); + } + } + /******* private static final String BADIPS[] = new String[] { "192.168.0.1", "127.0.0.1", "10.3.4.5", "172.16.3.4", "224.5.6.7" }; private static final String GOODIPS[] = new String[] { "192.167.0.1", "126.0.0.1", "11.3.4.5", "172.15.3.4", "223.5.6.7" };