Search in sources :

Example 16 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class PingIT method createSession.

private I2PSession createSession() throws Exception {
    I2PClient client = I2PClientFactory.createClient();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    client.createDestination(baos);
    I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties());
    sess.connect();
    return sess;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PClient(net.i2p.client.I2PClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 17 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class StreamingITBase method createSession.

protected I2PSession createSession() throws Exception {
    I2PClient client = I2PClientFactory.createClient();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    client.createDestination(baos);
    Properties p = getProperties();
    I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
    sess.connect();
    return sess;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PClient(net.i2p.client.I2PClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 18 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class PrivateKeyFile method open.

public I2PSession open(Properties opts) throws I2PSessionException, IOException {
    InputStream in = null;
    try {
        in = new BufferedInputStream(new FileInputStream(this.file));
        I2PSession s = this.client.createSession(in, opts);
        return s;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ioe) {
            }
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) I2PSession(net.i2p.client.I2PSession) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 19 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class PrivateKeyFile method getDestination.

/**
 *  If the destination is not set, read it in from the file.
 *  Also sets the local privKey and signingPrivKey.
 */
public Destination getDestination() throws I2PSessionException, IOException, DataFormatException {
    if (dest == null) {
        I2PSession s = open();
        if (s != null) {
            this.dest = new VerifiedDestination(s.getMyDestination());
            this.privKey = s.getDecryptionKey();
            this.signingPrivKey = s.getPrivateKey();
        }
    }
    return this.dest;
}
Also used : I2PSession(net.i2p.client.I2PSession)

Example 20 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class I2PSocketManagerFull method destroySocketManager.

/**
 * Destroy the socket manager, freeing all the associated resources.  This
 * method will block until all the managed sockets are closed.
 *
 * CANNOT be restarted.
 */
public void destroySocketManager() {
    if (!_isDestroyed.compareAndSet(false, true)) {
        // shouldn't happen, log a stack trace to find out why it happened
        _log.logCloseLoop("I2PSocketManager", getName());
        return;
    }
    _connectionManager.setAllowIncomingConnections(false);
    _connectionManager.shutdown();
    if (!_subsessions.isEmpty()) {
        for (I2PSession sess : _subsessions) {
            removeSubsession(sess);
        }
    }
    // yes, since the old lib did (and SAM wants it to, and i dont know why not)
    if ((_session != null) && (!_session.isClosed())) {
        try {
            _session.destroySession();
        } catch (I2PSessionException ise) {
            _log.warn("Unable to destroy the session", ise);
        }
        PcapWriter pcap = null;
        synchronized (_pcapInitLock) {
            pcap = pcapWriter;
        }
        if (pcap != null)
            pcap.flush();
    }
}
Also used : I2PSession(net.i2p.client.I2PSession) I2PSessionException(net.i2p.client.I2PSessionException)

Aggregations

I2PSession (net.i2p.client.I2PSession)37 Properties (java.util.Properties)13 I2PSessionException (net.i2p.client.I2PSessionException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Destination (net.i2p.data.Destination)10 I2PClient (net.i2p.client.I2PClient)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 IOException (java.io.IOException)8 I2PException (net.i2p.I2PException)5 Hash (net.i2p.data.Hash)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 I2PSimpleClient (net.i2p.client.I2PSimpleClient)3 I2PSocket (net.i2p.client.streaming.I2PSocket)3 DataFormatException (net.i2p.data.DataFormatException)3 Log (net.i2p.util.Log)3 InterruptedIOException (java.io.InterruptedIOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 GeneralSecurityException (java.security.GeneralSecurityException)2