From 2adcc31bb48af0dee979f2b4ab255d9af21fd097 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 27 Apr 2015 00:50:18 +0200 Subject: p2p/discover: new distance metric based on sha3(id) The previous metric was pubkey1^pubkey2, as specified in the Kademlia paper. We missed that EC public keys are not uniformly distributed. Using the hash of the public keys addresses that. It also makes it a bit harder to generate node IDs that are close to a particular node. --- p2p/discover/udp.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'p2p/discover/udp.go') diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 100a24e69..7213325da 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -65,10 +65,9 @@ type ( Expiration uint64 // Absolute timestamp at which the packet becomes invalid. } + // findnode is a query for nodes close to the given target. findnode struct { - // Id to look up. The responding node will send back nodes - // closest to the target. - Target NodeID + Target NodeID // doesn't need to be an actual public key Expiration uint64 } @@ -500,8 +499,9 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte // (which is a much bigger packet than findnode) to the victim. return errUnknownNode } + target := crypto.Sha3Hash(req.Target[:]) t.mutex.Lock() - closest := t.closest(req.Target, bucketSize).entries + closest := t.closest(target, bucketSize).entries t.mutex.Unlock() // TODO: this conversion could use a cached version of the slice -- cgit