Skip to content

Commit

Permalink
Cancel the SRP timer if we have resolved on the SRP domain but the kD… (
Browse files Browse the repository at this point in the history
#32948)

* Cancel the SRP timer if we have resolved on the SRP domain but the kDNSServiceFlagsMoreComing is set indicating there are more results coming

* Update src/platform/Darwin/DnssdImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Addressed review comments

---------

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed May 8, 2024
1 parent 83755d2 commit 1920997
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
15 changes: 8 additions & 7 deletions src/platform/Darwin/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,7 @@ ResolveContext::ResolveContext(DiscoverNodeDelegate * delegate, chip::Inet::IPAd

ResolveContext::~ResolveContext()
{
if (isSRPTimerRunning)
{
CancelSRPTimer();
}
CancelSRPTimerIfRunning();
}

void ResolveContext::DispatchFailure(const char * errorStr, CHIP_ERROR err)
Expand Down Expand Up @@ -647,10 +644,14 @@ void ResolveContext::SRPTimerExpiredCallback(chip::System::Layer * systemLayer,
sdCtx->Finalize();
}

void ResolveContext::CancelSRPTimer()
void ResolveContext::CancelSRPTimerIfRunning()
{
DeviceLayer::SystemLayer().CancelTimer(SRPTimerExpiredCallback, static_cast<void *>(this));
ChipLogProgress(Discovery, "SRP resolve timer for %s cancelled; resolve timed out", instanceName.c_str());
if (isSRPTimerRunning)
{
DeviceLayer::SystemLayer().CancelTimer(SRPTimerExpiredCallback, static_cast<void *>(this));
ChipLogProgress(Discovery, "SRP resolve timer for %s cancelled; resolve timed out", instanceName.c_str());
isSRPTimerRunning = false;
}
}

CHIP_ERROR ResolveContext::OnNewAddress(const InterfaceKey & interfaceKey, const struct sockaddr * address)
Expand Down
7 changes: 7 additions & 0 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i

if (flags & kDNSServiceFlagsMoreComing)
{
// If we now don't need to have a timer while we wait for SRP results, ensure that there is no such
// timer running. Otherwise the timer could fire before we get the rest of the results that flags
// say are coming, and trigger a finalize before we have all the data that is already available.
if (!sdCtx->shouldStartSRPTimerForResolve)
{
sdCtx->CancelSRPTimerIfRunning();
}
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/platform/Darwin/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ struct ResolveContext : public GenericContext
*/
static void SRPTimerExpiredCallback(chip::System::Layer * systemLayer, void * callbackContext);

/**
* @brief Cancels the timer that was started to wait for the resolution on the kSRPDot domain to happen.
*
*/
void CancelSRPTimerIfRunning();

private:
/**
* Try reporting the results we got on the provided interface index.
Expand All @@ -306,12 +312,6 @@ struct ResolveContext : public GenericContext
bool TryReportingResultsForInterfaceIndex(uint32_t interfaceIndex, const std::string & hostname, bool isSRPResult);

bool TryReportingResultsForInterfaceIndex(uint32_t interfaceIndex);

/**
* @brief Cancels the timer that was started to wait for the resolution on the kSRPDot domain to happen.
*
*/
void CancelSRPTimer();
};

} // namespace Dnssd
Expand Down

0 comments on commit 1920997

Please sign in to comment.