Changeset 7a1a1d5 for router


Ignore:
Timestamp:
Nov 17, 2016 2:27:55 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cd4d5a3
Parents:
66c2664
Message:

NetDB: When verifying store, don't use floodfills too close
to the store

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

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java

    r66c2664 r7a1a1d5  
    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/util/MaskedIPSet.java

    r66c2664 r7a1a1d5  
    3333      * As of 0.9.24, returned set will include netdb family as well.
    3434      *
     35      * @param peer non-null
    3536      * @param mask is 1-4 (number of bytes to match)
    3637      * @return an opaque set of masked IPs for this peer
    3738      */
    3839    public MaskedIPSet(RouterContext ctx, Hash peer, int mask) {
     40        this(ctx, ctx.netDb().lookupRouterInfoLocally(peer), mask);
     41    }
     42
     43    /**
     44      * The Set of IPs for this peer, with a given mask.
     45      * Includes the comm system's record of the IP, and all netDb addresses.
     46      *
     47      * As of 0.9.24, returned set will include netdb family as well.
     48      *
     49      * @param pinfo may be null
     50      * @param mask is 1-4 (number of bytes to match)
     51      * @return an opaque set of masked IPs for this peer
     52      */
     53    public MaskedIPSet(RouterContext ctx, RouterInfo pinfo, int mask) {
    3954        super(4);
    40         byte[] commIP = ctx.commSystem().getIP(peer);
     55        if (pinfo == null)
     56            return;
     57        byte[] commIP = ctx.commSystem().getIP(pinfo.getHash());
    4158        if (commIP != null)
    4259            add(maskedIP(commIP, mask));
    43         RouterInfo pinfo = ctx.netDb().lookupRouterInfoLocally(peer);
    44         if (pinfo == null)
    45             return;
    4660        Collection<RouterAddress> paddr = pinfo.getAddresses();
    4761        for (RouterAddress pa : paddr) {
Note: See TracChangeset for help on using the changeset viewer.