Skip to content

Commit 530dec2

Browse files
MinMDNS - do not ask for IP addresses for every SRV record that is seen (#33119)
* 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 <andreilitvin@google.com> * Fix for 1.3 compatibility * Undo submodule update --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent 4431f18 commit 530dec2

4 files changed

+56
-5
lines changed

src/lib/dnssd/ActiveResolveAttempts.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include <lib/support/logging/CHIPLogging.h>
2121

22-
#include <algorithm>
23-
2422
using namespace chip;
2523

2624
namespace mdns {
@@ -284,6 +282,32 @@ Optional<ActiveResolveAttempts::ScheduledAttempt> ActiveResolveAttempts::NextSch
284282
return Optional<ScheduledAttempt>::Missing();
285283
}
286284

285+
bool ActiveResolveAttempts::ShouldResolveIpAddress(PeerId peerId) const
286+
{
287+
for (auto & item : mRetryQueue)
288+
{
289+
if (item.attempt.IsEmpty())
290+
{
291+
continue;
292+
}
293+
if (item.attempt.IsBrowse())
294+
{
295+
return true;
296+
}
297+
298+
if (item.attempt.IsResolve())
299+
{
300+
auto & data = item.attempt.ResolveData();
301+
if (data.peerId == peerId)
302+
{
303+
return true;
304+
}
305+
}
306+
}
307+
308+
return false;
309+
}
310+
287311
bool ActiveResolveAttempts::IsWaitingForIpResolutionFor(SerializedQNameIterator hostName) const
288312
{
289313
for (auto & entry : mRetryQueue)

src/lib/dnssd/ActiveResolveAttempts.h

+6
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ class ActiveResolveAttempts
288288
/// IP resolution.
289289
bool IsWaitingForIpResolutionFor(SerializedQNameIterator hostName) const;
290290

291+
/// Determines if address resolution for the given peer ID is required
292+
///
293+
/// IP Addresses are required for active operational discovery of specific peers
294+
/// or if an active browse is being performed.
295+
bool ShouldResolveIpAddress(chip::PeerId peerId) const;
296+
291297
/// Check if a browse operation is active for the given discovery type
292298
bool HasBrowseFor(chip::Dnssd::DiscoveryType type) const;
293299

src/lib/dnssd/IncrementalResolve.h

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include <lib/dnssd/Resolver.h>
20+
#include <lib/dnssd/Types.h>
2021
#include <lib/dnssd/minimal_mdns/Parser.h>
2122
#include <lib/dnssd/minimal_mdns/RecordData.h>
2223
#include <lib/dnssd/minimal_mdns/core/QName.h>
@@ -104,6 +105,12 @@ class IncrementalResolver
104105

105106
ServiceNameType GetCurrentType() const { return mServiceNameType; }
106107

108+
PeerId OperationalParsePeerId() const
109+
{
110+
VerifyOrReturnValue(IsActiveOperationalParse(), PeerId());
111+
return mSpecificResolutionData.Get<OperationalNodeData>().peerId;
112+
}
113+
107114
/// Start parsing a new record. SRV records are the records we are mainly
108115
/// interested on, after which TXT and A/AAAA are looked for.
109116
///

src/lib/dnssd/Resolver_ImplMinimalMdns.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include "Resolver.h"
1919

20-
#include <limits>
21-
2220
#include <lib/core/CHIPConfig.h>
2321
#include <lib/dnssd/ActiveResolveAttempts.h>
2422
#include <lib/dnssd/IncrementalResolve.h>
@@ -373,7 +371,23 @@ void MinMdnsResolver::AdvancePendingResolverStates()
373371

374372
if (missing.Has(IncrementalResolver::RequiredInformationBitFlags::kIpAddress))
375373
{
376-
ScheduleIpAddressResolve(resolver->GetTargetHostName());
374+
if (resolver->IsActiveCommissionParse())
375+
{
376+
// Browse wants IP addresses
377+
ScheduleIpAddressResolve(resolver->GetTargetHostName());
378+
}
379+
else if (mActiveResolves.ShouldResolveIpAddress(resolver->OperationalParsePeerId()))
380+
{
381+
// Keep searching for IP addresses if an active resolve needs these IP addresses
382+
// otherwise ignore the data (received a SRV record without IP address, however we do not
383+
// seem interested in it. Probably just a device that came online).
384+
ScheduleIpAddressResolve(resolver->GetTargetHostName());
385+
}
386+
else
387+
{
388+
// This IP address is not interesting enough to run another discovery
389+
resolver->ResetToInactive();
390+
}
377391
continue;
378392
}
379393

0 commit comments

Comments
 (0)