maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.11k stars 170 forks source link

Increase maximum buffer for mDNS packets to 1.5KB. #29

Closed gongloo closed 6 years ago

gongloo commented 6 years ago

The mDNS packets used in HomeKit scale linearly in size with the number of HomeKit devices. With dozens of HomeKit devices, we blow right through the 512B packet buffer currently set as default. Increasing that default to 1.5K works around the issue entirely, empirically, and shouldn't have any lasting memory effect since these buffers live only within respective mDNS callbacks.

Of course, I could do this on a case-by-case basis via CFLAGS, but I suspect that the intent is that the default handles most usual cases. I'm not sure at what point HomeKit clients will split up the mDNS requests, but I decided not to dig further into it upon finding that 1.5K was enough to handle any amount of devices I could throw at it -- tested ~30 or so. My suspicion is that iOS devices will impose an MTU of <1.5K when serializing mDNS.

milliamp commented 6 years ago

Indeed, I have mine up at 1.5K to ensure more mDNS messages get decoded with 8 HomeKit devices adding their answers to mDNS questions and to stop the logging spam from the over-size message.