Search in sources :

Example 96 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class Snark method x_startTorrent.

private void x_startTorrent() {
    boolean ok = _util.connect();
    if (!ok)
        fatal("Unable to connect to I2P");
    if (coordinator == null) {
        I2PServerSocket serversocket = _util.getServerSocket();
        if (serversocket == null)
            fatal("Unable to listen for I2P connections");
        else {
            Destination d = serversocket.getManager().getSession().getMyDestination();
            if (_log.shouldLog(Log.INFO))
                _log.info("Listening on I2P destination " + d.toBase64() + " / " + d.calculateHash().toBase64());
        }
        if (_log.shouldLog(Log.INFO))
            _log.info("Starting PeerCoordinator, ConnectionAcceptor, and TrackerClient");
        activity = "Collecting pieces";
        coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
        coordinator.setUploaded(savedUploaded);
        if (_peerCoordinatorSet != null) {
            // multitorrent
            _peerCoordinatorSet.add(coordinator);
        } else {
            // single torrent
            acceptor = new ConnectionAcceptor(_util, new PeerAcceptor(coordinator));
        }
        // TODO pass saved closest DHT nodes to the tracker? or direct to the coordinator?
        trackerclient = new TrackerClient(_util, meta, additionalTrackerURL, coordinator, this);
    }
    // ensure acceptor is running when in multitorrent
    if (_peerCoordinatorSet != null && acceptor != null) {
        acceptor.startAccepting();
    }
    stopped = false;
    if (coordinator.halted()) {
        coordinator.restart();
        if (_peerCoordinatorSet != null)
            _peerCoordinatorSet.add(coordinator);
    }
    if (!trackerclient.started()) {
        trackerclient.start();
    } else if (trackerclient.halted()) {
        if (storage != null) {
            try {
                storage.reopen();
            } catch (IOException ioe) {
                try {
                    storage.close();
                } catch (IOException ioee) {
                    ioee.printStackTrace();
                }
                fatal("Could not reopen storage", ioe);
            }
        }
        trackerclient.start();
    } else {
        if (_log.shouldLog(Log.INFO))
            _log.info("NOT starting TrackerClient???");
    }
}
Also used : Destination(net.i2p.data.Destination) IOException(java.io.IOException) I2PServerSocket(net.i2p.client.streaming.I2PServerSocket)

Example 97 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class KRPC method receivePong.

/**
 *  If node info was previously created with the dummy NID,
 *  replace it with the received NID.
 */
private void receivePong(NodeInfo nInfo, byte[] nid) {
    if (nInfo.getNID().equals(FAKE_NID)) {
        NodeInfo newInfo = new NodeInfo(new NID(nid), nInfo.getHash(), nInfo.getPort());
        Destination dest = nInfo.getDestination();
        if (dest != null)
            newInfo.setDestination(dest);
        heardFrom(newInfo);
    }
    if (_log.shouldLog(Log.INFO))
        _log.info("Rcvd pong from: " + nInfo);
}
Also used : Destination(net.i2p.data.Destination)

Example 98 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class SAMv2StreamSession method connect.

/**
 * Connect the SAM STREAM session to the specified Destination
 *
 * @param id Unique id for the connection
 * @param dest Base64-encoded Destination to connect to
 * @param props Options to be used for connection
 *
 * @throws DataFormatException if the destination is not valid
 * @throws SAMInvalidDirectionException if trying to connect through a
 *                                      receive-only session
 * @return true if the communication with the SAM client is ok
 */
@Override
public boolean connect(int id, String dest, Properties props) throws DataFormatException, SAMInvalidDirectionException {
    if (!canCreate) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Trying to create an outgoing connection using a receive-only session");
        throw new SAMInvalidDirectionException("Trying to create connections through a receive-only session");
    }
    if (checkSocketHandlerId(id)) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("The specified id (" + id + ") is already in use");
        return false;
    }
    Destination d = SAMUtils.getDest(dest);
    I2PSocketOptions opts = socketMgr.buildOptions(props);
    if (props.getProperty(I2PSocketOptions.PROP_CONNECT_TIMEOUT) == null)
        opts.setConnectTimeout(60 * 1000);
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Connecting new I2PSocket...");
    // non-blocking connection (SAMv2)
    StreamConnector connector = new StreamConnector(id, d, opts);
    I2PAppThread connectThread = new I2PAppThread(connector, "StreamConnector" + id);
    connectThread.start();
    return true;
}
Also used : Destination(net.i2p.data.Destination) I2PSocketOptions(net.i2p.client.streaming.I2PSocketOptions) I2PAppThread(net.i2p.util.I2PAppThread)

