-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Balanced peers in kademlia #1207
Conversation
951d6ae
to
3ef78a6
Compare
/run beekeeper |
3ef78a6
to
eeb6974
Compare
/run beekeeper |
Looks good. Let's merge this after the release tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some occurences of a problem with check lengths, probably we should add some simple test as well that could show this
pkg/kademlia/kademlia.go
Outdated
// check proximity | ||
closestConnectedPO := swarm.Proximity(closestConnectedPeer.Bytes(), pseudoAddr.Bytes()) | ||
|
||
if int(closestConnectedPO) < i+k.bitSuffixLength { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need i + k.bitSuffixLength + 1 here because of the extra flipped bit in the common address
Also in line 284
pkg/kademlia/kademlia.go
Outdated
|
||
closestKnownPeerPO := swarm.Proximity(closestKnownPeer.Bytes(), pseudoAddr.Bytes()) | ||
|
||
if int(closestKnownPeerPO) != i+k.bitSuffixLength { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be < i+k.bitSuffixLength+1
pkg/kademlia/kademlia.go
Outdated
for i := range k.commonBinPrefixes[bin] { | ||
pseudoAddr := k.commonBinPrefixes[bin][i] | ||
|
||
err := k.connectedPeers.EachBinRev(func(peer swarm.Address, po uint8) (bool, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be substituted with checking proximity of closest connected peer
pkg/kademlia/kademlia.go
Outdated
return false | ||
} | ||
|
||
binCheckBitLen := int(bin) + k.bitSuffixLength |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be int(bin) + k.bitSuffixLength + 1 because of flipped bit in common addresses
@metacertain let's do a revision of the branch before merging it |
ea9e15d
to
fc6c168
Compare
So one other thing that was missing, is that actually we need an extended Proximity function that has a higher limit than MaxPO I think we can merge this now! |
/run beekeeper |
7e94c9f
to
c527b92
Compare
/run beekeeper |
c527b92
to
9b3ca1d
Compare
/run beekeeper |
9b3ca1d
to
bf19793
Compare
bf19793
to
99f8957
Compare
relates to: #57
Using base address for starting node of
00000000
rest of description is made here.For that base address we have following (random) addresses for different proximities (first 8 here):
Bits in common are what defines bin of some other address in relation to base address.
To have some sort of balancing, we try to have some dispersion of addresses for each bin (proximity).
We define this as bit suffix for bin, and if should be number > 0. If we set it to
1
we would have 2 possibilities, with2
we have 4, with3
we have 8, and so on.For 2 following suffixes are produced for address:
Using this config, for each bin we generate table of "balanced" addresses toward which we aspire to have connections to (this is generated on Kademlia instantiation and is based on node 'base' address). We use prefix for each bin as a staring point, and to it we append each of these suffixes, to create pseudo address prefixes:
The additional bit in these examples comes after the prefix, and is opposite of the bit of the one in the base address. Index of that bit is at
PO + 1
.With these prepared "balanced" address prefixes, for each bin we can check if we have balanced connections. We also use this information to decide if we want to connect to some other known peer in order to have balanced connected state.
The algorithm to determine if we need to connect to some other peer is done by:
This process is added as separate function just before existing process for connecting to peers in Kademlia, which looks at neighborhood depth to decide if more peer connections need to be made.