windy1 / zeroconf-rs

zeroconf is a cross-platform library that wraps underlying ZeroConf/mDNS implementations such as Bonjour or Avahi, providing an easy and idiomatic way to both register and browse services.
MIT License
76 stars 24 forks source link

Add support for subtypes #31

Closed ssnover closed 1 year ago

ssnover commented 1 year ago

Resolves #30

Tested, here's a log snippet:

[2023-09-13T00:01:24Z DEBUG zeroconf::linux::service] Registering service: AvahiMdnsService { client: None, poll: None, context: AvahiServiceContext { name: None, kind: "_matterc._udp", port: 5540, group: None } }
[2023-09-13T00:01:24Z DEBUG zeroconf::linux::service] Creating group
[2023-09-13T00:01:24Z DEBUG zeroconf::linux::service] Adding service: _matterc._udp
[2023-09-13T00:01:24Z DEBUG zeroconf::linux::service] Adding service subtype: _L250._sub._matterc._udp
[2023-09-13T00:01:24Z DEBUG zeroconf::linux::service] Adding service subtype: _S0._sub._matterc._udp
[2023-09-13T00:01:25Z DEBUG zeroconf::linux::service] Group established

And from avahi-browse (snipped extraneous info):

$ avahi-browse -t _matterc._udp -r
...
= wlp2s0 IPv6 pop-os                                        _matterc._udp        local
   hostname = [pop-os.local]
   address = [fd4d:e11e:2aab:1:c8b5:684f:3826:6afe]
   port = [5540]
   txt = ["PI=" "PH=33" "SAI=300" "SII=5000" "VP=65521+32768" "DN=TestOnOff" "CM=1" "D=250"]
...
ssnover commented 1 year ago

By the way, I'd recommend maybe pinning the Rust version used for clippy linting. In order for CI to pass I had to fix some warning level clippy lints that were introduced in the newest version.

windy1 commented 1 year ago

Hey there - I've been looking into this PR a bit deeper and there are a couple issues I currently see with it:

  1. We need to implement this functionality in Bonjour too so that we maintain feature parity between Avahi and Bonjour
  2. The implementation of SubType is specific to Avahi. In Bonjour, you register subtypes by appending them to the end of the normal type in a comma-separated list (so in the test you've modified it would be _http._tcp,_printer). Therefore, formatting to Avahi's specifications in ServiceType, which is intended to be cross-platform, is not appropriate. This formatting should be done independently from the ServiceType implementation.

Bonjour reference: https://developer.apple.com/documentation/dnssd/1804733-dnsserviceregister?language=objc

I appreciate you may not have the hardware to implement the Bonjour side of this so I've started a branch to amend your changes. Once I am happy with it I will submit a PR to this branch and then we can merge into main. Thanks for your patience.

windy1 commented 1 year ago

Superseded by #32