Skip to main content

MdnsState

Struct MdnsState 

Source
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>

Source

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).

Source

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.

Source

pub fn register_service( &self, spec: ServiceSpec, ) -> Result<ServiceHandle, RegisterServiceError>

Register a service; the driver starts probing/announcing it promptly.

Source

pub fn unregister_service(&self, handle: ServiceHandle)

Unregister a service and release its route slot.

Source

pub fn start_query( &self, spec: QuerySpec, ) -> Result<QueryHandle, StartQueryError>

Start a query / DNS-SD browse.

Source

pub fn cancel_query(&self, handle: QueryHandle)

Cancel a query and free its slot.

Source

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.

Source

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.

Source

pub fn poll_service_update( &self, handle: ServiceHandle, ) -> Option<ServiceUpdate>

Pop one pending update for a registered service.

Source

pub fn poll_query_update(&self, handle: QueryHandle) -> Option<QueryUpdate>

Pop one pending update for a query.

Source

pub fn poll_endpoint_event(&self) -> Option<EndpointEvent>

Pop one endpoint-level event.

Source

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.

Auto Trait Implementations§

§

impl<R> !Freeze for MdnsState<R>

§

impl<R> !RefUnwindSafe for MdnsState<R>

§

impl<R> !Sync for MdnsState<R>

§

impl<R> Send for MdnsState<R>
where R: Send,

§

impl<R> Unpin for MdnsState<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for MdnsState<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for MdnsState<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.