diff --git a/core/java/src/net/i2p/client/I2PSessionImpl.java b/core/java/src/net/i2p/client/I2PSessionImpl.java index 6b6052b54a..6dc9a0f8ce 100644 --- a/core/java/src/net/i2p/client/I2PSessionImpl.java +++ b/core/java/src/net/i2p/client/I2PSessionImpl.java @@ -85,8 +85,6 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa /** used to seperate things out so we can get rid of singletons */ protected I2PAppContext _context; - private int _totalReconnectAttempts; - /** monitor for waiting until a lease set has been granted */ private Object _leaseSetWait = new Object(); @@ -137,7 +135,6 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa loadConfig(options); _sessionId = null; _leaseSet = null; - _totalReconnectAttempts = 0; } /** @@ -564,8 +561,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa closeSocket(); } - private final static int MAX_RECONNECT_ATTEMPTS = 1; - private final static int MAX_TOTAL_RECONNECT_ATTEMPTS = 3; + private final static int MAX_RECONNECT_DELAY = 320*1000; + private final static int BASE_RECONNECT_DELAY = 10*1000; protected boolean shouldReconnect() { return true; @@ -573,24 +570,25 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa protected boolean reconnect() { closeSocket(); - if (_totalReconnectAttempts < MAX_TOTAL_RECONNECT_ATTEMPTS) { - _totalReconnectAttempts++; - } else { - if (_log.shouldLog(Log.CRIT)) - _log.log(Log.CRIT, getPrefix() + "Max number of reconnects exceeded [" - + _totalReconnectAttempts + "], we give up!"); - return false; - } if (_log.shouldLog(Log.INFO)) _log.info(getPrefix() + "Reconnecting..."); - for (int i = 0; i < MAX_RECONNECT_ATTEMPTS; i++) { + int i = 0; + while (true) { + long delay = BASE_RECONNECT_DELAY << i; + i++; + if (delay > MAX_RECONNECT_DELAY) + delay = MAX_RECONNECT_DELAY; + try { Thread.sleep(delay); } catch (InterruptedException ie) {} + try { connect(); + if (_log.shouldLog(Log.INFO)) + _log.info(getPrefix() + "Reconnected on attempt " + i); return true; } catch (I2PSessionException ise) { - if (_log.shouldLog(Log.ERROR)) _log.error(getPrefix() + "Error reconnecting on attempt " + i, ise); + if (_log.shouldLog(Log.ERROR)) + _log.error(getPrefix() + "Error reconnecting on attempt " + i, ise); } } - return false; } protected String getPrefix() { return "[" + (_sessionId == null ? -1 : _sessionId.getSessionId()) + "]: "; } diff --git a/history.txt b/history.txt index 36d0d181d8..ecef3c003b 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,8 @@ -$Id: history.txt,v 1.4 2004/09/03 11:52:27 hypercubus Exp $ +$Id: history.txt,v 1.5 2004/09/03 14:46:08 jrandom Exp $ + +2004-09-04 jrandom + * Update the SDK to automatically reconnect indefinitely with an + exponential delay on retries (capped at 5 minutes). * 2004-09-03 0.4 released diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 7a7e7b4097..12c8743d44 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -15,9 +15,9 @@ import net.i2p.CoreVersion; * */ public class RouterVersion { - public final static String ID = "$Revision: 1.20 $ $Date: 2004/09/03 02:22:24 $"; + public final static String ID = "$Revision: 1.21 $ $Date: 2004/09/03 14:46:07 $"; public final static String VERSION = "0.4"; - public final static long BUILD = 3; + public final static long BUILD = 4; public static void main(String args[]) { System.out.println("I2P Router version: " + VERSION); System.out.println("Router ID: " + RouterVersion.ID);