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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations