forked from I2P_Developers/i2p.i2p
* Router: Cleanup startup jobs and router.config reading; javadocs
This commit is contained in:
@@ -382,9 +382,6 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
|
||||
_context.keyManager().startup();
|
||||
|
||||
// why are we reading this again, it's read in the constructor
|
||||
readConfig();
|
||||
|
||||
setupHandlers();
|
||||
//if (ALLOW_DYNAMIC_KEYS) {
|
||||
// if ("true".equalsIgnoreCase(_context.getProperty(Router.PROP_HIDDEN, "false")))
|
||||
|
@@ -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 = 23;
|
||||
public final static long BUILD = 24;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "-rc";
|
||||
|
@@ -45,7 +45,9 @@ public class BootCommSystemJob extends JobImpl {
|
||||
// start I2CP
|
||||
getContext().jobQueue().addJob(new StartAcceptingClientsJob(getContext()));
|
||||
|
||||
getContext().jobQueue().addJob(new ReadConfigJob(getContext()));
|
||||
Job j = new ReadConfigJob(getContext());
|
||||
j.getTiming().setStartAfter(getContext().clock().now() + 60*1000);
|
||||
getContext().jobQueue().addJob(j);
|
||||
((RouterClock) getContext().clock()).addShiftListener(getContext().router());
|
||||
}
|
||||
|
||||
|
@@ -11,15 +11,15 @@ package net.i2p.router.startup;
|
||||
import net.i2p.router.Job;
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* For future restricted routes. Does nothing now.
|
||||
*/
|
||||
public class BuildTrustedLinksJob extends JobImpl {
|
||||
private Log _log;
|
||||
private Job _next;
|
||||
private final Job _next;
|
||||
|
||||
public BuildTrustedLinksJob(RouterContext context, Job next) {
|
||||
super(context);
|
||||
_log = getContext().logManager().getLog(BuildTrustedLinksJob.class);
|
||||
_next = next;
|
||||
}
|
||||
|
||||
|
@@ -72,29 +72,30 @@ public class ClientAppConfig {
|
||||
private static final String PREFIX = "clientApp.";
|
||||
|
||||
// let's keep this really simple
|
||||
// Following 4 may be edited in router console
|
||||
public String className;
|
||||
public String clientName;
|
||||
public String args;
|
||||
public long delay;
|
||||
public boolean disabled;
|
||||
public final long delay;
|
||||
/** @since 0.7.12 */
|
||||
public String classpath;
|
||||
public final String classpath;
|
||||
/** @since 0.7.12 */
|
||||
public String stopargs;
|
||||
public final String stopargs;
|
||||
/** @since 0.7.12 */
|
||||
public String uninstallargs;
|
||||
public final String uninstallargs;
|
||||
|
||||
public ClientAppConfig(String cl, String client, String a, long d, boolean dis) {
|
||||
this(cl, client, a, d, dis, null, null, null);
|
||||
}
|
||||
|
||||
/** @since 0.7.12 */
|
||||
public ClientAppConfig(String cl, String client, String a, long d, boolean dis, String cp, String sa, String ua) {
|
||||
className = cl;
|
||||
clientName = client;
|
||||
args = a;
|
||||
delay = d;
|
||||
disabled = dis;
|
||||
}
|
||||
|
||||
/** @since 0.7.12 */
|
||||
public ClientAppConfig(String cl, String client, String a, long d, boolean dis, String cp, String sa, String ua) {
|
||||
this(cl, client, a, d, dis);
|
||||
classpath = cp;
|
||||
stopargs = sa;
|
||||
uninstallargs = ua;
|
||||
|
@@ -30,12 +30,13 @@ import net.i2p.util.Log;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
|
||||
public class CreateRouterInfoJob extends JobImpl {
|
||||
private static Log _log = new Log(CreateRouterInfoJob.class);
|
||||
private final Log _log;
|
||||
private final Job _next;
|
||||
|
||||
public CreateRouterInfoJob(RouterContext ctx, Job next) {
|
||||
super(ctx);
|
||||
_next = next;
|
||||
_log = ctx.logManager().getLog(CreateRouterInfoJob.class);
|
||||
}
|
||||
|
||||
public String getName() { return "Create New Router Info"; }
|
||||
@@ -124,7 +125,7 @@ public class CreateRouterInfoJob extends JobImpl {
|
||||
*
|
||||
*/
|
||||
static long getCurrentPublishDate(RouterContext context) {
|
||||
_log.info("Setting published date to /now/");
|
||||
//_log.info("Setting published date to /now/");
|
||||
return context.clock().now();
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import net.i2p.util.Log;
|
||||
*
|
||||
*/
|
||||
public class LoadClientAppsJob extends JobImpl {
|
||||
private Log _log;
|
||||
private final Log _log;
|
||||
private static boolean _loaded = false;
|
||||
|
||||
public LoadClientAppsJob(RouterContext ctx) {
|
||||
@@ -51,12 +51,12 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
}
|
||||
|
||||
public static class DelayedRunClient extends JobImpl {
|
||||
private String _className;
|
||||
private String _clientName;
|
||||
private String _args[];
|
||||
private Log _log;
|
||||
private ThreadGroup _threadGroup;
|
||||
private ClassLoader _cl;
|
||||
private final String _className;
|
||||
private final String _clientName;
|
||||
private final String _args[];
|
||||
private final Log _log;
|
||||
private final ThreadGroup _threadGroup;
|
||||
private final ClassLoader _cl;
|
||||
|
||||
public DelayedRunClient(RouterContext enclosingContext, String className, String clientName, String args[], long delay) {
|
||||
this(enclosingContext, className, clientName, args, delay, null, null);
|
||||
@@ -211,11 +211,11 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
}
|
||||
|
||||
private final static class RunApp implements Runnable {
|
||||
private String _className;
|
||||
private String _appName;
|
||||
private String _args[];
|
||||
private Log _log;
|
||||
private ClassLoader _cl;
|
||||
private final String _className;
|
||||
private final String _appName;
|
||||
private final String _args[];
|
||||
private final Log _log;
|
||||
private final ClassLoader _cl;
|
||||
|
||||
public RunApp(String className, String appName, String args[], Log log, ClassLoader cl) {
|
||||
_className = className;
|
||||
@@ -246,6 +246,7 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
|
||||
public String getName() { return "Load up any client applications"; }
|
||||
|
||||
/****
|
||||
public static void main(String args[]) {
|
||||
test(null);
|
||||
test("hi how are you?");
|
||||
@@ -262,4 +263,5 @@ public class LoadClientAppsJob extends JobImpl {
|
||||
System.out.print("[" + parsed[i] + "] ");
|
||||
System.out.println();
|
||||
}
|
||||
****/
|
||||
}
|
||||
|
@@ -12,30 +12,45 @@ import java.io.File;
|
||||
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Simply read the router config
|
||||
* Simply read the router config periodically,
|
||||
* so that the user may make config changes externally.
|
||||
* This isn't advertised as a feature,
|
||||
* but it could be used, for example, to change bandwidth limits
|
||||
* at certain times of day.
|
||||
*
|
||||
* Unfortunately it will also read the file back in every time the
|
||||
* router writes it.
|
||||
*
|
||||
* So maybe this should just be disabled.
|
||||
*/
|
||||
public class ReadConfigJob extends JobImpl {
|
||||
private final static long DELAY = 30*1000; // reread every 30 seconds
|
||||
private long _lastRead = -1;
|
||||
private long _lastRead;
|
||||
|
||||
public ReadConfigJob(RouterContext ctx) {
|
||||
super(ctx);
|
||||
_lastRead = ctx.clock().now();
|
||||
}
|
||||
|
||||
public String getName() { return "Read Router Configuration"; }
|
||||
|
||||
public void runJob() {
|
||||
if (shouldReread()) {
|
||||
File configFile = new File(getContext().router().getConfigFilename());
|
||||
if (shouldReread(configFile)) {
|
||||
getContext().router().readConfig();
|
||||
_lastRead = getContext().clock().now();
|
||||
Log log = getContext().logManager().getLog(ReadConfigJob.class);
|
||||
if (log.shouldLog(Log.WARN))
|
||||
log.warn("Reloaded " + configFile);
|
||||
}
|
||||
getTiming().setStartAfter(getContext().clock().now() + DELAY);
|
||||
getContext().jobQueue().addJob(this);
|
||||
}
|
||||
|
||||
private boolean shouldReread() {
|
||||
File configFile = new File(getContext().router().getConfigFilename());
|
||||
private boolean shouldReread(File configFile) {
|
||||
if (!configFile.exists()) return false;
|
||||
if (configFile.lastModified() > _lastRead)
|
||||
return true;
|
||||
|
@@ -10,15 +10,12 @@ package net.i2p.router.startup;
|
||||
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/** start I2CP interface */
|
||||
public class StartAcceptingClientsJob extends JobImpl {
|
||||
private Log _log;
|
||||
|
||||
public StartAcceptingClientsJob(RouterContext context) {
|
||||
super(context);
|
||||
_log = context.logManager().getLog(StartAcceptingClientsJob.class);
|
||||
}
|
||||
|
||||
public String getName() { return "Start Accepting Clients"; }
|
||||
|
@@ -6,5 +6,31 @@
|
||||
<p>
|
||||
The startup consists of a number of different jobs, like loading data from files for the network database, creating new router information (keypairs), and so on.
|
||||
</p>
|
||||
<p><pre>
|
||||
|
||||
Calling order:
|
||||
|
||||
StartupJob
|
||||
LoadClientAppsJob
|
||||
starts clients and queues delayed client jobs
|
||||
start stats publisher
|
||||
LoadRouterInfoJob
|
||||
RebuildRouterInfoJob if necessary
|
||||
CreateRouterInfoJob if necessary
|
||||
BootCommSystemJob
|
||||
allow parallel operation in job queue
|
||||
BootNetworkDbJob
|
||||
starts netdb
|
||||
BuildTrustedLinksJob (never used)
|
||||
BootPeerManagerJob
|
||||
starts peer manager
|
||||
start comm system
|
||||
start tunnel manager
|
||||
StartAcceptingClientsJob
|
||||
starts client manager
|
||||
ReadConfigJob
|
||||
loops every 30 seconds
|
||||
|
||||
</pre></p>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user