private static void runApp(String args[]) { if ("encodestring".equalsIgnoreCase(args[0])) { System.out.println(encode(args[1].getBytes())); return; } InputStream in = System.in; OutputStream out = System.out; try { if (args.length >= 3) { out = new FileOutputStream(args[2]); } if (args.length >= 2) { in = new FileInputStream(args[1]); } if ("encode".equalsIgnoreCase(args[0])) { encode(in, out); return; } if ("decode".equalsIgnoreCase(args[0])) { decode(in, out); return; } } catch (IOException ioe) { ioe.printStackTrace(System.err); } finally { try { in.close(); } catch (IOException e) { } try { out.close(); } catch (IOException e) { } } }
/** Base64 Hash or Hash.i2p or name.i2p using naming service */ Destination getDestination(String ip) { if (ip == null) return null; if (ip.endsWith(".i2p")) { if (ip.length() < 520) { // key + ".i2p" if (_manager != null && ip.length() == BASE32_HASH_LENGTH + 8 && ip.endsWith(".b32.i2p")) { // Use existing I2PSession for b32 lookups if we have it // This is much more efficient than using the naming service I2PSession sess = _manager.getSession(); if (sess != null) { byte[] b = Base32.decode(ip.substring(0, BASE32_HASH_LENGTH)); if (b != null) { // Hash h = new Hash(b); Hash h = Hash.create(b); if (_log.shouldLog(Log.INFO)) _log.info("Using existing session for lookup of " + ip); try { return sess.lookupDest(h, 15 * 1000); } catch (I2PSessionException ise) { } } } } if (_log.shouldLog(Log.INFO)) _log.info("Using naming service for lookup of " + ip); return _context.namingService().lookup(ip); } if (_log.shouldLog(Log.INFO)) _log.info("Creating Destination for " + ip); try { return new Destination(ip.substring(0, ip.length() - 4)); // sans .i2p } catch (DataFormatException dfe) { return null; } } else { if (_log.shouldLog(Log.INFO)) _log.info("Creating Destination for " + ip); try { return new Destination(ip); } catch (DataFormatException dfe) { return null; } } }