Struct ipfs_embed::PeerId
[−]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
impl PeerId
impl PeerId
pub fn from_public_key(key: &PublicKey) -> PeerId
pub fn from_public_key(key: &PublicKey) -> PeerId
Builds a PeerId
from a public key.
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error>
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error>
Parses a PeerId
from bytes.
pub fn from_multihash(multihash: Multihash<64>) -> Result<PeerId, Multihash<64>>
pub fn from_multihash(multihash: Multihash<64>) -> Result<PeerId, Multihash<64>>
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
.
pub fn try_from_multiaddr(address: &Multiaddr) -> Option<PeerId>
pub fn try_from_multiaddr(address: &Multiaddr) -> Option<PeerId>
pub 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.
pub 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
.
pub 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
impl AsRef<Multihash<64>> for PeerId
impl AsRef<Multihash<64>> for PeerId
fn as_ref(&self) -> &Multihash<64>
fn as_ref(&self) -> &Multihash<64>
impl Ord for PeerId
impl Ord for PeerId
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
impl PartialOrd<PeerId> for PeerId
impl PartialOrd<PeerId> for PeerId
fn partial_cmp(&self, other: &PeerId) -> Option<Ordering>
fn partial_cmp(&self, other: &PeerId) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more