Skip to main content

Crate ebus_discovery_tokio

Crate ebus_discovery_tokio 

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

JobCall
Find the site’s broker before building its MQTT optionsfind_broker, or list_brokers to pick from every broker seen
Find the same broker again after its address changesreresolve
Advertise the host’s own servicesadvertise, 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.
MdnsBrowse
A browse of an Mdns backend.
MdnsGroup
A published group of an Mdns backend.
MdnsSdOptionsmdns-sd
Options for the mdns-sd backend.

Enums§

AdState
Where an advertisement stands.
Error
A discovery or advertising failure.
GroupReport
What a published Group reports.
HostName
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 ad under host: every record under one instance name, from Advertisement::instance_names. A collision on any record withdraws them all and registers them again under the next name, -2 through -99; after that the state is AdState::Failed. A host rename rebuilds the records for the new SRV target and registers them again in place.
find_broker
Run a BrokerSearch to its result: the configured broker at once in configured-only, else the broker the search settles on, or the configured broker when discovery-with-fallback finds no match. The browses stop once the result is set. A search that finds nothing runs until the caller stops it, for instance with tokio::time::timeout.
list_brokers
Browse for window from the start and return the accepted brokers, with cfg.wanted applied, ranked (BrokerConfig::rank). Each broker appears once, under the transport earliest in BrokerConfig::accepted. The browse covers the accepted types, and every broker type when cfg.wanted is a Wanted::DeviceId, whose id another transport of the broker may carry. A configuration BrokerSearch::new rejects is an Error::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 .local name; otherwise at the end of window, with the latest sighting. Ok(None) for a configured broker, for one not seen within window, and for one cfg no longer accepts.