* Client:

- Clean up retry code
      - Bring I2CP listen error to the summary bar
        http://forum.i2p/viewtopic.php?t=3133
This commit is contained in:
zzz
2009-03-02 16:07:48 +00:00
parent 03f16565fe
commit c4fa0d894f
6 changed files with 27 additions and 8 deletions

View File

@@ -72,6 +72,7 @@ public abstract class ClientManagerFacade implements Service {
public abstract void messageReceived(ClientMessage msg);
public boolean verifyClientLiveliness() { return true; }
public boolean isAlive() { return true; }
/**
* Does the client specified want their leaseSet published?
*/

View File

@@ -31,7 +31,7 @@ public class ClientListenerRunner implements Runnable {
private int _port;
private boolean _bindAllInterfaces;
private boolean _running;
private long _nextFailDelay = 1000;
private boolean _listening;
public static final String BIND_ALL_INTERFACES = "i2cp.tcp.bindAllInterfaces";
@@ -41,6 +41,7 @@ public class ClientListenerRunner implements Runnable {
_manager = manager;
_port = port;
_running = false;
_listening = false;
String val = context.getProperty(BIND_ALL_INTERFACES, "False");
_bindAllInterfaces = Boolean.valueOf(val).booleanValue();
@@ -48,6 +49,7 @@ public class ClientListenerRunner implements Runnable {
public void setPort(int port) { _port = port; }
public int getPort() { return _port; }
public boolean isListening() { return _running && _listening; }
/**
* Start up the socket listener, listens for connections, and
@@ -58,7 +60,7 @@ public class ClientListenerRunner implements Runnable {
*/
public void runServer() {
_running = true;
int curDelay = 0;
int curDelay = 1000;
while (_running) {
try {
if (_bindAllInterfaces) {
@@ -77,7 +79,8 @@ public class ClientListenerRunner implements Runnable {
if (_log.shouldLog(Log.DEBUG))
_log.debug("ServerSocket created, before accept: " + _socket);
curDelay = 0;
curDelay = 1000;
_listening = true;
while (_running) {
try {
Socket socket = _socket.accept();
@@ -96,6 +99,7 @@ public class ClientListenerRunner implements Runnable {
} catch (Throwable t) {
if (_context.router().isAlive())
_log.error("Fatal error running client listener - killing the thread!", t);
_listening = false;
return;
}
}
@@ -104,6 +108,7 @@ public class ClientListenerRunner implements Runnable {
_log.error("Error listening on port " + _port, ioe);
}
_listening = false;
if (_socket != null) {
try { _socket.close(); } catch (IOException ioe) {}
_socket = null;
@@ -111,14 +116,16 @@ public class ClientListenerRunner implements Runnable {
if (!_context.router().isAlive()) break;
_log.error("Error listening, waiting " + _nextFailDelay + "ms before we try again");
try { Thread.sleep(_nextFailDelay); } catch (InterruptedException ie) {}
curDelay += _nextFailDelay;
_nextFailDelay *= 5;
if (curDelay < 60*1000)
_log.error("Error listening, waiting " + (curDelay/1000) + "s before we try again");
else
_log.log(Log.CRIT, "I2CP error listening to port " + _port + " - is another I2P instance running? Resolve conflicts and restart");
try { Thread.sleep(curDelay); } catch (InterruptedException ie) {}
curDelay = Math.min(curDelay*3, 60*1000);
}
if (_context.router().isAlive())
_log.error("CANCELING I2CP LISTEN. delay = " + curDelay, new Exception("I2CP Listen cancelled!!!"));
_log.error("CANCELING I2CP LISTEN", new Exception("I2CP Listen cancelled!!!"));
_running = false;
}

View File

@@ -108,6 +108,8 @@ public class ClientManager {
}
}
public boolean isAlive() { return _listener.isListening(); }
public void registerConnection(ClientConnectionRunner runner) {
synchronized (_pendingRunners) {
_pendingRunners.add(runner);

View File

@@ -74,6 +74,8 @@ public class ClientManagerFacadeImpl extends ClientManagerFacade {
startup();
}
public boolean isAlive() { return _manager != null && _manager.isAlive(); }
private static final long MAX_TIME_TO_REBUILD = 10*60*1000;
public boolean verifyClientLiveliness() {
if (_manager == null) return true;