Skip to content

Commit a89ab24

Browse files
LaborEtArsd-a-v
authored andcommitted
LEAmDNS Fixes (#5641)
- Better separation of ESP wifi thread code from user thread code - Added a flag for 'update()'-less use (disabled by default) - The too fast updates for service queries are fixed - Switched fully to PolledTimeout; LEATimeFlag not needed anymore (BTW: a const 'expired()' method would be helpful) - The device should stay visible now even after the first TTL timeout - Improved service querying (queries five times now) - Fixed TTL (bug introduced with Fixes 1.0)
1 parent e9a6fd2 commit a89ab24

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

Diff for: libraries/ESP8266mDNS/src/LEAmDNS.cpp

+18-13
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,26 @@ MDNSResponder::~MDNSResponder(void) {
8787
*/
8888
bool MDNSResponder::begin(const char* p_pcHostname) {
8989

90-
bool bResult = false;
90+
bool bResult = (0 != m_pcHostname);
9191

92-
if (_setHostname(p_pcHostname)) {
93-
94-
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
95-
(void) pEvent;
96-
_restart();
97-
});
98-
99-
m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
100-
(void) pEvent;
101-
_restart();
102-
});
92+
if (0 == m_pcHostname) {
93+
if (_setHostname(p_pcHostname)) {
10394

104-
bResult = _restart();
95+
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
96+
(void) pEvent;
97+
_restart();
98+
});
99+
100+
m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
101+
(void) pEvent;
102+
_restart();
103+
});
104+
105+
bResult = _restart();
106+
}
107+
}
108+
else {
109+
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: Ignoring multiple calls (Ignored host domain: '%s')!\n"), (p_pcHostname ?: "-")););
105110
}
106111
DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: FAILED for '%s'!\n"), (p_pcHostname ?: "-")); } );
107112
return bResult;

Diff for: libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
480480

481481
sendParameter.m_bResponse = true;
482482
sendParameter.m_bAuthorative = true;
483-
sendParameter.m_bCacheFlush = false;
484483

485484
bResult = _sendMDNSMessage(sendParameter);
486485
}
@@ -1214,7 +1213,7 @@ bool MDNSResponder::_sendHostProbe(void) {
12141213

12151214
//sendParameter.m_pQuestions->m_bUnicast = true;
12161215
sendParameter.m_pQuestions->m_Header.m_Attributes.m_u16Type = DNS_RRTYPE_ANY;
1217-
sendParameter.m_pQuestions->m_Header.m_Attributes.m_u16Class = (/*0x8000 |*/ DNS_RRCLASS_IN); // Unicast & INternet
1216+
sendParameter.m_pQuestions->m_Header.m_Attributes.m_u16Class = (0x8000 | DNS_RRCLASS_IN); // Unicast & INternet
12181217

12191218
// Add known answers
12201219
#ifdef MDNS_IP4_SUPPORT

Diff for: libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,7 @@ bool MDNSResponder::_writeMDNSAnswer_PTR_TYPE(MDNSResponder::stcMDNSService& p_r
14391439

14401440
stcMDNS_RRDomain dnssdDomain;
14411441
stcMDNS_RRDomain serviceDomain;
1442-
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR,
1443-
((p_rSendParameter.m_bCacheFlush ? 0x8000 : 0) | DNS_RRCLASS_IN)); // Cache flush? & INternet
1442+
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR, DNS_RRCLASS_IN); // No cache flush! only INternet
14441443
bool bResult = ((_buildDomainForDNSSD(dnssdDomain)) && // _services._dns-sd._udp.local
14451444
(_writeMDNSRRDomain(dnssdDomain, p_rSendParameter)) &&
14461445
(_writeMDNSRRAttributes(attributes, p_rSendParameter)) && // TYPE & CLASS
@@ -1465,8 +1464,7 @@ bool MDNSResponder::_writeMDNSAnswer_PTR_NAME(MDNSResponder::stcMDNSService& p_r
14651464
MDNSResponder::stcMDNSSendParameter& p_rSendParameter) {
14661465
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _writeMDNSAnswer_PTR_NAME\n")););
14671466

1468-
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR,
1469-
((p_rSendParameter.m_bCacheFlush ? 0x8000 : 0) | DNS_RRCLASS_IN)); // Cache flush? & INternet
1467+
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR, DNS_RRCLASS_IN); // No cache flush! only INternet
14701468
bool bResult = ((_writeMDNSServiceDomain(p_rService, false, false, p_rSendParameter)) && // _http._tcp.local
14711469
(_writeMDNSRRAttributes(attributes, p_rSendParameter)) && // TYPE & CLASS
14721470
(_write32((p_rSendParameter.m_bUnannounce ? 0 : MDNS_SERVICE_TTL), p_rSendParameter)) && // TTL

0 commit comments

Comments
 (0)