* NetDB: Move getDistance() to its own class

This commit is contained in:
zzz
2010-05-10 14:50:55 +00:00
parent a1e3ef9c5c
commit aea77cf225
2 changed files with 30 additions and 3 deletions

View File

@ -0,0 +1,27 @@
package net.i2p.router.networkdb.kademlia;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.math.BigInteger;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
/**
* Moved from PeerSelector
* @since 0.7.14
*/
public class HashDistance {
public static BigInteger getDistance(Hash targetKey, Hash routerInQuestion) {
// plain XOR of the key and router
byte diff[] = DataHelper.xor(routerInQuestion.getData(), targetKey.getData());
return new BigInteger(1, diff);
}
}

View File

@ -19,7 +19,7 @@ import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.networkdb.kademlia.PeerSelector;
import net.i2p.router.networkdb.kademlia.HashDistance;
import net.i2p.util.Log;
/**
@ -505,8 +505,8 @@ public abstract class TunnelPeerSelector {
Hash lh = SHA256Generator.getInstance().calculateHash(data);
System.arraycopy(((Hash) r).getData(), 0, data, 0, Hash.HASH_LENGTH);
Hash rh = SHA256Generator.getInstance().calculateHash(data);
BigInteger ll = PeerSelector.getDistance(_hash, lh);
BigInteger rr = PeerSelector.getDistance(_hash, rh);
BigInteger ll = HashDistance.getDistance(_hash, lh);
BigInteger rr = HashDistance.getDistance(_hash, rh);
return ll.compareTo(rr);
}
}