pub trait DiscoveryProtocol:
Send
+ Sync
+ 'static {
// Required methods
fn protocol_id(&self) -> ProtocolId;
fn claimed_prefixes(&self) -> &[Name];
fn on_face_up(&self, face_id: FaceId, ctx: &dyn DiscoveryContext);
fn on_face_down(&self, face_id: FaceId, ctx: &dyn DiscoveryContext);
fn on_inbound(
&self,
raw: &Bytes,
incoming_face: FaceId,
meta: &InboundMeta,
ctx: &dyn DiscoveryContext,
) -> bool;
fn on_tick(&self, now: Instant, ctx: &dyn DiscoveryContext);
// Provided method
fn tick_interval(&self) -> Duration { ... }
}Expand description
A pluggable discovery protocol.
Implementations observe face lifecycle events and inbound packets;
they mutate engine state exclusively through the DiscoveryContext
interface, making them decoupled from the engine and independently
testable.
§Namespace isolation
Each protocol declares which NDN name prefixes it uses via
[claimed_prefixes]. CompositeDiscovery checks at construction
time that no two protocols claim overlapping prefixes. All discovery
prefixes live under the reserved /ndn/local/ sub-tree.
Required Methods§
Sourcefn protocol_id(&self) -> ProtocolId
fn protocol_id(&self) -> ProtocolId
Unique protocol identifier.
Sourcefn claimed_prefixes(&self) -> &[Name]
fn claimed_prefixes(&self) -> &[Name]
NDN name prefixes this protocol reserves.
Typically sub-prefixes of /ndn/local/nd/ (neighbor discovery) or
/ndn/local/sd/ (service discovery). Used for namespace conflict
detection and inbound routing in CompositeDiscovery.
Sourcefn on_face_up(&self, face_id: FaceId, ctx: &dyn DiscoveryContext)
fn on_face_up(&self, face_id: FaceId, ctx: &dyn DiscoveryContext)
Called when a new face comes up (after FaceTable::insert).
Sourcefn on_face_down(&self, face_id: FaceId, ctx: &dyn DiscoveryContext)
fn on_face_down(&self, face_id: FaceId, ctx: &dyn DiscoveryContext)
Called when a face goes down (before FaceTable::remove).
Sourcefn on_inbound(
&self,
raw: &Bytes,
incoming_face: FaceId,
meta: &InboundMeta,
ctx: &dyn DiscoveryContext,
) -> bool
fn on_inbound( &self, raw: &Bytes, incoming_face: FaceId, meta: &InboundMeta, ctx: &dyn DiscoveryContext, ) -> bool
Called for every inbound raw packet before it enters the pipeline.
Returns true if the packet was consumed by this protocol and should
not be forwarded through the NDN pipeline. Return false to let
the packet continue normally.
meta carries the link-layer source address when the face layer
exposes it (multicast faces). Discovery protocols use meta.source
to create unicast reply faces without embedding addresses in the
Interest payload.
Sourcefn on_tick(&self, now: Instant, ctx: &dyn DiscoveryContext)
fn on_tick(&self, now: Instant, ctx: &dyn DiscoveryContext)
Periodic tick, called by the engine’s tick task at tick_interval.
Use this to send hellos, check timeouts, rotate probes, and update SWIM gossip state.
Provided Methods§
Sourcefn tick_interval(&self) -> Duration
fn tick_interval(&self) -> Duration
How often the engine should call on_tick.
The default (100 ms) works for most deployments. High-mobility profiles may use 20–50 ms; static deployments may use 1 s.