Changeset 11579b9 for router


Ignore:
Timestamp:
Nov 20, 2016 6:08:40 AM (4 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
97af7d0
Parents:
01cfb7b (diff), b0bba18 (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:

merge of '8bf9850eb3fe4fcfb63053838a188969b7ba9c5b'

and 'a40ea9b5f7545281195f00a80e31ae879197e76b'

Location:
router/java
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • router/java/build.xml

    r01cfb7b r11579b9  
    7979                <attribute name="Main-Class" value="net.i2p.router.CommandLine" />
    8080                <attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
     81                <attribute name="X-Compile-Source-JDK" value="${javac.version}" />
     82                <attribute name="X-Compile-Target-JDK" value="${javac.version}" />
    8183            </manifest>
    8284        </jar>
  • router/java/src/net/i2p/router/Blocklist.java

    r01cfb7b r11579b9  
    249249    *   44-byte Base64 router hash
    250250    *
     251    * Acceptable formats (IPV6 only):
     252    *   comment:IPv6 (must replace : with ; e.g. abcd;1234;0;12;;ff)
     253    *   IPv6 (must replace : with ; e.g. abcd;1234;0;12;;ff)
     254    *
    251255    * No whitespace allowed after the last ':'.
    252256    *
     
    291295                }
    292296                byte[] ip1 = e.ip1;
    293                 byte[] ip2 = e.ip2;
    294 
    295                 store(ip1, ip2, count++);
    296                 ipcount += 1 + toInt(ip2) - toInt(ip1); // includes dups, oh well
     297                if (ip1.length == 4) {
     298                    byte[] ip2 = e.ip2;
     299                    store(ip1, ip2, count++);
     300                    ipcount += 1 + toInt(ip2) - toInt(ip1); // includes dups, oh well
     301                } else {
     302                    // IPv6
     303                    add(ip1);
     304                }
    297305            }
    298306        } catch (IOException ioe) {
     
    394402        int mask = -1;
    395403        String comment = null;
    396         int index = buf.indexOf("#");
     404        int index = buf.indexOf('#');
    397405        if (index == 0)
    398406            return null;  // comment
    399         index = buf.lastIndexOf(":");
     407        index = buf.lastIndexOf(':');
    400408        if (index >= 0) {
    401409            comment = buf.substring(0, index);
    402410            start1 = index + 1;
    403411        }
    404         if (end1 - start1 == 44 && buf.substring(start1).indexOf(".") < 0) {
     412        if (end1 - start1 == 44 && buf.substring(start1).indexOf('.') < 0) {
    405413            byte b[] = Base64.decode(buf.substring(start1));
    406414            if (b != null)
    407415                return new Entry(comment, Hash.create(b), null, null);
    408416        }
    409         index = buf.indexOf("-", start1);
     417        index = buf.indexOf('-', start1);
    410418        if (index >= 0) {
    411419            end1 = index;
    412420            start2 = index + 1;
    413421        } else {
    414             index = buf.indexOf("/", start1);
     422            index = buf.indexOf('/', start1);
    415423            if (index >= 0) {
    416424                end1 = index;
     
    421429            return null;  // blank
    422430        try {
    423             InetAddress pi = InetAddress.getByName(buf.substring(start1, end1));
     431            String sip = buf.substring(start1, end1);
     432            // IPv6
     433            sip = sip.replace(';', ':');
     434            InetAddress pi = InetAddress.getByName(sip);
    424435            if (pi == null) return null;
    425436            ip1 = pi.getAddress();
    426             if (ip1.length != 4)
    427                 throw new UnknownHostException();
     437            //if (ip1.length != 4)
     438            //    throw new UnknownHostException();
    428439            if (start2 >= 0) {
    429440                pi = InetAddress.getByName(buf.substring(start2));
     
    463474            }
    464475        } catch (UnknownHostException uhe) {
    465             if (shouldLog && _log.shouldLog(Log.ERROR))
    466                 _log.error("Format error in the blocklist file: " + buf);
     476            if (shouldLog)
     477                _log.logAlways(Log.WARN, "Format error in the blocklist file: " + buf);
    467478            return null;
    468479        } catch (NumberFormatException nfe) {
    469             if (shouldLog && _log.shouldLog(Log.ERROR))
    470                 _log.error("Format error in the blocklist file: " + buf);
     480            if (shouldLog)
     481                _log.logAlways(Log.WARN, "Format error in the blocklist file: " + buf);
    471482            return null;
    472483        } catch (IndexOutOfBoundsException ioobe) {
    473             if (shouldLog && _log.shouldLog(Log.ERROR))
    474                 _log.error("Format error in the blocklist file: " + buf);
     484            if (shouldLog)
     485                _log.logAlways(Log.WARN, "Format error in the blocklist file: " + buf);
    475486            return null;
    476487        }
     
    744755    }
    745756
     757    /**
     758     *  IPv4 only
     759     */
    746760    private void store(byte ip1[], byte ip2[], int idx) {
    747761        _blocklist[idx] = toEntry(ip1, ip2);
     
    10361050
    10371051/****
    1038     public static void main(String args[]) {
    1039         Blocklist b = new Blocklist();
    1040         if ( (args != null) && (args.length == 1) )
    1041             b.readBlocklistFile(args[0]);
     1052    public static void main(String args[]) throws Exception {
     1053        Blocklist b = new Blocklist(new Router().getContext());
     1054        if (args != null && args.length == 1) {
     1055            File f = new File(args[0]);
     1056            b.allocate(Collections.singletonList(f));
     1057            int count = b.readBlocklistFile(f, 0);
     1058            b.merge(count);
     1059            Writer w = new java.io.OutputStreamWriter(System.out);
     1060            b.renderStatusHTML(w);
     1061        }
    10421062        System.out.println("Saved " + b._blocklistSize + " records");
    10431063        String tests[] = {"0.0.0.0", "0.0.0.1", "0.0.0.2", "0.0.0.255", "1.0.0.0",
  • router/java/src/net/i2p/router/CommandLine.java

    r01cfb7b r11579b9  
    2424        "net.i2p.router.transport.GeoIPv6",
    2525        "net.i2p.router.transport.udp.MTU",
    26         //"net.i2p.router.transport.UPnP"
     26        "net.i2p.router.transport.UPnP"
    2727    });
    2828
  • router/java/src/net/i2p/router/RouterVersion.java

    r01cfb7b r11579b9  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 6;
     21    public final static long BUILD = 9;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/client/ClientMessageEventListener.java

    r01cfb7b r11579b9  
    330330            }
    331331            if (user == null || user.length() == 0 || pw == null || pw.length() == 0) {
    332                 _log.error("I2CP auth failed");
     332                _log.logAlways(Log.WARN, "I2CP authentication failed");
    333333                _runner.disconnectClient("Authorization required, specify i2cp.username and i2cp.password in options");
    334334                _authorized = false;
     
    337337            PasswordManager mgr = new PasswordManager(_context);
    338338            if (!mgr.checkHash(PROP_AUTH, user, pw)) {
    339                 _log.error("I2CP auth failed user: " + user);
     339                _log.logAlways(Log.WARN, "I2CP authentication failed, user: " + user);
    340340                _runner.disconnectClient("Authorization failed, user = " + user);
    341341                _authorized = false;
  • router/java/src/net/i2p/router/crypto/FamilyKeyCrypto.java

    r01cfb7b r11579b9  
    1111import java.security.cert.X509Certificate;
    1212import java.security.cert.X509CRL;
     13import java.util.Collections;
    1314import java.util.HashMap;
    1415import java.util.Map;
     
    4546    private final Map<Hash, String> _verified;
    4647    private final Set<Hash> _negativeCache;
     48    private final Set<Hash> _ourFamily;
    4749    // following for verification only, otherwise null
    4850    private final String _fname;
     
    8385        if (_fname != null) {
    8486            if (_fname.contains("/") || _fname.contains("\\") ||
    85                 _fname.contains("..") || (new File(_fname)).isAbsolute())
    86                 throw new GeneralSecurityException("Illegal family name");
     87                _fname.contains("..") || (new File(_fname)).isAbsolute() ||
     88                _fname.length() <= 0)
     89                throw new GeneralSecurityException("Illegal family name: " + _fname);
    8790        }
    8891        _privkey = (_fname != null) ? initialize() : null;
     
    9093        _verified = new ConcurrentHashMap<Hash, String>(4);
    9194        _negativeCache = new ConcurrentHashSet<Hash>(4);
     95        _ourFamily = (_privkey != null) ? new ConcurrentHashSet<Hash>(4) : Collections.<Hash>emptySet();
    9296    }
    9397   
     
    146150
    147151    /**
     152     *  Do we have a valid family?
     153     *  @since 0.9.28
     154     */
     155    public boolean hasFamily() {
     156        return _pubkey != null;
     157    }
     158
     159    /**
     160     *  Get verified members of our family.
     161     *  Will not contain ourselves.
     162     *
     163     *  @return non-null, not a copy, do not modify
     164     *  @since 0.9.28
     165     */
     166    public Set<Hash> getOurFamily() {
     167        return _ourFamily;
     168    }
     169
     170    /**
     171     *  Get our family name.
     172     *
     173     *  @return name or null
     174     *  @since 0.9.28
     175     */
     176    public String getOurFamilyName() {
     177        return _fname;
     178    }
     179
     180    /**
    148181     *  Verify the family signature in a RouterInfo.
    149182     *  @return true if good sig or if no family specified at all
     
    153186        if (name == null)
    154187            return true;
     188        return verify(ri, name);
     189    }
     190
     191    /**
     192     *  Verify the family in a RouterInfo matches ours and the signature is good.
     193     *  Returns false if we don't have a family and sig, or they don't.
     194     *  Returns false for ourselves.
     195     *
     196     *  @return true if family matches with good sig
     197     *  @since 0.9.28
     198     */
     199    public boolean verifyOurFamily(RouterInfo ri) {
     200        if (_pubkey == null)
     201            return false;
     202        String name = ri.getOption(OPT_NAME);
     203        if (!_fname.equals(name))
     204            return false;
     205        Hash h = ri.getHash();
     206        if (_ourFamily.contains(h))
     207            return true;
     208        if (h.equals(_context.routerHash()))
     209            return false;
     210        boolean rv = verify(ri, name);
     211        if (rv) {
     212            _ourFamily.add(h);
     213            _log.logAlways(Log.INFO, "Found and verified member of our family (" + _fname + "): " + h);
     214        } else {
     215            if (_log.shouldWarn())
     216                _log.warn("Found spoofed member of our family (" + _fname + "): " + h);
     217        }
     218        return rv;
     219    }
     220
     221    /**
     222     *  Verify the family in a RouterInfo, name already retrieved
     223     *  @since 0.9.28
     224     */
     225    private boolean verify(RouterInfo ri, String name) {
    155226        Hash h = ri.getHash();
    156227        String ssig = ri.getOption(OPT_SIG);
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java

    r01cfb7b r11579b9  
    2020import net.i2p.router.RouterContext;
    2121import net.i2p.router.TunnelInfo;
     22import net.i2p.router.util.MaskedIPSet;
    2223import net.i2p.util.Log;
    2324
     
    4041    private MessageWrapper.WrappedMessage _wrappedMessage;
    4142    private final Set<Hash> _ignore;
     43    private final MaskedIPSet _ipSet;
    4244   
    4345    private static final int START_DELAY = 18*1000;
     
    4547    private static final int VERIFY_TIMEOUT = 20*1000;
    4648    private static final int MAX_PEERS_TO_TRY = 4;
     49    private static final int IP_CLOSE_BYTES = 3;
    4750   
    4851    /**
     
    6164        _ignore = new HashSet<Hash>(MAX_PEERS_TO_TRY);
    6265        if (sentTo != null) {
     66            _ipSet = new MaskedIPSet(ctx, sentTo, IP_CLOSE_BYTES);
    6367            _ignore.add(_sentTo);
     68        } else {
     69            _ipSet = new MaskedIPSet(4);
    6470        }
    6571        // wait some time before trying to verify the store
     
    189195                Hash peer = peers.get(0);
    190196                RouterInfo ri = _facade.lookupRouterInfoLocally(peer);
    191                 if (ri != null && StoreJob.supportsCert(ri, keyCert))
    192                     return peer;
    193                 if (_log.shouldLog(Log.INFO))
    194                     _log.info(getJobId() + ": Skipping verify w/ router that doesn't support key certs " + peer);
     197                if (ri != null && StoreJob.supportsCert(ri, keyCert)) {
     198                    Set<String> peerIPs = new MaskedIPSet(getContext(), ri, IP_CLOSE_BYTES);
     199                    if (!_ipSet.containsAny(peerIPs)) {
     200                        _ipSet.addAll(peerIPs);
     201                        return peer;
     202                    } else {
     203                        if (_log.shouldLog(Log.INFO))
     204                            _log.info(getJobId() + ": Skipping verify w/ router too close to the store " + peer);
     205                    }
     206                } else {
     207                    if (_log.shouldLog(Log.INFO))
     208                        _log.info(getJobId() + ": Skipping verify w/ router that doesn't support key certs " + peer);
     209                }
    195210                _ignore.add(peer);
    196211            }
  • router/java/src/net/i2p/router/peermanager/PeerManager.java

    r01cfb7b r11579b9  
    1818import java.util.Set;
    1919import java.util.concurrent.ConcurrentHashMap;
     20import java.util.concurrent.atomic.AtomicBoolean;
    2021
    2122import net.i2p.data.Hash;
     
    4445    /** value strings are lower case */
    4546    private final Map<Hash, String> _capabilitiesByPeer;
     47    private final AtomicBoolean _storeLock = new AtomicBoolean();
     48    private volatile long _lastStore;
     49
    4650    private static final long REORGANIZE_TIME = 45*1000;
    4751    private static final long REORGANIZE_TIME_MEDIUM = 123*1000;
     
    5357     */
    5458    private static final long REORGANIZE_TIME_LONG = 351*1000;
     59    private static final long STORE_TIME = 19*60*60*1000;
     60    private static final long EXPIRE_AGE = 3*24*60*60*1000;
    5561   
    5662    public static final String TRACKED_CAPS = "" +
     
    98104
    99105    /**
     106     *  Reorganize the profiles. Also periodically store them,
     107     *  and delete very old ones.
     108     *
    100109     *  This takes too long to run on the SimpleTimer2 queue
    101110     *  @since 0.9.10
    102111     */
    103112    private class ReorgThread extends I2PThread {
    104         private SimpleTimer2.TimedEvent _event;
     113        private final SimpleTimer2.TimedEvent _event;
    105114
    106115        public ReorgThread(SimpleTimer2.TimedEvent event) {
     
    118127            }
    119128            long orgtime = System.currentTimeMillis() - start;
     129            if (_lastStore == 0) {
     130                _lastStore = start;
     131            } else if (start - _lastStore > STORE_TIME) {
     132                _lastStore = start;
     133                try {
     134                    _log.debug("Periodic profile store start");
     135                    storeProfiles();
     136                    _persistenceHelper.deleteOldProfiles(EXPIRE_AGE);
     137                    _log.debug("Periodic profile store end");
     138                } catch (Throwable t) {
     139                    _log.log(Log.CRIT, "Error storing profiles", t);
     140                }
     141            }
    120142            long uptime = _context.router().getUptime();
    121143            long delay;
     
    131153   
    132154    void storeProfiles() {
    133         Set<Hash> peers = selectPeers();
    134         for (Hash peer : peers) {
    135             storeProfile(peer);
     155        // lock in case shutdown bumps into periodic store
     156        if (!_storeLock.compareAndSet(false, true))
     157            return;
     158        try {
     159            Set<Hash> peers = selectPeers();
     160            for (Hash peer : peers) {
     161                storeProfile(peer);
     162            }
     163        } finally {
     164            _storeLock.set(false);
    136165        }
    137166    }
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    r01cfb7b r11579b9  
    2525import net.i2p.router.RouterContext;
    2626import net.i2p.router.tunnel.pool.TunnelPeerSelector;
     27import net.i2p.router.util.MaskedIPSet;
    2728import net.i2p.router.util.RandomIterator;
    2829import net.i2p.stat.Rate;
     
    12461247    private void locked_selectPeers(Map<Hash, PeerProfile> peers, int howMany, Set<Hash> toExclude, Set<Hash> matches, int mask) {
    12471248        List<Hash> all = new ArrayList<Hash>(peers.keySet());
    1248         Set<String> IPSet = new HashSet<String>(8);
     1249        MaskedIPSet IPSet = new MaskedIPSet(8);
    12491250        // use RandomIterator to avoid shuffling the whole thing
    12501251        for (Iterator<Hash> iter = new RandomIterator<Hash>(all); (matches.size() < howMany) && iter.hasNext(); ) {
     
    12781279     * @param IPMatches all IPs so far, modified by this routine
    12791280     */
    1280     private boolean notRestricted(Hash peer, Set<String> IPSet, int mask) {
    1281         Set<String> peerIPs = maskedIPSet(peer, mask);
    1282         if (containsAny(IPSet, peerIPs))
     1281    private boolean notRestricted(Hash peer, MaskedIPSet IPSet, int mask) {
     1282        Set<String> peerIPs = new MaskedIPSet(_context, peer, mask);
     1283        if (IPSet.containsAny(peerIPs))
    12831284            return false;
    12841285        IPSet.addAll(peerIPs);
    12851286        return true;
    1286     }
    1287 
    1288     /**
    1289       * The Set of IPs for this peer, with a given mask.
    1290       * Includes the comm system's record of the IP, and all netDb addresses.
    1291       *
    1292       * As of 0.9.24, returned set will include netdb family as well.
    1293       *
    1294       * @return an opaque set of masked IPs for this peer
    1295       */
    1296     private Set<String> maskedIPSet(Hash peer, int mask) {
    1297         Set<String> rv = new HashSet<String>(4);
    1298         byte[] commIP = _context.commSystem().getIP(peer);
    1299         if (commIP != null)
    1300             rv.add(maskedIP(commIP, mask));
    1301         RouterInfo pinfo = _context.netDb().lookupRouterInfoLocally(peer);
    1302         if (pinfo == null)
    1303             return rv;
    1304         Collection<RouterAddress> paddr = pinfo.getAddresses();
    1305         for (RouterAddress pa : paddr) {
    1306             byte[] pib = pa.getIP();
    1307             if (pib == null) continue;
    1308             rv.add(maskedIP(pib, mask));
    1309         }
    1310         String family = pinfo.getOption("family");
    1311         if (family != null) {
    1312             // TODO should KNDF put a family-verified indicator in the RI,
    1313             // after checking the sig, or does it matter?
    1314             // What's the threat here of not avoid ding a router
    1315             // falsely claiming to be in the family?
    1316             // Prefix with something so an IP can't be spoofed
    1317             rv.add('x' + family);
    1318         }
    1319         return rv;
    1320     }
    1321 
    1322     /**
    1323      * generate an arbitrary unique value for this ip/mask (mask = 1-4)
    1324      * If IPv6, force mask = 6.
    1325      */
    1326     private static String maskedIP(byte[] ip, int mask) {
    1327         final StringBuilder buf = new StringBuilder(1 + (mask*2));
    1328         final char delim;
    1329         if (ip.length == 16) {
    1330             mask = 6;
    1331             delim = ':';
    1332         } else {
    1333             delim = '.';
    1334         }
    1335         buf.append(delim);
    1336         buf.append(Long.toHexString(DataHelper.fromLong(ip, 0, mask)));
    1337         return buf.toString();
    1338     }
    1339 
    1340     /** does a contain any of the elements in b? */
    1341     private static <T> boolean  containsAny(Set<T> a, Set<T> b) {
    1342         if (a.isEmpty() || b.isEmpty())
    1343             return false;
    1344         for (T o : b) {
    1345             if (a.contains(o))
    1346                 return true;
    1347         }
    1348         return false;
    13491287    }
    13501288
  • router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java

    r01cfb7b r11579b9  
    230230    }
    231231   
     232    /**
     233     *  Delete profile files with timestamps older than 'age' ago
     234     *  @since 0.9.28
     235     */
     236    public void deleteOldProfiles(long age) {
     237        long cutoff = System.currentTimeMillis() - age;
     238        List<File> files = selectFiles();
     239        int i = 0;
     240        for (File f :  files) {
     241            if (!f.isFile())
     242                continue;
     243            if (f.lastModified() < cutoff) {
     244                i++;
     245                f.delete();
     246            }
     247        }
     248        if (_log.shouldWarn())
     249            _log.warn("Deleted " + i + " old profiles");
     250    }
     251
    232252    private boolean isExpired(long lastSentToSuccessfully) {
    233253        long timeSince = _context.clock().now() - lastSentToSuccessfully;
  • router/java/src/net/i2p/router/tasks/OOMListener.java

    r01cfb7b r11579b9  
    5050            log.log(Log.CRIT, "free mem: " + Runtime.getRuntime().freeMemory() +
    5151                              " total mem: " + Runtime.getRuntime().totalMemory());
     52            // Can't find any System property or wrapper property that gives
     53            // you the actual config file path, have to guess
     54            String path;
     55            if (SystemVersion.isLinuxService()) {
     56                path = "/etc/i2p";
     57            } else {
     58                path = _context.getBaseDir().toString();
     59            }
    5260            if (_context.hasWrapper()) {
    53                 // Can't find any System property or wrapper property that gives
    54                 // you the actual config file path, have to guess
    55                 String path;
    56                 if (SystemVersion.isLinuxService()) {
    57                     path = "/etc/i2p";
    58                 } else {
    59                     path = _context.getBaseDir().toString();
    60                 }
    6161                log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in " +
     62                                  path + File.separatorChar + "wrapper.config");
     63            } else if (!SystemVersion.isWindows()) {
     64                log.log(Log.CRIT, "To prevent future shutdowns, increase MAXMEMOPT in " +
     65                                  path + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper");
     66            } else {
     67                log.log(Log.CRIT, "To prevent future shutdowns, run the restartable version of I2P, and increase wrapper.java.maxmemory in " +
    6268                                  path + File.separatorChar + "wrapper.config");
    6369            }
  • router/java/src/net/i2p/router/transport/TransportManager.java

    r01cfb7b r11579b9  
    1212import java.io.Writer;
    1313import java.net.InetAddress;
     14import java.net.Inet6Address;
    1415import java.net.UnknownHostException;
    1516import java.util.ArrayList;
     
    166167                int port = udp.getRequestedPort();
    167168                if (port > 0)
    168                     ntcp.externalAddressReceived(SOURCE_CONFIG, null, port);
     169                    ntcp.externalAddressReceived(SOURCE_CONFIG, (byte[]) null, port);
    169170            }
    170171        }
     
    183184    private void initializeAddress(Transport t) {
    184185        Set<String> ipset = Addresses.getAddresses(false, true);  // non-local, include IPv6
     186        //
     187        // Avoid IPv6 temporary addresses if we have a non-temporary one
     188        //
     189        boolean hasNonTempV6Address = false;
     190        List<InetAddress> addresses = new ArrayList<InetAddress>(4);
     191        List<Inet6Address> tempV6Addresses = new ArrayList<Inet6Address>(4);
    185192        for (String ips : ipset) {
    186193            try {
    187                 InetAddress ia = InetAddress.getByName(ips);
    188                 byte[] ip = ia.getAddress();
    189                 t.externalAddressReceived(SOURCE_INTERFACE, ip, 0);
     194                InetAddress addr = InetAddress.getByName(ips);
     195                if (ips.contains(":") && (addr instanceof Inet6Address)) {
     196                    Inet6Address v6addr = (Inet6Address) addr;
     197                    // getAddresses(false, true) will not return deprecated addresses
     198                    //if (Addresses.isDeprecated(v6addr)) {
     199                    //    if (_log.shouldWarn())
     200                    //        _log.warn("Not binding to deprecated temporary address " + bt);
     201                    //    continue;
     202                    //}
     203                    if (Addresses.isTemporary(v6addr)) {
     204                        // Save temporary addresses
     205                        // we only use these if we don't have a non-temporary adress
     206                        tempV6Addresses.add(v6addr);
     207                        continue;
     208                    }
     209                    hasNonTempV6Address = true;
     210                }
     211                addresses.add(addr);
    190212            } catch (UnknownHostException e) {
    191213                _log.error("UDP failed to bind to local address", e);
    192214            }
     215        }
     216        // we only use these if we don't have a non-temporary adress
     217        if (!tempV6Addresses.isEmpty()) {
     218            if (hasNonTempV6Address) {
     219                if (_log.shouldWarn()) {
     220                    for (Inet6Address addr : tempV6Addresses) {
     221                        _log.warn("Not binding to temporary address " + addr.getHostAddress());
     222                    }
     223                }
     224            } else {
     225                addresses.addAll(tempV6Addresses);
     226            }
     227        }
     228        for (InetAddress ia : addresses) {
     229            byte[] ip = ia.getAddress();
     230            t.externalAddressReceived(SOURCE_INTERFACE, ip, 0);
    193231        }
    194232    }
  • router/java/src/net/i2p/router/transport/TransportUtil.java

    r01cfb7b r11579b9  
    2626    public static final String SSU_IPV6_CONFIG = "i2np.udp.ipv6";
    2727    public static final String PROP_IPV4_FIREWALLED = "i2np.ipv4.firewalled";
     28    /** @since 0.9.28 */
     29    public static final String PROP_IPV6_FIREWALLED = "i2np.ipv6.firewalled";
    2830
    2931    public enum IPv6Config {
     
    100102     *
    101103     *  @param transportStyle ignored
    102      *  @since 0.9.27
     104     *  @since 0.9.27, implemented in 0.9.28
    103105     */
    104106    public static boolean isIPv6Firewalled(RouterContext ctx, String transportStyle) {
    105         // TODO
    106         //return ctx.getBooleanProperty(PROP_IPV6_FIREWALLED);
    107         return false;
     107        return ctx.getBooleanProperty(PROP_IPV6_FIREWALLED);
    108108    }
    109109
  • router/java/src/net/i2p/router/transport/UPnP.java

    r01cfb7b r11579b9  
    5959 * some code has been borrowed from Limewire : @see com.limegroup.gnutella.UPnPManager
    6060 *
     61 * Public only for command line usage. Not a public API, not for external use.
     62 *
    6163 * @see "http://www.upnp.org/"
    6264 * @see "http://en.wikipedia.org/wiki/Universal_Plug_and_Play"
     
    6971 * TODO: Implement EventListener and react on ip-change
    7072 */
    71 class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
     73public class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
    7274        private final Log _log;
    7375        private final I2PAppContext _context;
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    r01cfb7b r11579b9  
    151151        _context.statManager().createRateStat("ntcp.inboundEstablished", "", "ntcp", RATES);
    152152        _context.statManager().createRateStat("ntcp.inboundEstablishedDuplicate", "", "ntcp", RATES);
     153        _context.statManager().createRateStat("ntcp.inboundIPv4Conn", "Inbound IPv4 NTCP Connection", "ntcp", RATES);
     154        _context.statManager().createRateStat("ntcp.inboundIPv6Conn", "Inbound IPv6 NTCP Connection", "ntcp", RATES);
    153155        //_context.statManager().createRateStat("ntcp.infoMessageEnqueued", "", "ntcp", RATES);
    154156        //_context.statManager().createRateStat("ntcp.floodInfoMessageEnqueued", "", "ntcp", RATES);
     
    214216            old = _conByIdent.put(peer, con);
    215217        }
    216         if (con.isIPv6())
     218        if (con.isIPv6()) {
    217219            _lastInboundIPv6 = con.getCreated();
    218         else
     220            _context.statManager().addRateData("ntcp.inboundIPv6Conn", 1);
     221        } else {
    219222            _lastInboundIPv4 = con.getCreated();
     223            _context.statManager().addRateData("ntcp.inboundIPv4Conn", 1);
     224        }
    220225        return old;
    221226    }
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r01cfb7b r11579b9  
    290290        _context.statManager().createRateStat("udp.dropPeerDroplist", "How many peers currently have their packets dropped outright when a new peer is added to the list?", "udp", RATES);
    291291        _context.statManager().createRateStat("udp.dropPeerConsecutiveFailures", "How many consecutive failed sends to a peer did we attempt before giving up and reestablishing a new session (lifetime is inactivity perood)", "udp", RATES);
     292        _context.statManager().createRateStat("udp.inboundIPv4Conn", "Inbound IPv4 UDP Connection", "udp", RATES);
     293        _context.statManager().createRateStat("udp.inboundIPv6Conn", "Inbound IPv4 UDP Connection", "udp", RATES);
    292294        // following are for PacketBuider
    293295        //_context.statManager().createRateStat("udp.packetAuthTime", "How long it takes to encrypt and MAC a packet for sending", "udp", RATES);
     
    781783        if (isIPv6) {
    782784            _lastInboundIPv6 = _context.clock().now();
     785            _context.statManager().addRateData("udp.inboundIPv6Conn", 1);
    783786            // former workaround for lack of IPv6 peer testing
    784787            //if (_currentOurV6Address != null)
     
    789792            // use OS clock since its an ordering thing, not a time thing
    790793            _lastInboundReceivedOn = System.currentTimeMillis();
     794            _context.statManager().addRateData("udp.inboundIPv4Conn", 1);
    791795        }
    792796    }
     
    17661770            // never get any introducers)
    17671771            int count = _peersByIdent.size();
    1768             if (alwaysPreferUDP() || count < _min_peers ||
    1769                 (_haveIPv6Address && count < _min_v6_peers) ||
    1770                 (introducersRequired() && _introManager.introducerCount() < MIN_INTRODUCER_POOL))
     1772            if (alwaysPreferUDP()) {
    17711773                return _cachedBid[SLOW_PREFERRED_BID];
    1772             else if (preferUDP())
     1774            } else if (count < _min_peers ||
     1775                       (_haveIPv6Address && count < _min_v6_peers) ||
     1776                       (introducersRequired() && _introManager.introducerCount() < MIN_INTRODUCER_POOL)) {
     1777                 // Even if we haven't hit our minimums, give NTCP a chance some of the time.
     1778                 // This may make things work a little faster at startup
     1779                 // (especially when we have an IPv6 address and the increased minimums),
     1780                 // and if UDP is completely blocked we'll still have some connectivity.
     1781                 // TODO After some time, decide that UDP is blocked/broken and return TRANSIENT_FAIL_BID?
     1782                if (_context.random().nextInt(4) == 0)
     1783                    return _cachedBid[SLOWEST_BID];
     1784                else
     1785                    return _cachedBid[SLOW_PREFERRED_BID];
     1786            } else if (preferUDP()) {
    17731787                return _cachedBid[SLOW_BID];
    1774             else if (haveCapacity()) {
     1788            } else if (haveCapacity()) {
    17751789                if (addr.getCost() > DEFAULT_COST)
    17761790                    return _cachedBid[SLOWEST_COST_BID];
  • router/java/src/net/i2p/router/tunnel/BloomFilterIVValidator.java

    r01cfb7b r11579b9  
    105105        // Can't find any System property or wrapper property that gives
    106106        // you the actual config file path, have to guess
    107         // TODO if !SystemVersion.hasWrapper ...
    108107        String path;
    109108        if (SystemVersion.isLinuxService()) {
     
    115114            "Configured for " + DataHelper.formatSize(KBps *1024L) +
    116115            "Bps share bandwidth but only " +
    117             DataHelper.formatSize(maxMemory) + "B available memory." +
    118             " Recommend increasing wrapper.java.maxmemory in " +
    119             path + File.separatorChar + "wrapper.config" +
    120             // getMaxMemory() returns significantly lower than wrapper config, so add 10%
    121             " to at least " + (recMaxMem * 11 / 10 / (1024*1024)) + " (MB)" +
    122             " if the actual share bandwidth exceeds " +
    123             DataHelper.formatSize(threshKBps * 1024L) + "Bps.";
     116            DataHelper.formatSize(maxMemory) + "B available memory.";
     117        if (_context.hasWrapper()) {
     118            msg += " Recommend increasing wrapper.java.maxmemory in " +
     119                   path + File.separatorChar + "wrapper.config";
     120        } else if (!SystemVersion.isWindows()) {
     121            msg += " Recommend increasing MAXMEMOPT in " +
     122                   path + File.separatorChar + "runplain.sh or /usr/bin/i2prouter-nowrapper";
     123        } else {
     124            msg += " Recommend running the restartable version of I2P, and increasing wrapper.java.maxmemory in " +
     125                   path + File.separatorChar + "wrapper.config";
     126        }
     127        // getMaxMemory() returns significantly lower than wrapper config, so add 10%
     128        msg += " to at least " + (recMaxMem * 11 / 10 / (1024*1024)) + " (MB)" +
     129               " if the actual share bandwidth exceeds " +
     130               DataHelper.formatSize(threshKBps * 1024L) + "Bps.";
    124131        System.out.println("WARN: " + msg);
    125132        _context.logManager().getLog(BloomFilterIVValidator.class).logAlways(Log.WARN, msg);
  • router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java

    r01cfb7b r11579b9  
    2626abstract class BuildRequestor {
    2727    private static final List<Integer> ORDER = new ArrayList<Integer>(TunnelBuildMessage.MAX_RECORD_COUNT);
     28    private static final String MIN_VARIABLE_VERSION = "0.7.12";
     29    private static final boolean SEND_VARIABLE = true;
     30    private static final int SHORT_RECORDS = 4;
     31    private static final List<Integer> SHORT_ORDER = new ArrayList<Integer>(SHORT_RECORDS);
     32    /** 5 (~2600 bytes) fits nicely in 3 tunnel messages */
     33    private static final int MEDIUM_RECORDS = 5;
     34    private static final List<Integer> MEDIUM_ORDER = new ArrayList<Integer>(MEDIUM_RECORDS);
    2835    static {
    29         for (int i = 0; i < TunnelBuildMessage.MAX_RECORD_COUNT; i++)
     36        for (int i = 0; i < TunnelBuildMessage.MAX_RECORD_COUNT; i++) {
    3037            ORDER.add(Integer.valueOf(i));
     38        }
     39        for (int i = 0; i < SHORT_RECORDS; i++) {
     40            SHORT_ORDER.add(Integer.valueOf(i));
     41        }
     42        for (int i = 0; i < MEDIUM_RECORDS; i++) {
     43            MEDIUM_ORDER.add(Integer.valueOf(i));
     44        }
    3145    }
    3246
     
    224238        return true;
    225239    }
    226    
    227     private static final String MIN_VARIABLE_VERSION = "0.7.12";
    228     /** change this to true in 0.7.13 if testing goes well */
    229     private static final boolean SEND_VARIABLE = true;
    230     /** 5 (~2600 bytes) fits nicely in 3 tunnel messages */
    231     private static final int SHORT_RECORDS = 5;
    232     private static final List<Integer> SHORT_ORDER = new ArrayList<Integer>(SHORT_RECORDS);
    233     static {
    234         for (int i = 0; i < SHORT_RECORDS; i++)
    235             SHORT_ORDER.add(Integer.valueOf(i));
    236     }
    237240
    238241    /** @since 0.7.12 */
     
    257260        long replyTunnel = 0;
    258261        Hash replyRouter = null;
    259         boolean useVariable = SEND_VARIABLE && cfg.getLength() <= SHORT_RECORDS;
     262        boolean useVariable = SEND_VARIABLE && cfg.getLength() <= MEDIUM_RECORDS;
    260263        if (cfg.isInbound()) {
    261264            //replyTunnel = 0; // as above
     
    296299        List<Integer> order;
    297300        if (useVariable) {
    298             msg = new VariableTunnelBuildMessage(ctx, SHORT_RECORDS);
    299             order = new ArrayList<Integer>(SHORT_ORDER);
    300             //if (log.shouldLog(Log.INFO))
    301             //    log.info("Using new VTBM");
     301            if (cfg.getLength() <= SHORT_RECORDS) {
     302                msg = new VariableTunnelBuildMessage(ctx, SHORT_RECORDS);
     303                order = new ArrayList<Integer>(SHORT_ORDER);
     304            } else {
     305                msg = new VariableTunnelBuildMessage(ctx, MEDIUM_RECORDS);
     306                order = new ArrayList<Integer>(MEDIUM_ORDER);
     307            }
    302308        } else {
    303309            msg = new TunnelBuildMessage(ctx);
  • router/java/src/org/cybergarage/http/HTTPHeader.java

    r01cfb7b r11579b9  
    117117        public final static String getValue(String data, String name)
    118118        {
     119                // I2P #1480 avoid IAE
     120                if (data.length() <= 0)
     121                        return "";
    119122                /* Thanks for Stephan Mehlhase (2010-10-26) */
    120123                StringReader strReader = new StringReader(data);
  • router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java

    r01cfb7b r11579b9  
    9393                if (0 < localAddr.length())
    9494                        return localAddr;
     95                // I2P prevent NPE #1681
     96                if (ssdpUniSock == null)
     97                        return "";
    9598                return ssdpUniSock.getLocalAddress().getHostAddress();
    9699        }
Note: See TracChangeset for help on using the changeset viewer.