HAP-NodeJS icon indicating copy to clipboard operation
HAP-NodeJS copied to clipboard

Add systemd-resolved mDNS advertiser support

Open elyscape opened this issue 1 year ago • 3 comments

:recycle: Current situation

Homebridge currently supports three different mDNS advertisers, two that run in-process and one that uses Avahi over D-Bus. For a while now, systemd-resolved has supported acting as an mDNS advertiser and resolver. If Homebridge is run on a system that uses systemd-resolved for mDNS, this can cause conflicts similar to homebridge/homebridge#3077.

:bulb: Proposed solution

systemd-resolved, like Avahi, exposes a D-Bus interface for managing mDNS services. This pull request adds a systemd-resolved mDNS advertiser that makes use of this interface. The code was heavily based on that of the Avahi advertiser.

:gear: Release Notes

  • Added a new mDNS advertiser named resolved that uses systemd-resolved via D-Bus.

:heavy_plus_sign: Additional Information

In order for homebridge to have the permission to use this interface, a .pkla file with the following contents will need to be installed to /etc/polkit-1/localauthority/10-vendor.d/:

[Homebridge RegisterService]
Identity=unix-user:homebridge
Action=org.freedesktop.resolve1.register-service
ResultAny=yes

[Homebridge UnregisterService]
Identity=unix-user:homebridge
Action=org.freedesktop.resolve1.unregister-service
ResultAny=yes

Testing

Seems to work for me!

See: homebridge/homebridge#3224

elyscape avatar Aug 27 '22 02:08 elyscape

Pull Request Test Coverage Report for Build 3358831774

  • 16 of 76 (21.05%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 51.988%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/lib/Accessory.ts 5 7 71.43%
src/lib/Advertiser.ts 11 69 15.94%
<!-- Total: 16 76
Files with Coverage Reduction New Missed Lines %
src/lib/Accessory.ts 1 43.01%
<!-- Total: 1
Totals Coverage Status
Change from base Build 3313107827: -0.2%
Covered Lines: 5812
Relevant Lines: 10223

💛 - Coveralls

coveralls avatar Sep 13 '22 09:09 coveralls

Dealt with conflicts from master and ESLint warning. This should be ready whenever.

elyscape avatar Sep 16 '22 00:09 elyscape

Can we please add this to the in-code documentation so users can easily find that.

Sure. Where should I put it?

Further, can programatically detect, if we are missing the permission for systemd-resolved such that we can issue an according warning (maybe with a link to a Wiki documentation page illustration how to configure permissions)?

If we're missing the appropriate permissions, there are a number of different errors that can occur as a result. Rather than try to figure out what they all are, how do you feel about making the error handler always issue that warning in response to failures?

elyscape avatar Sep 20 '22 04:09 elyscape

@Supereg Any thoughts on what else I should do to get this in a mergable state?

elyscape avatar Oct 13 '22 21:10 elyscape

Tests should work now, btw.

elyscape avatar Oct 18 '22 23:10 elyscape

@Supereg, I have opened this Pull Request on the UI to add resolved: https://github.com/oznu/homebridge-config-ui-x/pull/1427

donavanbecker avatar Oct 31 '22 15:10 donavanbecker