Search in sources :

Example 1 with SigAlgo

use of net.i2p.crypto.SigAlgo in project i2p.i2p by i2p.

the class I2PSocketManagerFull method connect.

/**
 * Create a new connected socket. Blocks until the socket is created,
 * unless the connectDelay option (i2p.streaming.connectDelay) is
 * set and greater than zero. If so this will return immediately,
 * and the client may quickly write initial data to the socket and
 * this data will be bundled in the SYN packet.
 *
 * @param peer Destination to connect to
 * @param options I2P socket options to be used for connecting, may be null
 *
 * @return I2PSocket if successful
 * @throws NoRouteToHostException if the peer is not found or not reachable
 * @throws I2PException if there is some other I2P-related problem
 */
public I2PSocket connect(Destination peer, I2PSocketOptions options) throws I2PException, NoRouteToHostException {
    if (peer == null)
        throw new NullPointerException();
    if (options == null)
        options = _defaultOptions;
    ConnectionOptions opts = null;
    if (options instanceof ConnectionOptions)
        opts = new ConnectionOptions((ConnectionOptions) options);
    else
        opts = new ConnectionOptions(options);
    if (_log.shouldLog(Log.INFO))
        _log.info("Connecting to " + peer.calculateHash().toBase64().substring(0, 6) + " with options: " + opts);
    // pick the subsession here
    I2PSession session = _session;
    if (!_subsessions.isEmpty()) {
        updateUserDsaList();
        Hash h = peer.calculateHash();
        SigAlgo myAlgo = session.getMyDestination().getSigType().getBaseAlgorithm();
        if ((myAlgo == SigAlgo.EC && _ecUnsupported.contains(h)) || (myAlgo == SigAlgo.EdDSA && _edUnsupported.contains(h)) || (!_userDsaOnly.isEmpty() && _userDsaOnly.contains(h))) {
            // FIXME just taking the first one for now
            for (I2PSession sess : _subsessions) {
                if (sess.getMyDestination().getSigType() == SigType.DSA_SHA1) {
                    session = sess;
                    break;
                }
            }
        }
    }
    verifySession(session);
    // the following blocks unless connect delay > 0
    Connection con = _connectionManager.connect(peer, opts, session);
    if (con == null)
        throw new TooManyStreamsException("Too many streams, max " + _defaultOptions.getMaxConns());
    I2PSocketFull socket = new I2PSocketFull(con, _context);
    con.setSocket(socket);
    if (con.getConnectionError() != null) {
        con.disconnect(false);
        throw new NoRouteToHostException(con.getConnectionError());
    }
    return socket;
}
Also used : SigAlgo(net.i2p.crypto.SigAlgo) I2PSession(net.i2p.client.I2PSession) Hash(net.i2p.data.Hash) ConvertToHash(net.i2p.util.ConvertToHash) NoRouteToHostException(java.net.NoRouteToHostException)

Aggregations

NoRouteToHostException (java.net.NoRouteToHostException)1 I2PSession (net.i2p.client.I2PSession)1 SigAlgo (net.i2p.crypto.SigAlgo)1 Hash (net.i2p.data.Hash)1 ConvertToHash (net.i2p.util.ConvertToHash)1