From f307ffbd05da084d03ec608c1a863a0e13e63b35 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 23 Apr 2024 13:42:58 -0400 Subject: [PATCH 1/3] MinMDNS - do not ask for IP addresses for every SRV record that is seen (#33095) * Initial version of a test app - ability to just send a packet into the world * Update constants to match a real advertisement * Only resolve IP addresses if we are interested in this path * Fix up logic: this is per peer id * Remove unused include * Undo debug code * Undo extra header add * Add header back, but with full path * Fix up some more headers * Remove unhelpful comment * Move tester program out (will be part of another PR) --------- Co-authored-by: Andrei Litvin --- src/lib/dnssd/ActiveResolveAttempts.cpp | 28 ++++++++++++++++++++-- src/lib/dnssd/ActiveResolveAttempts.h | 6 +++++ src/lib/dnssd/IncrementalResolve.h | 7 ++++++ src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 20 +++++++++++++--- 4 files changed, 56 insertions(+), 5 deletions(-) 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..bb469ca0b9df66 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->IsActiveBrowseParse()) + { + // 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; } From 98be23afc1b01ef9d0e8b117f769c12234a3fa15 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 23 Apr 2024 13:57:02 -0400 Subject: [PATCH 2/3] Fix for 1.3 compatibility --- src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 2 +- third_party/silabs/matter_support | 2 +- third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index bb469ca0b9df66..7625286dd31b38 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -371,7 +371,7 @@ void MinMdnsResolver::AdvancePendingResolverStates() if (missing.Has(IncrementalResolver::RequiredInformationBitFlags::kIpAddress)) { - if (resolver->IsActiveBrowseParse()) + if (resolver->IsActiveCommissionParse()) { // Browse wants IP addresses ScheduleIpAddressResolve(resolver->GetTargetHostName()); diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 53f098de9fdc7d..0dbd0dd89fa90d 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 53f098de9fdc7db248a72eabbe07d8ce4876daab +Subproject commit 0dbd0dd89fa90dc6e0d1d2636563ea980c010c19 diff --git a/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx b/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx index 93adb547344293..374a26a45a5b05 160000 --- a/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx +++ b/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx @@ -1 +1 @@ -Subproject commit 93adb5473442932cdd056e20770ce1326bd8afb7 +Subproject commit 374a26a45a5b05cd87c62d9a5da04d9e6d0ed319 From ce0d9b123d786753c179e177582818203ead7b9b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 23 Apr 2024 13:59:24 -0400 Subject: [PATCH 3/3] Undo submodule update --- third_party/silabs/matter_support | 2 +- third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 0dbd0dd89fa90d..53f098de9fdc7d 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 0dbd0dd89fa90dc6e0d1d2636563ea980c010c19 +Subproject commit 53f098de9fdc7db248a72eabbe07d8ce4876daab diff --git a/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx b/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx index 374a26a45a5b05..93adb547344293 160000 --- a/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx +++ b/third_party/ti_simplelink_sdk/repo_cc13xx_cc26xx @@ -1 +1 @@ -Subproject commit 374a26a45a5b05cd87c62d9a5da04d9e6d0ed319 +Subproject commit 93adb5473442932cdd056e20770ce1326bd8afb7