homebridge / HAP-NodeJS

Node.js implementation of the HomeKit Accessory Protocol (HAP)
Apache License 2.0
2.68k stars 630 forks source link

Lot of mDNS queries #1021

Closed miguelpruivo closed 6 months ago

miguelpruivo commented 7 months ago

Current Situation

Hi, I'm using NRCHKB (node-red with HomeKit) and I was inspecting wireshark to find that all my HK accessories from node-red are sending mDNS queries every like 5 seconds each one. So, I have around 15 accessories in node-red using this lib, which results in 15*5 = 75 mDNS queries every 5 seconds just for this accessories.

All my other network mDNS accessories that are using HK (30+) doesn't poll this often. For example, I captured traffic for 30 minutes and from my node-red instance, I got 9k packets of mdns and in second place, the accessory that had more packets, had around 300, all the other were around 300 or a bit below.

I know that NRCHKB uses this under the hood for mdns/homekit so I'd like to understand what's happening or what can be done.

Thanks.

Logs

N/A

Configuration

N/A

Environment

Process Supervisor

hb-service

Additional Context

No response

Supereg commented 7 months ago

Hey Miguel,

this behavior is likely caused by the legacy (but still default) mDNS advertiser hap-bonjour. HAP-NodeJS supports a range of different mDNS advertiser. Next to our re-written and typescript native implementation ciao there are also native solutions like avahi and resolved support. I would personally recommend using avahi when possible. There is a great article providing information on each of those options: mDNS Options. The wiki article describes how to configure this for Homebridge. When using plain hap-nodejs, you can configure the advertiser via the PublishOptions of the publish method of an Accessory. Hope this helps you getting started.

miguelpruivo commented 7 months ago

Hi @Supereg thank you for the clarification.

the thing is that I’m limited to NRCHKB implementation since I’m using that package to expose my accessories. I think I can opt for other mdns advertisers but wouldn’t changing that, break anything?

Also, most if not all my accessories in network use bonjour (I assume it’s the apple’s default) and generate much less traffic. So I’m not sure if this is due to some TTL or anything else.

cheers.

NorthernMan54 commented 7 months ago

@miguelpruivo Have you tried asking the same question to the HomeKit bridged team ? They may have some options available.

also have you tried a setting up a basic setup on a seperate machine, to see if it’s something in your setup.

PS I also run HomeKit bridged, but haven’t noticed this issue

PSS am away from my setup for a while so can’t run wireshark to see

Supereg commented 7 months ago

Hi @Supereg thank you for the clarification.

the thing is that I’m limited to NRCHKB implementation since I’m using that package to expose my accessories. I think I can opt for other mdns advertisers but wouldn’t changing that, break anything?

Also, most if not all my accessories in network use bonjour (I assume it’s the apple’s default) and generate much less traffic. So I’m not sure if this is due to some TTL or anything else.

cheers.

Opting for different mens advertisers should not break anything. Otherwise, you can also easily revert the setting if you find your setup perform worse than before. Does the NRCHKB implementation allow you to change the advertiser setting yourself?

bonjour is actually just how Apple calls mDNS. It was originally developed by Apple but is now a recognized internet standard. Also, our bonjour-hap library has nothing to do with Apple's bonjour implementation. It's just a different implementation of mDNS. Hope that clears up some stuff.

Yes, the increased traffic is a known issue with the legacy bonjour-hap implementation. That's why we originally created our new ciao library to replace it. However, we found that this caused a bunch of problems with a lot of people that had crazy VLAN setups. mDNS is not meant to bridge across VLANs, however people managed to do it with bonjour-hap and it didn't work with ciao anymore (sometimes). So we kinda reverted back to have bonjour-hap as the default. Meanwhile, we also explored other possibilities like avahi (over dBus) which works flawlessly. However, some people don't have that installed. So again we are falling back to our legacy implementation.

Shaquu commented 7 months ago

We allow using another advertisers in node red node (nrchkb). @miguelpruivo

Please head to host node (bridge or accessory) and pick desired advertiser.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 6 months ago

This issue has been closed as no further activity has occurred.