Skip to content

LEAmDNS Fixes 1.1 #5619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,14 @@ void loop(void) {
MDNS.update();

// Update time (if needed)
//static unsigned long ulNextTimeUpdate = UPDATE_CYCLE;
static clsMDNSTimeFlag timeFlag(UPDATE_CYCLE);
if (timeFlag.flagged()/*ulNextTimeUpdate < millis()*/) {
static esp8266::polledTimeout::periodic timeout(UPDATE_CYCLE);
if (timeout.expired()) {

if (hMDNSService) {
// Just trigger a new MDNS announcement, this will lead to a call to
// 'MDNSDynamicServiceTxtCallback', which will update the time TXT item
MDNS.announce();
}
//ulNextTimeUpdate = (millis() + UPDATE_CYCLE); // Set update 'timer'
timeFlag.restart();
}
}

Expand Down
60 changes: 0 additions & 60 deletions libraries/ESP8266mDNS/src/LEATimeFlag.h

This file was deleted.

21 changes: 17 additions & 4 deletions libraries/ESP8266mDNS/src/LEAmDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ MDNSResponder::MDNSResponder(void)
m_pcHostname(0),
m_pServiceQueries(0),
m_fnServiceTxtCallback(0),
m_pServiceTxtCallbackUserdata(0) {
m_pServiceTxtCallbackUserdata(0),
#ifdef ENABLE_ESP_MDNS_RESPONDER_PASSIV_MODE
m_bPassivModeEnabled(true) {
#else
m_bPassivModeEnabled(false) {
#endif

}

Expand Down Expand Up @@ -123,7 +128,7 @@ bool MDNSResponder::begin(const char* p_pcHostname,
*/
bool MDNSResponder::close(void) {

_announce(false);
_announce(false, true);
_resetProbeStatus(false); // Stop probing

_releaseServiceQueries();
Expand Down Expand Up @@ -205,6 +210,7 @@ MDNSResponder::hMDNSService MDNSResponder::addService(const char* p_pcName,
}
}
} // else: bad arguments
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] addService: %s to add '%s.%s.%s'!\n"), (hResult ? "Succeeded" : "FAILED"), (p_pcName ?: "-"), p_pcService, p_pcProtocol); );
DEBUG_EX_ERR(if (!hResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] addService: FAILED to add '%s.%s.%s'!\n"), (p_pcName ?: "-"), p_pcService, p_pcProtocol); } );
return hResult;
}
Expand Down Expand Up @@ -768,13 +774,17 @@ MDNSResponder::hMDNSServiceQuery MDNSResponder::installServiceQuery(const char*
pServiceQuery->m_bLegacyQuery = false;

if (_sendMDNSServiceQuery(*pServiceQuery)) {
pServiceQuery->m_u8SentCount = 1;
pServiceQuery->m_ResendTimeout.reset(MDNS_DYNAMIC_QUERY_RESEND_DELAY);

hResult = (hMDNSServiceQuery)pServiceQuery;
}
else {
_removeServiceQuery(pServiceQuery);
}
}
DEBUG_EX_ERR(if (!hResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] installServiceQuery: FAILED for '%s.%s'!\n"), (p_pcService ?: "-"), (p_pcProtocol ?: "-")); } );
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] installServiceQuery: %s for '%s.%s'!\n\n"), (hResult ? "Succeeded" : "FAILED"), (p_pcService ?: "-"), (p_pcProtocol ?: "-")););
DEBUG_EX_ERR(if (!hResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] installServiceQuery: FAILED for '%s.%s'!\n\n"), (p_pcService ?: "-"), (p_pcProtocol ?: "-")); } );
return hResult;
}

Expand Down Expand Up @@ -1073,6 +1083,9 @@ bool MDNSResponder::notifyAPChange(void) {
*/
bool MDNSResponder::update(void) {

if (m_bPassivModeEnabled) {
m_bPassivModeEnabled = false;
}
return _process(true);
}

Expand All @@ -1083,7 +1096,7 @@ bool MDNSResponder::update(void) {
*/
bool MDNSResponder::announce(void) {

return (_announce());
return (_announce(true, true));
}

/*
Expand Down
66 changes: 47 additions & 19 deletions libraries/ESP8266mDNS/src/LEAmDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* Reference:
* Used mDNS messages:
* A (0x01): eg. esp8266.local A OP TTL 123.456.789.012
* AAAA (01Cx): eg. esp8266.local AAAA OP TTL 1234:5678::90
* AAAA (0x1C): eg. esp8266.local AAAA OP TTL 1234:5678::90
* PTR (0x0C, srv name): eg. _http._tcp.local PTR OP TTL MyESP._http._tcp.local
* PTR (0x0C, srv type): eg. _services._dns-sd._udp.local PTR OP TTL _http._tcp.local
* PTR (0x0C, IP4): eg. 012.789.456.123.in-addr.arpa PTR OP TTL esp8266.local
Expand Down Expand Up @@ -107,7 +107,8 @@
#include "lwip/udp.h"
#include "debug.h"
#include "include/UdpContext.h"
#include "LEATimeFlag.h"
#include <limits>
#include <PolledTimeout.h>

#include "ESP8266WiFi.h"

Expand Down Expand Up @@ -786,8 +787,9 @@ class MDNSResponder {
*/
struct stcProbeInformation {
enuProbingStatus m_ProbingStatus;
uint8_t m_u8ProbesSent;
clsMDNSTimeFlag m_NextProbeTimeFlag;
uint8_t m_u8SentCount; // Used for probes and announcements
esp8266::polledTimeout::oneShot m_Timeout; // Used for probes and announcements
//clsMDNSTimeFlag m_TimeFlag; // Used for probes and announcements
bool m_bConflict;
bool m_bTiebreakNeeded;
MDNSProbeResultCallbackFn m_fnProbeResultCallback;
Expand Down Expand Up @@ -842,14 +844,32 @@ class MDNSResponder {
* stcTTL
*/
struct stcTTL {
clsMDNSTimeFlag m_TTLTimeFlag;
bool m_bUpdateScheduled;
/**
* timeoutLevel_t
*/
typedef uint8_t timeoutLevel_t;
/**
* TIMEOUTLEVELs
*/
const timeoutLevel_t TIMEOUTLEVEL_UNSET = 0;
const timeoutLevel_t TIMEOUTLEVEL_BASE = 80;
const timeoutLevel_t TIMEOUTLEVEL_INTERVAL = 5;
const timeoutLevel_t TIMEOUTLEVEL_FINAL = 100;

stcTTL(uint32_t p_u32TTL = 0);
uint32_t m_u32TTL;
esp8266::polledTimeout::oneShot m_TTLTimeout;
timeoutLevel_t m_timeoutLevel;

stcTTL(void);
bool set(uint32_t p_u32TTL);

bool has80Percent(void) const;
bool isOutdated(void) const;
bool flagged(void) const;
bool restart(void);

bool prepareDeletion(void);
bool finalTimeoutLevel(void) const;

unsigned long timeout(void) const;
};
#ifdef MDNS_IP4_SUPPORT
/**
Expand All @@ -861,7 +881,7 @@ class MDNSResponder {
stcTTL m_TTL;

stcIP4Address(IPAddress p_IPAddress,
uint32_t p_u32TTL = 0);
uint32_t p_u32TTL = 0);
};
#endif
#ifdef MDNS_IP6_SUPPORT
Expand All @@ -872,6 +892,9 @@ class MDNSResponder {
stcIP6Address* m_pNext;
IP6Address m_IPAddress;
stcTTL m_TTL;

stcIP6Address(IPAddress p_IPAddress,
uint32_t p_u32TTL = 0);
};
#endif

Expand Down Expand Up @@ -932,13 +955,15 @@ class MDNSResponder {
#endif
};

stcMDNSServiceQuery* m_pNext;
stcMDNS_RRDomain m_ServiceTypeDomain; // eg. _http._tcp.local
MDNSServiceQueryCallbackFn m_fnCallback;
void* m_pUserdata;
bool m_bLegacyQuery;
bool m_bAwaitingAnswers;
stcAnswer* m_pAnswers;
stcMDNSServiceQuery* m_pNext;
stcMDNS_RRDomain m_ServiceTypeDomain; // eg. _http._tcp.local
MDNSServiceQueryCallbackFn m_fnCallback;
void* m_pUserdata;
bool m_bLegacyQuery;
uint8_t m_u8SentCount;
esp8266::polledTimeout::oneShot m_ResendTimeout;
bool m_bAwaitingAnswers;
stcAnswer* m_pAnswers;

stcMDNSServiceQuery(void);
~stcMDNSServiceQuery(void);
Expand Down Expand Up @@ -1012,6 +1037,7 @@ class MDNSResponder {
WiFiEventHandler m_GotIPHandler;
MDNSDynamicServiceTxtCallbackFn m_fnServiceTxtCallback;
void* m_pServiceTxtCallbackUserdata;
bool m_bPassivModeEnabled;
stcProbeInformation m_HostProbeInformation;

/** CONTROL **/
Expand Down Expand Up @@ -1047,7 +1073,8 @@ class MDNSResponder {
bool _cancelProbingForService(stcMDNSService& p_rService);

/* ANNOUNCE */
bool _announce(bool p_bAnnounce = true);
bool _announce(bool p_bAnnounce,
bool p_bIncludeServices);
bool _announceService(stcMDNSService& p_rService,
bool p_bAnnounce = true);

Expand All @@ -1064,7 +1091,8 @@ class MDNSResponder {
IPAddress p_IPAddress);
bool _sendMDNSServiceQuery(const stcMDNSServiceQuery& p_ServiceQuery);
bool _sendMDNSQuery(const stcMDNS_RRDomain& p_QueryDomain,
uint16_t p_u16QueryType);
uint16_t p_u16QueryType,
stcMDNSServiceQuery::stcAnswer* p_pKnownAnswers = 0);

IPAddress _getResponseMulticastInterface(int p_iWiFiOpModes) const;

Expand Down
Loading