Export TXTEntry so callers can set TXT records on advertised services#277
Export TXTEntry so callers can set TXT records on advertised services#277mcuelenaere wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #277 +/- ##
==========================================
+ Coverage 80.57% 80.62% +0.04%
==========================================
Files 7 7
Lines 1596 1600 +4
==========================================
+ Hits 1286 1290 +4
Misses 201 201
Partials 109 109
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
691e4cb to
a54bccf
Compare
JetKVM devices now advertise themselves as the DNS-SD service type `_jetkvm._tcp` on the local network, so macOS/iOS clients can discover every device on the LAN via NWBrowser(for: .bonjour(type: "_jetkvm._tcp", domain: nil)), and `dns-sd -B _jetkvm._tcp` / `avahi-browse -r _jetkvm._tcp` work too. The advertised record carries: - instance: the device hostname (e.g. jetkvm-abc123) - host: <hostname>.local (existing A/AAAA resolution preserved) - port: 80, or 443 when TLS is enabled - TXT: version=<fw>, id=<deviceId>, setup=<true|false> Implementation uses pion/mdns/v2 (already in the tree transitively via pion/webrtc). pion takes the IPv4 and IPv6 multicast packet conns separately, so the existing MDNSMode=ipv4_only / ipv6_only config is honored by simply not binding the disabled family — no custom responder, no second mDNS library. We switch from the legacy Server() (A/AAAA only) to NewServer() so PTR/SRV/TXT are answered too. Lifecycle: - starts on the first networkStateChanged once the network is up - refreshes after device setup completes so the `setup` TXT flips - refreshes after a TLS mode change so the advertised port follows - Stop() closes the sockets on shutdown NOTE: DNS-SD TXT publication needs an exported TXTEntry API that is not yet in a tagged pion/mdns release; go.mod pins pion/mdns/v2 to a fork branch via `replace` until pion/mdns#277 merges and ships. This PR stays in draft until then. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The DNS-SD server support (pion#253) lets callers advertise a service via WithService, but ServiceInstance.Text used the unexported txtKeyValue element type, so external callers had no way to populate TXT records. Rename txtKeyValue to the exported TXTEntry and add NewTXTEntry and NewTXTFlag constructors to hide the nil-vs-empty Value distinction. The renamed type was never exported, so this is backward-compatible. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
a54bccf to
7ee4387
Compare
backkem
left a comment
There was a problem hiding this comment.
nits:
NewTXTEntry/NewTXTFlagdon't validate keys (empty, contains=, non-ASCII). Validation only fires at encode time and even then only checks empty key + length. Pre-existing gap, but constructors are the natural place to add it.NewTXTEntryonly acceptsstringvalues. RFC 6763 §6.5 allows opaque binary. Callers can still useTXTEntry{Key: "k", Value: bytes}directly, but worth a godoc note.testReverseadds TXT entries but never asserts on them in the avahi-browse response. The e2e change is cosmetic as-is.
I think only the 1st one is worth considering changing before we merge because it would require changing the signature of NewTXTEntry/NewTXTFlag to add in a follow-up. What do others think?
|
Something else worth noting about text entries (that is kind of a pre-existing problem) is that keys are not case sensitive. Not sure how this should play out in practice since right now this is just a slice so we don't have any way to force this behavior until encode time. |
Summary
The DNS-SD server support (#253) lets callers advertise a service with
WithService, butServiceInstance.Textused the unexportedtxtKeyValueelement type — so external callers had no exported type, constructor, or setter to populate TXT records. The server already serializedTextandBrowse()already decoded into it; the only missing piece was the public API to construct entries.This renames
txtKeyValue→ the exportedTXTEntryand adds two ergonomic constructors that hide the nil-vs-emptyValuefootgun.Before
After
Backward compatibility
Fully backward-compatible:
txtKeyValuewas never exported, so no external caller could reference it. Existing validation (non-empty key, 255-byte per-string limit, case-insensitive dedup keeping first) is unchanged.Tests
TestNewTXTEntry/TestNewTXTFlag— constructor semantics, incl. explicit empty value (key=) vs boolean flag (nil → barekey)TestNewTXTConstructors_Encode— entries → wire strings → decode round-tripTestCreateServiceAnswerTXTWithEntries— server emits the configured TXT entries in its TXT answertestReversenow advertises a TXT entry + flag against avahi-browseRefs #253