Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

network/kademlia: Prioritize closest peer when suggesting peer for neighborhood #1918

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aperonam
Copy link
Contributor

@aperonam aperonam commented Oct 29, 2019

As described in https://github.com/nolash/SWIPs/blob/hive/SWIPs/swip-hive.md, when suggesting peers, if unconected peers in the neighborhood, it should always prioritize connecting to the closest neighbor, e.g

=========================================================================
population: 2 (4), NeighbourhoodSize: 2, MinBinSize: 2, MaxBinSize: 16
============ DEPTH: 0 ==========================================
000  0                              |  1 f800 (0)
001  0                              |  1 7000 (0)
002  1 2000                       |  1 2000 (0)
003  1 1000                       |  1 1000 (0)
004  0                              |  0
005  0                              |  0
006  0                              |  0
007  0                              |  0
008  0                              |  0
009  0                              |  0
010  0                              |  0
011  0                              |  0
012  0                              |  0
013  0                              |  0
014  0                              |  0
015  0                              |  0
========================================================================= 

In this situation , although bin0 is shallower, since both bin1 and bin0 are in the neighborhood, the suggested peer should be for bin1 (closest neighbor)

This PR modifies kademlia SuggestPeers method in order to prioritize connecting to the closest neighbor.
TestSuggestPeer has also been modified to explicitly test this behavior

Fixes #1897

currBinIndex := len(bins) - 1
valIterator := func(val pot.Val, po int) bool {
if po < bins[currBinIndex] {
currBinIndex--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currBinIndex = po?

valIterator := func(val pot.Val, po int) bool {
if po < bins[currBinIndex] {
currBinIndex--
if currBinIndex < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this mean that you continue processing all bins up to 0 in the order nearest to farthest? The ordering should only be up to depth. Shallower than depth the existing algorithm should be used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kademlia sugestPeers should prioritize the closest peer in the neighbourhood
2 participants