Changeset 5998f5c9


Ignore:
Timestamp:
Mar 7, 2008 11:24:49 PM (13 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b1beb46c
Parents:
0c75725
Message:
  • ClientPeerSelector?: Implement strict ordering of peers, based on XOR distance from a random hash separately generated for each tunnel pool
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    r0c75725 r5998f5c9  
     12008-03-08 zzz
     2    * ClientPeerSelector: Implement strict ordering of peers,
     3      based on XOR distance from a random hash
     4      separately generated for each tunnel pool
     5
    162008-03-07 zzz
    27    * Naming: Optimize lookups for a destkey
  • router/java/src/net/i2p/router/RouterVersion.java

    r0c75725 r5998f5c9  
    1818    public final static String ID = "$Revision: 1.548 $ $Date: 2008-02-10 15:00:00 $";
    1919    public final static String VERSION = "0.6.1.31";
    20     public final static long BUILD = 3203;
     20    public final static long BUILD = 3204;
    2121    public static void main(String args[]) {
    2222        System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
  • router/java/src/net/i2p/router/networkdb/kademlia/PeerSelector.java

    r0c75725 r5998f5c9  
    2626import net.i2p.util.Log;
    2727
    28 class PeerSelector {
     28public class PeerSelector {
    2929    protected Log _log;
    3030    protected RouterContext _context;
     
    181181    }
    182182   
    183     protected BigInteger getDistance(Hash targetKey, Hash routerInQuestion) {
     183    public static BigInteger getDistance(Hash targetKey, Hash routerInQuestion) {
    184184        // plain XOR of the key and router
    185185        byte diff[] = DataHelper.xor(routerInQuestion.getData(), targetKey.getData());
  • router/java/src/net/i2p/router/tunnel/pool/ClientPeerSelector.java

    r0c75725 r5998f5c9  
    2929        matches.remove(ctx.routerHash());
    3030        ArrayList rv = new ArrayList(matches);
    31         // Todo - Rather than shuffle, sort using xor distance from settings.getRandomKey()
    32         Collections.shuffle(rv, ctx.random());
     31        if (rv.size() > 1)
     32            orderPeers(rv, settings.getRandomKey());
    3333        if (settings.isInbound())
    3434            rv.add(0, ctx.routerHash());
  • router/java/src/net/i2p/router/tunnel/pool/ExploratoryPeerSelector.java

    r0c75725 r5998f5c9  
    4444        matches.remove(ctx.routerHash());
    4545        ArrayList rv = new ArrayList(matches);
    46         Collections.shuffle(rv, ctx.random());
     46        if (rv.size() > 1)
     47            orderPeers(rv, settings.getRandomKey());
    4748        if (settings.isInbound())
    4849            rv.add(0, ctx.routerHash());
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java

    r0c75725 r5998f5c9  
    22
    33import java.util.*;
     4import java.math.BigInteger;
    45import net.i2p.I2PAppContext;
    56import net.i2p.data.*;
     
    89import net.i2p.router.TunnelPoolSettings;
    910import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
     11import net.i2p.router.networkdb.kademlia.PeerSelector;
    1012import net.i2p.router.peermanager.PeerProfile;
    1113import net.i2p.util.Log;
     
    450452        return rv;
    451453    }
     454
     455    protected void orderPeers(List rv, Hash hash) {
     456            Collections.sort(rv, new HashComparator(hash));
     457    }
     458
     459    private class HashComparator implements Comparator {
     460        private Hash _hash;
     461
     462        private HashComparator(Hash h) {
     463            _hash = h;
     464        }
     465        public int compare(Object l, Object r) {
     466            BigInteger ll = PeerSelector.getDistance(_hash, (Hash) l);
     467            BigInteger rr = PeerSelector.getDistance(_hash, (Hash) r);
     468            return ll.compareTo(rr);
     469        }
     470    }
    452471}
Note: See TracChangeset for help on using the changeset viewer.