Changeset 2318a2b for router/java


Ignore:
Timestamp:
Nov 27, 2016 2:58:34 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
850f150
Parents:
8d494ad
Message:

NetDb?: Add same-port check in peer selector
Convert FloodfillPeerSelector? MaskedIPSet to use the one now in util

Location:
router/java/src/net/i2p/router
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/RouterVersion.java

    r8d494ad r2318a2b  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 11;
     21    public final static long BUILD = 12;
    2222
    2323    /** for example "-test" */
    24     public final static String EXTRA = "";
     24    public final static String EXTRA = "-rc";
    2525    public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
    2626    public static void main(String args[]) {
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

    r8d494ad r2318a2b  
    2626import net.i2p.router.RouterContext;
    2727import net.i2p.router.peermanager.PeerProfile;
     28import net.i2p.router.util.MaskedIPSet;
    2829import net.i2p.router.util.RandomIterator;
    2930import net.i2p.stat.Rate;
     
    227228        int limit = Math.max(5, howMany);
    228229        limit = Math.min(limit, ffs.size());
    229         Set<Integer> maskedIPs = new HashSet<Integer>(limit + 4);
     230        MaskedIPSet maskedIPs = new MaskedIPSet(limit * 3);
    230231        // split sorted list into 3 sorted lists
    231232        for (int i = 0; found < howMany && i < limit; i++) {
     
    236237            // put anybody in the same /16 at the end
    237238            RouterInfo info = _context.netDb().lookupRouterInfoLocally(entry);
    238             Set<Integer> entryIPs = maskedIPSet(entry, info, 2);
     239            MaskedIPSet entryIPs = new MaskedIPSet(_context, entry, info, 2);
    239240            boolean sameIP = false;
    240             for (Integer ip : entryIPs) {
     241            for (String ip : entryIPs) {
    241242                if (!maskedIPs.add(ip))
    242243                    sameIP = true;
     
    245246                badff.add(entry);
    246247                if (_log.shouldLog(Log.DEBUG))
    247                     _log.debug("Same /16: " + entry);
     248                    _log.debug("Same /16, family, or port: " + entry);
    248249            } else if (info != null && now - info.getPublished() > 3*60*60*1000) {
    249250                badff.add(entry);
     
    325326    }
    326327   
    327 
    328     /**
    329       * The Set of IPs for this peer, with a given mask.
    330       * Includes the comm system's record of the IP, and all netDb addresses.
    331       *
    332       * @param pinfo may be null
    333       * @return an opaque set of masked IPs for this peer
    334       * @since 0.9.5 modified from ProfileOrganizer
    335       */
    336     private Set<Integer> maskedIPSet(Hash peer, RouterInfo pinfo, int mask) {
    337         Set<Integer> rv = new HashSet<Integer>(4);
    338         byte[] commIP = _context.commSystem().getIP(peer);
    339         if (commIP != null)
    340             rv.add(maskedIP(commIP, mask));
    341         if (pinfo == null)
    342             return rv;
    343         Collection<RouterAddress> paddr = pinfo.getAddresses();
    344         for (RouterAddress pa : paddr) {
    345             byte[] pib = pa.getIP();
    346             if (pib == null) continue;
    347             rv.add(maskedIP(pib, mask));
    348         }
    349         return rv;
    350     }
    351 
    352     /**
    353      * generate an arbitrary unique value for this ip/mask (mask = 1-4)
    354      * If IPv6, force mask = 8.
    355      * @since 0.9.5 copied from ProfileOrganizer
    356      */
    357     private static Integer maskedIP(byte[] ip, int mask) {
    358         int rv = ip[0];
    359         if (ip.length == 16) {
    360             for (int i = 1; i < 8; i++) {
    361                 rv <<= i * 4;
    362                 rv ^= ip[i];
    363             }
    364         } else {
    365             for (int i = 1; i < mask; i++) {
    366                 rv <<= 8;
    367                 rv ^= ip[i];
    368             }
    369         }
    370         return Integer.valueOf(rv);
    371     }
    372 
    373328    private class FloodfillSelectionCollector implements SelectionCollector<Hash> {
    374329        private final TreeSet<Hash> _sorted;
  • router/java/src/net/i2p/router/util/MaskedIPSet.java

    r8d494ad r2318a2b  
    3838      */
    3939    public MaskedIPSet(RouterContext ctx, Hash peer, int mask) {
    40         this(ctx, ctx.netDb().lookupRouterInfoLocally(peer), mask);
     40        this(ctx, peer, ctx.netDb().lookupRouterInfoLocally(peer), mask);
    4141    }
    4242
     
    5252      */
    5353    public MaskedIPSet(RouterContext ctx, RouterInfo pinfo, int mask) {
     54        this(ctx, pinfo != null ? pinfo.getHash() : null, pinfo, mask);
     55    }
     56
     57    /**
     58      * The Set of IPs for this peer, with a given mask.
     59      * Includes the comm system's record of the IP, and all netDb addresses.
     60      *
     61      * As of 0.9.24, returned set will include netdb family as well.
     62      *
     63      * @param pinfo may be null
     64      * @param mask is 1-4 (number of bytes to match)
     65      * @return an opaque set of masked IPs for this peer
     66      */
     67    public MaskedIPSet(RouterContext ctx, Hash peer, RouterInfo pinfo, int mask) {
    5468        super(4);
    5569        if (pinfo == null)
    5670            return;
    57         byte[] commIP = ctx.commSystem().getIP(pinfo.getHash());
     71        byte[] commIP = ctx.commSystem().getIP(peer);
    5872        if (commIP != null)
    5973            add(maskedIP(commIP, mask));
     
    6377            if (pib == null) continue;
    6478            add(maskedIP(pib, mask));
     79            // Routers with a common port may be run
     80            // by a single entity with a common configuration
     81            int port = pa.getPort();
     82            if (port > 0)
     83                add("p" + port);
    6584        }
    6685        String family = pinfo.getOption("family");
Note: See TracChangeset for help on using the changeset viewer.