delete that stupid 'interactive' mode where we dump things to stdout on command

(hello, we have an admin console now, duh)
formatting touchups.
This commit is contained in:
jrandom
2004-04-20 07:06:39 +00:00
committed by zzz
parent 3c762c9a02
commit bed7d09764

View File

@ -74,15 +74,15 @@ public class Router {
public final static String PROP_KEYS_FILENAME_DEFAULT = "router.keys"; public final static String PROP_KEYS_FILENAME_DEFAULT = "router.keys";
private Router() { private Router() {
_config = new Properties(); _config = new Properties();
_configFilename = System.getProperty(PROP_CONFIG_FILE, "router.config"); _configFilename = System.getProperty(PROP_CONFIG_FILE, "router.config");
_routerInfo = null; _routerInfo = null;
_higherVersionSeen = false; _higherVersionSeen = false;
// grumble about sun's java caching DNS entries *forever* // grumble about sun's java caching DNS entries *forever*
System.setProperty("sun.net.inetaddr.ttl", "0"); System.setProperty("sun.net.inetaddr.ttl", "0");
System.setProperty("networkaddress.cache.ttl", "0"); System.setProperty("networkaddress.cache.ttl", "0");
// (no need for keepalive) // (no need for keepalive)
System.setProperty("http.keepAlive", "false"); System.setProperty("http.keepAlive", "false");
} }
public String getConfigFilename() { return _configFilename; } public String getConfigFilename() { return _configFilename; }
@ -95,9 +95,9 @@ public class Router {
public RouterInfo getRouterInfo() { return _routerInfo; } public RouterInfo getRouterInfo() { return _routerInfo; }
public void setRouterInfo(RouterInfo info) { public void setRouterInfo(RouterInfo info) {
_routerInfo = info; _routerInfo = info;
if (info != null) if (info != null)
JobQueue.getInstance().addJob(new PersistRouterInfoJob()); JobQueue.getInstance().addJob(new PersistRouterInfoJob());
} }
/** /**
@ -113,21 +113,21 @@ public class Router {
public long getUptime() { return Clock.getInstance().now() - Clock.getInstance().getOffset() - _started; } public long getUptime() { return Clock.getInstance().now() - Clock.getInstance().getOffset() - _started; }
private void runRouter() { private void runRouter() {
_started = Clock.getInstance().now(); _started = Clock.getInstance().now();
Runtime.getRuntime().addShutdownHook(new ShutdownHook()); Runtime.getRuntime().addShutdownHook(new ShutdownHook());
I2PThread.setOOMEventListener(new I2PThread.OOMEventListener() { I2PThread.setOOMEventListener(new I2PThread.OOMEventListener() {
public void outOfMemory(OutOfMemoryError oom) { public void outOfMemory(OutOfMemoryError oom) {
_log.log(Log.CRIT, "Thread ran out of memory", oom); _log.log(Log.CRIT, "Thread ran out of memory", oom);
shutdown(); shutdown();
} }
}); });
setupHandlers(); setupHandlers();
startupQueue(); startupQueue();
JobQueue.getInstance().addJob(new CoallesceStatsJob()); JobQueue.getInstance().addJob(new CoallesceStatsJob());
JobQueue.getInstance().addJob(new UpdateRoutingKeyModifierJob()); JobQueue.getInstance().addJob(new UpdateRoutingKeyModifierJob());
warmupCrypto(); warmupCrypto();
SessionKeyPersistenceHelper.getInstance().startup(); SessionKeyPersistenceHelper.getInstance().startup();
JobQueue.getInstance().addJob(new StartupJob()); JobQueue.getInstance().addJob(new StartupJob());
} }
/** /**
@ -135,11 +135,11 @@ public class Router {
* *
*/ */
private final static class CoallesceStatsJob extends JobImpl { private final static class CoallesceStatsJob extends JobImpl {
public String getName() { return "Coallesce stats"; } public String getName() { return "Coallesce stats"; }
public void runJob() { public void runJob() {
StatManager.getInstance().coallesceStats(); StatManager.getInstance().coallesceStats();
requeue(60*1000); requeue(60*1000);
} }
} }
/** /**
@ -148,278 +148,262 @@ public class Router {
* uses it. * uses it.
*/ */
private final static class UpdateRoutingKeyModifierJob extends JobImpl { private final static class UpdateRoutingKeyModifierJob extends JobImpl {
private Calendar _cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); private Calendar _cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
public String getName() { return "Update Routing Key Modifier"; } public String getName() { return "Update Routing Key Modifier"; }
public void runJob() { public void runJob() {
RoutingKeyGenerator.getInstance().generateDateBasedModData(); RoutingKeyGenerator.getInstance().generateDateBasedModData();
requeue(getTimeTillMidnight()); requeue(getTimeTillMidnight());
} }
private long getTimeTillMidnight() { private long getTimeTillMidnight() {
long now = Clock.getInstance().now(); long now = Clock.getInstance().now();
_cal.setTime(new Date(now)); _cal.setTime(new Date(now));
_cal.add(Calendar.DATE, 1); _cal.add(Calendar.DATE, 1);
_cal.set(Calendar.HOUR_OF_DAY, 0); _cal.set(Calendar.HOUR_OF_DAY, 0);
_cal.set(Calendar.MINUTE, 0); _cal.set(Calendar.MINUTE, 0);
_cal.set(Calendar.SECOND, 0); _cal.set(Calendar.SECOND, 0);
_cal.set(Calendar.MILLISECOND, 0); _cal.set(Calendar.MILLISECOND, 0);
long then = _cal.getTime().getTime(); long then = _cal.getTime().getTime();
_log.debug("Time till midnight: " + (then-now) + "ms"); _log.debug("Time till midnight: " + (then-now) + "ms");
if (then - now <= 60*1000) { if (then - now <= 60*1000) {
// everyone wave at kaffe. // everyone wave at kaffe.
// "Hi Kaffe" // "Hi Kaffe"
return 60*1000; return 60*1000;
} else { } else {
return then - now; return then - now;
} }
} }
} }
private void warmupCrypto() { private void warmupCrypto() {
RandomSource.getInstance().nextBoolean(); RandomSource.getInstance().nextBoolean();
new DHSessionKeyBuilder(); // load the class so it starts the precalc process new DHSessionKeyBuilder(); // load the class so it starts the precalc process
} }
private void startupQueue() { private void startupQueue() {
JobQueue.getInstance().runQueue(1); JobQueue.getInstance().runQueue(1);
} }
private void setupHandlers() { private void setupHandlers() {
InNetMessagePool.getInstance().registerHandlerJobBuilder(GarlicMessage.MESSAGE_TYPE, new GarlicMessageHandler()); InNetMessagePool.getInstance().registerHandlerJobBuilder(GarlicMessage.MESSAGE_TYPE, new GarlicMessageHandler());
InNetMessagePool.getInstance().registerHandlerJobBuilder(TunnelMessage.MESSAGE_TYPE, new TunnelMessageHandler()); InNetMessagePool.getInstance().registerHandlerJobBuilder(TunnelMessage.MESSAGE_TYPE, new TunnelMessageHandler());
InNetMessagePool.getInstance().registerHandlerJobBuilder(SourceRouteReplyMessage.MESSAGE_TYPE, new SourceRouteReplyMessageHandler()); InNetMessagePool.getInstance().registerHandlerJobBuilder(SourceRouteReplyMessage.MESSAGE_TYPE, new SourceRouteReplyMessageHandler());
} }
public String renderStatusHTML() { public String renderStatusHTML() {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
buf.append("<html><head><title>I2P Router Console</title></head><body>\n"); buf.append("<html><head><title>I2P Router Console</title></head><body>\n");
buf.append("<h1>Router console</h1>\n"); buf.append("<h1>Router console</h1>\n");
buf.append("<i><a href=\"/routerConsole.html\">console</a> | <a href=\"/routerStats.html\">stats</a></i><br>\n"); buf.append("<i><a href=\"/routerConsole.html\">console</a> | <a href=\"/routerStats.html\">stats</a></i><br>\n");
buf.append("<form action=\"/routerConsole.html\">");
buf.append("<select name=\"go\" onChange='location.href=this.value'>");
buf.append("<option value=\"/routerConsole.html#bandwidth\">Bandwidth</option>\n");
buf.append("<option value=\"/routerConsole.html#clients\">Clients</option>\n");
buf.append("<option value=\"/routerConsole.html#transports\">Transports</option>\n");
buf.append("<option value=\"/routerConsole.html#profiles\">Peer Profiles</option>\n");
buf.append("<option value=\"/routerConsole.html#tunnels\">Tunnels</option>\n");
buf.append("<option value=\"/routerConsole.html#jobs\">Jobs</option>\n");
buf.append("<option value=\"/routerConsole.html#shitlist\">Shitlist</option>\n");
buf.append("<option value=\"/routerConsole.html#pending\">Pending messages</option>\n");
buf.append("<option value=\"/routerConsole.html#netdb\">Network Database</option>\n");
buf.append("<option value=\"/routerConsole.html#logs\">Log messages</option>\n");
buf.append("</select>");
buf.append("</form>");
buf.append("<hr />\n");
if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) )
buf.append("<b>Router: </b> ").append(_routerInfo.getIdentity().getHash().toBase64()).append("<br />\n");
buf.append("<b>As of: </b> ").append(new Date(Clock.getInstance().now())).append(" (uptime: ").append(DataHelper.formatDuration(getUptime())).append(") <br />\n");
buf.append("<b>Started on: </b> ").append(new Date(getWhenStarted())).append("<br />\n");
buf.append("<b>Clock offset: </b> ").append(Clock.getInstance().getOffset()).append("ms (OS time: ").append(new Date(Clock.getInstance().now() - Clock.getInstance().getOffset())).append(")<br />\n");
long tot = Runtime.getRuntime().totalMemory()/1024;
long free = Runtime.getRuntime().freeMemory()/1024;
buf.append("<b>Memory:</b> In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB <br />\n");
buf.append("<b>Version:</b> Router: ").append(RouterVersion.VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br />\n");
if (_higherVersionSeen)
buf.append("<b><font color=\"red\">HIGHER VERSION SEEN</font><b> - please <a href=\"http://i2p.dnsalias.net/\">check</a> to see if there is a new release out<br />\n");
buf.append("<hr /><a name=\"bandwidth\"> </a><h2>Bandwidth</h2>\n");
long sent = BandwidthLimiter.getInstance().getTotalSendBytes();
long received = BandwidthLimiter.getInstance().getTotalReceiveBytes();
buf.append("<ul>");
buf.append("<li> ").append(sent).append(" bytes sent, ");
buf.append(received).append(" bytes received</li>");
DecimalFormat fmt = new DecimalFormat("##0.00");
// we use the unadjusted time, since thats what getWhenStarted is based off
long lifetime = Clock.getInstance().now()-Clock.getInstance().getOffset() - getWhenStarted();
lifetime /= 1000;
if ( (sent > 0) && (received > 0) ) {
double sendKBps = sent / (lifetime*1024.0);
double receivedKBps = received / (lifetime*1024.0);
buf.append("<li>Lifetime rate: ");
buf.append(fmt.format(sendKBps)).append("KBps sent ");
buf.append(fmt.format(receivedKBps)).append("KBps received");
buf.append("</li>");
}
RateStat sendRate = StatManager.getInstance().getRate("transport.sendMessageSize"); buf.append("<form action=\"/routerConsole.html\">");
for (int i = 0; i < sendRate.getPeriods().length; i++) { buf.append("<select name=\"go\" onChange='location.href=this.value'>");
Rate rate = sendRate.getRate(sendRate.getPeriods()[i]); buf.append("<option value=\"/routerConsole.html#bandwidth\">Bandwidth</option>\n");
double bytes = rate.getLastTotalValue() + rate.getCurrentTotalValue(); buf.append("<option value=\"/routerConsole.html#clients\">Clients</option>\n");
long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime(); buf.append("<option value=\"/routerConsole.html#transports\">Transports</option>\n");
if (ms <= 0) { buf.append("<option value=\"/routerConsole.html#profiles\">Peer Profiles</option>\n");
bytes = 0; buf.append("<option value=\"/routerConsole.html#tunnels\">Tunnels</option>\n");
ms = 1; buf.append("<option value=\"/routerConsole.html#jobs\">Jobs</option>\n");
} buf.append("<option value=\"/routerConsole.html#shitlist\">Shitlist</option>\n");
buf.append("<li>"); buf.append("<option value=\"/routerConsole.html#pending\">Pending messages</option>\n");
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous send avg: "); buf.append("<option value=\"/routerConsole.html#netdb\">Network Database</option>\n");
double bps = bytes*1000.0d/ms; buf.append("<option value=\"/routerConsole.html#logs\">Log messages</option>\n");
if (bps > 2048) { buf.append("</select>");
bps /= 1024.0d; buf.append("</form>");
buf.append(fmt.format(bps)).append(" KBps");
} else { buf.append("<hr />\n");
buf.append(fmt.format(bps)).append(" Bps");
} if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) )
buf.append(" over ").append((long)bytes).append(" bytes"); buf.append("<b>Router: </b> ").append(_routerInfo.getIdentity().getHash().toBase64()).append("<br />\n");
buf.append("</li><li>"); buf.append("<b>As of: </b> ").append(new Date(Clock.getInstance().now())).append(" (uptime: ").append(DataHelper.formatDuration(getUptime())).append(") <br />\n");
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period send avg: "); buf.append("<b>Started on: </b> ").append(new Date(getWhenStarted())).append("<br />\n");
// we include lastPeriod + current *partial* period, and jrandom is too lazy to calculate how buf.append("<b>Clock offset: </b> ").append(Clock.getInstance().getOffset()).append("ms (OS time: ").append(new Date(Clock.getInstance().now() - Clock.getInstance().getOffset())).append(")<br />\n");
// much of that partial is contained here, so 2*period it is. long tot = Runtime.getRuntime().totalMemory()/1024;
bps = bytes*1000.0d/(2*rate.getPeriod()); long free = Runtime.getRuntime().freeMemory()/1024;
if (bps > 2048) { buf.append("<b>Memory:</b> In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB <br />\n");
bps /= 1024.0d; buf.append("<b>Version:</b> Router: ").append(RouterVersion.VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br />\n");
buf.append(fmt.format(bps)).append(" KBps"); if (_higherVersionSeen)
} else { buf.append("<b><font color=\"red\">HIGHER VERSION SEEN</font><b> - please <a href=\"http://i2p.dnsalias.net/\">check</a> to see if there is a new release out<br />\n");
buf.append(fmt.format(bps)).append(" Bps");
} buf.append("<hr /><a name=\"bandwidth\"> </a><h2>Bandwidth</h2>\n");
buf.append(" over ").append((long)bytes).append(" bytes"); long sent = BandwidthLimiter.getInstance().getTotalSendBytes();
buf.append("</li>"); long received = BandwidthLimiter.getInstance().getTotalReceiveBytes();
} buf.append("<ul>");
RateStat receiveRate = StatManager.getInstance().getRate("transport.receiveMessageSize"); buf.append("<li> ").append(sent).append(" bytes sent, ");
for (int i = 0; i < receiveRate.getPeriods().length; i++) { buf.append(received).append(" bytes received</li>");
Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]);
double bytes = rate.getLastTotalValue() + rate.getCurrentTotalValue(); DecimalFormat fmt = new DecimalFormat("##0.00");
long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime();
if (ms <= 0) { // we use the unadjusted time, since thats what getWhenStarted is based off
bytes = 0; long lifetime = Clock.getInstance().now()-Clock.getInstance().getOffset() - getWhenStarted();
ms = 1; lifetime /= 1000;
} if ( (sent > 0) && (received > 0) ) {
buf.append("<li>"); double sendKBps = sent / (lifetime*1024.0);
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous receive avg: "); double receivedKBps = received / (lifetime*1024.0);
double bps = bytes*1000.0d/ms; buf.append("<li>Lifetime rate: ");
if (bps > 2048) { buf.append(fmt.format(sendKBps)).append("KBps sent ");
bps /= 1024.0d; buf.append(fmt.format(receivedKBps)).append("KBps received");
buf.append(fmt.format(bps)).append(" KBps "); buf.append("</li>");
} else { }
buf.append(fmt.format(bps)).append(" Bps ");
} RateStat sendRate = StatManager.getInstance().getRate("transport.sendMessageSize");
buf.append(" over ").append((long)bytes).append(" bytes"); for (int i = 0; i < sendRate.getPeriods().length; i++) {
buf.append("</li><li>"); Rate rate = sendRate.getRate(sendRate.getPeriods()[i]);
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: "); double bytes = rate.getLastTotalValue() + rate.getCurrentTotalValue();
// we include lastPeriod + current *partial* period, and jrandom is too lazy to calculate how long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime();
// much of that partial is contained here, so 2*period it is. if (ms <= 0) {
bps = bytes*1000.0d/(2*rate.getPeriod()); bytes = 0;
if (bps > 2048) { ms = 1;
bps /= 1024.0d; }
buf.append(fmt.format(bps)).append(" KBps"); buf.append("<li>");
} else { buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous send avg: ");
buf.append(fmt.format(bps)).append(" Bps"); double bps = bytes*1000.0d/ms;
} if (bps > 2048) {
buf.append(" over ").append((long)bytes).append(" bytes"); bps /= 1024.0d;
buf.append("</li>"); buf.append(fmt.format(bps)).append(" KBps");
} } else {
buf.append(fmt.format(bps)).append(" Bps");
buf.append("</ul>\n"); }
buf.append("<i>Instantaneous averages count how fast the transfers go when we're trying to transfer data, "); buf.append(" over ").append((long)bytes).append(" bytes");
buf.append("while period averages count how fast the transfers go across the entire period, even when we're not "); buf.append("</li><li>");
buf.append("trying to transfer data. Lifetime averages count how many elephants there are on the moon [like anyone reads this text]</i>"); buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period send avg: ");
buf.append("\n"); // we include lastPeriod + current *partial* period, and jrandom is too lazy to calculate how
// much of that partial is contained here, so 2*period it is.
buf.append("<hr /><a name=\"clients\"> </a>\n"); bps = bytes*1000.0d/(2*rate.getPeriod());
buf.append(ClientManagerFacade.getInstance().renderStatusHTML()); if (bps > 2048) {
buf.append("\n<hr /><a name=\"transports\"> </a>\n"); bps /= 1024.0d;
buf.append(CommSystemFacade.getInstance().renderStatusHTML()); buf.append(fmt.format(bps)).append(" KBps");
buf.append("\n<hr /><a name=\"profiles\"> </a>\n"); } else {
buf.append(PeerManagerFacade.getInstance().renderStatusHTML()); buf.append(fmt.format(bps)).append(" Bps");
buf.append("\n<hr /><a name=\"tunnels\"> </a>\n"); }
buf.append(TunnelManagerFacade.getInstance().renderStatusHTML()); buf.append(" over ").append((long)bytes).append(" bytes");
buf.append("\n<hr /><a name=\"jobs\"> </a>\n"); buf.append("</li>");
buf.append(JobQueue.getInstance().renderStatusHTML()); }
buf.append("\n<hr /><a name=\"shitlist\"> </a>\n");
buf.append(Shitlist.getInstance().renderStatusHTML()); RateStat receiveRate = StatManager.getInstance().getRate("transport.receiveMessageSize");
buf.append("\n<hr /><a name=\"pending\"> </a>\n"); for (int i = 0; i < receiveRate.getPeriods().length; i++) {
buf.append(OutboundMessageRegistry.getInstance().renderStatusHTML()); Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]);
buf.append("\n<hr /><a name=\"netdb\"> </a>\n"); double bytes = rate.getLastTotalValue() + rate.getCurrentTotalValue();
buf.append(NetworkDatabaseFacade.getInstance().renderStatusHTML()); long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime();
buf.append("\n<hr /><a name=\"logs\"> </a>\n"); if (ms <= 0) {
List msgs = LogConsoleBuffer.getInstance().getMostRecentMessages(); bytes = 0;
buf.append("\n<h2>Most recent console messages:</h2><table border=\"1\">\n"); ms = 1;
for (Iterator iter = msgs.iterator(); iter.hasNext(); ) { }
String msg = (String)iter.next(); buf.append("<li>");
buf.append("<tr><td valign=\"top\" align=\"left\"><pre>").append(msg); buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous receive avg: ");
buf.append("</pre></td></tr>\n"); double bps = bytes*1000.0d/ms;
} if (bps > 2048) {
buf.append("</table>"); bps /= 1024.0d;
buf.append("</body></html>\n"); buf.append(fmt.format(bps)).append(" KBps ");
return buf.toString(); } else {
buf.append(fmt.format(bps)).append(" Bps ");
}
buf.append(" over ").append((long)bytes).append(" bytes");
buf.append("</li><li>");
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: ");
// we include lastPeriod + current *partial* period, and jrandom is too lazy to calculate how
// much of that partial is contained here, so 2*period it is.
bps = bytes*1000.0d/(2*rate.getPeriod());
if (bps > 2048) {
bps /= 1024.0d;
buf.append(fmt.format(bps)).append(" KBps");
} else {
buf.append(fmt.format(bps)).append(" Bps");
}
buf.append(" over ").append((long)bytes).append(" bytes");
buf.append("</li>");
}
buf.append("</ul>\n");
buf.append("<i>Instantaneous averages count how fast the transfers go when we're trying to transfer data, ");
buf.append("while period averages count how fast the transfers go across the entire period, even when we're not ");
buf.append("trying to transfer data. Lifetime averages count how many elephants there are on the moon [like anyone reads this text]</i>");
buf.append("\n");
buf.append("<hr /><a name=\"clients\"> </a>\n");
buf.append(ClientManagerFacade.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"transports\"> </a>\n");
buf.append(CommSystemFacade.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"profiles\"> </a>\n");
buf.append(PeerManagerFacade.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"tunnels\"> </a>\n");
buf.append(TunnelManagerFacade.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"jobs\"> </a>\n");
buf.append(JobQueue.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"shitlist\"> </a>\n");
buf.append(Shitlist.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"pending\"> </a>\n");
buf.append(OutboundMessageRegistry.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"netdb\"> </a>\n");
buf.append(NetworkDatabaseFacade.getInstance().renderStatusHTML());
buf.append("\n<hr /><a name=\"logs\"> </a>\n");
List msgs = LogConsoleBuffer.getInstance().getMostRecentMessages();
buf.append("\n<h2>Most recent console messages:</h2><table border=\"1\">\n");
for (Iterator iter = msgs.iterator(); iter.hasNext(); ) {
String msg = (String)iter.next();
buf.append("<tr><td valign=\"top\" align=\"left\"><pre>").append(msg);
buf.append("</pre></td></tr>\n");
}
buf.append("</table>");
buf.append("</body></html>\n");
return buf.toString();
} }
public void shutdown() { public void shutdown() {
try { JobQueue.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the job queue", t); } try { JobQueue.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the job queue", t); }
try { StatisticsManager.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the stats manager", t); } try { StatisticsManager.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the stats manager", t); }
try { ClientManagerFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the client manager", t); } try { ClientManagerFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the client manager", t); }
try { TunnelManagerFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the tunnel manager", t); } try { TunnelManagerFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the tunnel manager", t); }
try { NetworkDatabaseFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the networkDb", t); } try { NetworkDatabaseFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the networkDb", t); }
try { CommSystemFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the comm system", t); } try { CommSystemFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the comm system", t); }
try { PeerManagerFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the peer manager", t); } try { PeerManagerFacade.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the peer manager", t); }
try { SessionKeyPersistenceHelper.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the session key manager", t); } try { SessionKeyPersistenceHelper.getInstance().shutdown(); } catch (Throwable t) { _log.log(Log.CRIT, "Error shutting down the session key manager", t); }
dumpStats(); dumpStats();
_log.log(Log.CRIT, "Shutdown complete", new Exception("Shutdown")); _log.log(Log.CRIT, "Shutdown complete", new Exception("Shutdown"));
try { LogManager.getInstance().shutdown(); } catch (Throwable t) { } try { LogManager.getInstance().shutdown(); } catch (Throwable t) { }
try { Thread.sleep(1000); } catch (InterruptedException ie) {} try { Thread.sleep(1000); } catch (InterruptedException ie) {}
Runtime.getRuntime().halt(-1); Runtime.getRuntime().halt(-1);
} }
private void dumpStats() { private void dumpStats() {
_log.log(Log.CRIT, "Lifetime stats:\n\n" + StatsGenerator.generateStatsPage()); _log.log(Log.CRIT, "Lifetime stats:\n\n" + StatsGenerator.generateStatsPage());
} }
public static void main(String args[]) { public static void main(String args[]) {
Router.getInstance().runRouter(); Router.getInstance().runRouter();
if (args.length > 0) {
_log.info("Not interactive");
} else {
_log.info("Interactive");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while ( (line = in.readLine()) != null) {
ClientMessagePool.getInstance().dumpPoolInfo();
OutNetMessagePool.getInstance().dumpPoolInfo();
InNetMessagePool.getInstance().dumpPoolInfo();
}
} catch (IOException ioe) {
_log.error("Error dumping queue", ioe);
}
}
} }
private class ShutdownHook extends Thread { private class ShutdownHook extends Thread {
public void run() { public void run() {
_log.log(Log.CRIT, "Shutting down the router...", new Exception("Shutting down")); _log.log(Log.CRIT, "Shutting down the router...", new Exception("Shutting down"));
shutdown(); shutdown();
} }
} }
/** update the router.info file whenever its, er, updated */ /** update the router.info file whenever its, er, updated */
private static class PersistRouterInfoJob extends JobImpl { private static class PersistRouterInfoJob extends JobImpl {
public String getName() { return "Persist Updated Router Information"; } public String getName() { return "Persist Updated Router Information"; }
public void runJob() { public void runJob() {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Persisting updated router info"); _log.debug("Persisting updated router info");
String infoFilename = Router.getInstance().getConfigSetting(PROP_INFO_FILENAME); String infoFilename = Router.getInstance().getConfigSetting(PROP_INFO_FILENAME);
if (infoFilename == null) if (infoFilename == null)
infoFilename = PROP_INFO_FILENAME_DEFAULT; infoFilename = PROP_INFO_FILENAME_DEFAULT;
RouterInfo info = Router.getInstance().getRouterInfo(); RouterInfo info = Router.getInstance().getRouterInfo();
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
fos = new FileOutputStream(infoFilename); fos = new FileOutputStream(infoFilename);
info.writeBytes(fos); info.writeBytes(fos);
} catch (DataFormatException dfe) { } catch (DataFormatException dfe) {
_log.error("Error rebuilding the router information", dfe); _log.error("Error rebuilding the router information", dfe);
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Error writing out the rebuilt router information", ioe); _log.error("Error writing out the rebuilt router information", ioe);
} finally { } finally {
if (fos != null) try { fos.close(); } catch (IOException ioe) {} if (fos != null) try { fos.close(); } catch (IOException ioe) {}
} }
} }
} }
} }