Struct libp2p_core::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(public_key: PublicKey) -> PeerId
pub fn from_public_key(public_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(data: Multihash) -> Result<PeerId, Multihash>
pub fn from_multihash(data: Multihash) -> Result<PeerId, Multihash>
Turns a Multihash into a PeerId. If the multihash doesn’t use the correct algorithm,
returns back the data as an error.
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 that this is not the same as the public key of the peer.
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Returns a raw bytes representation of this PeerId.
Note that this is not the same as the public key of the peer.
sourcepub fn digest(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
pub fn digest(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Returns the raw bytes of the hash 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 PeerIds hash algorithm is not supported when encoding the
given public key, otherwise Some boolean as the result of an equality check.