pub struct RoutingEntry {
pub peer_id: String,
pub multiaddrs: Vec<String>,
pub latency_ms: Option<u64>,
pub last_seen: Instant,
pub ttl: Duration,
}Expand description
A single provider record held inside the routing table.
Fields§
§peer_id: StringLibp2p peer identifier (string form).
multiaddrs: Vec<String>Known multiaddrs for this peer.
latency_ms: Option<u64>Observed round-trip latency in milliseconds, if measured.
last_seen: InstantMonotonic timestamp of the last time this entry was refreshed.
ttl: DurationHow long this entry remains valid after creation / refresh.
Implementations§
Source§impl RoutingEntry
impl RoutingEntry
Sourcepub fn new(peer_id: String, multiaddrs: Vec<String>) -> Self
pub fn new(peer_id: String, multiaddrs: Vec<String>) -> Self
Create a new entry with default TTL and no latency measurement.
Sourcepub fn with_ttl(peer_id: String, multiaddrs: Vec<String>, ttl: Duration) -> Self
pub fn with_ttl(peer_id: String, multiaddrs: Vec<String>, ttl: Duration) -> Self
Create an entry with a custom TTL.
Sourcepub fn with_latency(
peer_id: String,
multiaddrs: Vec<String>,
latency_ms: u64,
ttl: Duration,
) -> Self
pub fn with_latency( peer_id: String, multiaddrs: Vec<String>, latency_ms: u64, ttl: Duration, ) -> Self
Create an entry with observed latency and a custom TTL.
Sourcepub fn affinity_score(&self) -> f64
pub fn affinity_score(&self) -> f64
Compute a floating-point affinity score used for ranking.
Formula:
- Base score: 1.0
- Subtract
0.001 × latency_msif latency is known. - Subtract 0.5 if less than 10 % of the TTL remains.
- Add 0.2 if the entry was seen within the last 5 minutes.
Higher scores rank first.
Sourcepub fn is_expired(&self, now: Instant) -> bool
pub fn is_expired(&self, now: Instant) -> bool
Return true when the entry’s TTL has elapsed relative to now.
Trait Implementations§
Source§impl Clone for RoutingEntry
impl Clone for RoutingEntry
Source§fn clone(&self) -> RoutingEntry
fn clone(&self) -> RoutingEntry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RoutingEntry
impl RefUnwindSafe for RoutingEntry
impl Send for RoutingEntry
impl Sync for RoutingEntry
impl Unpin for RoutingEntry
impl UnsafeUnpin for RoutingEntry
impl UnwindSafe for RoutingEntry
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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