Struct sc_peerset::PeerId
source · [−]pub struct PeerId { /* private fields */ }
Expand description
Identifier of a peer of the network.
The data is a multihash of the public key of the peer.
Implementations
sourceimpl PeerId
impl PeerId
sourcepub fn from_public_key(key: PublicKey) -> PeerId
pub fn from_public_key(key: PublicKey) -> PeerId
Builds a PeerId
from a public key.
sourcepub fn from_multihash(
multihash: Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
) -> Result<PeerId, Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>
pub fn from_multihash(
multihash: Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
) -> Result<PeerId, Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>
Tries to turn a Multihash
into a PeerId
.
If the multihash does not use a valid hashing algorithm for peer IDs,
or the hash value does not satisfy the constraints for a hashed
peer ID, it is returned as an Err
.
sourcepub fn random() -> PeerId
pub fn random() -> PeerId
Generates a random peer ID from a cryptographically secure PRNG.
This is useful for randomly walking on a DHT, or for testing purposes.
sourcepub fn to_bytes(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn to_bytes(&self) -> Vec<u8, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns a raw bytes representation of this PeerId
.
sourcepub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool>
pub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool>
Checks whether the public key passed as parameter matches the public key of this PeerId
.
Returns None
if this PeerId
s hash algorithm is not supported when encoding the
given public key, otherwise Some
boolean as the result of an equality check.
Trait Implementations
sourceimpl AsRef<Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for PeerId
impl AsRef<Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for PeerId
sourceimpl Ord for PeerId
impl Ord for PeerId
sourceimpl PartialOrd<PeerId> for PeerId
impl PartialOrd<PeerId> for PeerId
sourcepub fn partial_cmp(&self, other: &PeerId) -> Option<Ordering>
pub fn partial_cmp(&self, other: &PeerId) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryFrom<Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for PeerId
impl TryFrom<Multihash<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for PeerId
impl Copy for PeerId
impl Eq for PeerId
impl StructuralEq for PeerId
impl StructuralPartialEq for PeerId
Auto Trait Implementations
impl RefUnwindSafe for PeerId
impl Send for PeerId
impl Sync for PeerId
impl Unpin for PeerId
impl UnwindSafe for PeerId
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more