I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit aea77cf2 authored by zzz's avatar zzz
Browse files

* NetDB: Move getDistance() to its own class

parent a1e3ef9c
No related branches found
No related tags found
No related merge requests found
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);
}
}
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment