Make I2pTunnel wait for router to reach RUNNING state (ticket #2377)

This commit is contained in:
zab2
2019-03-11 20:00:04 +00:00
parent 7e6fd01eef
commit 7db602d959
5 changed files with 51 additions and 12 deletions

View File

@@ -822,6 +822,16 @@ public class Router implements RouterClock.ClockShiftListener {
}
}
/**
* @return true if router is RUNNING, i.e NetDB and Expl. tunnels are ready.
* @since 0.9.39
*/
public boolean isRunning() {
synchronized(_stateLock) {
return _state == State.RUNNING;
}
}
/**
* Only for Restarter, after soft restart is complete.
* Not for external use.

View File

@@ -67,7 +67,7 @@ public class ClientAppConfig {
/** wait 2 minutes before starting up client apps */
private final static long DEFAULT_STARTUP_DELAY = 2*60*1000;
/** speed up i2ptunnel without rewriting clients.config */
private final static long I2PTUNNEL_STARTUP_DELAY = 35*1000;
private final static long I2PTUNNEL_STARTUP_DELAY = -1000;
private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile";
private static final String DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config";
@@ -185,13 +185,17 @@ public class ClientAppConfig {
if (onBoot != null)
onStartup = "true".equals(onBoot) || "yes".equals(onBoot);
// speed up the start of i2ptunnel for everybody without rewriting clients.config
long delay = onStartup ? 0 :
(className.equals("net.i2p.i2ptunnel.TunnelControllerGroup") ?
I2PTUNNEL_STARTUP_DELAY : DEFAULT_STARTUP_DELAY);
if (delayStr != null && !onStartup)
try { delay = 1000*Integer.parseInt(delayStr); } catch (NumberFormatException nfe) {}
long delay;
if (onStartup) {
delay = 0;
} else if (className.equals("net.i2p.i2ptunnel.TunnelControllerGroup")) {
// speed up the start of i2ptunnel for everybody without rewriting clients.config
delay = I2PTUNNEL_STARTUP_DELAY;
} else {
delay = DEFAULT_STARTUP_DELAY;
if (delayStr != null)
try { delay = 1000*Integer.parseInt(delayStr); } catch (NumberFormatException nfe) {}
}
rv.add(new ClientAppConfig(className, clientName, args, delay, dis,
classpath, stopargs, uninstallargs));
}

View File

@@ -56,14 +56,18 @@ public class LoadClientAppsJob extends JobImpl {
continue;
}
String argVal[] = parseArgs(app.args);
if (app.delay <= 0) {
if (app.delay == 0) {
// run this guy now
runClient(app.className, app.clientName, argVal, getContext(), _log);
} else {
} else if (app.delay > 0) {
// wait before firing it up
DelayedRunClient drc = new DelayedRunClient(getContext().simpleTimer2(), getContext(), app.className,
app.clientName, argVal);
drc.schedule(app.delay);
} else {
WaitForRunningClient wfrc = new WaitForRunningClient(getContext().simpleTimer2(), getContext(),
app.className, app.clientName, argVal);
wfrc.schedule(1000);
}
}
}
@@ -72,7 +76,7 @@ public class LoadClientAppsJob extends JobImpl {
* Public for router console only, not for use by others, subject to change
*/
public static class DelayedRunClient extends SimpleTimer2.TimedEvent {
private final RouterContext _ctx;
protected final RouterContext _ctx;
private final String _className;
private final String _clientName;
private final String _args[];
@@ -103,6 +107,21 @@ public class LoadClientAppsJob extends JobImpl {
runClient(_className, _clientName, _args, _ctx, _log, _threadGroup, _cl);
}
}
private static class WaitForRunningClient extends DelayedRunClient {
WaitForRunningClient(SimpleTimer2 pool, RouterContext enclosingContext, String className, String clientName,
String args[]) {
super(pool, enclosingContext, className, clientName, args, null, null);
}
public void timeReached() {
if (!_ctx.router().isRunning()) {
reschedule(1000);
return;
}
super.timeReached();
}
}
/**
* Parse arg string into an array of args.