Expand description
eBus DNS-SD contract.
The service types an eBus entity advertises and browses (framework.md,
“Detail: mDNS Discovery”), the broker transports with the specification’s
preference order, the broker modes, and address scopes. With alloc: TXT
record decoding, checks and building; the advertisement model; merging the
sightings an mDNS backend reports into instances; and broker ranking and
selection, including the BrokerSearch state machine.
The crate performs no I/O and reads no clock: backends in a runtime crate
feed it sightings and the time as an Instant. Where the specification
leaves a choice open it follows python-service-discovery.
A search for a plain MQTT broker, fed one sighting by hand where a backend would report it:
use ebus_discovery::{
BrokerConfig, BrokerSearch, Instant, InstanceKey, ScopedAddr, Sighting, Slot, TxtRecord,
};
let mut search = BrokerSearch::new(Instant(0), BrokerConfig::default())?;
search.handle(
Instant(0),
Sighting::Seen {
key: InstanceKey {
service_type: "_mqtt._tcp".into(),
name: "site-broker".into(),
},
slot: Slot::Whole,
server: "broker.local.".into(),
port: 1883,
txt: TxtRecord::new(),
addrs: vec![ScopedAddr::new([192, 168, 1, 10].into())],
},
);
while let Some(at) = search.poll_timeout() {
search.handle_timeout(at);
if search.result().is_some() {
break;
}
}
let broker = search.result().expect("a broker");
assert_eq!((broker.host.as_str(), broker.port), ("broker.local", 1883));§Features
std(default): linksstd; impliesalloc.alloc: everything that allocates: TXT records, the advertisement model, instances, broker ranking andBrokerSearch.log: diagnostics through thelogcrate.
Structs§
- Advertisement
alloc - Everything a host advertises, all under one instance name.
- Broker
Config alloc - How a host finds its broker, from its defaults overridden by its REST “MQTT broker configuration” (framework.md:93, 607).
- Broker
Endpoint alloc - A broker to connect to, discovered or configured.
- Broker
Search alloc - One broker search, with no I/O: the backend’s sightings and the time go in; requeries and, once, the result come out.
- Broker
Service alloc - A broker this host runs (ebus.py:494-546; framework.md:299-326).
- EbusTxt
alloc - A parsed
_ebus._tcpTXT record (ebus.py:178-216). - Http
Service alloc - A REST API advertised as
_http._tcpor_https._tcp(ebus.py:445-477). - Identity
alloc - An entity’s
_ebus._tcpand_device-info._tcpcontent (ebus.py:330-438). - Instance
alloc - A service instance as the table holds it.
- Instance
Key alloc - A service instance’s identity: its type and instance name.
- Instance
Table alloc - The instances a backend currently reports, keyed by (service type, instance name), with no I/O.
- Instant
- Milliseconds on the caller’s monotonic clock.
- Parse
Mode Error - A broker mode string that names no mode.
- Scoped
Addr - An address an mDNS backend reported, with the interface it was seen on.
- Service
Record alloc - One service an advertisement registers.
- TxtRecord
alloc - A DNS-SD TXT record: ordered keys, each with a value or none.
- TxtReport
alloc - What
check_txtfound near the limits; nothing here stops a record.
Enums§
- Addr
Scope - The reachability class of an address, declared in candidate preference order (record.py:51-61): routable addresses before link-local ones.
- Broker
Config Error alloc - A broker configuration a search cannot run with.
- Broker
Mode - How an entity finds its broker (framework.md:102, 614-622).
- Broker
Type - A broker transport, declared in the specification’s preference order
(framework.md:330-335), so
Ordranks the most preferred first. That order is the default; a client sets its own withBrokerConfig::accept. - Sighting
alloc - One report from a backend.
- Slot
alloc - Where a backend resolved an instance.
- TxtError
alloc - A TXT record mDNS cannot carry, or an advertisement that cannot be built.
- UrlError
alloc - A configured broker URL that cannot be used.
- Wanted
alloc - The particular broker a host wants among those discovered.
Constants§
- BROKER_
TYPES - Every broker type, in the specification’s preference order.
- DEVICE_
INFO_ SERVICE - The
_device-info._tcpservice every eBus entity advertises (framework.md:77). - EBUS_
SERVICE - The
_ebus._tcpservice every eBus entity advertises (framework.md:77). - EBUS_
VERSION - The framework.md version this crate implements, the default
ebus_versionTXT value: theframeworkvalue in.ebus-spec.json. - HTTPS_
SERVICE - An HTTPS REST API (framework.md:79).
- HTTP_
SERVICE - A plain HTTP REST API (framework.md:79).
- MAX_
DEFAULT_ INSTANCE_ OCTETS alloc - Longest device id used as the default instance name: one 63-octet DNS
label less the
-99suffix. - MAX_
RENAME_ SUFFIX alloc - Instance-name suffixes tried on a collision:
-2through-99. - ROLE_
BROKER_ HOST - The
broker-hostrole (framework.md:106, 248). - ROLE_
CONTROLLER - The
controllerrole (framework.md:248). - ROLE_
DEVICE - The
devicerole (framework.md:248). - TCP_
BROKER_ TYPES - The broker types an MQTT-over-TCP client can use; the accepted types when no TLS is configured (ebus.py:54).
- TXTVERS
- The
txtversvalue of every record this crate builds. - TXT_
STRING_ MAX alloc - Longest single TXT string (
key=value): one length byte. - TXT_
STRING_ WARN alloc - A TXT string longer than this is reported by
check_txt. - TXT_
TOTAL_ WARN alloc - A TXT record longer than this on the wire is reported by
check_txt(RFC 6763 section 6.2).
Functions§
- candidate_
addresses alloc - The addresses worth trying, most preferred first:
ScopedAddr::is_candidateones, ordered byAddrScope::preference, then by address, without duplicates. - check_
txt alloc - Check that mDNS can carry
txt(ebus.py:282-311): every key non-empty, without=and printable ASCII, and every string at mostTXT_STRING_MAXbytes. Strings and records near the limits are listed in the report and logged as warnings. - is_
local_ name - True for a name in the
.localmDNS domain, ignoring ASCII case and a trailing dot. - match_
configured alloc - The discovered broker that is the configured one (ebus.py:712-742).
- parse_
ebus_ txt alloc - Parse an
_ebus._tcprecord:roles,device_idandauth_methodsare comma-separated lists, and a missing key parses as empty. - rank_
brokers alloc - One endpoint per distinct broker, ranked in the client’s preference order (ebus.py:675-702).
- same_
host - True when two host names are equal ignoring case and one trailing dot each (ebus.py:661-662).
- select_
broker alloc - Choose the broker to connect to (ebus.py:745-795).
- strip_
dot namewithout one trailing dot (instance.py:18-20).