nictuku / dht

Kademlia/Mainline DHT node in Go.
Other
826 stars 144 forks source link

Choose closest nodes without calculating distance? #55

Open ltzmaxwell opened 6 years ago

ltzmaxwell commented 6 years ago

It seems that function "lookupFiltered" is only choosing nodes that "wasContactedRecently", without calculating distance, right?

nictuku commented 6 years ago

Hi @ltzMaxwell. It's been a while since I wrote that code, but I assume that lookupFiltered uses traverse, which is by itself the distance calculation method.

Since the tree can be traversed multiple times for the same infohash, we skip the nodes that have been contacted already. So we specifically try to avoid a node that wasContactedRecently.

That's in this line: https://github.com/nictuku/dht/blob/b0d0998de3924b5d8a5f13c314870343b37e3d70/routing.go#L225

So I think the function is working. What do you think?