Search in sources :

Example 71 with Log

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

the class I2PTunnelClientBase method buildSocketManager.

/**
 * As of 0.9.20 this is fast, and does NOT connect the manager to the router.
 * Call verifySocketManager() for that.
 *
 * @param pkf absolute path or null
 * @return non-null
 * @throws IllegalArgumentException if the I2CP configuration is b0rked so
 *                                  badly that we cant create a socketManager
 */
protected static I2PSocketManager buildSocketManager(I2PTunnel tunnel, String pkf, Logging log) {
    // shadows instance _log
    Log _log = tunnel.getContext().logManager().getLog(I2PTunnelClientBase.class);
    Properties props = new Properties();
    props.putAll(tunnel.getClientOptions());
    int portNum = 7654;
    if (tunnel.port != null) {
        try {
            portNum = Integer.parseInt(tunnel.port);
        } catch (NumberFormatException nfe) {
            throw new IllegalArgumentException("Invalid port specified [" + tunnel.port + "]", nfe);
        }
    }
    I2PSocketManager sockManager = null;
    FileInputStream fis = null;
    try {
        if (pkf != null) {
            // Persistent client dest
            fis = new FileInputStream(pkf);
            sockManager = I2PSocketManagerFactory.createDisconnectedManager(fis, tunnel.host, portNum, props);
        } else {
            sockManager = I2PSocketManagerFactory.createDisconnectedManager(null, tunnel.host, portNum, props);
        }
    } catch (I2PSessionException ise) {
        throw new IllegalArgumentException("Can't create socket manager", ise);
    } catch (IOException ioe) {
        if (log != null)
            log.log("Error opening key file " + ioe);
        _log.error("Error opening key file", ioe);
        throw new IllegalArgumentException("Error opening key file", ioe);
    } finally {
        if (fis != null)
            try {
                fis.close();
            } catch (IOException ioe) {
            }
    }
    sockManager.setName("Client");
    if (_log.shouldLog(Log.INFO))
        _log.info(tunnel.getClientOptions().getProperty("inbound.nickname") + ": Built a new socket manager [s=" + sockManager.getSession() + "]");
    tunnel.addSession(sockManager.getSession());
    return sockManager;
}
Also used : I2PSocketManager(net.i2p.client.streaming.I2PSocketManager) Log(net.i2p.util.Log) I2PSessionException(net.i2p.client.I2PSessionException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 72 with Log

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

the class I2PTunnelClientBase method addSubsession.

/**
 *  Add a DSA_SHA1 subsession to the shared client if necessary.
 *
 *  @return subsession, or null if none was added
 *  @since 0.9.20
 */
protected static synchronized I2PSession addSubsession(I2PTunnel tunnel) {
    I2PSession sess = socketManager.getSession();
    if (sess.getMyDestination().getSigType() == SigType.DSA_SHA1)
        return null;
    Properties props = new Properties();
    props.putAll(tunnel.getClientOptions());
    String name = props.getProperty("inbound.nickname");
    if (name != null)
        props.setProperty("inbound.nickname", name + " (DSA)");
    name = props.getProperty("outbound.nickname");
    if (name != null)
        props.setProperty("outbound.nickname", name + " (DSA)");
    props.setProperty(I2PClient.PROP_SIGTYPE, "DSA_SHA1");
    try {
        return socketManager.addSubsession(null, props);
    } catch (I2PSessionException ise) {
        Log log = tunnel.getContext().logManager().getLog(I2PTunnelClientBase.class);
        if (log.shouldLog(Log.WARN))
            log.warn("Failed to add subssession", ise);
        return null;
    }
}
Also used : Log(net.i2p.util.Log) I2PSession(net.i2p.client.I2PSession) I2PSessionException(net.i2p.client.I2PSessionException) Properties(java.util.Properties)

Example 73 with Log

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

the class InternalSocketRunner method run.

@Override
public final void run() {
    try {
        this.ss = new InternalServerSocket(this.port);
        this.open = true;
        while (this.open) {
            Socket s = this.ss.accept();
            this.client.manageConnection(s);
        }
    } catch (IOException ex) {
        if (this.open) {
            Log log = new Log(InternalSocketRunner.class);
            log.error("Error listening for internal connections on port " + this.port, ex);
            stopRunning();
        }
    }
}
Also used : Log(net.i2p.util.Log) InternalServerSocket(net.i2p.util.InternalServerSocket) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) InternalServerSocket(net.i2p.util.InternalServerSocket)

Example 74 with Log

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

the class PersistDHT method loadDHT.

public static synchronized void loadDHT(KRPC krpc, File file) {
    Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
    int count = 0;
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1"));
        String line = null;
        while ((line = br.readLine()) != null) {
            if (line.startsWith("#"))
                continue;
            try {
                krpc.heardAbout(new NodeInfo(line));
                count++;
            // TODO limit number? this will flush the router's SDS caches
            } catch (IllegalArgumentException iae) {
                if (log.shouldLog(Log.WARN))
                    log.warn("Error reading DHT entry", iae);
            } catch (DataFormatException dfe) {
                if (log.shouldLog(Log.WARN))
                    log.warn("Error reading DHT entry", dfe);
            }
        }
    } catch (IOException ioe) {
        if (log.shouldLog(Log.WARN) && file.exists())
            log.warn("Error reading the DHT File", ioe);
    } finally {
        if (br != null)
            try {
                br.close();
            } catch (IOException ioe) {
            }
    }
    if (log.shouldLog(Log.INFO))
        log.info("Loaded " + count + " nodes from " + file);
}
Also used : DataFormatException(net.i2p.data.DataFormatException) InputStreamReader(java.io.InputStreamReader) Log(net.i2p.util.Log) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 75 with Log

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

the class PersistDHT method saveDHT.

/**
 *  @param saveAll if true, don't check last seen time
 */
public static synchronized void saveDHT(DHTNodes nodes, boolean saveAll, File file) {
    if (nodes.size() <= 0)
        return;
    Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
    int count = 0;
    long maxAge = saveAll ? 0 : I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
    PrintWriter out = null;
    try {
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "ISO-8859-1")));
        out.println("# DHT nodes, format is NID:Hash:Destination:port");
        for (NodeInfo ni : nodes.values()) {
            if (ni.lastSeen() < maxAge)
                continue;
            // DHTNodes shouldn't contain us, if that changes check here
            out.println(ni.toPersistentString());
            count++;
        }
        if (out.checkError())
            throw new IOException("Failed write to " + file);
    } catch (IOException ioe) {
        if (log.shouldLog(Log.WARN))
            log.warn("Error writing the DHT File", ioe);
    } finally {
        if (out != null)
            out.close();
    }
    if (log.shouldLog(Log.INFO))
        log.info("Stored " + count + " nodes to " + file);
}
Also used : Log(net.i2p.util.Log) OutputStreamWriter(java.io.OutputStreamWriter) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

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