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§
Source§impl 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_bytes(data: Vec<u8>) -> Result<PeerId, Vec<u8>>
pub fn from_bytes(data: Vec<u8>) -> Result<PeerId, Vec<u8>>
Checks whether data
is a valid PeerId
. If so, returns the PeerId
. If not, returns
back the data as an error.
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 into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Returns a raw bytes representation of this PeerId
.
NOTE: This byte representation is not necessarily consistent with
equality of peer IDs. That is, two peer IDs may be considered equal
while having a different byte representation as per into_bytes
.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns a raw bytes representation of this PeerId
.
NOTE: This byte representation is not necessarily consistent with
equality of peer IDs. That is, two peer IDs may be considered equal
while having a different byte representation as per as_bytes
.
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§
Source§impl AsRef<[u8]> for PeerId
NOTE: This byte representation is not necessarily consistent with
equality of peer IDs. That is, two peer IDs may be considered equal
while having a different byte representation as per AsRef<[u8]>
.
impl AsRef<[u8]> for PeerId
NOTE: This byte representation is not necessarily consistent with
equality of peer IDs. That is, two peer IDs may be considered equal
while having a different byte representation as per AsRef<[u8]>
.
Source§impl Ord for PeerId
impl Ord for PeerId
Source§impl PartialOrd for PeerId
impl PartialOrd for PeerId
Source§impl 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 Eq for PeerId
Auto Trait Implementations§
impl !Freeze for PeerId
impl RefUnwindSafe for PeerId
impl Send for PeerId
impl Sync for PeerId
impl Unpin for PeerId
impl UnwindSafe for PeerId
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
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more