Skip to main content

PeerEntry

Struct PeerEntry 

Source
pub struct PeerEntry {
    pub peer_id: String,
    pub addresses: Vec<Address>,
    pub network_id: String,
    pub last_seen: u64,
    pub via: Provenance,
    pub flags: Vec<String>,
    pub payment: Option<PaymentClaim>,
}
Expand description

The unit of exchange — a peer entry (SPEC §3). Constructed via PeerEntry::new + the builder methods for outgoing advertisements; decoded tolerantly for inbound validation.

Fields§

§peer_id: String

The advertised peer’s mTLS identity, <64hex>.

§addresses: Vec<Address>

Candidate addresses, most-direct-first. MAY be empty (reachable only via shared infrastructure, e.g. relay rendezvous by peer_id; see the relay-only flag).

§network_id: String

The network the peer belongs to. MUST equal the link’s network.

§last_seen: u64

Unix seconds when the advertiser last had first-hand evidence of the peer (SPEC §8.2).

§via: Provenance

The advertiser’s provenance for this entry (SPEC §8.1).

§flags: Vec<String>

Per-peer capability flags (SPEC §3.2). Optional; defaults to empty.

§payment: Option<PaymentClaim>

The peer’s self-signed payment address (SPEC §3.4). Optional and omitted entirely when absent, so a record stays readable by peers predating the field.

Read it with verified_payment_address — the claim’s own fields are private precisely so an unchecked payee cannot be obtained from it.

Implementations§

Source§

impl PeerEntry

Source

pub fn new( peer_id: impl Into<String>, network_id: impl Into<String>, last_seen: u64, via: Provenance, ) -> Self

A new entry for peer_id on network_id, last seen at last_seen (Unix seconds), with provenance via. Add addresses/flags with the builder methods.

Source

pub fn with_address(self, addr: Address) -> Self

Builder: append a candidate address.

Source

pub fn with_flag(self, flag: impl Into<String>) -> Self

Builder: append a capability flag token.

Source

pub fn with_payment(self, claim: PaymentClaim) -> Self

Builder: attach the peer’s self-signed payment claim (SPEC §3.4).

Source

pub fn verified_payment_address( &self, verifier: &impl SignatureVerifier, ) -> Result<&str, PaymentClaimError>

The peer’s payment address, only when the attached claim proves this peer designated it on this entry’s network (SPEC §3.4.3); otherwise the reason there is no payee.

This is deliberately a different question from whether the entry is usable at all: an entry whose claim fails here is still a perfectly good dial hint (see validate), because letting a corrupted payee cost a peer its reachability would hand a relaying attacker a way to partition it. Reachability and payability are two verdicts on one record, and they are answered by two different methods.

verifier supplies the signature primitive for the peer’s key type (SPEC §3.4.3); the SHA-256(SPKI) == peer_id binding is checked by this crate regardless of what the verifier does.

Source

pub fn validate(&self, ctx: &ValidateCtx<'_>) -> Result<(), EntrySkip>

Validate this entry against the receiver’s link context (SPEC §3.3). Returns the reason a conformant receiver skips it, or Ok(()) to keep it. Skipping is silent — no strike.

Source

pub fn clamped(&self, now_secs: u64) -> PeerEntry

A copy with a future last_seen clamped to now_secs (SPEC §3.3 — a receiver SHOULD clamp a last_seen in the future to its own clock).

Source

pub fn fingerprint(&self) -> String

The per-link advertised-content fingerprint — a stable string over the addresses and flags excluding last_seen (SPEC §9.1), so heartbeat churn (a fresher last_seen alone) never re-advertises an unchanged peer. Two entries with the same fingerprint are “the same advertisement” for delta purposes.

This allocates (a Vec<String> per call plus the final formatted String) and is intended for display/debugging/tests. The delta hot path uses the allocation-free fingerprint_hash instead (#179 MED optimization).

Source

pub fn fingerprint_hash(&self) -> u64

The allocation-free equivalent of fingerprint: a 64-bit hash over the same canonical content (addresses + flags, sorted, excluding last_seen) with the same equality semantics — two entries with equal fingerprint() strings MUST have equal fingerprint_hash() values (and vice versa for practical purposes; a hash collision is possible but not a correctness concern for this delta-suppression use). Used as the told-map value (SPEC §9.1) so the per-tick, per-link delta comparison is a Copy, allocation-free u64 equality check instead of building + sorting + formatting a String per advertisable entry per link per tick (#179 MED optimization).

Sorts addresses/flags by reference (Vec<&Address> / Vec<&str>, no cloning) before feeding a stable field-separated byte stream to the hasher, so the result is independent of input order while never allocating an intermediate String.

Trait Implementations§

Source§

impl Clone for PeerEntry

Source§

fn clone(&self) -> PeerEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PeerEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PeerEntry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for PeerEntry

Source§

impl PartialEq for PeerEntry

Source§

fn eq(&self, other: &PeerEntry) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for PeerEntry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for PeerEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V