Skip to content

Add the ebus_discovery target: TXT records, MdnsBackend, broker discovery - #8

Merged
dcj merged 5 commits into
mainfrom
feat/ebus-discovery-target
Oct 9, 2026
Merged

dcj merged 5 commits into
mainfrom
feat/ebus-discovery-target

Conversation

@dcj

@dcj dcj commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Closes #5. Part of #3.

Adds ebus_discovery, a CMake target that depends on the standard library only (discovery/, doc/discovery.md), linked by ebus_core and built by PlatformIO through library.json like ebus_mqtt.

Header Contents
ebus/discovery/txt_records.h EbusIdentity and txt_build_ebus(), txt_build_device_info(), txt_build_http(), txt_build_log(), which fill a fixed-size TxtRecord (borrowed pointers, no heap)
ebus/discovery/mdns_backend.h MdnsBackend: advertise(), browse() with a per-instance callback, resolve()
ebus/discovery/broker_browse.h broker_browse() and broker_reresolve(), esp32-sdk's broker selection over MdnsBackend
ebus/discovery/broker_discovery.h, mdns_strings.h Moved from include/platform/; the old paths forward here

The TXT keys, order and omission rules follow framework.md, ebus-service-discovery's Identity / HttpService, and esp32-sdk's network.cpp; test_discovery_txt repeats both libraries' records with file:line references. doc/discovery.md lists the remaining differences (the _ebus._tcp port, the homie_* keys, the HTTP version default).

Verified locally: top-level CMake build and CTest (Clang and GCC 16, warnings as errors), the POSIX port and its e2e tests against a local mosquitto, ebus_discovery compiled with its own include directory only, and esp32-sdk main with this branch as lib/ebus_core: ./ebus-esp32 build (esp32-poe-iso) and ./ebus-esp32 test pass; flash +92 bytes against cpp-sdk 0.2.0, RAM unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Npk6WmkpnBRzWkuhK6uCuz

dcj and others added 5 commits October 9, 2026 07:30
ebus_discovery is the second component of the split: discovery/include/
ebus/discovery/ and discovery/src/, built by discovery/CMakeLists.txt with
only its own include directory and no dependency. broker_discovery.h,
broker_discovery.cpp and mdns_strings.h move into it unchanged in
behavior. ebus_core links it, so consumers keep one target.

<platform/broker_discovery.h> and <platform/mdns_strings.h> stay as
forwarding headers, so esp32-sdk's includes build unchanged.

The broker suite becomes test_discovery_broker, which links
ebus_discovery alone. library.json compiles discovery/src/ and adds
discovery/include to the include path.

Part of #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Npk6WmkpnBRzWkuhK6uCuz
ebus/discovery/txt_records.h builds the TXT records of _ebus._tcp,
_device-info._tcp, _http._tcp and _telnet._tcp from one EbusIdentity,
with the keys, order and omission rules of framework.md and of
ebus-service-discovery's Identity and HttpService, plus the homie_domain,
homie_version and homie_roles keys esp32-sdk advertises today. Roles and
auth methods are bit sets, written in the order framework.md lists them.

A TxtRecord holds up to EBUS_TXT_MAX_PAIRS pointers to the caller's
strings and to constants; nothing is allocated. txt_record_add() refuses
an invalid or duplicate key (case-insensitive) and a "key=value" over 255
bytes, as the Python check_txt() does; a builder that fails leaves the
record empty.

mdns_strings.h gains broker_ca, hw_version, broker-host and the
individual auth method values.

test_discovery_txt repeats the Python library's TXT cases and the records
esp32-sdk's network.cpp builds, with file:line references.

Part of #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Npk6WmkpnBRzWkuhK6uCuz
ebus/discovery/mdns_backend.h is the interface a port implements over
its mDNS stack: advertise() one service type with a TXT record, browse()
a service type with a callback per instance, and resolve() a bare host
name. Results are borrowed for the callback, so neither side allocates.
The host name claim stays in the port's stack setup.

ebus/discovery/broker_browse.h moves esp32-sdk's broker selection onto
it: broker_browse() takes the first instance with an address, in the
list's service order, with the service's default port when the SRV
record has none; broker_reresolve() is the single host query after
repeated reconnect failures. broker_service_type() gives the DNS-SD
type of each broker service, and mdns_strings.h the full types of the
services an entity advertises.

test_discovery_backend runs both against a fake backend.

Part of #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Npk6WmkpnBRzWkuhK6uCuz
Part of #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Npk6WmkpnBRzWkuhK6uCuz
doc/discovery.md covers the headers, the builders and their rules, the
remaining differences between esp32-sdk, ebus-service-discovery and
framework.md, the MdnsBackend contract, broker discovery over it, and the
options for a POSIX backend. README, doc/core.md, the changelog and
.ebus-spec.json's note name the new target.

Part of #3
Closes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Npk6WmkpnBRzWkuhK6uCuz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an ebus_discovery target: record parsing, broker modes and TXT contents

1 participant