Changeset bf42cc1


Ignore:
Timestamp:
Oct 25, 2017 10:00:12 AM (3 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
20a58a2
Parents:
e44fb48f (diff), 9ae9abd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

propagate from branch 'i2p.i2p.str4d.ui' (head 396ff40bde06334be0bd26509dc5e31b75f2c2f5)

to branch 'i2p.i2p' (head 9ba94555553a2d114c9c44022b0ff6e228972d33)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    re44fb48f rbf42cc1  
    7474   - Sync theme to console theme by default, override if user sets theme
    7575     (unless universal themeing is enabled)
     76
     772017-10-24 zzz
     78 * NTCP: Convert configured NTCP hostname to IP address
     79   before publishing (proposal #141)
     80
     812017-10-21 zzz
     82 * UDP: Reduce log level on IP change (ticket #2053)
    7683
    77842017-10-11 zzz
  • router/java/src/net/i2p/router/RouterVersion.java

    re44fb48f rbf42cc1  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 5;
     21    public final static long BUILD = 6;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    re44fb48f rbf42cc1  
    2424import java.util.Vector;
    2525import java.util.concurrent.ConcurrentHashMap;
     26
     27import org.apache.http.conn.util.InetAddressUtils;
    2628
    2729import net.i2p.crypto.SigType;
     
    8991    private long _lastInboundIPv6;
    9092
     93    // note: SSU version is i2np.udp.host, not hostname
    9194    public final static String PROP_I2NP_NTCP_HOSTNAME = "i2np.ntcp.hostname";
    9295    public final static String PROP_I2NP_NTCP_PORT = "i2np.ntcp.port";
     
    243246                    if (addr != null) {
    244247                        con = new NTCPConnection(_context, this, ident, addr);
    245                         if (_log.shouldLog(Log.DEBUG))
    246                             _log.debug("Send on a new con: " + con + " at " + addr + " for " + ih);
     248                        //if (_log.shouldLog(Log.DEBUG))
     249                        //    _log.debug("Send on a new con: " + con + " at " + addr + " for " + ih);
    247250                        // Note that outbound conns go in the map BEFORE establishment
    248251                        _conByIdent.put(ih, con);
     
    370373        boolean established = isEstablished(toAddress.getIdentity());
    371374        if (established) { // should we check the queue size?  nah, if its valid, use it
    372             if (_log.shouldLog(Log.DEBUG))
    373                 _log.debug("fast bid when trying to send to " + peer + " as its already established");
     375            //if (_log.shouldLog(Log.DEBUG))
     376            //    _log.debug("fast bid when trying to send to " + peer + " as its already established");
    374377            return _fastBid;
    375378        }
     
    402405
    403406        if (!allowConnection()) {
    404             if (_log.shouldLog(Log.WARN))
    405                 _log.warn("no bid when trying to send to " + peer + ", max connection limit reached");
     407            //if (_log.shouldLog(Log.WARN))
     408            //    _log.warn("no bid when trying to send to " + peer + ", max connection limit reached");
    406409            return _transientFail;
    407410        }
     
    410413        //    return null; // dont talk to yourself
    411414
    412         if (_log.shouldLog(Log.DEBUG))
    413             _log.debug("slow bid when trying to send to " + peer);
     415        //if (_log.shouldLog(Log.DEBUG))
     416        //    _log.debug("slow bid when trying to send to " + peer);
    414417        if (haveCapacity()) {
    415418            if (addr.getCost() > DEFAULT_COST)
     
    600603            skews.addElement(Long.valueOf(_lastBadSkew));
    601604
    602         if (_log.shouldLog(Log.DEBUG))
    603             _log.debug("NTCP transport returning " + skews.size() + " peer clock skews.");
     605        //if (_log.shouldLog(Log.DEBUG))
     606        //    _log.debug("NTCP transport returning " + skews.size() + " peer clock skews.");
    604607        return skews;
    605608    }
     
    809812
    810813    /**
    811      *  @return configured host or null. Must be one of our local interfaces.
     814     *  @return configured host (as an IP String) or null. Must be one of our local interfaces.
    812815     *  @since IPv6 moved from bindAddress()
    813816     */
     
    917920     *  Generally returns null
    918921     *  caller must synch on this
     922     *  Note this is only called from startListening()
     923     *
     924     *  TODO return a list of one or more
     925     *  TODO only returns non-null if port is configured
    919926     */
    920927    private RouterAddress configureLocalAddress() {
     
    941948     * which should be rare.
    942949     * Otherwise, notifyReplaceAddress() below takes care of it.
    943      * Note this is called both from above and from NTCPTransport.startListening()
     950     * Note this is only called from startListening() via configureLocalAddress()
     951     *
     952     * TODO return a list of one or more
     953     * TODO unlike in UDP rebuildExternalAddress(), this only runs once, at startup,
     954     * so we won't pick up IP changes.
     955     * TODO only returns non-null if port is configured
    944956     *
    945957     * @since IPv6 moved from CSFI
    946958     */
    947959    private RouterAddress createNTCPAddress() {
    948         // Fixme doesn't check PROP_BIND_INTERFACE
    949         String name = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
    950         if ( (name == null) || (name.trim().length() <= 0) || ("null".equals(name)) )
    951             return null;
    952960        int p = _context.getProperty(PROP_I2NP_NTCP_PORT, -1);
    953961        if (p <= 0 || p >= 64*1024)
    954962            return null;
     963
     964        String name = getConfiguredIP();
     965        if (name == null)
     966            return null;
     967
    955968        OrderedProperties props = new OrderedProperties();
    956969        props.setProperty(RouterAddress.PROP_HOST, name);
     
    959972        RouterAddress addr = new RouterAddress(STYLE, props, cost);
    960973        return addr;
     974    }
     975
     976    /**
     977     * Return a single configured IP (as a String) or null if not configured or invalid.
     978     * Resolves a hostname to an IP.
     979     * Called at startup via createNTCPAddress() and later via externalAddressReceived()
     980     *
     981     * TODO return a list of one or more
     982     *
     983     * @since 0.9.32
     984     */
     985    private String getConfiguredIP() {
     986        // Fixme doesn't check PROP_BIND_INTERFACE
     987        String name = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
     988        if ( (name == null) || (name.trim().length() <= 0) || ("null".equals(name)) )
     989            return null;
     990        String[] hosts = DataHelper.split(name, "[,; \r\n\t]");
     991        List<String> ipstrings = new ArrayList<String>(2);
     992        // we only take one each of v4 and v6
     993        boolean v4 = false;
     994        boolean v6 = false;
     995        // prevent adding a type if disabled
     996        TransportUtil.IPv6Config cfg = getIPv6Config();
     997        if (cfg == IPV6_DISABLED)
     998            v6 = true;
     999        else if (cfg == IPV6_ONLY)
     1000            v4 = true;
     1001        for (int i = 0; i < hosts.length; i++) {
     1002            String h = hosts[i];
     1003            if (h.length() <= 0)
     1004                continue;
     1005            if (InetAddressUtils.isIPv4Address(h)) {
     1006                if (v4)
     1007                    continue;
     1008                v4 = true;
     1009                ipstrings.add(h);
     1010            } else if (InetAddressUtils.isIPv6Address(h)) {
     1011                if (v6)
     1012                    continue;
     1013                v6 = true;
     1014                ipstrings.add(h);
     1015            } else {
     1016                int valid = 0;
     1017                List<byte[]> ips = Addresses.getIPs(h);
     1018                if (ips != null) {
     1019                    for (byte[] ip : ips) {
     1020                        if (!isValid(ip)) {
     1021                            if (_log.shouldWarn())
     1022                                _log.warn("skipping invalid " + Addresses.toString(ip) + " for " + h);
     1023                            continue;
     1024                        }
     1025                        if ((v4 && ip.length == 4) || (v6 && ip.length == 16)) {
     1026                            if (_log.shouldWarn())
     1027                                _log.warn("skipping additional " + Addresses.toString(ip) + " for " + h);
     1028                            continue;
     1029                        }
     1030                        if (ip.length == 4)
     1031                            v4 = true;
     1032                        else if (ip.length == 16)
     1033                            v6 = true;
     1034                        valid++;
     1035                        if (_log.shouldDebug())
     1036                            _log.debug("adding " + Addresses.toString(ip) + " for " + h);
     1037                        ipstrings.add(Addresses.toString(ip));
     1038                    }
     1039                }
     1040                if (valid == 0)
     1041                    _log.error("No valid IPs for configured hostname " + h);
     1042                continue;
     1043            }
     1044        }
     1045
     1046        if (ipstrings.isEmpty()) {
     1047            _log.error("No valid IPs for configuration: " + name);
     1048            return null;
     1049        }
     1050
     1051        // get first IPv4, if none then first IPv6
     1052        // TODO return both
     1053        String ip = null;
     1054        for (String ips : ipstrings) {
     1055            if (ips.contains(".")) {
     1056                ip = ips;
     1057                break;
     1058            }
     1059        }
     1060        if (ip == null)
     1061            ip = ipstrings.get(0);
     1062        return ip;
    9611063    }
    9621064   
     
    11061208        String ohost = newProps.getProperty(RouterAddress.PROP_HOST);
    11071209        String enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP, "true").toLowerCase(Locale.US);
    1108         String name = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
     1210        String name = getConfiguredIP();
    11091211        // hostname config trumps auto config
    11101212        if (name != null && name.length() > 0)
Note: See TracChangeset for help on using the changeset viewer.