pub struct PeerStats {Show 20 fields
pub peer_id: String,
pub connected_at: Instant,
pub requests_sent: u64,
pub successes: u64,
pub timeouts: u64,
pub failures: u64,
pub srtt_ms: f64,
pub rttvar_ms: f64,
pub rto_ms: u64,
pub consecutive_rto_backoffs: u32,
pub backoff_level: u32,
pub backed_off_until: Option<Instant>,
pub last_success: Option<Instant>,
pub last_failure: Option<Instant>,
pub bytes_received: u64,
pub bytes_sent: u64,
pub cashu_paid_sat: u64,
pub cashu_received_sat: u64,
pub cashu_payment_receipts: u64,
pub cashu_payment_defaults: u64,
}Expand description
Per-peer performance statistics
Fields§
§peer_id: StringPeer identifier
connected_at: InstantWhen this peer was connected
requests_sent: u64Total requests sent to this peer
successes: u64Total successful responses received
timeouts: u64Total timeouts
failures: u64Total failures (bad data, disconnects, etc.)
srtt_ms: f64Smoothed round-trip time (RFC 2988 SRTT)
rttvar_ms: f64RTT variance (RFC 2988 RTTVAR)
rto_ms: u64Retransmission timeout (computed from SRTT and RTTVAR)
consecutive_rto_backoffs: u32Consecutive RTO backoffs (for capping)
backoff_level: u32Current backoff level (how many times we’ve backed off)
backed_off_until: Option<Instant>When backoff expires (None if not backed off)
last_success: Option<Instant>Last successful response timestamp
last_failure: Option<Instant>Last failure timestamp
bytes_received: u64Total bytes received from this peer
bytes_sent: u64Total bytes sent to this peer
cashu_paid_sat: u64Total sats paid to this peer through an external payment channel.
cashu_received_sat: u64Total sats this peer paid us after successful delivery.
cashu_payment_receipts: u64Number of successful post-delivery payments received from this peer.
cashu_payment_defaults: u64Number of times this peer failed to pay after successful delivery.
Implementations§
Source§impl PeerStats
impl PeerStats
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Get success rate (0.0 to 1.0)
Sourcepub fn selection_rate(&self) -> f64
pub fn selection_rate(&self) -> f64
Get selection rate (selections per second since connected)
Sourcepub fn is_backed_off(&self) -> bool
pub fn is_backed_off(&self) -> bool
Check if peer is currently backed off
Sourcepub fn backoff_remaining(&self) -> Duration
pub fn backoff_remaining(&self) -> Duration
Get remaining backoff time
Sourcepub fn record_request(&mut self, bytes: u64)
pub fn record_request(&mut self, bytes: u64)
Record a request being sent
Sourcepub fn record_success(&mut self, rtt_ms: u64, bytes: u64)
pub fn record_success(&mut self, rtt_ms: u64, bytes: u64)
Record a successful response with RTT Uses RFC 2988 algorithm for smoothed RTT calculation
Sourcepub fn record_timeout(&mut self)
pub fn record_timeout(&mut self)
Record a timeout
Sourcepub fn record_failure(&mut self)
pub fn record_failure(&mut self)
Record a failure (bad data, disconnect, etc.)
Sourcepub fn record_cashu_payment(&mut self, amount_sat: u64)
pub fn record_cashu_payment(&mut self, amount_sat: u64)
Record an out-of-band payment to this peer (e.g. Cashu channel transfer).
Sourcepub fn record_cashu_receipt(&mut self, amount_sat: u64)
pub fn record_cashu_receipt(&mut self, amount_sat: u64)
Record a settled payment received from this peer after we served data.
Sourcepub fn record_cashu_payment_default(&mut self)
pub fn record_cashu_payment_default(&mut self)
Record that this peer failed to pay after successful delivery.
Sourcepub fn score(&self) -> f64
pub fn score(&self) -> f64
Calculate peer score for selection (higher is better) Combines success rate, RTT, and recent performance
Sourcepub fn utility_score(&self, total_requests: u64) -> f64
pub fn utility_score(&self, total_requests: u64) -> f64
Utility-centric score with exploration bonus (UCB-style).
Balances:
- good/bad outcome ratio (successes vs failures+timeouts),
- latency efficiency,
- bytes efficiency (received vs sent),
- uncertainty bonus for less-tested peers.
Sourcepub fn tit_for_tat_score(&self, total_requests: u64) -> f64
pub fn tit_for_tat_score(&self, total_requests: u64) -> f64
Tit-for-tat style score:
- reward peers that answer our requests with useful bytes (reciprocity)
- reward reliable responders
- penalize timeout/failure-heavy peers (retaliation)
- keep a small exploration term for under-sampled peers
Sourcepub fn cashu_priority_boost(&self) -> f64
pub fn cashu_priority_boost(&self) -> f64
Normalize paid amount to a bounded priority score in [0, 1).
Sourcepub fn payment_reliability_multiplier(&self) -> f64
pub fn payment_reliability_multiplier(&self) -> f64
Cooperative peers that actually pay us should not be penalized; repeated defaults quickly reduce their desirability.
pub fn exceeds_payment_default_threshold(&self, threshold: u64) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerStats
impl RefUnwindSafe for PeerStats
impl Send for PeerStats
impl Sync for PeerStats
impl Unpin for PeerStats
impl UnsafeUnpin for PeerStats
impl UnwindSafe for PeerStats
Blanket Implementations§
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> 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<'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
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>
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>
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