/** * Pull the default context, creating a new one if necessary, else using * the first one created. * * Warning - do not save the returned value, or the value of any methods below, * in a static field, or you will get the old context if a new router is * started in the same JVM after the first is shut down, * e.g. on Android. */ public static I2PAppContext getGlobalContext() { // skip the global lock - _gAC must be volatile // http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html I2PAppContext rv = _globalAppContext; if (rv != null) return rv; synchronized (I2PAppContext.class) { if (_globalAppContext == null) { _globalAppContext = new I2PAppContext(false, null); } } return _globalAppContext; }
public void setUp() { _context = new I2PAppContext(); }
/** * Outputs to stdout for dieharder: * <code> * java -cp build/i2p.jar net.i2p.util.FortunaRandomSource | dieharder -a -g 200 * </code> */ public static void main(String args[]) { try { java.util.Properties props = new java.util.Properties(); props.setProperty("prng.buffers", "12"); I2PAppContext ctx = new I2PAppContext(props); RandomSource rand = ctx.random(); byte[] buf = new byte[65536]; while (true) { rand.nextBytes(buf); System.out.write(buf); } } catch (IOException e) { e.printStackTrace(); } } }
private RunStandalone(String args[]) throws Exception { Properties p = new Properties(); if (APP_CONFIG_FILE.exists()) { try { DataHelper.loadProps(p, APP_CONFIG_FILE); } catch (IOException ioe) {} } _context = new I2PAppContext(p); File base = _context.getBaseDir(); File xml = new File(base, "jetty-i2psnark.xml"); _jettyStart = new JettyStart(_context, null, new String[] { xml.getAbsolutePath() } ); if (args.length > 1) { _port = Integer.parseInt(args[1]); } if (args.length > 0) { _host = args[0]; } }
/** @since 0.9.26 */ public static void test(String[] args) { Properties ctxProps = new Properties(); String PROP_FORCE = "i2p.naming.blockfile.writeInAppContext"; ctxProps.setProperty(PROP_FORCE, "true"); I2PAppContext ctx = new I2PAppContext(ctxProps); NamingService ns = getNamingService("hosts.txt"); File published = new File("test-published.txt"); Log log = new Log(new File("test-log.txt")); SubscriptionList subscriptions = new SubscriptionList("test-sub.txt"); update(ns, published, subscriptions, log); ctx.logManager().flush(); }
@Before public void setUp() throws Exception { _context = new I2PAppContext(); }
public static void main(String args[]) { runTest(new I2PAppContext()); System.out.println("Running as MD5"); Properties props = new Properties(); //props.setProperty("i2p.fakeHMAC", "true"); props.setProperty("i2p.HMACMD5", "true"); runTest(new I2PAppContext(props)); } private static void runTest(I2PAppContext ctx) {
public static void main(String args[]) { if (args.length < 3) { System.err.println("Usage: TestSwarm samHost samPort myDestFile [peerDestFile ]*"); return; } I2PAppContext ctx = new I2PAppContext(); String files[] = new String[args.length - 3]; System.arraycopy(args, 3, files, 0, files.length); TestSwarm swarm = new TestSwarm(ctx, args[0], args[1], args[2], files); swarm.startup(); }
Properties props = new Properties(); props.setProperty(PROP_ADVANCED, "true"); I2PAppContext ctx = new I2PAppContext(props); UPnP cp = new UPnP(ctx); org.cybergarage.upnp.UPnP.setEnable(org.cybergarage.upnp.UPnP.USE_ONLY_IPV4_ADDR);
if (args.length > 0 && args[0].equals("force")) ctxProps.setProperty(PROP_FORCE, "true"); I2PAppContext ctx = new I2PAppContext(ctxProps); BlockfileNamingService bns = new BlockfileNamingService(ctx); Properties sprops = new Properties();
new I2PAppContext(props); ok = signCLI(stype, ctype, ftype, a.get(0), a.get(1), a.get(2), a.get(3), a.get(4), "", kspass); } else if ("bulksign".equals(cmd)) { Properties props = new Properties(); props.setProperty("prng.bufferSize", "16384"); new I2PAppContext(props); ok = bulkSignCLI(stype, ctype, a.get(0), a.get(1), a.get(2), a.get(3), kspass); } else if ("verifysig".equals(cmd)) { Properties props = new Properties(); props.setProperty("prng.bufferSize", "16384"); new I2PAppContext(props); ok = genKeysCLI(stype, a.get(0), a.get(1), crlfile, a.get(2), kspass); } else if ("extract".equals(cmd)) {
_defaultContext = new I2PAppContext(buildRouterProps(0)); _defaultContext.clock().setOffset(0);
@SuppressWarnings("deprecation") public void testLong(){ I2PAppContext ctx = new I2PAppContext(); SessionKey key = ctx.keyGenerator().generateSessionKey(); byte iv[] = new byte[16]; RandomSource.getInstance().nextBytes(iv); byte lbuf[] = new byte[1024]; RandomSource.getInstance().nextBytes(lbuf); byte le[] = ctx.aes().safeEncrypt(lbuf, key, iv, 2048); byte ld[] = ctx.aes().safeDecrypt(le, key, iv); assertTrue(DataHelper.eq(ld, lbuf)); }
public void testShort(){ I2PAppContext ctx = new I2PAppContext(); SessionKey key = ctx.keyGenerator().generateSessionKey(); byte iv[] = new byte[16]; RandomSource.getInstance().nextBytes(iv); byte sbuf[] = new byte[16]; RandomSource.getInstance().nextBytes(sbuf); byte se[] = new byte[16]; ctx.aes().encrypt(sbuf, 0, se, 0, key, iv, sbuf.length); byte sd[] = new byte[16]; ctx.aes().decrypt(se, 0, sd, 0, key, iv, se.length); assertTrue(DataHelper.eq(sd, sbuf)); } }
public void testDHSessionKeyBuilder(){ I2PAppContext ctx = new I2PAppContext(); for (int i = 0; i < 5; i++) { DHSessionKeyBuilder builder1 = new DHSessionKeyBuilder(); DHSessionKeyBuilder builder2 = new DHSessionKeyBuilder(); BigInteger pub1 = builder1.getMyPublicValue(); BigInteger pub2 = builder2.getMyPublicValue(); try { builder2.setPeerPublicValue(pub1); builder1.setPeerPublicValue(pub2); } catch (DHSessionKeyBuilder.InvalidPublicParameterException ippe) { assertTrue(ippe.getMessage(), true); } SessionKey key1 = builder1.getSessionKey(); SessionKey key2 = builder2.getSessionKey(); assertEquals(key1, key2); byte iv[] = new byte[16]; RandomSource.getInstance().nextBytes(iv); String origVal = "1234567890123456"; // 16 bytes max using AESEngine byte enc[] = new byte[16]; byte dec[] = new byte[16]; ctx.aes().encrypt(DataHelper.getASCII(origVal), 0, enc, 0, key1, iv, 16); ctx.aes().decrypt(enc, 0, dec, 0, key2, iv, 16); String tranVal = new String(dec); assertEquals(origVal, tranVal); } } }