Search in sources :

Example 1 with I2PSocketManager

use of net.i2p.client.streaming.I2PSocketManager in project i2p.i2p by i2p.

the class FetchAndAdd method get.

/**
 *  Copied from I2PSnarkUtil so we may add ourselves as a status listener
 *  @return null on failure
 */
private File get() {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Fetching [" + _url + "]");
    File out = null;
    try {
        out = SecureFile.createTempFile("torrentFile", null, _mgr.util().getTempDir());
    } catch (IOException ioe) {
        _log.error("temp file error", ioe);
        _mgr.addMessage("Temp file error: " + ioe);
        if (out != null)
            out.delete();
        return null;
    }
    out.deleteOnExit();
    if (!_mgr.util().connected()) {
        _mgr.addMessage(_t("Opening the I2P tunnel"));
        if (!_mgr.util().connect())
            return null;
    }
    I2PSocketManager manager = _mgr.util().getSocketManager();
    if (manager == null)
        return null;
    _eepGet = new I2PSocketEepGet(_ctx, manager, RETRIES, out.getAbsolutePath(), _url);
    _eepGet.addStatusListener(this);
    _eepGet.addHeader("User-Agent", I2PSnarkUtil.EEPGET_USER_AGENT);
    if (_eepGet.fetch()) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Fetch successful [" + _url + "]: size=" + out.length());
        return out;
    } else {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Fetch failed [" + _url + ']');
        out.delete();
        return null;
    }
}
Also used : I2PSocketManager(net.i2p.client.streaming.I2PSocketManager) I2PSocketEepGet(net.i2p.client.streaming.I2PSocketEepGet) IOException(java.io.IOException) SecureFile(net.i2p.util.SecureFile) File(java.io.File)

Example 2 with I2PSocketManager

use of net.i2p.client.streaming.I2PSocketManager in project i2p.i2p by i2p.

the class I2PTunnelServer method createManager.

/**
 * @throws IllegalArgumentException if the I2CP configuration is b0rked so
 *                                  badly that we cant create a socketManager
 * @since 0.9.8
 */
private I2PSocketManager createManager(InputStream privData) {
    Properties props = new Properties();
    props.putAll(getTunnel().getClientOptions());
    int portNum = 7654;
    if (getTunnel().port != null) {
        try {
            portNum = Integer.parseInt(getTunnel().port);
        } catch (NumberFormatException nfe) {
            _log.error("Invalid port specified [" + getTunnel().port + "], reverting to " + portNum);
        }
    }
    try {
        I2PSocketManager rv = I2PSocketManagerFactory.createDisconnectedManager(privData, getTunnel().host, portNum, props);
        rv.setName("I2PTunnel Server");
        getTunnel().addSession(rv.getSession());
        String alt = props.getProperty(PROP_ALT_PKF);
        if (alt != null)
            addSubsession(rv, alt);
        return rv;
    } catch (I2PSessionException ise) {
        throw new IllegalArgumentException("Can't create socket manager", ise);
    } finally {
        try {
            privData.close();
        } catch (IOException ioe) {
        }
    }
}
Also used : I2PSocketManager(net.i2p.client.streaming.I2PSocketManager) I2PSessionException(net.i2p.client.I2PSessionException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 3 with I2PSocketManager

use of net.i2p.client.streaming.I2PSocketManager in project i2p.i2p by i2p.

the class I2PSnarkUtil method disconnect.

/**
 * Destroy the destination itself
 */
public synchronized void disconnect() {
    if (_dht != null) {
        _dht.stop();
        _dht = null;
    }
    _startedTime = 0;
    I2PSocketManager mgr = _manager;
    // FIXME this can cause race NPEs elsewhere
    _manager = null;
    _banlist.clear();
    if (mgr != null) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Disconnecting from I2P", new Exception("I did it"));
        mgr.destroySocketManager();
    }
    // this will delete a .torrent file d/l in progress so don't do that...
    FileUtil.rmdir(_tmpDir, false);
    // in case the user will d/l a .torrent file next...
    _tmpDir.mkdirs();
}
Also used : I2PSocketManager(net.i2p.client.streaming.I2PSocketManager) URISyntaxException(java.net.URISyntaxException) DataFormatException(net.i2p.data.DataFormatException) IOException(java.io.IOException) I2PSessionException(net.i2p.client.I2PSessionException) I2PException(net.i2p.I2PException)

Example 4 with I2PSocketManager

use of net.i2p.client.streaming.I2PSocketManager in project i2p.i2p by i2p.

the class IdleChecker method setTunnels.

/**
 *  Set in / out / in backup / out backup tunnel counts
 */
private void setTunnels(String i, String o, String ib, String ob) {
    _consec = 0;
    I2PSocketManager mgr = _util.getSocketManager();
    if (mgr != null) {
        I2PSession sess = mgr.getSession();
        if (sess != null) {
            if (_log.shouldLog(Log.INFO))
                _log.info("New tunnel settings " + i + " / " + o + " / " + ib + " / " + ob);
            Properties newProps = new Properties();
            newProps.setProperty("inbound.quantity", i);
            newProps.setProperty("outbound.quantity", o);
            newProps.setProperty("inbound.backupQuantity", ib);
            newProps.setProperty("outbound.backupQuantity", ob);
            sess.updateOptions(newProps);
            _lastIn = i;
            _lastOut = o;
        }
    }
}
Also used : I2PSocketManager(net.i2p.client.streaming.I2PSocketManager) I2PSession(net.i2p.client.I2PSession) Properties(java.util.Properties)

Example 5 with I2PSocketManager

use of net.i2p.client.streaming.I2PSocketManager 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)

Aggregations

I2PSocketManager (net.i2p.client.streaming.I2PSocketManager)7 IOException (java.io.IOException)5 Properties (java.util.Properties)4 I2PSessionException (net.i2p.client.I2PSessionException)3 I2PException (net.i2p.I2PException)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 URISyntaxException (java.net.URISyntaxException)1 I2PSession (net.i2p.client.I2PSession)1 I2PSocket (net.i2p.client.streaming.I2PSocket)1 I2PSocketEepGet (net.i2p.client.streaming.I2PSocketEepGet)1 DataFormatException (net.i2p.data.DataFormatException)1 Destination (net.i2p.data.Destination)1 Hash (net.i2p.data.Hash)1 Log (net.i2p.util.Log)1 SecureFile (net.i2p.util.SecureFile)1