[mdns] Tighten ESP8266 guards, expand window to 15s, document derivation

- mdns_esp8266.cpp: narrow setup()'s listener block and on_ip_state from
  USE_MDNS_EVENT_DRIVEN_POLLING to USE_MDNS_WIFI_LISTENER. ESP8266 has no
  ethernet so the practical effect is identical, but the tighter guard is
  symmetric with mdns_rp2040.cpp and more defensible if the listener macros
  ever drift.
- MDNS_POLL_WINDOW_MS 12000 → 15000. The RFC-compliant LEAmDNS phase is ~9s
  worst case, but a blocked main loop (long component setup, WiFi scan, flash
  writes) can stretch the deadlines between our polls. 6s of margin absorbs
  that without materially extending the steady-state quiet period.
- Header comment for MDNS_POLL_WINDOW_MS now breaks down the 9s derivation
  with the exact LEAmDNS constants (MDNS_PROBE_DELAY × MDNS_PROBE_COUNT +
  MDNS_ANNOUNCE_DELAY × MDNS_ANNOUNCE_COUNT + jitter + debounce hop) so
  future library bumps can be justified against the same math.
This commit is contained in:
J. Nick Koston
2026-04-23 21:48:18 -05:00
parent 097377f7b5
commit 811d4ddfbd
2 changed files with 13 additions and 3 deletions
+11 -1
View File
@@ -76,7 +76,17 @@ class MDNSComponent final : public Component
// and update() becomes pure overhead. We arm a bounded polling window from IP state
// listener events so update() runs only during that phase.
static constexpr uint32_t MDNS_UPDATE_INTERVAL_MS = 50;
static constexpr uint32_t MDNS_POLL_WINDOW_MS = 12000; // ~9s phase + jitter/restart margin
// Must exceed LEAmDNS's longest restart-to-announce-complete path:
// MDNS_PROBE_DELAY (250ms) × MDNS_PROBE_COUNT (3) = 750ms probing
// + MDNS_ANNOUNCE_DELAY (1000ms) × MDNS_ANNOUNCE_COUNT (8) = 8000ms announcing
// + rand() % MDNS_PROBE_DELAY jitter on first probe (0250ms)
// + debounced schedule_function() hop when statusChangeCB fires on ESP8266
// ≈ 9s nominal. 15s gives ~6s margin to absorb main-loop blocking (long
// component setup, WiFi scan, flash writes) that could stretch the deadlines
// between our polls. If LEAmDNS ever extends its phase (upstream library
// update) this constant needs to grow. Constants defined in LEAmDNS_Priv.h
// (ESP8266 core 3.1.2 / arduino-pico 5.5.1).
static constexpr uint32_t MDNS_POLL_WINDOW_MS = 15000;
static constexpr uint32_t MDNS_POLL_ID = 0;
static constexpr uint32_t MDNS_POLL_STOP_ID = 1;
#endif
+2 -2
View File
@@ -48,7 +48,7 @@ void MDNSComponent::start_polling_window_() {
void MDNSComponent::setup() {
this->setup_buffers_and_register_(register_esp8266);
#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
#ifdef USE_MDNS_WIFI_LISTENER
// LEAmDNS's own LwipIntf::statusChangeCB drives _restart() on netif changes; we just
// arm the window around the initial probe/announce and each reconnect. Unconditional
// here is safe: setup_priority::AFTER_CONNECTION guarantees the network is up.
@@ -57,7 +57,7 @@ void MDNSComponent::setup() {
#endif
}
#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
#ifdef USE_MDNS_WIFI_LISTENER
void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network::IPAddress &,
const network::IPAddress &) {
// IP listener only fires on acquisition (not loss), so any notification is a fresh