Skip to main content

PeerSelector

Struct PeerSelector 

Source
pub struct PeerSelector { /* private fields */ }
Expand description

Adaptive peer selector

Tracks peer performance and selects peers intelligently:

  • Prefers high success rate peers
  • Prefers low latency peers
  • Backs off failing peers exponentially
  • Ensures fairness (no peer gets >30% of traffic with 5+ peers)

Implementations§

Source§

impl PeerSelector

Source

pub fn new() -> Self

Create a new peer selector with default weighted strategy

Source

pub fn with_strategy(strategy: SelectionStrategy) -> Self

Create with specific strategy

Source

pub fn set_fairness(&mut self, enabled: bool)

Enable/disable fairness constraints

Source

pub fn set_cashu_payment_weight(&mut self, weight: f64)

Configure payment-priority influence when ranking peers. 0.0 disables payment influence and preserves reputation-only behavior.

Source

pub fn add_peer(&mut self, peer_id: impl Into<String>)

Add a peer to track

Source

pub fn remove_peer(&mut self, peer_id: &str)

Remove a peer

Source

pub fn get_stats(&self, peer_id: &str) -> Option<&PeerStats>

Get peer stats (immutable)

Source

pub fn get_stats_mut(&mut self, peer_id: &str) -> Option<&mut PeerStats>

Get peer stats (mutable)

Source

pub fn all_stats(&self) -> impl Iterator<Item = &PeerStats>

Get all peer stats

Source

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

Record a request being sent to a peer

Source

pub fn record_success(&mut self, peer_id: &str, rtt_ms: u64, bytes: u64)

Record a successful response

Source

pub fn record_timeout(&mut self, peer_id: &str)

Record a timeout

Source

pub fn record_failure(&mut self, peer_id: &str)

Record a failure

Source

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

Record payment channel credit for a peer.

Source

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

Record a settled post-delivery payment received from a peer.

Source

pub fn record_cashu_payment_default(&mut self, peer_id: &str)

Record that a peer failed to settle after we delivered successfully.

Source

pub fn is_peer_blocked_for_payment_defaults( &self, peer_id: &str, threshold: u64, ) -> bool

Source

pub fn select_peers(&mut self) -> Vec<String>

Select peers ordered by preference

Returns all available peers sorted by preference (best first). Respects backoff states and fairness constraints.

Source

pub fn select_best(&mut self) -> Option<String>

Select single best peer

Source

pub fn select_top(&mut self, n: usize) -> Vec<String>

Select top N peers

Source

pub fn summary(&self) -> SelectorSummary

Get summary statistics across all peers

Source

pub fn export_peer_metadata_snapshot(&self) -> PeerMetadataSnapshot

Export persisted peer metadata keyed by stable principal identity.

Source

pub fn import_peer_metadata_snapshot(&mut self, snapshot: &PeerMetadataSnapshot)

Import persisted metadata and apply it to currently tracked peers.

Trait Implementations§

Source§

impl Debug for PeerSelector

Source§

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

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

impl Default for PeerSelector

Source§

fn default() -> PeerSelector

Returns the “default value” for a type. 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> 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, 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