Changeset 796a231


Ignore:
Timestamp:
Nov 24, 2013 4:38:51 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
1d7eedd
Parents:
ffa03f2
Message:

NetDB:

  • Move net.i2p.kademlia package from i2psnark to core, and convert netdb to use it.
  • Delete old implementation in netdb
  • Fixups in netdb for generics
  • Add debug output to /debug

This is the next step in the development plan, in which we previously:

  • Copied the code from netdb to the i2p.zzz.kademlia branch, fixed it, and made it generic for hash size (June 2012);
  • Moved it from the i2p.zzz.kademlia branch to the i2p.i2p.zzz.dhtsnark branch, and implemented KRPC with it (June 2012);
  • Propped it from i2p.i2p.zzz.dhtsnark to trunk for 0.9.2 (July-Sept. 2012);
  • Proved it out in 0.9.2 - 0.9.9 (Oct. 2012 - Nov. 2013)

The plan was to maintain the KBucketSet public methods throughout the development
so we could drop the new version back into netdb, so here we drop it in.

Setting of K=16, B=3 is just an initial guess, to be reviewed.
This moves about 18 KB from i2psnark.jar to i2p.jar and removes about 12 KB from router.jar.
Unit test fixup: todo.

Files:
5 deleted
12 edited
10 moved

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/jsp/debug.jsp

    rffa03f2 r796a231  
    2121     */
    2222    net.i2p.router.RouterContext ctx = (net.i2p.router.RouterContext) net.i2p.I2PAppContext.getGlobalContext();
     23
     24    /*
     25     *  Print out the status for the NetDB
     26     */
     27    out.print("<h2>Router DHT</h2>");
     28    ctx.netDb().renderStatusHTML(out);
    2329
    2430    /*
  • build.xml

    rffa03f2 r796a231  
    477477            <group title="BOB Demos" packages="net.i2p.BOB.Demos.echo.echoclient:net.i2p.BOB.Demos.echo.echoserver" />
    478478            <group title="Desktopgui Application" packages="net.i2p.desktopgui:net.i2p.desktopgui.*" />
    479             <group title="I2PSnark Application" packages="org.klomp.snark:org.klomp.snark.*:net.i2p.kademlia" />
     479            <group title="I2PSnark Application" packages="org.klomp.snark:org.klomp.snark.*" />
    480480            <group title="I2PTunnel Application" packages="net.i2p.i2ptunnel:net.i2p.i2ptunnel.*" />
    481481            <group title="Installer Utilities" packages="net.i2p.installer" />
  • core/java/src/net/i2p/kademlia/KBucket.java

    rffa03f2 r796a231  
    1818 *
    1919 * Refactored from net.i2p.router.networkdb.kademlia
    20  * @since 0.9.2
     20 * @since 0.9.2 in i2psnark, moved to core in 0.9.10
    2121 */
    2222public interface KBucket<T extends SimpleDataStructure> {
  • core/java/src/net/i2p/kademlia/KBucketImpl.java

    rffa03f2 r796a231  
    4242 *
    4343 *  Refactored from net.i2p.router.networkdb.kademlia
    44  *  @since 0.9.2
     44 *  @since 0.9.2 in i2psnark, moved to core in 0.9.10
    4545 */
    4646class KBucketImpl<T extends SimpleDataStructure> implements KBucket<T> {
  • core/java/src/net/i2p/kademlia/KBucketSet.java

    rffa03f2 r796a231  
    3636 *
    3737 * Refactored from net.i2p.router.networkdb.kademlia
    38  * @since 0.9.2
     38 * @since 0.9.2 in i2psnark, moved to core in 0.9.10
    3939 */
    4040public class KBucketSet<T extends SimpleDataStructure> {
  • core/java/src/net/i2p/kademlia/KBucketTrimmer.java

    rffa03f2 r796a231  
    55/**
    66 *  Called when a kbucket can no longer be split and is too big
    7  *  @since 0.9.2
     7 *  @since 0.9.2 in i2psnark, moved to core in 0.9.10
    88 */
    99public interface KBucketTrimmer<K extends SimpleDataStructure> {
  • core/java/src/net/i2p/kademlia/RandomIfOldTrimmer.java

    rffa03f2 r796a231  
    66/**
    77 *  Removes a random element, but only if the bucket hasn't changed in 5 minutes.
    8  *  @since 0.9.2
     8 *  @since 0.9.2 in i2psnark, moved to core in 0.9.10
    99 */
    1010public class RandomIfOldTrimmer<T extends SimpleDataStructure> extends RandomTrimmer<T> {
  • core/java/src/net/i2p/kademlia/RandomTrimmer.java

    rffa03f2 r796a231  
    99/**
    1010 *  Removes a random element. Not resistant to flooding.
    11  *  @since 0.9.2
     11 *  @since 0.9.2 in i2psnark, moved to core in 0.9.10
    1212 */
    1313public class RandomTrimmer<T extends SimpleDataStructure> implements KBucketTrimmer<T> {
  • core/java/src/net/i2p/kademlia/RejectTrimmer.java

    rffa03f2 r796a231  
    55/**
    66 *  Removes nothing and always rejects the add. Flood resistant..
    7  *  @since 0.9.2
     7 *  @since 0.9.2 in i2psnark, moved to core in 0.9.10
    88 */
    99public class RejectTrimmer<T extends SimpleDataStructure> implements KBucketTrimmer<T> {
  • core/java/src/net/i2p/kademlia/SelectionCollector.java

    rffa03f2 r796a231  
    55/**
    66 * Visit kbuckets, gathering matches
    7  * @since 0.9.2
     7 * @since 0.9.2 in i2psnark, moved to core in 0.9.10
    88 */
    99public interface SelectionCollector<T extends SimpleDataStructure> {
  • core/java/src/net/i2p/kademlia/XORComparator.java

    rffa03f2 r796a231  
    88 * Help sort Hashes in relation to a base key using the XOR metric
    99 *
    10  * @since 0.9.2
     10 * @since 0.9.2 in i2psnark, moved to core in 0.9.10
    1111 */
    12 class XORComparator<T extends SimpleDataStructure> implements Comparator<T> {
     12public class XORComparator<T extends SimpleDataStructure> implements Comparator<T> {
    1313    private final byte[] _base;
    1414
  • core/java/src/net/i2p/kademlia/package.html

    rffa03f2 r796a231  
    22This is a major rewrite of KBucket, KBucketSet, and KBucketImpl from net.i2p.router.networkdb.kademlia.
    33The classes are now generic to support SHA1. SHA256, or other key lengths.
    4 The long-term goal is to prove out this new implementation in i2psnark,
    5 then move it to core, then convert the network database to use it.
     4Packaged in i2psnark since 0.9.2, and moved to core in 0.9.10
     5so the network database can use it.
    66</p></body></html>
  • router/java/src/net/i2p/router/NetworkDatabaseFacade.java

    rffa03f2 r796a231  
    7575    public boolean isInitialized() { return true; }
    7676    public void rescan() {}
    77     /** @deprecated moved to router console */
     77
     78    /** Debug only - all user info moved to NetDbRenderer in router console */
    7879    public void renderStatusHTML(Writer out) throws IOException {}
    7980    /** public for NetDbRenderer in routerconsole */
  • router/java/src/net/i2p/router/networkdb/kademlia/ExploreJob.java

    rffa03f2 r796a231  
    1616import net.i2p.data.TunnelId;
    1717import net.i2p.data.i2np.DatabaseLookupMessage;
     18import net.i2p.kademlia.KBucketSet;
    1819import net.i2p.router.RouterContext;
    1920import net.i2p.util.Log;
     
    9899        }
    99100
    100         KBucketSet ks = _facade.getKBuckets();
     101        KBucketSet<Hash> ks = _facade.getKBuckets();
    101102        Hash rkey = getContext().routingKeyGenerator().getRoutingKey(getState().getTarget());
    102103        // in a few releases, we can (and should) remove this,
  • router/java/src/net/i2p/router/networkdb/kademlia/ExploreKeySelectorJob.java

    rffa03f2 r796a231  
    99 */
    1010
     11import java.util.Collection;
    1112import java.util.HashSet;
    1213import java.util.Iterator;
     
    1415
    1516import net.i2p.data.Hash;
     17import net.i2p.kademlia.KBucket;
     18import net.i2p.kademlia.KBucketSet;
    1619import net.i2p.router.JobImpl;
    1720import net.i2p.router.RouterContext;
     
    3033   
    3134    private final static long RERUN_DELAY_MS = 60*1000;
     35    private final static long OLD_BUCKET_TIME = 15*60*1000;
    3236   
    3337    public ExploreKeySelectorJob(RouterContext context, KademliaNetworkDatabaseFacade facade) {
     
    4347            return;
    4448        }
    45         Set<Hash> toExplore = selectKeysToExplore();
     49        Collection<Hash> toExplore = selectKeysToExplore();
    4650        _log.info("Filling the explorer pool with: " + toExplore);
    4751        if (toExplore != null)
     
    5559     *
    5660     */
    57     private Set<Hash> selectKeysToExplore() {
     61    private Collection<Hash> selectKeysToExplore() {
    5862        Set<Hash> alreadyQueued = _facade.getExploreKeys();
    59         if (alreadyQueued.size() > KBucketSet.NUM_BUCKETS) return null;
    60         Set<Hash> toExplore = new HashSet<Hash>(KBucketSet.NUM_BUCKETS - alreadyQueued.size());
    61         for (int i = 0; i < KBucketSet.NUM_BUCKETS; i++) {
    62             KBucket bucket = _facade.getKBuckets().getBucket(i);
    63             if (bucket.getKeyCount() < KBucketSet.BUCKET_SIZE) {
    64                 boolean already = false;
    65                 for (Iterator<Hash> iter = alreadyQueued.iterator(); iter.hasNext(); ) {
    66                     Hash key = iter.next();
    67                     if (bucket.shouldContain(key)) {
    68                         already = true;
    69                         _log.debug("Bucket " + i + " is already queued for exploration \t" + key);
    70                         break;
    71                     }
    72                 }
    73                 if (!already) {
    74                     // no keys are queued for exploring this still-too-small bucket yet
    75                     Hash key = bucket.generateRandomKey();
    76                     _log.debug("Bucket " + i + " is NOT queued for exploration, and it only has " + bucket.getKeyCount() + " keys, so explore with \t" + key);
    77                     toExplore.add(key);
    78                 }
    79             } else {
    80                 _log.debug("Bucket " + i + " already has enough keys (" + bucket.getKeyCount() + "), no need to explore further");
    81             }
    82         }
    83         return toExplore;
     63        if (alreadyQueued.size() > KademliaNetworkDatabaseFacade.MAX_EXPLORE_QUEUE)
     64            return null;
     65        return _facade.getKBuckets().getExploreKeys(OLD_BUCKET_TIME);
    8466    }
    8567   
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodOnlySearchJob.java

    rffa03f2 r796a231  
    99import net.i2p.data.Hash;
    1010import net.i2p.data.i2np.DatabaseLookupMessage;
     11import net.i2p.kademlia.KBucketSet;
    1112import net.i2p.router.Job;
    1213import net.i2p.router.MessageSelector;
     
    7172        // new
    7273        List<Hash> floodfillPeers;
    73         KBucketSet ks = _facade.getKBuckets();
     74        KBucketSet<Hash> ks = _facade.getKBuckets();
    7475        if (ks != null) {
    7576            Hash rkey = getContext().routingKeyGenerator().getRoutingKey(_key);
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

    rffa03f2 r796a231  
    2121import net.i2p.data.RouterAddress;
    2222import net.i2p.data.RouterInfo;
     23import net.i2p.kademlia.KBucketSet;
     24import net.i2p.kademlia.SelectionCollector;
     25import net.i2p.kademlia.XORComparator;
    2326import net.i2p.router.RouterContext;
    2427import net.i2p.router.peermanager.PeerProfile;
     
    5457     */
    5558    @Override
    56     List<Hash> selectMostReliablePeers(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) {
     59    List<Hash> selectMostReliablePeers(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) {
    5760        return selectNearestExplicitThin(key, maxNumRouters, peersToIgnore, kbuckets, true);
    5861    }
     
    6972     */
    7073    @Override
    71     List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) {
     74    List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) {
    7275        return selectNearestExplicitThin(key, maxNumRouters, peersToIgnore, kbuckets, false);
    7376    }
     
    8285     * @return List of Hash for the peers selected
    8386     */
    84     List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets, boolean preferConnected) {
     87    List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets, boolean preferConnected) {
    8588        if (peersToIgnore == null)
    8689            peersToIgnore = Collections.singleton(_context.routerHash());
     
    105108     *  List is not sorted and not shuffled.
    106109     */
    107     List<Hash> selectFloodfillParticipants(KBucketSet kbuckets) {
     110    List<Hash> selectFloodfillParticipants(KBucketSet<Hash> kbuckets) {
    108111        Set<Hash> ignore = Collections.singleton(_context.routerHash());
    109112        return selectFloodfillParticipants(ignore, kbuckets);
     
    117120     *  List is not sorted and not shuffled.
    118121     */
    119     private List<Hash> selectFloodfillParticipants(Set<Hash> toIgnore, KBucketSet kbuckets) {
     122    private List<Hash> selectFloodfillParticipants(Set<Hash> toIgnore, KBucketSet<Hash> kbuckets) {
    120123      /*****
    121124        if (kbuckets == null) return Collections.EMPTY_LIST;
     
    156159     *  Group 3: All others
    157160     */
    158     List<Hash> selectFloodfillParticipants(Hash key, int maxNumRouters, KBucketSet kbuckets) {
     161    List<Hash> selectFloodfillParticipants(Hash key, int maxNumRouters, KBucketSet<Hash> kbuckets) {
    159162        Set<Hash> ignore = Collections.singleton(_context.routerHash());
    160163        return selectFloodfillParticipants(key, maxNumRouters, ignore, kbuckets);
     
    176179     *  @param kbuckets now unused
    177180     */
    178     List<Hash> selectFloodfillParticipants(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet kbuckets) {
     181    List<Hash> selectFloodfillParticipants(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet<Hash> kbuckets) {
    179182        if (toIgnore == null) {
    180183            toIgnore = Collections.singleton(_context.routerHash());
     
    194197     *  @param kbuckets now unused
    195198     */
    196     private List<Hash> selectFloodfillParticipantsIncludingUs(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet kbuckets) {
     199    private List<Hash> selectFloodfillParticipantsIncludingUs(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet<Hash> kbuckets) {
    197200        List<Hash> ffs = selectFloodfillParticipants(toIgnore, kbuckets);
    198         TreeSet<Hash> sorted = new TreeSet<Hash>(new XORComparator(key));
     201        TreeSet<Hash> sorted = new TreeSet<Hash>(new XORComparator<Hash>(key));
    199202        sorted.addAll(ffs);
    200203
     
    340343    }
    341344
    342     private class FloodfillSelectionCollector implements SelectionCollector {
     345    private class FloodfillSelectionCollector implements SelectionCollector<Hash> {
    343346        private final TreeSet<Hash> _sorted;
    344347        private final List<Hash>  _floodfillMatches;
     
    355358        public FloodfillSelectionCollector(Hash key, Set<Hash> toIgnore, int wanted) {
    356359            _key = key;
    357             _sorted = new TreeSet<Hash>(new XORComparator(key));
     360            _sorted = new TreeSet<Hash>(new XORComparator<Hash>(key));
    358361            _floodfillMatches = new ArrayList<Hash>(8);
    359362            _toIgnore = toIgnore;
     
    476479     */
    477480    @Override
    478     List<Hash> selectNearest(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) {
     481    List<Hash> selectNearest(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) {
    479482        Hash rkey = _context.routingKeyGenerator().getRoutingKey(key);
    480483        if (peersToIgnore != null && peersToIgnore.contains(Hash.FAKE_HASH)) {
  • router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java

    rffa03f2 r796a231  
    1717import net.i2p.data.i2np.DatabaseLookupMessage;
    1818import net.i2p.data.i2np.I2NPMessage;
     19import net.i2p.kademlia.KBucketSet;
     20import net.i2p.kademlia.XORComparator;
    1921import net.i2p.router.CommSystemFacade;
    2022import net.i2p.router.Job;
     
    9496        _expiration = _timeoutMs + ctx.clock().now();
    9597        _rkey = ctx.routingKeyGenerator().getRoutingKey(key);
    96         _toTry = new TreeSet<Hash>(new XORComparator(_rkey));
     98        _toTry = new TreeSet<Hash>(new XORComparator<Hash>(_rkey));
    9799        _unheardFrom = new HashSet<Hash>(CONCURRENT_SEARCHES);
    98100        _failedPeers = new HashSet<Hash>(TOTAL_SEARCH_LIMIT);
     
    110112        // pick some floodfill peers and send out the searches
    111113        List<Hash> floodfillPeers;
    112         KBucketSet ks = _facade.getKBuckets();
     114        KBucketSet<Hash> ks = _facade.getKBuckets();
    113115        if (ks != null) {
    114116            // Ideally we would add the key to an exclude list, so we don't try to query a ff peer for itself,
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    rffa03f2 r796a231  
    1010
    1111import java.io.IOException;
     12import java.io.Writer;
     13import java.util.Collection;
    1214import java.util.Collections;
    1315import java.util.Date;
     
    2628import net.i2p.data.i2np.DatabaseLookupMessage;
    2729import net.i2p.data.i2np.DatabaseStoreMessage;
     30import net.i2p.kademlia.KBucketSet;
     31import net.i2p.kademlia.RejectTrimmer;
     32import net.i2p.kademlia.SelectionCollector;
    2833import net.i2p.router.Job;
    2934import net.i2p.router.NetworkDatabaseFacade;
     
    4247public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
    4348    protected final Log _log;
    44     private KBucketSet _kb; // peer hashes sorted into kbuckets, but within kbuckets, unsorted
     49    private KBucketSet<Hash> _kb; // peer hashes sorted into kbuckets, but within kbuckets, unsorted
    4550    private DataStore _ds; // hash to DataStructure mapping, persisted when necessary
    4651    /** where the data store is pushing the data */
     
    133138    protected final static long PUBLISH_JOB_DELAY = 5*60*1000l;
    134139
    135     private static final int MAX_EXPLORE_QUEUE = 128;
     140    static final int MAX_EXPLORE_QUEUE = 128;
     141
     142    /**
     143     *  kad K
     144     *  Was 500 in old implementation but that was with B ~= -8!
     145     */
     146    private static final int BUCKET_SIZE = 16;
     147    private static final int KAD_B = 3;
    136148
    137149    public KademliaNetworkDatabaseFacade(RouterContext context) {
     
    169181    }
    170182
    171     KBucketSet getKBuckets() { return _kb; }
     183    KBucketSet<Hash> getKBuckets() { return _kb; }
    172184    DataStore getDataStore() { return _ds; }
    173185   
     
    186198    }
    187199   
    188     public void removeFromExploreKeys(Set<Hash> toRemove) {
     200    public void removeFromExploreKeys(Collection<Hash> toRemove) {
    189201        if (!_initialized) return;
    190202        _exploreKeys.removeAll(toRemove);
     
    192204    }
    193205
    194     public void queueForExploration(Set<Hash> keys) {
     206    public void queueForExploration(Collection<Hash> keys) {
    195207        if (!_initialized) return;
    196208        for (Iterator<Hash> iter = keys.iterator(); iter.hasNext() && _exploreKeys.size() < MAX_EXPLORE_QUEUE; ) {
     
    241253        RouterInfo ri = _context.router().getRouterInfo();
    242254        String dbDir = _context.getProperty(PROP_DB_DIR, DEFAULT_DB_DIR);
    243         _kb = new KBucketSet(_context, ri.getIdentity().getHash());
     255        _kb = new KBucketSet<Hash>(_context, ri.getIdentity().getHash(),
     256                                   BUCKET_SIZE, KAD_B, new RejectTrimmer<Hash>());
    244257        try {
    245258            _ds = new PersistentDataStore(_context, dbDir, this);
     
    369382    }
    370383   
    371     private class CountRouters implements SelectionCollector {
     384    private class CountRouters implements SelectionCollector<Hash> {
    372385        private int _count;
    373386        public int size() { return _count; }
     
    10431056        _context.jobQueue().addJob(new StoreJob(_context, this, key, ds, onSuccess, onFailure, sendTimeout, toIgnore));
    10441057    }
     1058
     1059    /**
     1060     * Debug info, HTML formatted
     1061     * @since 0.9.10
     1062     */
     1063    @Override
     1064    public void renderStatusHTML(Writer out) throws IOException {
     1065        out.write(_kb.toString().replace("\n", "<br>\n"));
     1066    }
    10451067}
  • router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java

    rffa03f2 r796a231  
    1818import net.i2p.data.Hash;
    1919import net.i2p.data.RouterInfo;
     20import net.i2p.kademlia.KBucketSet;
     21import net.i2p.kademlia.SelectionCollector;
    2022import net.i2p.router.RouterContext;
    2123import net.i2p.router.util.HashDistance;
     
    4244     * @return ordered list of Hash objects
    4345     */
    44     List<Hash> selectMostReliablePeers(Hash key, int numClosest, Set<Hash> alreadyChecked, KBucketSet kbuckets) {
     46    List<Hash> selectMostReliablePeers(Hash key, int numClosest, Set<Hash> alreadyChecked, KBucketSet<Hash> kbuckets) {
    4547        // get the peers closest to the key
    4648        return selectNearestExplicit(key, numClosest, alreadyChecked, kbuckets);
     
    5557     * @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined)
    5658     */
    57     List<Hash> selectNearestExplicit(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) {
     59    List<Hash> selectNearestExplicit(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) {
    5860        //if (true)
    5961            return selectNearestExplicitThin(key, maxNumRouters, peersToIgnore, kbuckets);
     
    9597     * @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined)
    9698     */
    97     List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) {
     99    List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) {
    98100        if (peersToIgnore == null)
    99101            peersToIgnore = new HashSet<Hash>(1);
     
    110112   
    111113    /** UNUSED */
    112     private class MatchSelectionCollector implements SelectionCollector {
     114    private class MatchSelectionCollector implements SelectionCollector<Hash> {
    113115        private TreeMap<BigInteger, Hash> _sorted;
    114116        private Hash _key;
     
    201203     * @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined)
    202204     */
    203     List<Hash> selectNearest(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet kbuckets) {
     205    List<Hash> selectNearest(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) {
    204206        // sure, this may not be exactly correct per kademlia (peers on the border of a kbucket in strict kademlia
    205207        // would behave differently) but I can see no reason to keep around an /additional/ more complicated algorithm.
  • router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java

    rffa03f2 r796a231  
    1111
    1212import net.i2p.data.Hash;
     13import net.i2p.kademlia.XORComparator;
    1314import net.i2p.router.RouterContext;
    1415
     
    6263        if (_attemptedPeers.size() <= max)
    6364            return new HashSet<Hash>(_attemptedPeers);
    64         TreeSet<Hash> closest = new TreeSet<Hash>(new XORComparator(target));
     65        TreeSet<Hash> closest = new TreeSet<Hash>(new XORComparator<Hash>(target));
    6566        closest.addAll(_attemptedPeers);
    6667        Set<Hash> rv = new HashSet<Hash>(max);
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    rffa03f2 r796a231  
    2020import net.i2p.data.i2np.DatabaseStoreMessage;
    2121import net.i2p.data.i2np.I2NPMessage;
     22import net.i2p.kademlia.KBucketSet;
    2223import net.i2p.router.Job;
    2324import net.i2p.router.JobImpl;
     
    234235    private List<Hash> getClosestFloodfillRouters(Hash key, int numClosest, Set<Hash> alreadyChecked) {
    235236        Hash rkey = getContext().routingKeyGenerator().getRoutingKey(key);
    236         KBucketSet ks = _facade.getKBuckets();
     237        KBucketSet<Hash> ks = _facade.getKBuckets();
    237238        if (ks == null) return new ArrayList<Hash>();
    238239        return ((FloodfillPeerSelector)_peerSelector).selectFloodfillParticipants(rkey, numClosest, alreadyChecked, ks);
Note: See TracChangeset for help on using the changeset viewer.