pub struct CapabilityRegistry { /* private fields */ }Expand description
Central registry for peer capability advertisements.
The registry enforces:
- Requirement filtering — peers must satisfy
require_allandrequire_anyfrom theCapabilityConfigto be accepted. - Capacity limiting — at most
max_peersentries are held. - TTL expiry — stale entries can be purged via
CapabilityRegistry::purge_expired.
All methods take &mut self; the registry is not internally synchronised.
Wrap in an Arc<Mutex<_>> for concurrent access.
Implementations§
Source§impl CapabilityRegistry
impl CapabilityRegistry
Sourcepub fn new(config: CapabilityConfig) -> Self
pub fn new(config: CapabilityConfig) -> Self
Create a new registry with the given configuration.
Sourcepub fn register(&mut self, peer: PeerCapabilitySet) -> bool
pub fn register(&mut self, peer: PeerCapabilitySet) -> bool
Register peer in the registry.
Returns true on success, false when:
- The peer does not meet the configured requirements
(
meets_requirements), or - The registry is at capacity (
max_peers).
If the same peer_id is already present the old entry is replaced
(the stats counters still increment as if it were a new registration).
Sourcepub fn meets_requirements(&self, peer: &PeerCapabilitySet) -> bool
pub fn meets_requirements(&self, peer: &PeerCapabilitySet) -> bool
Returns true if peer satisfies the configured require_all and
require_any constraints.
require_all: the peer must possess every listed capability.require_any: the peer must possess at least one listed capability (no constraint when the list is empty).
Sourcepub fn remove(&mut self, peer_id: &str) -> bool
pub fn remove(&mut self, peer_id: &str) -> bool
Remove the peer identified by peer_id from the registry.
Returns true if the peer was present and removed, false otherwise.
Sourcepub fn get_peer(&self, peer_id: &str) -> Option<&PeerCapabilitySet>
pub fn get_peer(&self, peer_id: &str) -> Option<&PeerCapabilitySet>
Retrieve the PeerCapabilitySet for peer_id, if present.
Sourcepub fn peers_with_capability(
&self,
cap: &PeerCapability,
) -> Vec<&PeerCapabilitySet>
pub fn peers_with_capability( &self, cap: &PeerCapability, ) -> Vec<&PeerCapabilitySet>
Return all peers that advertise cap.
Sourcepub fn peers_with_all(&self, caps: &[PeerCapability]) -> Vec<&PeerCapabilitySet>
pub fn peers_with_all(&self, caps: &[PeerCapability]) -> Vec<&PeerCapabilitySet>
Return all peers that advertise every capability in caps.
Sourcepub fn peers_with_any(&self, caps: &[PeerCapability]) -> Vec<&PeerCapabilitySet>
pub fn peers_with_any(&self, caps: &[PeerCapability]) -> Vec<&PeerCapabilitySet>
Return all peers that advertise at least one capability in caps.
Sourcepub fn purge_expired(&mut self, now: u64) -> usize
pub fn purge_expired(&mut self, now: u64) -> usize
Remove all peers whose advertised_at is older than now - ttl_ms.
Returns the number of entries purged.
Sourcepub fn capability_name(cap: &PeerCapability) -> &'static str
pub fn capability_name(cap: &PeerCapability) -> &'static str
Returns a &'static str label for well-known capability variants.
For PeerCapability::Custom the returned string is always
"custom". Use PeerCapability::key when you need the full
dynamic key including the custom payload.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Returns the number of peers currently in the registry.
Sourcepub fn stats(&self) -> &CapabilityStats
pub fn stats(&self) -> &CapabilityStats
Returns a reference to the runtime statistics snapshot.
The snapshot reflects the live state of the registry; the histogram entries are decremented on removal, so they track currently registered peers rather than lifetime totals.
Sourcepub fn local_capabilities(&self) -> &[PeerCapability]
pub fn local_capabilities(&self) -> &[PeerCapability]
Returns the local capabilities configured for this node.
Auto Trait Implementations§
impl Freeze for CapabilityRegistry
impl RefUnwindSafe for CapabilityRegistry
impl Send for CapabilityRegistry
impl Sync for CapabilityRegistry
impl Unpin for CapabilityRegistry
impl UnsafeUnpin for CapabilityRegistry
impl UnwindSafe for CapabilityRegistry
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