Expand description
mDNS broker discovery and host advertisement for eBus on tokio.
The protocol decisions live in the sans-IO ebus_discovery crate; this
crate runs them over an mDNS stack. A host makes one Mdns and uses it
for its two jobs:
| Job | Call |
|---|---|
| Find the site’s broker before building its MQTT options | find_broker, or list_brokers to pick from every broker seen |
| Find the same broker again after its address changes | reresolve |
| Advertise the host’s own services | advertise, then Advertiser::update and Advertiser::withdraw |
The backends implement Backend: Avahi under the avahi feature, a
client of avahi-daemon over D-Bus that compiles only on Linux, and
mdns-sd under the mdns-sd feature, with its own responder thread and
sockets. Mdns::system picks the backend at run time. Built with
neither feature, Mdns::system returns Error::NoBackend; a host can
still pass its own Backend to the search and advertising functions.
use ebus_discovery_tokio::ebus_discovery::{BrokerConfig, BrokerEndpoint, BrokerMode};
use ebus_discovery_tokio::{Mdns, find_broker};
let mdns = Mdns::system().await?;
let mut cfg = BrokerConfig::default();
cfg.mode = Some(BrokerMode::DiscoveryWithFallback);
cfg.url = Some(BrokerEndpoint::from_url("mqtt://broker.example:1883")?);
let broker = find_broker(&mdns, cfg).await?;
let (host, port) = (broker.connect_host().into_owned(), broker.port);Re-exports§
pub use ebus_discovery;
Structs§
- Advertiser
- A running advertisement. Dropping it withdraws the records from the advertiser’s task.
- Mdns
- The mDNS backend a host holds; clones share one backend.
- Mdns
Browse - A browse of an
Mdnsbackend. - Mdns
Group - A published group of an
Mdnsbackend. - Mdns
SdOptions mdns-sd - Options for the mdns-sd backend.
Enums§
- AdState
- Where an advertisement stands.
- Error
- A discovery or advertising failure.
- Group
Report - What a published
Groupreports. - Host
Name - The host name a host advertises its services under: the SRV target.
Traits§
- Backend
- An mDNS stack: browsing and publishing.
- Browse
- A running browse of one service type; dropping it stops the browse.
- Group
- Published records under one instance name; dropping it withdraws them.
Functions§
- advertise
- Advertise
adunderhost: every record under one instance name, fromAdvertisement::instance_names. A collision on any record withdraws them all and registers them again under the next name,-2through-99; after that the state isAdState::Failed. A host rename rebuilds the records for the new SRV target and registers them again in place. - find_
broker - Run a
BrokerSearchto its result: the configured broker at once inconfigured-only, else the broker the search settles on, or the configured broker whendiscovery-with-fallbackfinds no match. The browses stop once the result is set. A search that finds nothing runs until the caller stops it, for instance withtokio::time::timeout. - list_
brokers - Browse for
windowfrom the start and return the accepted brokers, withcfg.wantedapplied, ranked (BrokerConfig::rank). Each broker appears once, under the transport earliest inBrokerConfig::accepted. The browse covers the accepted types, and every broker type whencfg.wantedis aWanted::DeviceId, whose id another transport of the broker may carry. A configurationBrokerSearch::newrejects is anError::Config. - reresolve
- The same broker looked up again by its instance name and type, with its
current addresses, after its host’s address changed. Returns once the
broker is seen with an IPv4 candidate address, or with any address when
its host is not a
.localname; otherwise at the end ofwindow, with the latest sighting.Ok(None)for a configured broker, for one not seen withinwindow, and for onecfgno longer accepts.