pub struct SubprotocolRegistry { /* private fields */ }Expand description
Registry of subprotocols supported by this node.
Keyed by subprotocol_id: u16. Does NOT store the daemon itself
(that stays in DaemonRegistry). This maps protocol IDs to metadata
and provides query methods.
Implementations§
Source§impl SubprotocolRegistry
impl SubprotocolRegistry
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a registry pre-populated with core subprotocols.
Sourcepub fn register(
&self,
descriptor: SubprotocolDescriptor,
) -> Option<SubprotocolDescriptor>
pub fn register( &self, descriptor: SubprotocolDescriptor, ) -> Option<SubprotocolDescriptor>
Register a subprotocol.
If a subprotocol with the same ID is already registered, it is replaced (version upgrade). Returns the previous descriptor if any.
Sourcepub fn unregister(&self, id: u16) -> Option<SubprotocolDescriptor>
pub fn unregister(&self, id: u16) -> Option<SubprotocolDescriptor>
Unregister a subprotocol by ID.
Sourcepub fn get(&self, id: u16) -> Option<Ref<'_, u16, SubprotocolDescriptor>>
pub fn get(&self, id: u16) -> Option<Ref<'_, u16, SubprotocolDescriptor>>
Look up a subprotocol by ID.
Sourcepub fn is_handled(&self, id: u16) -> bool
pub fn is_handled(&self, id: u16) -> bool
Check if a handler is present for this subprotocol (not just forwarding).
Sourcepub fn is_registered(&self, id: u16) -> bool
pub fn is_registered(&self, id: u16) -> bool
Check if a subprotocol ID is registered (handler or forwarding-only).
Sourcepub fn list(&self) -> Vec<SubprotocolDescriptor>
pub fn list(&self) -> Vec<SubprotocolDescriptor>
List all registered subprotocols.
Sourcepub fn capability_filter_for(id: u16) -> CapabilityFilter
pub fn capability_filter_for(id: u16) -> CapabilityFilter
Build a CapabilityFilter that finds nodes supporting a given subprotocol.
Returns a filter requiring the tag subprotocol:0x{id:04x}.
Get all capability tags for registered subprotocols.
Add these to the local node’s CapabilitySet and re-broadcast
via CapabilityAd so other nodes can discover support.
Returned in ascending subprotocol-id order, matching
SubprotocolManifest::from_registry‘s sort. Without this,
the two channels’ byte streams diverge — fine today, but a
future digest-dedup optimisation that hashes either output
would silently disagree with the other side.
Sourcepub fn enrich_capabilities(&self, caps: CapabilitySet) -> CapabilitySet
pub fn enrich_capabilities(&self, caps: CapabilitySet) -> CapabilitySet
Enrich a CapabilitySet with tags for all handled subprotocols.
Call this when building the local node’s capability set before
broadcasting via CapabilityAnnouncement or CapabilityAd.
This ensures other nodes can discover which subprotocols this
node supports (including migration) through the capability graph.
§Example
let caps = CapabilitySet::new();
let caps = subprotocol_registry.enrich_capabilities(caps);
// caps now has tags like "subprotocol:0x0400", "subprotocol:0x0500", etc.