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
impl PeerSelector
Sourcepub fn with_strategy(strategy: SelectionStrategy) -> Self
pub fn with_strategy(strategy: SelectionStrategy) -> Self
Create with specific strategy
Sourcepub fn set_fairness(&mut self, enabled: bool)
pub fn set_fairness(&mut self, enabled: bool)
Enable/disable fairness constraints
Sourcepub fn set_cashu_payment_weight(&mut self, weight: f64)
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.
Sourcepub fn remove_peer(&mut self, peer_id: &str)
pub fn remove_peer(&mut self, peer_id: &str)
Remove a peer
Sourcepub fn get_stats_mut(&mut self, peer_id: &str) -> Option<&mut PeerStats>
pub fn get_stats_mut(&mut self, peer_id: &str) -> Option<&mut PeerStats>
Get peer stats (mutable)
Sourcepub fn record_request(&mut self, peer_id: &str, bytes: u64)
pub fn record_request(&mut self, peer_id: &str, bytes: u64)
Record a request being sent to a peer
Sourcepub fn record_success(&mut self, peer_id: &str, rtt_ms: u64, bytes: u64)
pub fn record_success(&mut self, peer_id: &str, rtt_ms: u64, bytes: u64)
Record a successful response
Sourcepub fn record_timeout(&mut self, peer_id: &str)
pub fn record_timeout(&mut self, peer_id: &str)
Record a timeout
Sourcepub fn record_failure(&mut self, peer_id: &str)
pub fn record_failure(&mut self, peer_id: &str)
Record a failure
Sourcepub fn record_cashu_payment(&mut self, peer_id: &str, amount_sat: u64)
pub fn record_cashu_payment(&mut self, peer_id: &str, amount_sat: u64)
Record payment channel credit for a peer.
Sourcepub fn record_cashu_receipt(&mut self, peer_id: &str, amount_sat: u64)
pub fn record_cashu_receipt(&mut self, peer_id: &str, amount_sat: u64)
Record a settled post-delivery payment received from a peer.
Sourcepub fn record_cashu_payment_default(&mut self, peer_id: &str)
pub fn record_cashu_payment_default(&mut self, peer_id: &str)
Record that a peer failed to settle after we delivered successfully.
pub fn is_peer_blocked_for_payment_defaults( &self, peer_id: &str, threshold: u64, ) -> bool
Sourcepub fn select_peers(&mut self) -> Vec<String>
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.
Sourcepub fn select_best(&mut self) -> Option<String>
pub fn select_best(&mut self) -> Option<String>
Select single best peer
Sourcepub fn select_top(&mut self, n: usize) -> Vec<String>
pub fn select_top(&mut self, n: usize) -> Vec<String>
Select top N peers
Sourcepub fn summary(&self) -> SelectorSummary
pub fn summary(&self) -> SelectorSummary
Get summary statistics across all peers
Sourcepub fn export_peer_metadata_snapshot(&self) -> PeerMetadataSnapshot
pub fn export_peer_metadata_snapshot(&self) -> PeerMetadataSnapshot
Export persisted peer metadata keyed by stable principal identity.
Sourcepub fn import_peer_metadata_snapshot(&mut self, snapshot: &PeerMetadataSnapshot)
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
impl Debug for PeerSelector
Source§impl Default for PeerSelector
impl Default for PeerSelector
Source§fn default() -> PeerSelector
fn default() -> PeerSelector
Auto Trait Implementations§
impl Freeze for PeerSelector
impl RefUnwindSafe for PeerSelector
impl Send for PeerSelector
impl Sync for PeerSelector
impl Unpin for PeerSelector
impl UnsafeUnpin for PeerSelector
impl UnwindSafe for PeerSelector
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> 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