Changeset b7ff4fe8


Ignore:
Timestamp:
Jul 4, 2011 6:48:31 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c8397990
Parents:
435683c
Message:
  • Netdb exploration:
    • Remove floodfills from dont-include list in exploration DatabaseLookupMessage?, as the dont-include-floodfills flag has been supported since release 0.7.9. This will make exploration work better, as there is room for non-floodfills in the don't-include list now.
    • Reduce min and max exploration intervals
    • Explore aggressively at startup and if known routers is low
    • Explore slowly if known routers is high
Location:
router/java/src/net/i2p/router/networkdb/kademlia
Files:
4 edited

Legend:

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

    r435683c rb7ff4fe8  
    3535    public int countLeaseSets();
    3636
     37    /**
     38     *  @return total size (RI and LS)
     39     *  @since 0.8.8
     40     */
     41    public int size();
    3742}
  • router/java/src/net/i2p/router/networkdb/kademlia/ExploreJob.java

    r435683c rb7ff4fe8  
    9999        // as routers will honor the above flag, and we want the table to include
    100100        // only non-floodfills.
    101         if (available > 0 && ks != null) {
    102             List peers = _peerSelector.selectFloodfillParticipants(rkey, available, ks);
    103             int len = peers.size();
    104             if (len > 0)
    105                 msg.getDontIncludePeers().addAll(peers);
    106         }
     101        // Removed in 0.8.8, good thing, as we had well over MAX_CLOSEST floodfills.
     102        //if (available > 0 && ks != null) {
     103        //    List peers = _peerSelector.selectFloodfillParticipants(rkey, available, ks);
     104        //    int len = peers.size();
     105        //    if (len > 0)
     106        //        msg.getDontIncludePeers().addAll(peers);
     107        //}
    107108       
    108109        available = MAX_CLOSEST - msg.getDontIncludePeers().size();
  • router/java/src/net/i2p/router/networkdb/kademlia/StartExplorersJob.java

    r435683c rb7ff4fe8  
    1010
    1111import java.util.HashSet;
    12 import java.util.Iterator;
    1312import java.util.Set;
    1413
     
    2524 */
    2625class StartExplorersJob extends JobImpl {
    27     private Log _log;
    28     private KademliaNetworkDatabaseFacade _facade;
     26    private final Log _log;
     27    private final KademliaNetworkDatabaseFacade _facade;
    2928   
    3029    /** don't explore more than 1 bucket at a time */
    3130    private static final int MAX_PER_RUN = 1;
    3231    /** dont explore the network more often than this */
    33     private static final int MIN_RERUN_DELAY_MS = 5*60*1000;
    34     /** explore the network at least once every thirty minutes */
    35     private static final int MAX_RERUN_DELAY_MS = 30*60*1000;
     32    private static final int MIN_RERUN_DELAY_MS = 99*1000;
     33    /** explore the network at least this often */
     34    private static final int MAX_RERUN_DELAY_MS = 15*60*1000;
     35    /** aggressively explore during this time - same as KNDF expiration grace period */
     36    private static final int STARTUP_TIME = 60*60*1000;
     37    /** super-aggressively explore if we have less than this many routers */
     38    private static final int LOW_ROUTERS = 125;
     39    /** aggressively explore if we have less than this many routers */
     40    private static final int MIN_ROUTERS = 250;
     41    /** explore slowly if we have more than this many routers */
     42    private static final int MAX_ROUTERS = 800;
    3643   
    3744    public StartExplorersJob(RouterContext context, KademliaNetworkDatabaseFacade facade) {
     
    4552        if (! (((FloodfillNetworkDatabaseFacade)_facade).floodfillEnabled() ||
    4653               getContext().router().gracefulShutdownInProgress())) {
    47             Set toExplore = selectKeysToExplore();
     54            int num = MAX_PER_RUN;
     55            if (_facade.getDataStore().size() < LOW_ROUTERS)
     56                num *= 2;
     57            Set<Hash> toExplore = selectKeysToExplore(num);
    4858            if (_log.shouldLog(Log.DEBUG))
    4959                _log.debug("Keys to explore during this run: " + toExplore);
    5060            _facade.removeFromExploreKeys(toExplore);
    51             for (Iterator iter = toExplore.iterator(); iter.hasNext(); ) {
    52                 Hash key = (Hash)iter.next();
     61            for (Hash key : toExplore) {
    5362                getContext().jobQueue().addJob(new ExploreJob(getContext(), _facade, key));
    5463            }
     
    7180    }
    7281   
    73     /** how long should we wait before exploring? */
     82    /**
     83     *  How long should we wait before exploring?
     84     *  We wait as long as it's been since we were last successful,
     85     *  with exceptions.
     86     */
    7487    private long getNextRunDelay() {
     88        // we don't explore if floodfill
     89        if (((FloodfillNetworkDatabaseFacade)_facade).floodfillEnabled())
     90            return MAX_RERUN_DELAY_MS;
     91
     92        // If we don't know too many peers, or just started, explore aggressively
     93        // Use DataStore.size() which includes leasesets because it's faster
     94        if (getContext().router().getUptime() < STARTUP_TIME ||
     95            _facade.getDataStore().size() < MIN_ROUTERS)
     96            return MIN_RERUN_DELAY_MS;
     97        if (_facade.getDataStore().size() > MAX_ROUTERS)
     98            return MAX_RERUN_DELAY_MS;
     99
    75100        long delay = getContext().clock().now() - _facade.getLastExploreNewDate();
    76101        if (delay < MIN_RERUN_DELAY_MS)
     
    88113     * may be empty. In that case, generate random keys.
    89114     */
    90     private Set selectKeysToExplore() {
    91         Set queued = _facade.getExploreKeys();
     115    private Set<Hash> selectKeysToExplore(int num) {
     116        Set<Hash> queued = _facade.getExploreKeys();
    92117        if (_log.shouldLog(Log.DEBUG))
    93118            _log.debug("Keys waiting for exploration: " + queued.size());
    94         Set rv = new HashSet(MAX_PER_RUN);
    95         for (Iterator iter = queued.iterator(); iter.hasNext(); ) {
    96             if (rv.size() >= MAX_PER_RUN) break;
    97             rv.add(iter.next());
     119        Set<Hash> rv = new HashSet(num);
     120        for (Hash key : queued) {
     121            if (rv.size() >= num) break;
     122            rv.add(key);
    98123        }
    99         for (int i = rv.size(); i < MAX_PER_RUN; i++) {
     124        for (int i = rv.size(); i < num; i++) {
    100125            byte hash[] = new byte[Hash.HASH_LENGTH];
    101126            getContext().random().nextBytes(hash);
  • router/java/src/net/i2p/router/networkdb/kademlia/TransientDataStore.java

    r435683c rb7ff4fe8  
    4848   
    4949    public void rescan() {}
     50
     51    /**
     52     *  @return total size (RI and LS)
     53     *  @since 0.8.8
     54     */
     55    public int size() {
     56        return _data.size();
     57    }
    5058
    5159    public Set<Hash> getKeys() {
Note: See TracChangeset for help on using the changeset viewer.