diff options
author | Felix Lange <fjl@twurst.com> | 2015-04-27 06:50:18 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-05-06 22:10:41 +0800 |
commit | 2adcc31bb48af0dee979f2b4ab255d9af21fd097 (patch) | |
tree | e13845f15c96a87ac0fc9345f3a0ee90cfd006da /p2p/discover/udp.go | |
parent | d457a1187dbbbf08bcce437789732dab02a73b0f (diff) | |
download | go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.tar go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.tar.gz go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.tar.bz2 go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.tar.lz go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.tar.xz go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.tar.zst go-tangerine-2adcc31bb48af0dee979f2b4ab255d9af21fd097.zip |
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.
Diffstat (limited to 'p2p/discover/udp.go')
-rw-r--r-- | p2p/discover/udp.go | 8 |
1 files changed, 4 insertions, 4 deletions
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 |