use of net.i2p.util.Log in project i2p.i2p by i2p.
the class PluginStarter method isPluginRunning.
public static boolean isPluginRunning(String pluginName, RouterContext ctx) {
Log log = ctx.logManager().getLog(PluginStarter.class);
boolean isJobRunning = false;
Collection<SimpleTimer2.TimedEvent> pending = _pendingPluginClients.get(pluginName);
if (pending != null && !pending.isEmpty()) {
// TODO have a pending indication too
isJobRunning = true;
}
boolean isWarRunning = false;
if (pluginWars.containsKey(pluginName)) {
Iterator<String> it = pluginWars.get(pluginName).iterator();
while (it.hasNext() && !isWarRunning) {
String warName = it.next();
if (WebAppStarter.isWebAppRunning(warName)) {
isWarRunning = true;
}
}
}
boolean isClientThreadRunning = isClientThreadRunning(pluginName, ctx);
if (log.shouldLog(Log.DEBUG))
log.debug("plugin name = <" + pluginName + ">; threads running? " + isClientThreadRunning + "; webapp running? " + isWarRunning + "; jobs running? " + isJobRunning);
return isClientThreadRunning || isWarRunning || isJobRunning;
//
// if (log.shouldLog(Log.DEBUG))
// log.debug("plugin name = <" + pluginName + ">; threads running? " + isClientThreadRunning(pluginName) + "; webapp running? " + WebAppStarter.isWebAppRunning(pluginName) + "; jobs running? " + isJobRunning);
// return isClientThreadRunning(pluginName) || WebAppStarter.isWebAppRunning(pluginName) || isJobRunning;
//
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class PluginStarter method runClientApps.
/**
* @param action "start" or "stop" or "uninstall"
* @throws Exception just about anything if an app has a delay less than zero, caller would be wise to catch Throwable
* If no apps have a delay less than zero, it shouldn't throw anything
*/
private static void runClientApps(RouterContext ctx, File pluginDir, List<ClientAppConfig> apps, String action) throws Exception {
Log log = ctx.logManager().getLog(PluginStarter.class);
// initialize pluginThreadGroup and _pendingPluginClients
String pluginName = pluginDir.getName();
if (!pluginThreadGroups.containsKey(pluginName))
pluginThreadGroups.put(pluginName, new ThreadGroup(pluginName));
ThreadGroup pluginThreadGroup = pluginThreadGroups.get(pluginName);
if (action.equals("start"))
_pendingPluginClients.put(pluginName, new ConcurrentHashSet<SimpleTimer2.TimedEvent>());
for (ClientAppConfig app : apps) {
// bypass all the logic below.
if (action.equals("stop")) {
String[] argVal = LoadClientAppsJob.parseArgs(app.args);
// Do this after parsing so we don't need to worry about quoting
for (int i = 0; i < argVal.length; i++) {
if (argVal[i].indexOf('$') >= 0) {
argVal[i] = argVal[i].replace("$I2P", ctx.getBaseDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$CONFIG", ctx.getConfigDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$PLUGIN", pluginDir.getAbsolutePath());
}
}
ClientApp ca = ctx.routerAppManager().getClientApp(app.className, argVal);
if (ca != null) {
// even if (ca.getState() != ClientAppState.RUNNING), we do this, we don't want to fall thru
try {
ca.shutdown(LoadClientAppsJob.parseArgs(app.stopargs));
} catch (Throwable t) {
throw new Exception(t);
}
continue;
}
}
if (action.equals("start") && app.disabled)
continue;
String[] argVal;
if (action.equals("start")) {
// start
argVal = LoadClientAppsJob.parseArgs(app.args);
} else {
String args;
if (action.equals("stop"))
args = app.stopargs;
else if (action.equals("uninstall"))
args = app.uninstallargs;
else
throw new IllegalArgumentException("bad action");
// args must be present
if (args == null || args.length() <= 0)
continue;
argVal = LoadClientAppsJob.parseArgs(args);
}
// do this after parsing so we don't need to worry about quoting
for (int i = 0; i < argVal.length; i++) {
if (argVal[i].indexOf('$') >= 0) {
argVal[i] = argVal[i].replace("$I2P", ctx.getBaseDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$CONFIG", ctx.getConfigDir().getAbsolutePath());
argVal[i] = argVal[i].replace("$PLUGIN", pluginDir.getAbsolutePath());
}
}
ClassLoader cl = null;
if (app.classpath != null) {
String cp = app.classpath;
if (cp.indexOf('$') >= 0) {
cp = cp.replace("$I2P", ctx.getBaseDir().getAbsolutePath());
cp = cp.replace("$CONFIG", ctx.getConfigDir().getAbsolutePath());
cp = cp.replace("$PLUGIN", pluginDir.getAbsolutePath());
}
// Old way - add for the whole JVM
// addToClasspath(cp, app.clientName, log);
// New way - add only for this client
// We cache the ClassLoader we start the client with, so
// we can reuse it for stopping and uninstalling.
// If we don't, the client won't be able to find its
// static members.
String clCacheKey = pluginName + app.className + app.args;
if (!action.equals("start"))
cl = _clCache.get(clCacheKey);
if (cl == null) {
URL[] urls = classpathToURLArray(cp, app.clientName, log);
if (urls != null) {
cl = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
if (action.equals("start"))
_clCache.put(clCacheKey, cl);
}
}
}
if (app.delay < 0 && action.equals("start")) {
// this will throw exceptions
LoadClientAppsJob.runClientInline(app.className, app.clientName, argVal, log, cl);
} else if (app.delay == 0 || !action.equals("start")) {
// quick check, will throw ClassNotFoundException on error
LoadClientAppsJob.testClient(app.className, cl);
// run this guy now
LoadClientAppsJob.runClient(app.className, app.clientName, argVal, ctx, log, pluginThreadGroup, cl);
} else {
// If it bombs after that, then we throw the ClassNotFoundException.
try {
// quick check
LoadClientAppsJob.testClient(app.className, cl);
} catch (ClassNotFoundException ex) {
// Under normal circumstances there will be no delay at all.
try {
if (app.delay > 1) {
Thread.sleep(2000);
} else {
Thread.sleep(1000);
}
} catch (InterruptedException ie) {
}
// quick check, will throw ClassNotFoundException on error
LoadClientAppsJob.testClient(app.className, cl);
}
// wait before firing it up
SimpleTimer2.TimedEvent evt = new TrackedDelayedClient(pluginName, ctx.simpleTimer2(), ctx, app.className, app.clientName, argVal, pluginThreadGroup, cl);
evt.schedule(app.delay);
}
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class BlocklistEntries method verify.
public synchronized boolean verify(I2PAppContext ctx) {
if (verified)
return true;
if (signer == null || sig == null || supdated == null)
return false;
if (updated > ctx.clock().now() + MAX_FUTURE)
return false;
Log log = ctx.logManager().getLog(BlocklistEntries.class);
String[] ss = DataHelper.split(sig, ":", 2);
if (ss.length != 2) {
log.error("blocklist feed bad sig: " + sig);
return false;
}
SigType type = SigType.parseSigType(ss[0]);
if (type == null) {
log.error("blocklist feed bad sig: " + sig);
return false;
}
if (!type.isAvailable()) {
log.error("blocklist feed sigtype unavailable: " + sig);
return false;
}
byte[] bsig = Base64.decode(ss[1]);
if (bsig == null) {
log.error("blocklist feed bad sig: " + sig);
return false;
}
Signature ssig;
try {
ssig = new Signature(type, bsig);
} catch (IllegalArgumentException iae) {
log.error("blocklist feed bad sig: " + sig);
return false;
}
// look in both install dir and config dir for the signer cert
KeyRing ring = new DirKeyRing(new File(ctx.getBaseDir(), "certificates"));
PublicKey pubkey;
try {
pubkey = ring.getKey(signer, CONTENT_ROUTER, type);
} catch (IOException ioe) {
log.error("blocklist feed error", ioe);
return false;
} catch (GeneralSecurityException gse) {
log.error("blocklist feed error", gse);
return false;
}
if (pubkey == null) {
boolean diff = true;
try {
diff = !ctx.getBaseDir().getCanonicalPath().equals(ctx.getConfigDir().getCanonicalPath());
} catch (IOException ioe) {
}
if (diff) {
ring = new DirKeyRing(new File(ctx.getConfigDir(), "certificates"));
try {
pubkey = ring.getKey(signer, CONTENT_ROUTER, type);
} catch (IOException ioe) {
log.error("blocklist feed error", ioe);
return false;
} catch (GeneralSecurityException gse) {
log.error("blocklist feed error", gse);
return false;
}
}
if (pubkey == null) {
log.error("unknown signer for blocklist feed: " + signer);
return false;
}
}
SigningPublicKey spubkey;
try {
spubkey = SigUtil.fromJavaKey(pubkey, type);
} catch (GeneralSecurityException gse) {
log.error("blocklist feed bad sig: " + sig, gse);
return false;
}
StringBuilder buf = new StringBuilder(256);
buf.append(supdated).append('\n');
for (String s : entries) {
buf.append(s).append('\n');
}
for (String s : removes) {
buf.append('!').append(s).append('\n');
}
byte[] data = DataHelper.getUTF8(buf.toString());
boolean rv = ctx.dsa().verifySignature(ssig, data, spubkey);
if (rv)
log.info("blocklist feed sig ok");
else
log.error("blocklist feed sig verify fail: " + signer);
verified = rv;
return rv;
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class ConfigLoggingHelper method getNewClassBox.
/**
* All the classes the log manager knows about, except ones that
* already have overrides
* @since 0.8.1
*/
public String getNewClassBox() {
List<Log> logs = _context.logManager().getLogs();
Set<String> limits = _context.logManager().getLimits().stringPropertyNames();
TreeSet<String> sortedLogs = new TreeSet<String>();
for (Log log : logs) {
String name = log.getName();
if (!limits.contains(name))
sortedLogs.add(name);
// add higher classes of length 3 or more
int dots = 0;
int lastdot = -1;
int nextdot = 0;
while ((nextdot = name.indexOf('.', lastdot + 1)) > 0) {
if (++dots >= 3) {
String subst = name.substring(0, nextdot);
if (!limits.contains(subst))
sortedLogs.add(subst);
}
lastdot = nextdot;
}
}
StringBuilder buf = new StringBuilder(65536);
buf.append("<select name=\"newlogclass\">\n" + "<option value=\"\" selected=\"selected\">").append(_t("Select a class to add")).append("</option>\n");
for (String l : sortedLogs) {
buf.append("<option value=\"").append(l).append("\">").append(l).append("</option>\n");
}
buf.append("</select>\n");
buf.append(getLogLevelBox("newloglevel", "WARN", false));
return buf.toString();
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class KeyStoreUtil method log.
// private static void info(I2PAppContext ctx, String msg) {
// log(ctx, Log.INFO, msg, null);
// }
// private static void error(I2PAppContext ctx, String msg, Throwable t) {
// log(ctx, Log.ERROR, msg, t);
// }
private static void log(I2PAppContext ctx, int level, String msg, Throwable t) {
if (level >= Log.WARN && !ctx.isRouterContext()) {
System.out.println(msg);
if (t != null)
t.printStackTrace();
}
Log l = ctx.logManager().getLog(KeyStoreUtil.class);
l.log(level, msg, t);
}
Aggregations