Search in sources :

Example 56 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class PluginStarter method deferredDeletePlugins.

/**
 *  Deferred deletion of plugins that we failed to delete before.
 *
 *  @since 0.9.13
 */
private static void deferredDeletePlugins(RouterContext ctx) {
    Log log = ctx.logManager().getLog(PluginStarter.class);
    boolean changed = false;
    Properties props = pluginProperties();
    for (Iterator<Map.Entry<Object, Object>> iter = props.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry<Object, Object> e = iter.next();
        String name = (String) e.getKey();
        if (name.startsWith(PREFIX) && name.endsWith(ENABLED)) {
            // deferred deletion of a plugin
            if (e.getValue().equals(DELETED)) {
                String app = name.substring(PREFIX.length(), name.lastIndexOf(ENABLED));
                // shouldn't happen, this is run early
                if (isPluginRunning(app, ctx))
                    continue;
                File pluginDir = new File(ctx.getConfigDir(), PLUGIN_DIR + '/' + app);
                boolean deleted = FileUtil.rmdir(pluginDir, false);
                if (deleted) {
                    log.logAlways(Log.WARN, "Deferred deletion of " + pluginDir + " successful");
                    iter.remove();
                    changed = true;
                } else {
                    if (log.shouldLog(Log.WARN))
                        log.warn("Deferred deletion of " + pluginDir + " failed");
                }
            }
        }
    }
    if (changed)
        storePluginProperties(props);
}
Also used : Log(net.i2p.util.Log) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) File(java.io.File)

Example 57 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class PluginStarter method startPlugins.

/**
 * this shouldn't throw anything
 */
static void startPlugins(RouterContext ctx) {
    Log log = ctx.logManager().getLog(PluginStarter.class);
    Properties props = pluginProperties();
    for (Map.Entry<Object, Object> e : props.entrySet()) {
        String name = (String) e.getKey();
        if (name.startsWith(PREFIX) && name.endsWith(ENABLED)) {
            if (Boolean.parseBoolean((String) e.getValue())) {
                String app = name.substring(PREFIX.length(), name.lastIndexOf(ENABLED));
                // plugins could have been started after update
                if (isPluginRunning(app, ctx))
                    continue;
                try {
                    if (!startPlugin(ctx, app))
                        log.error("Failed to start plugin: " + app);
                } catch (Throwable t) {
                    log.error("Failed to start plugin: " + app, t);
                }
            }
        }
    }
}
Also used : Log(net.i2p.util.Log) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 58 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class PluginStopper method stopPlugins.

/**
 *  Stop all running plugins
 *
 *  this shouldn't throw anything
 */
private static void stopPlugins(RouterContext ctx) {
    Log log = ctx.logManager().getLog(PluginStopper.class);
    List<String> pl = getPlugins();
    // reverse the order
    Collections.reverse(pl);
    for (String app : pl) {
        if (isPluginRunning(app, ctx)) {
            try {
                stopPlugin(ctx, app);
            } catch (Throwable e) {
                if (log.shouldLog(Log.WARN))
                    log.warn("Failed to stop plugin: " + app, e);
            }
        }
    }
}
Also used : Log(net.i2p.util.Log)

Example 59 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class OutboundGatewayProcessor method decrypt.

/**
 * Iteratively undo the crypto that the various layers in the tunnel added.  This is used
 * by the outbound gateway (preemptively undoing the crypto peers will add).
 */
private void decrypt(I2PAppContext ctx, TunnelCreatorConfig cfg, byte[] iv, byte[] orig, int offset, int length) {
    Log log = ctx.logManager().getLog(OutboundGatewayProcessor.class);
    byte[] cur = SimpleByteCache.acquire(HopProcessor.IV_LENGTH);
    for (int i = cfg.getLength() - 1; i >= 1; i--) {
        // dont include hop 0, since that is the creator
        decrypt(ctx, iv, orig, offset, length, cur, cfg.getConfig(i));
        if (log.shouldLog(Log.DEBUG)) {
            log.debug("IV at hop " + i + ": " + Base64.encode(orig, offset, HopProcessor.IV_LENGTH));
        // log.debug("hop " + i + ": " + Base64.encode(orig, offset + HopProcessor.IV_LENGTH, length - HopProcessor.IV_LENGTH));
        }
    }
    SimpleByteCache.release(cur);
}
Also used : Log(net.i2p.util.Log)

Example 60 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class IRCFilter method filterDCCOut.