Example 99 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class ConfigTunnelsHelper method getForm.

public String getForm() {
    StringBuilder buf = new StringBuilder(1024);
    // HTML: <input> cannot be inside a <table>
    buf.append("<input type=\"hidden\" name=\"pool.0\" value=\"exploratory\" >\n");
    int cur = 1;
    Set<Destination> clients = _context.clientManager().listClients();
    for (Destination dest : clients) {
        buf.append("<input type=\"hidden\" name=\"pool.").append(cur).append("\" value=\"");
        buf.append(dest.calculateHash().toBase64()).append("\" >\n");
        cur++;
    }
    buf.append("<table id=\"tunnelconfig\">\n");
    TunnelPoolSettings exploratoryIn = _context.tunnelManager().getInboundSettings();
    TunnelPoolSettings exploratoryOut = _context.tunnelManager().getOutboundSettings();
    renderForm(buf, 0, "exploratory", _t("Exploratory tunnels"), exploratoryIn, exploratoryOut);
    cur = 1;
    for (Destination dest : clients) {
        TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(dest.calculateHash());
        TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(dest.calculateHash());
        if (in == null || in.getAliasOf() != null || out == null || out.getAliasOf() != null)
            continue;
        String name = in.getDestinationNickname();
        if (name == null)
            name = out.getDestinationNickname();
        if (name == null)
            name = dest.calculateHash().toBase64().substring(0, 6);
        String prefix = dest.calculateHash().toBase64().substring(0, 4);
        renderForm(buf, cur, prefix, _t("Client tunnels for {0}", DataHelper.escapeHTML(_t(name))), in, out);
        cur++;
    }
    buf.append("</table>\n");
    return buf.toString();
}
Also used : Destination(net.i2p.data.Destination) TunnelPoolSettings(net.i2p.router.TunnelPoolSettings)

Example 100 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class ConfigKeyringHelper method render.

/**
 *  @since 0.9.33 moved from PersistentKeyRing
 */
private void render(StringBuilder buf, boolean local) {
    buf.append("\n<table class=\"configtable\"><tr><th align=\"left\">").append(_t("Destination")).append("<th align=\"left\">").append(_t("Name")).append("<th align=\"left\">").append(_t("Encryption Key")).append("</tr>");
    for (Map.Entry<Hash, SessionKey> e : _context.keyRing().entrySet()) {
        Hash h = e.getKey();
        if (local != _context.clientManager().isLocal(h))
            continue;
        buf.append("\n<tr><td>");
        buf.append(h.toBase32());
        buf.append("</td><td>");
        Destination dest = _context.netDb().lookupDestinationLocally(h);
        if (dest != null && local) {
            TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(h);
            if (in != null && in.getDestinationNickname() != null)
                buf.append(in.getDestinationNickname());
        } else {
            String host = _context.namingService().reverseLookup(h);
            if (host != null)
                buf.append(host);
        }
        buf.append("</td><td>");
        SessionKey sk = e.getValue();
        buf.append(sk.toBase64());
        buf.append("</td>\n");
    }
    buf.append("</table>\n");
}
Also used : Destination(net.i2p.data.Destination) SessionKey(net.i2p.data.SessionKey) TunnelPoolSettings(net.i2p.router.TunnelPoolSettings) Hash(net.i2p.data.Hash) Map(java.util.Map)

Aggregations

Destination (net.i2p.data.Destination)149 IOException (java.io.IOException)46 DataFormatException (net.i2p.data.DataFormatException)33 Properties (java.util.Properties)29 I2PException (net.i2p.I2PException)26 Hash (net.i2p.data.Hash)18 ArrayList (java.util.ArrayList)13 File (java.io.File)12 I2PSessionException (net.i2p.client.I2PSessionException)12 SigType (net.i2p.crypto.SigType)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 I2PSession (net.i2p.client.I2PSession)10 I2PSocket (net.i2p.client.streaming.I2PSocket)10 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 I2PClient (net.i2p.client.I2PClient)7 I2PSocketOptions (net.i2p.client.streaming.I2PSocketOptions)7 Test (org.junit.Test)6