diff --git a/src/lib/dnssd/ActiveResolveAttempts.cpp b/src/lib/dnssd/ActiveResolveAttempts.cpp index fe0cc16ebb26aa..f49056896e0b2e 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.cpp +++ b/src/lib/dnssd/ActiveResolveAttempts.cpp @@ -19,8 +19,6 @@ #include -#include - using namespace chip; namespace mdns { @@ -284,6 +282,32 @@ Optional ActiveResolveAttempts::NextSch return Optional::Missing(); } +bool ActiveResolveAttempts::ShouldResolveIpAddress(PeerId peerId) const +{ + for (auto & item : mRetryQueue) + { + if (item.attempt.IsEmpty()) + { + continue; + } + if (item.attempt.IsBrowse()) + { + return true; + } + + if (item.attempt.IsResolve()) + { + auto & data = item.attempt.ResolveData(); + if (data.peerId == peerId) + { + return true; + } + } + } + + return false; +} + bool ActiveResolveAttempts::IsWaitingForIpResolutionFor(SerializedQNameIterator hostName) const { for (auto & entry : mRetryQueue) diff --git a/src/lib/dnssd/ActiveResolveAttempts.h b/src/lib/dnssd/ActiveResolveAttempts.h index 15796abf85b20c..c3758ac3438c25 100644 --- a/src/lib/dnssd/ActiveResolveAttempts.h +++ b/src/lib/dnssd/ActiveResolveAttempts.h @@ -288,6 +288,12 @@ class ActiveResolveAttempts /// IP resolution. bool IsWaitingForIpResolutionFor(SerializedQNameIterator hostName) const; + /// Determines if address resolution for the given peer ID is required + /// + /// IP Addresses are required for active operational discovery of specific peers + /// or if an active browse is being performed. + bool ShouldResolveIpAddress(chip::PeerId peerId) const; + /// Check if a browse operation is active for the given discovery type bool HasBrowseFor(chip::Dnssd::DiscoveryType type) const; diff --git a/src/lib/dnssd/IncrementalResolve.h b/src/lib/dnssd/IncrementalResolve.h index b28b3cb897b5f3..f4ee4b8d66052a 100644 --- a/src/lib/dnssd/IncrementalResolve.h +++ b/src/lib/dnssd/IncrementalResolve.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include #include @@ -104,6 +105,12 @@ class IncrementalResolver ServiceNameType GetCurrentType() const { return mServiceNameType; } + PeerId OperationalParsePeerId() const + { + VerifyOrReturnValue(IsActiveOperationalParse(), PeerId()); + return mSpecificResolutionData.Get().peerId; + } + /// Start parsing a new record. SRV records are the records we are mainly /// interested on, after which TXT and A/AAAA are looked for. /// diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 64461965367b13..7625286dd31b38 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -17,8 +17,6 @@ #include "Resolver.h" -#include - #include #include #include @@ -373,7 +371,23 @@ void MinMdnsResolver::AdvancePendingResolverStates() if (missing.Has(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)) { - ScheduleIpAddressResolve(resolver->GetTargetHostName()); + if (resolver->IsActiveCommissionParse()) + { + // Browse wants IP addresses + ScheduleIpAddressResolve(resolver->GetTargetHostName()); + } + else if (mActiveResolves.ShouldResolveIpAddress(resolver->OperationalParsePeerId())) + { + // Keep searching for IP addresses if an active resolve needs these IP addresses + // otherwise ignore the data (received a SRV record without IP address, however we do not + // seem interested in it. Probably just a device that came online). + ScheduleIpAddressResolve(resolver->GetTargetHostName()); + } + else + { + // This IP address is not interesting enough to run another discovery + resolver->ResetToInactive(); + } continue; }