[−][src]Struct iprs::peer_id::PeerId
Unique identifier of a peer in the network.
Peer IDs are derived by hashing the encoded public-key with multihash.
PublicKey to PeerId:
- Encode the public key as described in the keys section.
- If the length of the serialized bytes is less than or equal to 42, compute the "identity" multihash of the serialized bytes. In other words, no hashing is performed, but the multihash format is still followed. The idea here is that if the serialized byte array is short enough, we can fit it in a multihash verbatim without having to condense it using a hash function.
- If the length is greater than 42, then hash it using it using the SHA256 multihash.
Implementations
impl PeerId
[src]
pub fn from_public_key(key: PublicKey) -> Result<PeerId>
[src]
Builds a PeerId
from a public key.
pub fn generate() -> Result<PeerId>
[src]
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 from_text(text: &str) -> Result<PeerId>
[src]
Decode a base encoded PeerId, human readable text. Peerid format can either be in legacy format (base58btc) or multi-base encoded CID format.
pub fn to_base58btc(&self) -> Result<String>
[src]
Encode peer-id to base58btc format.
pub fn to_base_text(&self, base: Base) -> Result<String>
[src]
Encode peer-id to multi-base encoded CID format.
pub fn encode(&self) -> Result<Vec<u8>>
[src]
Encode PeerId into multihash-binary-format.
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.
pub fn decode(buf: &[u8]) -> Result<(PeerId, &[u8])>
[src]
Decode PeerId from multihash-binary-format.
pub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool>
[src]
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.
pub fn to_short_string(&self) -> String
[src]
Return the peer-id as condensed version of PeerID::to_string().
pub fn to_public_key(&self) -> Result<Option<PublicKey>>
[src]
Sometimes PeerID could be encoded using IDENTITY hash. Which means, unlike when it is encoded as public-key's hash, it is possible to extract the public-key from the peer-id.
Trait Implementations
impl Clone for PeerId
[src]
impl Debug for PeerId
[src]
impl Display for PeerId
[src]
impl Eq for PeerId
[src]
impl From<Multihash> for PeerId
[src]
impl From<PeerId> for Multihash
[src]
impl Hash for PeerId
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<PeerId> for PeerId
[src]
impl StructuralEq for PeerId
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,