Skip to main content

PeerStats

Struct PeerStats 

Source
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: String

Peer identifier

§connected_at: Instant

When this peer was connected

§requests_sent: u64

Total requests sent to this peer

§successes: u64

Total successful responses received

§timeouts: u64

Total timeouts

§failures: u64

Total failures (bad data, disconnects, etc.)

§srtt_ms: f64

Smoothed round-trip time (RFC 2988 SRTT)

§rttvar_ms: f64

RTT variance (RFC 2988 RTTVAR)

§rto_ms: u64

Retransmission timeout (computed from SRTT and RTTVAR)

§consecutive_rto_backoffs: u32

Consecutive RTO backoffs (for capping)

§backoff_level: u32

Current 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: u64

Total bytes received from this peer

§bytes_sent: u64

Total bytes sent to this peer

§cashu_paid_sat: u64

Total sats paid to this peer through an external payment channel.

§cashu_received_sat: u64

Total sats this peer paid us after successful delivery.

§cashu_payment_receipts: u64

Number of successful post-delivery payments received from this peer.

§cashu_payment_defaults: u64

Number of times this peer failed to pay after successful delivery.

Implementations§

Source§

impl PeerStats

Source

pub fn new(peer_id: impl Into<String>) -> Self

Create new peer stats

Source

pub fn success_rate(&self) -> f64

Get success rate (0.0 to 1.0)

Source

pub fn selection_rate(&self) -> f64

Get selection rate (selections per second since connected)

Source

pub fn is_backed_off(&self) -> bool

Check if peer is currently backed off

Source

pub fn backoff_remaining(&self) -> Duration

Get remaining backoff time

Source

pub fn record_request(&mut self, bytes: u64)

Record a request being sent

Source

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

Source

pub fn record_timeout(&mut self)

Record a timeout

Source

pub fn record_failure(&mut self)

Record a failure (bad data, disconnect, etc.)

Source

pub fn record_cashu_payment(&mut self, amount_sat: u64)

Record an out-of-band payment to this peer (e.g. Cashu channel transfer).

Source

pub fn record_cashu_receipt(&mut self, amount_sat: u64)

Record a settled payment received from this peer after we served data.

Source

pub fn record_cashu_payment_default(&mut self)

Record that this peer failed to pay after successful delivery.

Source

pub fn score(&self) -> f64

Calculate peer score for selection (higher is better) Combines success rate, RTT, and recent performance

Source

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.
Source

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
Source

pub fn cashu_priority_boost(&self) -> f64

Normalize paid amount to a bounded priority score in [0, 1).

Source

pub fn payment_reliability_multiplier(&self) -> f64

Cooperative peers that actually pay us should not be penalized; repeated defaults quickly reduce their desirability.

Source

pub fn exceeds_payment_default_threshold(&self, threshold: u64) -> bool

Trait Implementations§

Source§

impl Clone for PeerStats

Source§

fn clone(&self) -> PeerStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PeerStats

Source§

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

Formats the value using the given formatter. Read more

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more