Search in sources :

Example 26 with OrderedProperties

use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.

the class SnarkManager method getConfig.

/**
 *  The config for a torrent
 *  @param ih 20-byte infohash
 *  @return non-null, possibly empty
 *  @since 0.9.15
 */
private Properties getConfig(byte[] ih) {
    Properties rv = new OrderedProperties();
    File conf = configFile(_configDir, ih);
    synchronized (_configLock) {
        // one lock for all
        try {
            DataHelper.loadProps(rv, conf);
        } catch (IOException ioe) {
        }
    }
    return rv;
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties) IOException(java.io.IOException) OrderedProperties(net.i2p.util.OrderedProperties) Properties(java.util.Properties) File(java.io.File)

Example 27 with OrderedProperties

use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.

the class I2PTunnel method runClientOptions.

/**
 * Configure the extra I2CP options to use in any subsequent I2CP sessions.
 * Generic options used for clients and servers
 * Usage: "clientoptions[ key=value]*" .
 *
 * Sets the event "clientoptions_onResult" = "ok" after completion.
 *
 * Deprecated To be made private, use setClientOptions().
 * This does NOT update a running TunnelTask.
 *
 * @param args each args[i] is a key=value pair to add to the options
 * @param l logger to receive events and output
 */
public void runClientOptions(String[] args, Logging l) {
    if (args != null && args.length > 0) {
        int i = 0;
        if (args[0].equals("-a")) {
            i++;
        } else if (args[0].equals("-c")) {
            _clientOptions.clear();
            l.log("Client options cleared");
            return;
        } else if (args[0].equals("-x")) {
            i++;
            for (; i < args.length; i++) {
                if (_clientOptions.remove(args[i]) != null)
                    l.log("Removed " + args[i]);
            }
            return;
        } else {
            _clientOptions.clear();
        }
        for (; i < args.length; i++) {
            int index = args[i].indexOf('=');
            if (index <= 0)
                continue;
            String key = args[i].substring(0, index);
            String val = args[i].substring(index + 1);
            _clientOptions.setProperty(key, val);
        }
    } else {
        l.log("Usage:\n" + "  clientoptions                   // show help and list current options\n" + "  clientoptions [key=value ]*     // sets current options\n" + "  clientoptions -a [key=value ]*  // adds to current options\n" + "  clientoptions -c                // clears current options\n" + "  clientoptions -x [key ]*        // removes listed options\n" + "\nCurrent options:");
        Properties p = new OrderedProperties();
        p.putAll(_clientOptions);
        for (Map.Entry<Object, Object> e : p.entrySet()) {
            l.log("  [" + e.getKey() + "] = [" + e.getValue() + ']');
        }
    }
    notifyEvent("clientoptions_onResult", "ok");
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties) OrderedProperties(net.i2p.util.OrderedProperties) Properties(java.util.Properties) Map(java.util.Map)

Example 28 with OrderedProperties

use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.

the class SessionConfig method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder("[SessionConfig: ");
    buf.append("\n\tDestination: ").append(getDestination());
    buf.append("\n\tSignature: ").append(getSignature());
    buf.append("\n\tCreation Date: ").append(getCreationDate());
    buf.append("\n\tOptions: #: ").append(_options.size());
    Properties sorted = new OrderedProperties();
    sorted.putAll(_options);
    for (Map.Entry<Object, Object> e : sorted.entrySet()) {
        String key = (String) e.getKey();
        String val = (String) e.getValue();
        buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]");
    }
    buf.append("]");
    return buf.toString();
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties) Properties(java.util.Properties) OrderedProperties(net.i2p.util.OrderedProperties) Map(java.util.Map)

Example 29 with OrderedProperties

use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.

the class NTCPTransport method externalAddressReceived.

/**
 *  UDP changed addresses, tell NTCP and restart.
 *  Port may be set to indicate requested port even if ip is null.
 *
 *  @param ip previously validated; may be null to indicate IPv4 failure or port info only
 *  @since IPv6 moved from CSFI.notifyReplaceAddress()
 */
