pub struct NodeCapabilityRegistry { /* private fields */ }Expand description
Thread-safe registry that maps peer IDs to their node-level capability advertisements.
§Example
use ipfrs_network::capability_registry::{
NodeCapability, NodeCapabilities, NodeCapabilityRegistry,
};
let registry = NodeCapabilityRegistry::default();
let caps = NodeCapabilities::new(
"peer-1",
vec![NodeCapability::ContentRouting],
"0.2.0",
);
registry.register(caps);
let found = registry.find_by_capability("content_routing");
assert_eq!(found.len(), 1);Implementations§
Source§impl NodeCapabilityRegistry
impl NodeCapabilityRegistry
Sourcepub fn register(&self, caps: NodeCapabilities)
pub fn register(&self, caps: NodeCapabilities)
Register or replace the capability advertisement for the peer described
by caps.peer_id.
Sourcepub fn unregister(&self, peer_id: &str)
pub fn unregister(&self, peer_id: &str)
Remove the advertisement for peer_id from the registry.
This is a no-op when the peer is not registered.
Sourcepub fn get(&self, peer_id: &str) -> Option<NodeCapabilities>
pub fn get(&self, peer_id: &str) -> Option<NodeCapabilities>
Return a clone of the NodeCapabilities for peer_id, or None if the
peer is not registered.
Sourcepub fn find_by_capability(&self, name: &str) -> Vec<NodeCapabilities>
pub fn find_by_capability(&self, name: &str) -> Vec<NodeCapabilities>
Return clones of all non-expired peer records that advertise the
capability identified by name.
Expiry is evaluated relative to now_ms obtained from the system clock
at the time of the call.
Sourcepub fn evict_expired(&self, now_ms: u64) -> usize
pub fn evict_expired(&self, now_ms: u64) -> usize
Remove all expired entries from the registry and return the number of entries that were evicted.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Return the number of peers currently registered (including expired ones that have not yet been evicted).
Sourcepub fn capability_histogram(&self) -> HashMap<String, usize>
pub fn capability_histogram(&self) -> HashMap<String, usize>
Return a histogram mapping each capability name to the number of currently-registered peers (including stale ones) that advertise it.
Trait Implementations§
Source§impl Debug for NodeCapabilityRegistry
impl Debug for NodeCapabilityRegistry
Source§impl Default for NodeCapabilityRegistry
impl Default for NodeCapabilityRegistry
Source§fn default() -> NodeCapabilityRegistry
fn default() -> NodeCapabilityRegistry
Auto Trait Implementations§
impl !Freeze for NodeCapabilityRegistry
impl RefUnwindSafe for NodeCapabilityRegistry
impl Send for NodeCapabilityRegistry
impl Sync for NodeCapabilityRegistry
impl Unpin for NodeCapabilityRegistry
impl UnsafeUnpin for NodeCapabilityRegistry
impl UnwindSafe for NodeCapabilityRegistry
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