1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

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)
This commit is contained in:
LaborEtArs 2019-01-22 12:21:42 +01:00 committed by david gauchard
parent e9a6fd2f82
commit a89ab24edc
3 changed files with 21 additions and 19 deletions

View File

@ -87,21 +87,26 @@ MDNSResponder::~MDNSResponder(void) {
*/
bool MDNSResponder::begin(const char* p_pcHostname) {
bool bResult = false;
bool bResult = (0 != m_pcHostname);
if (_setHostname(p_pcHostname)) {
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
(void) pEvent;
_restart();
});
m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
(void) pEvent;
_restart();
});
if (0 == m_pcHostname) {
if (_setHostname(p_pcHostname)) {
bResult = _restart();
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
(void) pEvent;
_restart();
});
m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
(void) pEvent;
_restart();
});
bResult = _restart();
}
}
else {
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: Ignoring multiple calls (Ignored host domain: '%s')!\n"), (p_pcHostname ?: "-")););
}
DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: FAILED for '%s'!\n"), (p_pcHostname ?: "-")); } );
return bResult;

View File

@ -480,7 +480,6 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
sendParameter.m_bResponse = true;
sendParameter.m_bAuthorative = true;
sendParameter.m_bCacheFlush = false;
bResult = _sendMDNSMessage(sendParameter);
}
@ -1214,7 +1213,7 @@ bool MDNSResponder::_sendHostProbe(void) {
//sendParameter.m_pQuestions->m_bUnicast = true;
sendParameter.m_pQuestions->m_Header.m_Attributes.m_u16Type = DNS_RRTYPE_ANY;
sendParameter.m_pQuestions->m_Header.m_Attributes.m_u16Class = (/*0x8000 |*/ DNS_RRCLASS_IN); // Unicast & INternet
sendParameter.m_pQuestions->m_Header.m_Attributes.m_u16Class = (0x8000 | DNS_RRCLASS_IN); // Unicast & INternet
// Add known answers
#ifdef MDNS_IP4_SUPPORT

View File

@ -1439,8 +1439,7 @@ bool MDNSResponder::_writeMDNSAnswer_PTR_TYPE(MDNSResponder::stcMDNSService& p_r
stcMDNS_RRDomain dnssdDomain;
stcMDNS_RRDomain serviceDomain;
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR,
((p_rSendParameter.m_bCacheFlush ? 0x8000 : 0) | DNS_RRCLASS_IN)); // Cache flush? & INternet
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR, DNS_RRCLASS_IN); // No cache flush! only INternet
bool bResult = ((_buildDomainForDNSSD(dnssdDomain)) && // _services._dns-sd._udp.local
(_writeMDNSRRDomain(dnssdDomain, p_rSendParameter)) &&
(_writeMDNSRRAttributes(attributes, p_rSendParameter)) && // TYPE & CLASS
@ -1465,8 +1464,7 @@ bool MDNSResponder::_writeMDNSAnswer_PTR_NAME(MDNSResponder::stcMDNSService& p_r
MDNSResponder::stcMDNSSendParameter& p_rSendParameter) {
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _writeMDNSAnswer_PTR_NAME\n")););
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR,
((p_rSendParameter.m_bCacheFlush ? 0x8000 : 0) | DNS_RRCLASS_IN)); // Cache flush? & INternet
stcMDNS_RRAttributes attributes(DNS_RRTYPE_PTR, DNS_RRCLASS_IN); // No cache flush! only INternet
bool bResult = ((_writeMDNSServiceDomain(p_rService, false, false, p_rSendParameter)) && // _http._tcp.local
(_writeMDNSRRAttributes(attributes, p_rSendParameter)) && // TYPE & CLASS
(_write32((p_rSendParameter.m_bUnannounce ? 0 : MDNS_SERVICE_TTL), p_rSendParameter)) && // TTL