From aea77cf225b17c627c3c75808b2b9ae65d756d76 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Mon, 10 May 2010 14:50:55 +0000 Subject: [PATCH] * NetDB: Move getDistance() to its own class --- .../networkdb/kademlia/HashDistance.java | 27 +++++++++++++++++++ .../tunnel/pool/TunnelPeerSelector.java | 6 ++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 router/java/src/net/i2p/router/networkdb/kademlia/HashDistance.java diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/HashDistance.java b/router/java/src/net/i2p/router/networkdb/kademlia/HashDistance.java new file mode 100644 index 0000000000..eb6ed1c743 --- /dev/null +++ b/router/java/src/net/i2p/router/networkdb/kademlia/HashDistance.java @@ -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); + } +} diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java index b2343aedb5..bb22ab0e44 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java @@ -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); } } -- GitLab