/**
 *<pre>
 *  DCC CHAT chat IP port        -> DCC CHAT chat xxx.b32.i2p i2p-port
 *  DCC SEND file IP port length -> DCC SEND file xxx.b32.i2p i2p-port length
 *  DCC RESUME file port offset  -> DCC RESUME file i2p-port offset
 *  DCC ACCEPT file port offset  -> DCC ACCEPT file i2p-port offset
 *  DCC xxx                      -> null
 *</pre>
 *
 *  @param pfx the message through the "DCC " part
 *  @param msg the message after the "DCC " part
 *  @param helper may be null
 *  @return the sanitized message or null to block
 *  @since 0.8.9
 */
private static String filterDCCOut(String pfx, String msg, DCCHelper helper) {
    // strip trailing ctcp (other one is in pfx)
    int ctcp = msg.indexOf(0x01);
    if (ctcp > 0)
        msg = msg.substring(0, ctcp);
    String[] args = DataHelper.split(msg, " ", 5);
    if (args.length <= 0)
        return null;
    String type = args[0];
    boolean haveIP = true;
    // no IP in these, replace port only
    if (type == "RESUME" || type == "ACCEPT") {
        haveIP = false;
    } else if (!(type.equals("CHAT") || type.equals("SEND"))) {
        if (ALLOW_ALL_DCC_OUT) {
            if (ctcp > 0)
                return pfx + msg + (char) 0x01;
            return pfx + msg;
        }
    }
    if (helper == null || !helper.isEnabled())
        return null;
    if (args.length < 3)
        return null;
    if (haveIP && args.length < 4)
        return null;
    String arg = args[1];
    byte[] ip = null;
    int nextArg = 2;
    if (haveIP) {
        try {
            String ips = args[nextArg++];
            long ipl = Long.parseLong(ips);
            if (ipl < 0x01000000) {
                // "reverse/firewall DCC"
                // http://en.wikipedia.org/wiki/Direct_Client-to-Client
                // xchat sends an IP of 199 and a port of 0
                Log log = new Log(IRCFilter.class);
                log.logAlways(Log.WARN, "Reverse / Firewall DCC, IP = 0x" + Long.toHexString(ipl));
            // return null;
            }
            ip = DataHelper.toLong(4, ipl);
        } catch (NumberFormatException nfe) {
            return null;
        }
    }
    int cPort;
    try {
        String cp = args[nextArg++];
        cPort = Integer.parseInt(cp);
    } catch (NumberFormatException nfe) {
        return null;
    }
    if (cPort < 0 || cPort > 65535)
        return null;
    int port = -1;
    if (haveIP) {
        if (cPort > 0) {
            // nonzero port but bogus IP? hmm. Fix IP and hope.
            if (ip[0] == 0)
                ip = new byte[] { 127, 0, 0, 1 };
            port = helper.newOutgoing(ip, cPort, type);
        } else {
            // "reverse/firewall DCC" - send it through without tracking
            Log log = new Log(IRCFilter.class);
            log.logAlways(Log.WARN, "Reverse / Firewall DCC, port = 0");
            port = cPort;
        }
    } else if (type.equals("ACCEPT")) {
        port = helper.acceptOutgoing(cPort);
    } else if (type.equals("RESUME")) {
        port = helper.resumeOutgoing(cPort);
    }
    if (port < 0)
        return null;
    StringBuilder buf = new StringBuilder(256);
    buf.append(pfx).append(type).append(' ').append(arg).append(' ');
    if (haveIP) {
        if (port > 0)
            buf.append(helper.getB32Hostname()).append(' ');
        else
            // "reverse/firewall DCC" - set dummy IP and send it through
            buf.append("0 ");
    }
    buf.append(port);
    while (args.length > nextArg) {
        buf.append(' ').append(args[nextArg++]);
    }
    if (pfx.indexOf(0x01) >= 0)
        buf.append((char) 0x01);
    return buf.toString();
}
Also used : Log(net.i2p.util.Log)

Aggregations

Log (net.i2p.util.Log)94 IOException (java.io.IOException)30 File (java.io.File)13 Properties (java.util.Properties)11 DataFormatException (net.i2p.data.DataFormatException)11 FileInputStream (java.io.FileInputStream)7 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 Hash (net.i2p.data.Hash)6 HashMap (java.util.HashMap)5 InputStream (java.io.InputStream)4 EventLog (net.i2p.router.util.EventLog)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 I2PAppContext (net.i2p.I2PAppContext)3 I2PSession (net.i2p.client.I2PSession)3 I2PSessionException (net.i2p.client.I2PSessionException)3 SigType (net.i2p.crypto.SigType)3 RouterInfo (net.i2p.data.router.RouterInfo)3