ndn_discovery/
no_discovery.rs1use std::time::Instant;
8
9use bytes::Bytes;
10use ndn_packet::Name;
11use ndn_transport::FaceId;
12
13use crate::{DiscoveryContext, DiscoveryProtocol, InboundMeta, ProtocolId};
14
15pub struct NoDiscovery;
30
31impl DiscoveryProtocol for NoDiscovery {
32 fn protocol_id(&self) -> ProtocolId {
33 ProtocolId("no-discovery")
34 }
35
36 fn claimed_prefixes(&self) -> &[Name] {
37 &[]
38 }
39
40 fn on_face_up(&self, _face_id: FaceId, _ctx: &dyn DiscoveryContext) {}
41 fn on_face_down(&self, _face_id: FaceId, _ctx: &dyn DiscoveryContext) {}
42
43 fn on_inbound(
44 &self,
45 _raw: &Bytes,
46 _incoming_face: FaceId,
47 _meta: &InboundMeta,
48 _ctx: &dyn DiscoveryContext,
49 ) -> bool {
50 false
51 }
52
53 fn on_tick(&self, _now: Instant, _ctx: &dyn DiscoveryContext) {}
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use crate::protocol::DiscoveryProtocol;
60
61 #[test]
62 fn no_discovery_claims_no_prefixes() {
63 assert!(NoDiscovery.claimed_prefixes().is_empty());
64 }
65
66 #[test]
67 fn no_discovery_never_consumes() {
68 struct StubCtx;
69 impl crate::DiscoveryContext for StubCtx {
70 fn alloc_face_id(&self) -> FaceId {
71 FaceId(0)
72 }
73 fn add_face(&self, _: std::sync::Arc<dyn ndn_transport::ErasedFace>) -> FaceId {
74 FaceId(0)
75 }
76 fn remove_face(&self, _: FaceId) {}
77 fn add_fib_entry(&self, _: &Name, _: FaceId, _: u32, _: ProtocolId) {}
78 fn remove_fib_entry(&self, _: &Name, _: FaceId, _: ProtocolId) {}
79 fn remove_fib_entries_by_owner(&self, _: ProtocolId) {}
80 fn neighbors(&self) -> std::sync::Arc<dyn crate::NeighborTableView> {
81 crate::NeighborTable::new()
82 }
83 fn update_neighbor(&self, _: crate::NeighborUpdate) {}
84 fn send_on(&self, _: FaceId, _: bytes::Bytes) {}
85 fn now(&self) -> std::time::Instant {
86 std::time::Instant::now()
87 }
88 }
89
90 let ctx = StubCtx;
91 let pkt = Bytes::from_static(b"\x05\x10hello");
92 assert!(!NoDiscovery.on_inbound(&pkt, FaceId(1), &InboundMeta::none(), &ctx));
93 }
94}