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) {} } } }
/** * Can't be used for writing * @since 0.9.26 */ public PrivateKeyFile(InputStream in) throws I2PSessionException { this("/dev/null"); I2PSession s = this.client.createSession(in, new Properties()); this.dest = s.getMyDestination(); this.privKey = s.getDecryptionKey(); this.signingPrivKey = s.getPrivateKey(); }
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; }
opts.setProperty(I2PClient.PROP_TCP_PORT, Integer.toString(i2cpPort)); I2PSession session = client.createSession(myPrivateKeyStream, opts); if (connect) session.connect();
public void testI2PClient() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); _client.createDestination(out); _client.createSession(new ByteArrayInputStream(out.toByteArray()), null); } }
private void init(boolean verify, InputStream privData, String privkeyname, Logging l) { this.l = l; // create i2pclient I2PClient client = I2PClientFactory.createClient(); try { // FIXME this may not pick up non-default I2CP host/port settings from tunnel _session = client.createSession(privData, getTunnel().getClientOptions()); connected(_session); } catch(I2PSessionException exc) { throw new RuntimeException("failed to create session", exc); } // Setup the source. Always expect repliable datagrams, optionally verify _i2pSource = new I2PSource(_session, verify, false); // Setup the sink. Always send raw datagrams. _i2pSink = new I2PSinkAnywhere(_session, true); }
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; }
/** * Create a new SAM message-based session handler * * @param destStream Input stream containing the destination keys * @param props Properties to setup the I2P session * @throws I2PSessionException */ public SAMMessageSessionHandler(InputStream destStream, Properties props) throws I2PSessionException { if (_log.shouldLog(Log.DEBUG)) _log.debug("Instantiating new SAM message-based session handler"); I2PClient client = I2PClientFactory.createClient(); if (!props.containsKey("inbound.nickname") && !props.containsKey("outbound.nickname")) { props.setProperty("inbound.nickname", "SAM UDP Client"); props.setProperty("outbound.nickname", "SAM UDP Client"); } _session = client.createSession(destStream, props); if (_log.shouldLog(Log.DEBUG)) _log.debug("Connecting I2P session..."); _session.connect(); if (_log.shouldLog(Log.DEBUG)) _log.debug("I2P session connected"); _session.addMuxedSessionListener(this, listenProtocol, listenPort); }
session = client.createSession(null, opts); session.connect(); rv = session.lookupDest(key, DEFAULT_TIMEOUT);
ByteArrayInputStream in = new ByteArrayInputStream(key); _session = client.createSession(in, tunnel.getClientOptions()); connected(_session); } catch(Exception exc) {
I2PSession session = null; try { session = client.createSession(null, opts); session.connect(); d = session.lookupDest(name);
I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); DSAEngine dsaEng = DSAEngine.getInstance();
public void testDatagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); I2PDatagramMaker dm = new I2PDatagramMaker(session); byte[] dg = dm.makeI2PDatagram(DataHelper.getASCII("What's the deal with 42?")); I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(dg); byte[] x = dd.getPayload(); assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); x = dd.extractPayload(); assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); assertEquals(d, dd.getSender()); assertEquals(d, dd.extractSender()); }
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); } }
private Ping() throws Exception { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { i2pSession.destroySession(); System.out.println("Finished"); } catch (I2PSessionException e) { e.printStackTrace(); } } }); // initialize i2pSession I2PClient i2pClient = I2PClientFactory.createClient(); ByteArrayOutputStream arrayStream = new ByteArrayOutputStream(); i2pClient.createDestination(arrayStream); byte[] destinationArray = arrayStream.toByteArray(); i2pSession = i2pClient.createSession(new ByteArrayInputStream(destinationArray), null); i2pSession.connect(); }
opts.setProperty(I2PClient.PROP_TCP_PORT, Integer.toString(i2cpPort)); I2PSession session = client.createSession(myPrivateKeyStream, opts); if (connect) session.connect();
private CommunicationPacket decryptDataPacket(RelayRequest request, Destination destination) throws I2PSessionException, DataFormatException, MalformedPacketException { for (String destKey: destKeys) if (destKey.startsWith(destination.toBase64())) { I2PSession i2pSession = i2pClient.createSession(new ByteArrayInputStream(Base64.decode(destKey)), null); return request.getStoredPacket(i2pSession); } fail("No matching I2PSession for I2P destination in packet: <" + destination.toBase64() + ">"); return null; }
I2PSession i2pSession = i2pClient.createSession(new ByteArrayInputStream(Base64.decode(localBase64DestKeys)), null);