public PrivateKeyFile(File file) { this(file, I2PClientFactory.createClient()); }
public PrivateKeyFile(String file) { this(new File(file), I2PClientFactory.createClient()); }
public void setUp(){ _client = I2PClientFactory.createClient(); }
I2PClient client = I2PClientFactory.createClient(); if (opts == null) opts = new Properties();
/** * 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(); } }
int i2cpPort, Properties opts) throws I2PSessionException { if (myPrivateKeyStream == null) { I2PClient client = I2PClientFactory.createClient(); ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024); try {
/** * 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(); } }
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); }
/** * 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); }
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 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; } }
@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))); }
I2PClient client = I2PClientFactory.createClient(); byte[] key; try {
@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"))); }
I2PClient client = I2PClientFactory.createClient(); File keyFile = getPrivateKeyFile(); if (keyFile == null) {
d = I2PClientFactory.createClient().createDestination(prikey); wlock(); try {
I2PClient client = I2PClientFactory.createClient();
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);
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); } }