Changeset bbb9218 for router


Ignore:
Timestamp:
Nov 20, 2016 10:25:00 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
86c0fe3
Parents:
fdff5ec
Message:

NetDB: When doing lookups, don't use floodfills too close

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

Legend:

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

    rfdff5ec rbbb9218  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 9;
     21    public final static long BUILD = 10;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java

    rfdff5ec rbbb9218  
    2828import net.i2p.router.TunnelInfo;
    2929import net.i2p.router.TunnelManagerFacade;
     30import net.i2p.router.util.MaskedIPSet;
    3031import net.i2p.router.util.RandomIterator;
    3132import net.i2p.util.Log;
     
    7475    /** Max number of peers to query */
    7576    private final int _totalSearchLimit;
     77    private final MaskedIPSet _ipSet;
     78    private final Set<Hash> _skippedPeers;
    7679   
    7780    private static final int MAX_NON_FF = 3;
     
    8083    /** Max number of peers to query if we are ff */
    8184    private static final int TOTAL_SEARCH_LIMIT_WHEN_FF = 3;
     85    /** Extra peers to get from peer selector, as we may discard some before querying */
     86    private static final int EXTRA_PEERS = 2;
     87    private static final int IP_CLOSE_BYTES = 3;
    8288    /** TOTAL_SEARCH_LIMIT * SINGLE_SEARCH_TIME, plus some extra */
    8389    private static final int MAX_SEARCH_TIME = 30*1000;
     
    139145                            TOTAL_SEARCH_LIMIT_WHEN_FF : TOTAL_SEARCH_LIMIT;
    140146        _totalSearchLimit = ctx.getProperty("netdb.searchLimit", totalSearchLimit);
     147        _ipSet = new MaskedIPSet(2 * (_totalSearchLimit + EXTRA_PEERS));
    141148        _singleSearchTime = ctx.getProperty("netdb.singleSearchTime", SINGLE_SEARCH_TIME);
    142149        _maxConcurrent = ctx.getProperty("netdb.maxConcurrent", MAX_CONCURRENT);
    143150        _unheardFrom = new HashSet<Hash>(CONCURRENT_SEARCHES);
    144151        _failedPeers = new HashSet<Hash>(_totalSearchLimit);
     152        _skippedPeers = new HashSet<Hash>(4);
    145153        _sentTime = new ConcurrentHashMap<Hash, Long>(_totalSearchLimit);
    146154        _fromLocalDest = fromLocalDest;
     
    164172            // Ideally we would add the key to an exclude list, so we don't try to query a ff peer for itself,
    165173            // but we're passing the rkey not the key, so we do it below instead in certain cases.
    166             floodfillPeers = ((FloodfillPeerSelector)_facade.getPeerSelector()).selectFloodfillParticipants(_rkey, _totalSearchLimit, ks);
     174            floodfillPeers = ((FloodfillPeerSelector)_facade.getPeerSelector()).selectFloodfillParticipants(_rkey, _totalSearchLimit + EXTRA_PEERS, ks);
    167175        } else {
    168176            floodfillPeers = new ArrayList<Hash>(_totalSearchLimit);
     
    246254        }
    247255        while (true) {
    248             Hash peer;
     256            Hash peer = null;
    249257            final int done, pend;
    250258            synchronized (this) {
     
    275283                    if (_toTry.isEmpty())
    276284                        return;
    277                     Iterator<Hash> iter = _toTry.iterator();
    278                     peer = iter.next();
    279                     iter.remove();
     285                    for (Iterator<Hash> iter = _toTry.iterator(); iter.hasNext(); ) {
     286                        Hash h = iter.next();
     287                        iter.remove();
     288                        Set<String> peerIPs = new MaskedIPSet(getContext(), h, IP_CLOSE_BYTES);
     289                        if (!_ipSet.containsAny(peerIPs)) {
     290                            _ipSet.addAll(peerIPs);
     291                            peer = h;
     292                            break;
     293                        }
     294                        if (_log.shouldLog(Log.INFO))
     295                            _log.info(getJobId() + ": Skipping query w/ router too close to others " + h);
     296                        _skippedPeers.add(h);
     297                        // go around again
     298                    }
     299                    if (peer == null)
     300                        return;
    280301                }
    281302                _unheardFrom.add(peer);
     
    500521        synchronized (this) {
    501522            if (_failedPeers.contains(peer) ||
    502                 _unheardFrom.contains(peer))
    503                 return;  // already tried
     523                _unheardFrom.contains(peer) ||
     524                _skippedPeers.contains(peer))
     525                return;  // already tried or skipped
    504526            if (!_toTry.add(peer))
    505527                return;  // already in the list
Note: See TracChangeset for help on using the changeset viewer.