use of net.i2p.util.Log in project i2p.i2p by i2p.
the class OOMListener method outOfMemory.
public void outOfMemory(OutOfMemoryError oom) {
try {
// prevent multiple parallel shutdowns (when you OOM, you OOM a lot...)
if (_context.router().isFinalShutdownInProgress())
return;
} catch (OutOfMemoryError oome) {
}
try {
// Only do this once
if (_wasCalled.getAndSet(true))
return;
} catch (OutOfMemoryError oome) {
}
try {
// boost priority to help us shut down
// this may or may not do anything...
Thread.currentThread().setPriority(Thread.MAX_PRIORITY - 1);
} catch (OutOfMemoryError oome) {
}
try {
Router.clearCaches();
} catch (OutOfMemoryError oome) {
}
Log log = null;
try {
log = _context.logManager().getLog(Router.class);
log.log(Log.CRIT, "Thread ran out of memory, shutting down I2P", oom);
log.log(Log.CRIT, "free mem: " + Runtime.getRuntime().freeMemory() + " total mem: " + Runtime.getRuntime().totalMemory());
// Can't find any System property or wrapper property that gives
// you the actual config file path, have to guess
String path;
if (SystemVersion.isLinuxService()) {
if (SystemVersion.isGentoo())
path = "/usr/share/i2p";
else
path = "/etc/i2p";
} else {
path = _context.getBaseDir().toString();
}
if (_context.hasWrapper()) {
log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in " + path + File.separatorChar + "wrapper.config");
} else if (!SystemVersion.isWindows()) {
log.log(Log.CRIT, "To prevent future shutdowns, increase MAXMEMOPT in " + path + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper");
} else {
log.log(Log.CRIT, "To prevent future shutdowns, run the restartable version of I2P, and increase wrapper.java.maxmemory in " + path + File.separatorChar + "wrapper.config");
}
} catch (OutOfMemoryError oome) {
}
try {
ThreadDump.dump(_context, 1);
} catch (OutOfMemoryError oome) {
}
try {
_context.router().eventLog().addEvent(EventLog.OOM);
} catch (OutOfMemoryError oome) {
}
try {
_context.router().shutdown(Router.EXIT_OOM);
} catch (OutOfMemoryError oome) {
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class Restarter method run.
public void run() {
_context.router().eventLog().addEvent(EventLog.SOFT_RESTART);
Log log = _context.logManager().getLog(Router.class);
log.error("Stopping the router for a restart...");
log.logAlways(Log.WARN, "Stopping the client manager");
// NOTE: DisconnectMessageHandler keys off "restart"
try {
_context.clientManager().shutdown("Router restart");
} catch (Throwable t) {
log.log(Log.CRIT, "Error stopping the client manager", t);
}
log.logAlways(Log.WARN, "Stopping the comm system");
_context.bandwidthLimiter().reinitialize();
try {
_context.messageRegistry().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the message registry", t);
}
try {
_context.commSystem().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the comm system", t);
}
log.logAlways(Log.WARN, "Stopping the tunnel manager");
try {
_context.tunnelManager().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the tunnel manager", t);
}
// try { _context.peerManager().restart(); } catch (Throwable t) { log.log(Log.CRIT, "Error restarting the peer manager", t); }
// try { _context.netDb().restart(); } catch (Throwable t) { log.log(Log.CRIT, "Error restarting the networkDb", t); }
// try { _context.jobQueue().restart(); } catch (Throwable t) { log.log(Log.CRIT, "Error restarting the job queue", t); }
log.logAlways(Log.WARN, "Router teardown complete, restarting the router...");
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException ie) {
}
log.logAlways(Log.WARN, "Restarting the comm system");
log.logAlways(Log.WARN, "Restarting the tunnel manager");
log.logAlways(Log.WARN, "Restarting the client manager");
try {
_context.clientMessagePool().restart();
} catch (Throwable t) {
log.log(Log.CRIT, "Error restarting the CMP", t);
}
try {
_context.clientManager().startup();
} catch (Throwable t) {
log.log(Log.CRIT, "Error starting the client manager", t);
}
_context.router().setIsAlive();
_context.router().rebuildRouterInfo();
log.logAlways(Log.WARN, "Restart complete");
((RouterClock) _context.clock()).addShiftListener(_context.router());
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class NtpClient method main.
/**
* Usage: NtpClient [-6] [servers...]
* default pool.ntp.org
*/
public static void main(String[] args) throws IOException {
boolean ipv6 = false;
if (args.length > 0 && args[0].equals("-6")) {
ipv6 = true;
if (args.length == 1)
args = new String[0];
else
args = Arrays.copyOfRange(args, 1, args.length);
}
if (args.length <= 0) {
args = new String[] { "pool.ntp.org" };
}
System.out.println("Querying " + Arrays.toString(args));
Log log = new Log(NtpClient.class);
try {
long[] rv = currentTimeAndStratum(args, DEFAULT_TIMEOUT, ipv6, log);
System.out.println("Current time: " + new java.util.Date(rv[0]) + " (stratum " + rv[1] + ") offset " + (rv[0] - System.currentTimeMillis()) + "ms");
} catch (IllegalArgumentException iae) {
System.out.println("Failed: " + iae.getMessage());
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class NetDbRenderer method renderStatusHTML.
/**
* @param mode 0: charts only; 1: full routerinfos; 2: abbreviated routerinfos
*/
public void renderStatusHTML(Writer out, int mode) throws IOException {
if (!_context.netDb().isInitialized()) {
out.write("<div id=\"notinitialized\">");
out.write(_t("Not initialized"));
out.write("</div>");
out.flush();
return;
}
Log log = _context.logManager().getLog(NetDbRenderer.class);
long start = System.currentTimeMillis();
boolean full = mode == 1;
boolean shortStats = mode == 2;
// this means show the router infos
boolean showStats = full || shortStats;
Hash us = _context.routerHash();
StringBuilder buf = new StringBuilder(8192);
if (showStats) {
RouterInfo ourInfo = _context.router().getRouterInfo();
renderRouterInfo(buf, ourInfo, true, true);
out.write(buf.toString());
buf.setLength(0);
}
ObjectCounter<String> versions = new ObjectCounter<String>();
ObjectCounter<String> countries = new ObjectCounter<String>();
int[] transportCount = new int[TNAMES.length];
Set<RouterInfo> routers = new TreeSet<RouterInfo>(new RouterInfoComparator());
routers.addAll(_context.netDb().getRouters());
for (RouterInfo ri : routers) {
Hash key = ri.getIdentity().getHash();
boolean isUs = key.equals(us);
if (!isUs) {
if (showStats) {
renderRouterInfo(buf, ri, false, full);
out.write(buf.toString());
buf.setLength(0);
}
String routerVersion = ri.getOption("router.version");
if (routerVersion != null)
versions.increment(routerVersion);
String country = _context.commSystem().getCountry(key);
if (country != null)
countries.increment(country);
transportCount[classifyTransports(ri)]++;
}
}
long end = System.currentTimeMillis();
if (log.shouldWarn())
log.warn("part 1 took " + (end - start));
start = end;
//
if (!showStats) {
// the summary table
buf.append("<table id=\"netdboverview\" border=\"0\" cellspacing=\"30\"><tr><th colspan=\"3\">").append(_t("Network Database Router Statistics")).append("</th></tr><tr><td style=\"vertical-align: top;\">");
// versions table
List<String> versionList = new ArrayList<String>(versions.objects());
if (!versionList.isEmpty()) {
Collections.sort(versionList, Collections.reverseOrder(new VersionComparator()));
buf.append("<table id=\"netdbversions\">\n");
buf.append("<tr><th>" + _t("Version") + "</th><th>" + _t("Count") + "</th></tr>\n");
for (String routerVersion : versionList) {
int num = versions.count(routerVersion);
String ver = DataHelper.stripHTML(routerVersion);
buf.append("<tr><td align=\"center\"><a href=\"/netdb?v=").append(ver).append("\">").append(ver);
buf.append("</a></td><td align=\"center\">").append(num).append("</td></tr>\n");
}
buf.append("</table>\n");
}
buf.append("</td><td style=\"vertical-align: top;\">");
out.write(buf.toString());
buf.setLength(0);
end = System.currentTimeMillis();
if (log.shouldWarn())
log.warn("part 2 took " + (end - start));
start = end;
// transports table
buf.append("<table id=\"netdbtransports\">\n");
buf.append("<tr><th align=\"left\">" + _t("Transports") + "</th><th>" + _t("Count") + "</th></tr>\n");
for (int i = 0; i < TNAMES.length; i++) {
int num = transportCount[i];
if (num > 0) {
buf.append("<tr><td>").append(_t(TNAMES[i]));
buf.append("</td><td align=\"center\">").append(num).append("</td></tr>\n");
}
}
buf.append("</table>\n");
buf.append("</td><td style=\"vertical-align: top;\">");
out.write(buf.toString());
buf.setLength(0);
end = System.currentTimeMillis();
if (log.shouldWarn())
log.warn("part 3 took " + (end - start));
start = end;
// country table
List<String> countryList = new ArrayList<String>(countries.objects());
if (!countryList.isEmpty()) {
Collections.sort(countryList, new CountryComparator());
buf.append("<table id=\"netdbcountrylist\">\n");
buf.append("<tr><th align=\"left\">" + _t("Country") + "</th><th>" + _t("Count") + "</th></tr>\n");
for (String country : countryList) {
int num = countries.count(country);
buf.append("<tr><td><a href=\"/netdb?c=").append(country).append("\">");
buf.append("<img height=\"11\" width=\"16\" alt=\"").append(country.toUpperCase(Locale.US)).append("\"");
buf.append(" src=\"/flags.jsp?c=").append(country).append("\">");
buf.append(getTranslatedCountry(country));
buf.append("</a></td><td align=\"center\">").append(num).append("</td></tr>\n");
}
buf.append("</table>\n");
}
buf.append("</td></tr></table>");
end = System.currentTimeMillis();
if (log.shouldWarn())
log.warn("part 4 took " + (end - start));
start = end;
//
// don't bother to reindent
//
}
// if !showStats
out.write(buf.toString());
out.flush();
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class BuildMessageTestStandalone method testBuildMessage.
public void testBuildMessage() {
I2PAppContext ctx = I2PAppContext.getGlobalContext();
Log log = ctx.logManager().getLog(getClass());
List<Integer> order = pickOrder();
TunnelCreatorConfig cfg = createConfig(ctx);
_replyRouter = new Hash();
byte[] h = new byte[Hash.HASH_LENGTH];
Arrays.fill(h, (byte) 0xFF);
_replyRouter.setData(h);
_replyTunnel = 42;
// populate and encrypt the message
TunnelBuildMessage msg = new TunnelBuildMessage(ctx);
for (int i = 0; i < order.size(); i++) {
int hop = order.get(i).intValue();
PublicKey key = null;
if (hop < _pubKeys.length)
key = _pubKeys[hop];
BuildMessageGenerator.createRecord(i, hop, msg, cfg, _replyRouter, _replyTunnel, ctx, key);
}
BuildMessageGenerator.layeredEncrypt(ctx, msg, cfg, order);
log.debug("\n================================================================" + "\nMessage fully encrypted" + "\n================================================================");
// now msg is fully encrypted, so lets go through the hops, decrypting and replying
// as necessary
BuildMessageProcessor proc = new BuildMessageProcessor(ctx);
for (int i = 0; i < cfg.getLength(); i++) {
// this not only decrypts the current hop's record, but encrypts the other records
// with the reply key
BuildRequestRecord req = proc.decrypt(msg, _peers[i], _privKeys[i]);
// If false, no records matched the _peers[i], or the decryption failed
assertTrue("foo @ " + i, req != null);
long ourId = req.readReceiveTunnelId();
byte[] replyIV = req.readReplyIV();
long nextId = req.readNextTunnelId();
Hash nextPeer = req.readNextIdentity();
boolean isInGW = req.readIsInboundGateway();
boolean isOutEnd = req.readIsOutboundEndpoint();
long time = req.readRequestTime();
long now = (ctx.clock().now() / (60l * 60l * 1000l)) * (60 * 60 * 1000);
int ourSlot = -1;
EncryptedBuildRecord reply = BuildResponseRecord.create(ctx, 0, req.readReplyKey(), req.readReplyIV(), -1);
for (int j = 0; j < TunnelBuildMessage.MAX_RECORD_COUNT; j++) {
if (msg.getRecord(j) == null) {
ourSlot = j;
msg.setRecord(j, reply);
break;
}
}
log.debug("Read slot " + ourSlot + " containing hop " + i + " @ " + _peers[i].toBase64() + " receives on " + ourId + " w/ replyIV " + Base64.encode(replyIV) + " sending to " + nextId + " on " + nextPeer.toBase64() + " inGW? " + isInGW + " outEnd? " + isOutEnd + " time difference " + (now - time));
}
log.debug("\n================================================================" + "\nAll hops traversed and replies gathered" + "\n================================================================");
// now all of the replies are populated, toss 'em into a reply message and handle it
TunnelBuildReplyMessage reply = new TunnelBuildReplyMessage(ctx);
for (int i = 0; i < TunnelBuildMessage.MAX_RECORD_COUNT; i++) reply.setRecord(i, msg.getRecord(i));
int[] statuses = (new BuildReplyHandler(ctx)).decrypt(reply, cfg, order);
if (statuses == null)
throw new RuntimeException("bar");
boolean allAgree = true;
for (int i = 0; i < cfg.getLength(); i++) {
Hash peer = cfg.getPeer(i);
int record = order.get(i).intValue();
if (statuses[record] != 0)
allAgree = false;
// else
// penalize peer according to the rejection cause
}
log.debug("\n================================================================" + "\nAll peers agree? " + allAgree + "\n================================================================");
}
Aggregations