/** * @param line part after the #! * @throws IllegalArgumentException on dup key and other errors */ private static OrderedProperties parseProps(String line) throws IllegalArgumentException { line = line.trim(); OrderedProperties rv = new OrderedProperties(); String[] entries = DataHelper.split(line, "#"); for (int i = 0; i < entries.length; i++) { String kv = entries[i]; int eq = kv.indexOf('='); if (eq <= 0 || eq == kv.length() - 1) throw new IllegalArgumentException("No value: \"" + kv + '"'); String k = kv.substring(0, eq); String v = kv.substring(eq + 1); Object old = rv.setProperty(k, v); if (old != null) throw new IllegalArgumentException("Dup key: " + k); } return rv; }
/** * Write as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] * This works whether constructed with name and dest, or just properties. * Does not include newline. * Must have been constructed with non-null properties. */ public void writeRemove(Writer out) throws IOException { if (props == null) throw new IllegalStateException(); if (name != null && dest != null) { props.setProperty(PROP_NAME, name); props.setProperty(PROP_DEST, dest); } writeProps(out); if (name != null && dest != null) { props.remove(PROP_NAME); props.remove(PROP_DEST); } }
/** * Sign as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] * Must have been constructed with non-null properties. */ public void signRemove(SigningPrivateKey spk) { if (props == null) throw new IllegalStateException(); if (props.containsKey(PROP_SIG)) throw new IllegalStateException(); props.setProperty(PROP_NAME, name); props.setProperty(PROP_DEST, dest); if (!props.containsKey(PROP_DATE)) props.setProperty(PROP_DATE, Long.toString(System.currentTimeMillis() / 1000)); StringWriter buf = new StringWriter(1024); try { writeProps(buf); } catch (IOException ioe) { throw new IllegalStateException(ioe); } props.remove(PROP_NAME); props.remove(PROP_DEST); Signature s = DSAEngine.getInstance().sign(DataHelper.getUTF8(buf.toString()), spk); if (s == null) throw new IllegalArgumentException("sig failed"); props.setProperty(PROP_SIG, s.toBase64()); }
/** * @param sigprop The signature property to set */ private void signIt(SigningPrivateKey spk, String sigprop) { if (props == null) throw new IllegalStateException(); if (props.containsKey(sigprop)) throw new IllegalStateException(); if (!props.containsKey(PROP_DATE)) props.setProperty(PROP_DATE, Long.toString(System.currentTimeMillis() / 1000)); StringWriter buf = new StringWriter(1024); buf.append(name); buf.append(KV_SEPARATOR); buf.append(dest); try { writeProps(buf); } catch (IOException ioe) { throw new IllegalStateException(ioe); } Signature s = DSAEngine.getInstance().sign(DataHelper.getUTF8(buf.toString()), spk); if (s == null) throw new IllegalArgumentException("sig failed"); props.setProperty(sigprop, s.toBase64()); }
private static RouterAddress createTCPAddress(int num) { OrderedProperties props = new OrderedProperties(); String name = "blah.random.host.org"; String port = "" + (1024+num); props.setProperty("host", name); props.setProperty("port", port); RouterAddress addr = new RouterAddress("TCP", props, 10); return addr; }
public DataStructure createDataStructure() throws DataFormatException { //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970 OrderedProperties options = new OrderedProperties(); options.setProperty("hostname", "localhost"); options.setProperty("portnum", "1234"); RouterAddress addr = new RouterAddress("Blah", options, 42); return addr; } public DataStructure createStructureToRead() { return new RouterAddress(); }
/** * This only creates an address if the hostname AND port are set in router.config, * which should be rare. * Otherwise, notifyReplaceAddress() below takes care of it. * Note this is only called from startListening() via configureLocalAddress() * * TODO return a list of one or more * TODO unlike in UDP rebuildExternalAddress(), this only runs once, at startup, * so we won't pick up IP changes. * TODO only returns non-null if port is configured * * @since IPv6 moved from CSFI */ private RouterAddress createNTCPAddress() { int p = _context.getProperty(PROP_I2NP_NTCP_PORT, -1); if (p <= 0 || p >= 64*1024) return null; String name = getConfiguredIP(); if (name == null) return null; OrderedProperties props = new OrderedProperties(); props.setProperty(RouterAddress.PROP_HOST, name); props.setProperty(RouterAddress.PROP_PORT, Integer.toString(p)); addNTCP2Options(props); int cost = getDefaultCost(false); RouterAddress addr = new RouterAddress(STYLE, props, cost); return addr; }
@SuppressWarnings("deprecation") @Test public void testSetOptionsAgain(){ OrderedProperties options = new OrderedProperties(); options.setProperty("hostname", "localhost"); options.setProperty("portnum", "1234"); RouterAddress addr = new RouterAddress("Blah", options, 42); options.setProperty("portnum", "2345"); exception.expect(IllegalStateException.class); addr.setOptions(options); }
@Test public void testToString(){ //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970 OrderedProperties options = new OrderedProperties(); options.setProperty("hostname", "localhost"); options.setProperty("portnum", "1234"); RouterAddress addr = new RouterAddress("Blah", options, 42); String ret = addr.toString(); //assertEquals("[RouterAddress: \n\tTransportStyle: Blah\n\tCost: 42\n\tExpiration: Fri Jan 02 00:00:00 UTC 1970\n\tOptions: #: 2\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret); assertEquals("[RouterAddress: \n\tType: Blah\n\tCost: 42\n\tOptions (2):\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret); } }
_log.warn("Binding only to " + bindToAddr); OrderedProperties props = new OrderedProperties(); props.setProperty(RouterAddress.PROP_HOST, bindTo); props.setProperty(RouterAddress.PROP_PORT, Integer.toString(port)); addNTCP2Options(props); int cost = getDefaultCost(false);
boolean introducersRequired = (!isIPv6) && introducersRequired(); if (!introducersRequired && allowDirectUDP() && port > 0 && host != null) { options.setProperty(UDPAddress.PROP_PORT, String.valueOf(port)); options.setProperty(UDPAddress.PROP_HOST, host); directIncluded = true; } else { options.setProperty(UDPAddress.PROP_CAPACITY, CAP_TESTING); else options.setProperty(UDPAddress.PROP_CAPACITY, CAP_TESTING_INTRO); options.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu)); options.setProperty(UDPAddress.PROP_INTRO_KEY, _introKey.toBase64()); } else { OrderedProperties localOpts = new OrderedProperties(); localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(port)); localOpts.setProperty(UDPAddress.PROP_HOST, host); local = new RouterAddress(STYLE, localOpts, cost); localOpts.setProperty(UDPAddress.PROP_PORT, String.valueOf(port)); localOpts.setProperty(UDPAddress.PROP_HOST, host); RouterAddress local = new RouterAddress(STYLE, localOpts, DEFAULT_COST); replaceCurrentExternalAddress(local, isIPv6);
@Test public void testNullEquals(){ //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970 OrderedProperties options = new OrderedProperties(); options.setProperty("hostname", "localhost"); options.setProperty("portnum", "1234"); RouterAddress addr = new RouterAddress("Blah", options, 42); assertFalse(addr.equals(null)); assertFalse(addr.equals("")); }
for (InetAddress ia : addrs) { OrderedProperties props = new OrderedProperties(); props.setProperty(RouterAddress.PROP_HOST, ia.getHostAddress()); props.setProperty(RouterAddress.PROP_PORT, Integer.toString(port)); addNTCP2Options(props); int cost = getDefaultCost(ia instanceof Inet6Address);
newProps.setProperty(RouterAddress.PROP_PORT, nport); changed = true; return; if (ohost == null || ! ohost.equalsIgnoreCase(nhost)) { newProps.setProperty(RouterAddress.PROP_HOST, nhost); changed = true; newProps.setProperty(RouterAddress.PROP_HOST, name); changed = true; } else if (ohost == null || ohost.length() <= 0) {