Search in sources :

Example 16 with I2PSocketOptions

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

the class I2PTunnelClientBase method getDefaultOptions.

/**
 * Create the default options (using the default timeout, etc).
 * Warning, this does not make a copy of I2PTunnel's client options,
 * it modifies them directly.
 */
protected I2PSocketOptions getDefaultOptions() {
    Properties defaultOpts = getTunnel().getClientOptions();
    I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
    if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT))
        opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);
    return opts;
}
Also used : I2PSocketOptions(net.i2p.client.streaming.I2PSocketOptions) Properties(java.util.Properties)

Example 17 with I2PSocketOptions

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

the class I2PTunnelHTTPClient method getDefaultOptions.

/**
 * Create the default options (using the default timeout, etc).
 * Warning, this does not make a copy of I2PTunnel's client options,
 * it modifies them directly.
 * Do not use overrides for per-socket options.
 */
@Override
protected I2PSocketOptions getDefaultOptions(Properties overrides) {
    Properties defaultOpts = getTunnel().getClientOptions();
    defaultOpts.putAll(overrides);
    if (!defaultOpts.contains(I2PSocketOptions.PROP_READ_TIMEOUT)) {
        defaultOpts.setProperty(I2PSocketOptions.PROP_READ_TIMEOUT, "" + DEFAULT_READ_TIMEOUT);
    }
    if (!defaultOpts.contains("i2p.streaming.inactivityTimeout")) {
        defaultOpts.setProperty("i2p.streaming.inactivityTimeout", "" + DEFAULT_READ_TIMEOUT);
    }
    // delayed start
    verifySocketManager();
    I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
    if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT)) {
        opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);
    }
    return opts;
}
Also used : I2PSocketOptions(net.i2p.client.streaming.I2PSocketOptions) Properties(java.util.Properties)

Example 18 with I2PSocketOptions

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

Aggregations

I2PSocketOptions (net.i2p.client.streaming.I2PSocketOptions)18 Properties (java.util.Properties)10 Destination (net.i2p.data.Destination)9 I2PSocket (net.i2p.client.streaming.I2PSocket)8 IOException (java.io.IOException)6 I2PException (net.i2p.I2PException)6 Outproxy (net.i2p.app.Outproxy)4 DataOutputStream (java.io.DataOutputStream)3 OutputStream (java.io.OutputStream)3 SOCKSException (net.i2p.socks.SOCKSException)3 InputStream (java.io.InputStream)2 Socket (java.net.Socket)2 List (java.util.List)2 ClientApp (net.i2p.app.ClientApp)2 ClientAppManager (net.i2p.app.ClientAppManager)2 DataFormatException (net.i2p.data.DataFormatException)2 I2PAppThread (net.i2p.util.I2PAppThread)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 InterruptedIOException (java.io.InterruptedIOException)1