pub struct Key<T> { /* private fields */ }
Expand description
A Key
is a cryptographic hash, identifying both the nodes participating in
the Kademlia DHT, as well as records stored in the DHT.
The set of all Key
s defines the Kademlia keyspace.
Key
s have an XOR metric as defined in the Kademlia paper, i.e. the bitwise XOR of
the hash digests, interpreted as an integer. See Key::distance
.
A Key
preserves the preimage of type T
of the hash function. See Key::preimage
.
Implementations§
source§impl<T> Key<T>
impl<T> Key<T>
sourcepub fn new_raw(preimage: T, hash: GenericArray<u8, U32>) -> Key<T>
pub fn new_raw(preimage: T, hash: GenericArray<u8, U32>) -> Key<T>
Construct a new Key
by providing the raw 32 byte hash.
sourcepub fn into_preimage(self) -> T
pub fn into_preimage(self) -> T
Converts the key into its preimage.
sourcepub fn distance<U>(&self, other: &Key<U>) -> Distance
pub fn distance<U>(&self, other: &Key<U>) -> Distance
Computes the distance of the keys according to the XOR metric.
sourcepub fn log2_distance<U>(&self, other: &Key<U>) -> Option<u64>
pub fn log2_distance<U>(&self, other: &Key<U>) -> Option<u64>
Computes the integer log-2 distance between two keys, assuming a 256-bit key. The output returns None if the key’s are identical. The range is 1-256.
Trait Implementations§
source§impl<TNodeId, TVal> AsRef<Key<TNodeId>> for ClosestValue<TNodeId, TVal>
impl<TNodeId, TVal> AsRef<Key<TNodeId>> for ClosestValue<TNodeId, TVal>
source§impl<TNodeId, TVal> AsRef<Key<TNodeId>> for PredicateValue<TNodeId, TVal>
impl<TNodeId, TVal> AsRef<Key<TNodeId>> for PredicateValue<TNodeId, TVal>
source§impl<TNodeId> From<PredicateKey<TNodeId>> for Key<TNodeId>
impl<TNodeId> From<PredicateKey<TNodeId>> for Key<TNodeId>
source§fn from(key: PredicateKey<TNodeId>) -> Self
fn from(key: PredicateKey<TNodeId>) -> Self
Converts to this type from the input type.
source§impl<T> PartialEq for Key<T>
impl<T> PartialEq for Key<T>
impl<T> Eq for Key<T>
Auto Trait Implementations§
impl<T> Freeze for Key<T>where
T: Freeze,
impl<T> RefUnwindSafe for Key<T>where
T: RefUnwindSafe,
impl<T> Send for Key<T>where
T: Send,
impl<T> Sync for Key<T>where
T: Sync,
impl<T> Unpin for Key<T>where
T: Unpin,
impl<T> UnwindSafe for Key<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more