-
Notifications
You must be signed in to change notification settings - Fork 959
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
[Kademlia] Rehash PeerId before inserting in a KBucketsTable #1025
Conversation
* Document * Move impl
protocols/kad/src/kbucket.rs
Outdated
} | ||
|
||
fn max_distance() -> NonZeroUsize { | ||
<Multihash as KBucketsPeerId>::max_distance() |
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.
If we change the hash to a [u8; 32]
, then that should be 256, and distance_with
adjusted accordingly.
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 have changed this as well. I think we could abstract the xor metric away, but I'm missing a trait for .leading_zeros()
in U512
and U256
. What do you think?
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.
Also for the case where we compare KadHash
and Multihash
I have taken max_distance
to be 512 and converted both hashes to U512
.
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 should split distance_with
and max_distance
in two different traits, something like:
trait MaxDistance: DistanceWith<Self> {
fn max_distance() -> u32;
}
trait DistanceWith<TOther> {
fn distance_with(&self, other: &TOther) -> u32;
}
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 would make that a new PR
We currently use
PeerId
directly as a key into a Kademlia table because it happens to be a hash of the address of a peer. However, the reference implementation uses a hash of the hash. This PR introduces a new struct,KadHash
that is to be used instead as key.There are actually two use cases for
PeerId
: as key into the Kademlia table and as an actual identifier of a peer.KadHash
supports both by storing thePeerId
and the new hash together.Function
Kademlia::initialize()
has become obsolete and has been removed.Function
Kademlia::without_init()
has been marked deprecated.This PR includes minor fixes for warnings.
Addresses: #694