pub struct MdnsState<R> { /* private fields */ }Expand description
Shared mDNS state: the engine behind a RefCell, plus a wake signal.
Share one instance between the driver task (Self::run) and the
application — via Rc or a &'static (StaticCell). Every method takes
&self (interior mutability). This is a single-executor (!Send) design:
the driver and the handle calls cooperate on one executor, so a RefCell
borrow never spans an .await.
Implementations§
Source§impl<R: Rng> MdnsState<R>
impl<R: Rng> MdnsState<R>
Sourcepub fn new(config: EndpointConfig, rng: R) -> Self
pub fn new(config: EndpointConfig, rng: R) -> Self
Create the shared state from a proto-layer config and an RNG (used for probe-tiebreak seeds and query transaction ids).
Sourcepub fn set_local_subnets(&self, subnets: Vec<IpCidr>)
pub fn set_local_subnets(&self, subnets: Vec<IpCidr>)
Set the device’s local subnets — the RFC 6762 §11 on-link heuristic used when
the transport can’t surface the received hop-limit (embassy-net re-exports
smoltcp’s UdpMetadata, which carries no RX TTL).
OPTIONAL. With no subnets configured the §11 gate accepts every inbound mDNS datagram (the groups are link-scoped multicast routers do not forward) rather than dropping all of it and going deaf. Configure the device’s own subnets to additionally REJECT sources outside them.
Sourcepub fn register_service(
&self,
spec: ServiceSpec,
) -> Result<ServiceHandle, RegisterServiceError>
pub fn register_service( &self, spec: ServiceSpec, ) -> Result<ServiceHandle, RegisterServiceError>
Register a service; the driver starts probing/announcing it promptly.
Sourcepub fn unregister_service(&self, handle: ServiceHandle)
pub fn unregister_service(&self, handle: ServiceHandle)
Unregister a service and release its route slot.
Sourcepub fn start_query(
&self,
spec: QuerySpec,
) -> Result<QueryHandle, StartQueryError>
pub fn start_query( &self, spec: QuerySpec, ) -> Result<QueryHandle, StartQueryError>
Start a query / DNS-SD browse.
Sourcepub fn cancel_query(&self, handle: QueryHandle)
pub fn cancel_query(&self, handle: QueryHandle)
Cancel a query and free its slot.
Sourcepub fn collected_answers(&self, handle: QueryHandle) -> Vec<CollectedAnswer>
pub fn collected_answers(&self, handle: QueryHandle) -> Vec<CollectedAnswer>
Snapshot the answers a query has collected so far — the browse / discovery
results — into an owned Vec. Empty if handle is not an active query. An
OWNED snapshot (not a borrow) because the engine lives behind a RefCell
whose guard cannot escape this call. Compare its length against
Self::query_accepted_count to detect answers the max_answers cap evicted
before you read them.
Sourcepub fn query_accepted_count(&self, handle: QueryHandle) -> Option<u64>
pub fn query_accepted_count(&self, handle: QueryHandle) -> Option<u64>
Total answers ever accepted by a query (including ones the max_answers cap
has since evicted from Self::collected_answers). None if handle is not
an active query.
Sourcepub fn poll_service_update(
&self,
handle: ServiceHandle,
) -> Option<ServiceUpdate>
pub fn poll_service_update( &self, handle: ServiceHandle, ) -> Option<ServiceUpdate>
Pop one pending update for a registered service.
Sourcepub fn poll_query_update(&self, handle: QueryHandle) -> Option<QueryUpdate>
pub fn poll_query_update(&self, handle: QueryHandle) -> Option<QueryUpdate>
Pop one pending update for a query.
Sourcepub fn poll_endpoint_event(&self) -> Option<EndpointEvent>
pub fn poll_endpoint_event(&self) -> Option<EndpointEvent>
Pop one endpoint-level event.
Sourcepub async fn run(
&self,
v4: Option<&mut UdpSocket<'_>>,
v6: Option<&mut UdpSocket<'_>>,
scratch: &mut [u8],
) -> !
pub async fn run( &self, v4: Option<&mut UdpSocket<'_>>, v6: Option<&mut UdpSocket<'_>>, scratch: &mut [u8], ) -> !
Run the mDNS driver loop over the given v4 and/or v6 sockets until the task is dropped. Never returns; spawn it as an embassy task.
Each socket must already be bound to port 5353 and joined to the relevant
mDNS group (224.0.0.251 / ff02::fb) via Stack::join_multicast_group.
Takes the sockets by &mut so it can ENFORCE the RFC 6762 §11 egress hop-limit
(255) once at startup — see crate::run.