pub struct PeerCapabilityRegistry { /* private fields */ }Expand description
Tick-based registry tracking which protocol-level Capability set each
peer advertises.
This is the primary data structure for capability-based peer selection. Advertisements carry a TTL expressed in ticks; callers must supply the current tick to all query operations so that expired entries are correctly filtered out without requiring a background eviction task.
§Example
use ipfrs_network::capability_registry::{
Capability, PeerCapabilityRegistry,
};
let mut registry = PeerCapabilityRegistry::new();
registry.advertise(
"peer-a".to_string(),
vec![Capability::Kademlia, Capability::Bitswap { version: 1 }],
/*current_tick=*/ 0,
/*ttl_ticks=*/ 100,
);
let peers = registry.peers_with_capability(&Capability::Kademlia, 0);
assert_eq!(peers, vec!["peer-a"]);Implementations§
Source§impl PeerCapabilityRegistry
impl PeerCapabilityRegistry
Sourcepub fn advertise(
&mut self,
peer_id: String,
capabilities: Vec<Capability>,
current_tick: u64,
ttl_ticks: u64,
)
pub fn advertise( &mut self, peer_id: String, capabilities: Vec<Capability>, current_tick: u64, ttl_ticks: u64, )
Insert or replace the advertisement for peer_id.
The advertisement expires at tick current_tick + ttl_ticks.
Sourcepub fn peers_with_capability(
&self,
cap: &Capability,
current_tick: u64,
) -> Vec<&str>
pub fn peers_with_capability( &self, cap: &Capability, current_tick: u64, ) -> Vec<&str>
Return a sorted list of peer IDs whose valid advertisements include cap.
Only advertisements that pass CapabilityAdvertisement::is_valid at
current_tick are considered. The result is sorted alphabetically.
Sourcepub fn peer_capabilities(
&self,
peer_id: &str,
current_tick: u64,
) -> Option<&[Capability]>
pub fn peer_capabilities( &self, peer_id: &str, current_tick: u64, ) -> Option<&[Capability]>
Return the capability slice for peer_id if its advertisement is valid
at current_tick, or None otherwise.
Returns None when:
- the peer is not in the registry, or
- the peer’s advertisement has expired.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Remove the advertisement for peer_id.
Returns true if the peer was found and removed, false if the peer
was not registered.
Sourcepub fn evict_expired(&mut self, current_tick: u64) -> usize
pub fn evict_expired(&mut self, current_tick: u64) -> usize
Remove all expired advertisements from the registry.
Returns the number of advertisements that were removed.
Sourcepub fn stats(&self, current_tick: u64) -> CapabilityRegistryStats
pub fn stats(&self, current_tick: u64) -> CapabilityRegistryStats
Return a CapabilityRegistryStats snapshot evaluated at current_tick.
Trait Implementations§
Source§impl Debug for PeerCapabilityRegistry
impl Debug for PeerCapabilityRegistry
Source§impl Default for PeerCapabilityRegistry
impl Default for PeerCapabilityRegistry
Source§fn default() -> PeerCapabilityRegistry
fn default() -> PeerCapabilityRegistry
Auto Trait Implementations§
impl Freeze for PeerCapabilityRegistry
impl RefUnwindSafe for PeerCapabilityRegistry
impl Send for PeerCapabilityRegistry
impl Sync for PeerCapabilityRegistry
impl Unpin for PeerCapabilityRegistry
impl UnsafeUnpin for PeerCapabilityRegistry
impl UnwindSafe for PeerCapabilityRegistry
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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