public void testI2PClient() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); _client.createDestination(out); _client.createSession(new ByteArrayInputStream(out.toByteArray()), null); } }
/** * Generate a random destination key. * Caller must close streams. Fails silently. * * @param priv Stream used to write the destination and private keys * @param pub Stream used to write the destination (may be null) * @param sigType what signature type * @since 0.9.14 */ public static void genRandomKey(OutputStream priv, OutputStream pub, SigType sigType) { //_log.debug("Generating random keys..."); try { I2PClient c = I2PClientFactory.createClient(); Destination d = c.createDestination(priv, sigType); priv.flush(); if (pub != null) { d.writeBytes(pub); pub.flush(); } } catch (I2PException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
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) {} } } }
/** * Create with the specified signature type if nonexistent. * * Also reads in the file to get the privKey and signingPrivKey, * which aren't available from I2PClient. * * @since 0.9.26 */ public Destination createIfAbsent(SigType type) throws I2PException, IOException, DataFormatException { if(!this.file.exists()) { OutputStream out = null; try { out = new SecureFileOutputStream(this.file); if (this.client != null) this.client.createDestination(out, type); else write(); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) {} } } } return getDestination(); }
/** * 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(); }
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; }
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try { client.createDestination(keyStream, getSigType(opts)); } catch (I2PException e) { throw new I2PSessionException("Error creating keys", e);
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; }
l.log("Unsupported sig type " + st); client.createDestination(out, stype); key = out.toByteArray(); } catch(Exception exc) { ByteArrayInputStream in = new ByteArrayInputStream(key); _session = client.createSession(in, tunnel.getClientOptions()); connected(_session); } catch(Exception exc) {
/** * Create a new destination, storing the destination and its private keys where * instructed. * Does NOT support non-default sig types. * Deprecated - only used by CLI * * @param writeTo location to store the destination and private keys * @param pubDest location to store the destination * @param l logger to send messages to */ private static void makeKey(OutputStream writeTo, OutputStream pubDest, Logging l) { try { l.log("Generating new keys..."); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(writeTo); l.log("New destination: " + d.toBase32()); writeTo.flush(); writeTo.close(); writePubKey(d, pubDest, l); } catch (I2PException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }
opts.setProperty(I2PClient.PROP_TCP_PORT, Integer.toString(i2cpPort)); I2PSession session = client.createSession(myPrivateKeyStream, opts); if (connect) session.connect();
public void testBadagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); DSAEngine dsaEng = DSAEngine.getInstance();
/** * Create a socket manager using a brand new destination connected to the * I2CP router on the given machine reachable through the given port. * * Blocks for a long time while the router builds tunnels. * The nonblocking createDisconnectedManager() is preferred. * * @param i2cpHost I2CP host null to use default, ignored if in router context * @param i2cpPort I2CP port <= 0 to use default, ignored if in router context * @param opts Streaming and I2CP options, may be null * @return the newly created socket manager, or null if there were errors */ public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts) { I2PClient client = I2PClientFactory.createClient(); ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try { client.createDestination(keyStream, getSigType(opts)); ByteArrayInputStream in = new ByteArrayInputStream(keyStream.toByteArray()); return createManager(in, i2cpHost, i2cpPort, opts); } catch (IOException ioe) { getLog().error("Error creating the destination for socket manager", ioe); return null; } catch (I2PException ie) { getLog().error("Error creating the destination for socket manager", ie); return 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); }
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()); }
@Test public void testCreateDiscMgr_customDest() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Destination dest = I2PClientFactory.createClient().createDestination(baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); I2PSocketManagerFull mgr = (I2PSocketManagerFull) I2PSocketManagerFactory.createDisconnectedManager(bais, null, 0, null); assertThat(mgr, is(not(nullValue()))); assertThat(mgr.getName(), is("manager")); assertThat(mgr.getSession().getMyDestination(), is(equalTo(dest))); }
/** * 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); }
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); } }
@Test public void testToString() throws Exception { Destination dest = I2PClientFactory.createClient().createDestination(new ByteArrayOutputStream()); I2PSocketAddress addr = new I2PSocketAddress(dest, 1234); assertThat(addr.toString(), is(equalTo(dest.calculateHash().toString() + ":1234"))); }
session = client.createSession(null, opts); session.connect(); rv = session.lookupDest(key, DEFAULT_TIMEOUT);