Search in sources :

Example 31 with I2PSession

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

the class BWLimits method getBWLimits.

public static int[] getBWLimits(String host, int port) {
    int[] rv = null;
    try {
        I2PClient client = new I2PSimpleClient();
        Properties opts = new Properties();
        opts.put(I2PClient.PROP_TCP_HOST, host);
        opts.put(I2PClient.PROP_TCP_PORT, "" + port);
        I2PSession session = client.createSession(null, opts);
        session.connect();
        rv = session.bandwidthLimits();
        session.destroySession();
    } catch (I2PSessionException ise) {
    }
    return rv;
}
Also used : I2PSimpleClient(net.i2p.client.I2PSimpleClient) I2PSession(net.i2p.client.I2PSession) I2PSessionException(net.i2p.client.I2PSessionException) I2PClient(net.i2p.client.I2PClient) Properties(java.util.Properties)

Example 32 with I2PSession

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

the class LookupDest method lookupHash.

/* Might be useful but not in the context of urls due to upper/lower case */
/**
 **
 *    static Destination lookupBase64Hash(I2PAppContext ctx, String key) {
 *        byte[] h = Base64.decode(key);
 *        if (h == null)
 *            return null;
 *        return lookupHash(ctx, h);
 *    }
 ***
 */
/**
 * @param h 32 byte hash
 */
static Destination lookupHash(I2PAppContext ctx, byte[] h) throws I2PSessionException {
    Hash key = Hash.create(h);
    Destination rv = null;
    I2PClient client = new I2PSimpleClient();
    Properties opts = new Properties();
    if (!ctx.isRouterContext()) {
        String s = ctx.getProperty(I2PClient.PROP_TCP_HOST);
        if (s != null)
            opts.put(I2PClient.PROP_TCP_HOST, s);
        s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
        if (s != null)
            opts.put(I2PClient.PROP_TCP_PORT, s);
        s = ctx.getProperty(PROP_ENABLE_SSL);
        if (s != null)
            opts.put(PROP_ENABLE_SSL, s);
        s = ctx.getProperty(PROP_USER);
        if (s != null)
            opts.put(PROP_USER, s);
        s = ctx.getProperty(PROP_PW);
        if (s != null)
            opts.put(PROP_PW, s);
    }
    I2PSession session = null;
    try {
        session = client.createSession(null, opts);
        session.connect();
        rv = session.lookupDest(key, DEFAULT_TIMEOUT);
    } finally {
        if (session != null)
            session.destroySession();
    }
    return rv;
}
Also used : Destination(net.i2p.data.Destination) I2PSimpleClient(net.i2p.client.I2PSimpleClient) I2PSession(net.i2p.client.I2PSession) I2PClient(net.i2p.client.I2PClient) Hash(net.i2p.data.Hash) Properties(java.util.Properties)

Example 33 with I2PSession

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

the class ElGamal2048_DSA1024 method generateEncryptionKeyPair.

@Override
public KeyPair generateEncryptionKeyPair() throws KeyException {
    I2PSession i2pSession = createI2PSession();
    net.i2p.data.PublicKey i2pPublicKey = i2pSession.getMyDestination().getPublicKey();
    net.i2p.data.PrivateKey i2pPrivateKey = i2pSession.getDecryptionKey();
    PublicKey publicKey = new ElGamalPublicKey(i2pPublicKey);
    PrivateKey privateKey = new ElGamalPrivateKey(i2pPrivateKey);
    return new KeyPair(publicKey, privateKey);
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PublicKey(java.security.PublicKey) I2PSession(net.i2p.client.I2PSession)

Example 34 with I2PSession

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

the class ElGamal2048_DSA1024 method generateSigningKeyPair.

@Override
public KeyPair generateSigningKeyPair() throws KeyException {
    I2PSession i2pSession = createI2PSession();
    net.i2p.data.SigningPublicKey i2pPublicKey = i2pSession.getMyDestination().getSigningPublicKey();
    net.i2p.data.SigningPrivateKey i2pPrivateKey = i2pSession.getPrivateKey();
    PublicKey publicKey = new DSAPublicKey(i2pPublicKey);
    PrivateKey privateKey = new DSAPrivateKey(i2pPrivateKey);
    return new KeyPair(publicKey, privateKey);
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) PublicKey(java.security.PublicKey) I2PSession(net.i2p.client.I2PSession)

Example 35 with I2PSession

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

the class ElGamal2048_DSA1024 method createI2PSession.

private I2PSession createI2PSession() throws KeyException {
    try {
        I2PClient i2pClient = I2PClientFactory.createClient();
        ByteArrayOutputStream arrayStream = new ByteArrayOutputStream();
        i2pClient.createDestination(arrayStream);
        byte[] destinationArray = arrayStream.toByteArray();
        I2PSession i2pSession = i2pClient.createSession(new ByteArrayInputStream(destinationArray), null);
        return i2pSession;
    } catch (Exception e) {
        throw new KeyException("Can't generate I2P destination.", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PClient(net.i2p.client.I2PClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyException(java.security.KeyException) DataFormatException(net.i2p.data.DataFormatException) GeneralSecurityException(java.security.GeneralSecurityException) KeyException(java.security.KeyException)

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