private synchronized void externalAddressReceived(byte[] ip, boolean isIPv6, int port) {
    // FIXME just take first address for now
    // FIXME if SSU set to hostname, NTCP will be set to IP
    RouterAddress oldAddr = getCurrentAddress(isIPv6);
    if (_log.shouldLog(Log.INFO))
        _log.info("Changing NTCP Address? was " + oldAddr);
    OrderedProperties newProps = new OrderedProperties();
    int cost;
    if (oldAddr == null) {
        cost = getDefaultCost(isIPv6);
    } else {
        cost = oldAddr.getCost();
        newProps.putAll(oldAddr.getOptionsMap());
    }
    RouterAddress newAddr = new RouterAddress(STYLE, newProps, cost);
    boolean changed = false;
    // Auto Port Setting
    // old behavior (<= 0.7.3): auto-port defaults to false, and true trumps explicit setting
    // new behavior (>= 0.7.4): auto-port defaults to true, but explicit setting trumps auto
    // TODO rewrite this to operate on ints instead of strings
    String oport = newProps.getProperty(RouterAddress.PROP_PORT);
    String nport = null;
    String cport = _context.getProperty(PROP_I2NP_NTCP_PORT);
    if (cport != null && cport.length() > 0) {
        nport = cport;
    } else if (_context.getBooleanPropertyDefaultTrue(PROP_I2NP_NTCP_AUTO_PORT)) {
        // it probably isn't mapping UDP and TCP the same.
        if (port > 0)
            // should always be true
            nport = Integer.toString(port);
    }
    if (_log.shouldLog(Log.INFO))
        _log.info("old port: " + oport + " config: " + cport + " new: " + nport);
    // if (oport == null || ! oport.equals(nport)) {
    if (oport == null && nport != null && nport.length() > 0) {
        newProps.setProperty(RouterAddress.PROP_PORT, nport);
        changed = true;
    }
    // Auto IP Setting
    // old behavior (<= 0.7.3): auto-ip defaults to false, and trumps configured hostname,
    // and ignores reachability status - leading to
    // "firewalled with inbound TCP enabled" warnings.
    // new behavior (>= 0.7.4): auto-ip defaults to true, and explicit setting trumps auto,
    // and only takes effect if reachability is OK.
    // And new "always" setting ignores reachability status, like
    // "true" was in 0.7.3
    String ohost = newProps.getProperty(RouterAddress.PROP_HOST);
    String enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP, "true").toLowerCase(Locale.US);
    String name = getConfiguredIP();
    // hostname config trumps auto config
    if (name != null && name.length() > 0)
        enabled = "false";
    // assume SSU is happy if the address is non-null
    // TODO is this sufficient?
    boolean ssuOK = ip != null;
    if (_log.shouldLog(Log.INFO))
        _log.info("old: " + ohost + " config: " + name + " auto: " + enabled + " ssuOK? " + ssuOK);
    if (enabled.equals("always") || (Boolean.parseBoolean(enabled) && ssuOK)) {
        if (!ssuOK) {
            if (_log.shouldLog(Log.WARN))
                _log.warn("null address with always config", new Exception());
            return;
        }
        // ip non-null
        String nhost = Addresses.toString(ip);
        if (_log.shouldLog(Log.INFO))
            _log.info("old: " + ohost + " config: " + name + " new: " + nhost);
        if (nhost == null || nhost.length() <= 0)
            return;
        if (ohost == null || !ohost.equalsIgnoreCase(nhost)) {
            newProps.setProperty(RouterAddress.PROP_HOST, nhost);
            changed = true;
        }
    } else if (enabled.equals("false") && name != null && name.length() > 0 && !name.equals(ohost)) {
        // otherwise createNTCPAddress() would have done it already
        if (_log.shouldLog(Log.INFO))
            _log.info("old host: " + ohost + " config: " + name + " new: " + name);
        newProps.setProperty(RouterAddress.PROP_HOST, name);
        changed = true;
    } else if (ohost == null || ohost.length() <= 0) {
        return;
    } else if (Boolean.parseBoolean(enabled) && !ssuOK) {
        // we are still firewalled (SW firewall, bad UPnP indication, etc.)
        if (_log.shouldLog(Log.INFO))
            _log.info("old host: " + ohost + " config: " + name + " new: null");
        newAddr = null;
        changed = true;
    }
    if (!changed) {
        if (oldAddr != null) {
            // change cost only?
            int oldCost = oldAddr.getCost();
            int newCost = getDefaultCost(ohost != null && ohost.contains(":"));
            if (ADJUST_COST && !haveCapacity())
                newCost += CONGESTION_COST_ADJUSTMENT;
            if (newCost != oldCost) {
                newAddr.setCost(newCost);
                if (_log.shouldLog(Log.WARN))
                    _log.warn("Changing NTCP cost from " + oldCost + " to " + newCost);
            // fall thru and republish
            } else {
                _log.info("No change to NTCP Address");
                return;
            }
        } else {
            _log.info("No change to NTCP Address");
            return;
        }
    }
    // stopListening stops the pumper, readers, and writers, so required even if
    // oldAddr == null since startListening starts them all again
    // 
    // really need to fix this so that we can change or create an inbound address
    // without tearing down everything
    // Especially on disabling the address, we shouldn't tear everything down.
    // 
    // if (_log.shouldLog(Log.WARN))
    // _log.warn("Halting NTCP to change address");
    // stopListening();
    // Wait for NTCP Pumper to stop so we don't end up with two...
    // while (isAlive()) {
    // try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
    // }
    restartListening(newAddr, isIPv6);
    if (_log.shouldLog(Log.WARN))
        _log.warn("Updating NTCP Address (ipv6? " + isIPv6 + ") with " + newAddr);
    return;
}
Also used : RouterAddress(net.i2p.data.router.RouterAddress) OrderedProperties(net.i2p.util.OrderedProperties) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 30 with OrderedProperties

use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.

the class RouterGenerator method createTCPAddress.

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;
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties) RouterAddress(net.i2p.data.router.RouterAddress)

Aggregations

OrderedProperties (net.i2p.util.OrderedProperties)34 Properties (java.util.Properties)20 IOException (java.io.IOException)16 File (java.io.File)12 Map (java.util.Map)8 RouterAddress (net.i2p.data.router.RouterAddress)6 UnknownHostException (java.net.UnknownHostException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 InetAddress (java.net.InetAddress)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 StructureTest (net.i2p.data.StructureTest)3 Test (org.junit.Test)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 Socket (java.net.Socket)2 GeneralSecurityException (java.security.GeneralSecurityException)2 I2PSessionException (net.i2p.client.I2PSessionException)2