Skip to content
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

[dns-sd] Untangle dependencies between Resolver and ResolverProxy #30563

Merged
merged 4 commits into from
Nov 23, 2023
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
2 changes: 0 additions & 2 deletions src/app/CASESessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include <transport/SessionDelegate.h>
#include <transport/SessionUpdateDelegate.h>

#include <lib/dnssd/ResolverProxy.h>

namespace chip {

class OperationalSessionSetupPoolDelegate;
Expand Down
2 changes: 0 additions & 2 deletions src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,13 @@ CHIP_ERROR DiscoveryCommands::SetupDiscoveryCommands()
ReturnErrorOnFailure(mDNSResolver.Init(chip::DeviceLayer::UDPEndPointManager()));
mReady = true;
}
mDNSResolver.SetOperationalDelegate(this);
mDNSResolver.SetCommissioningDelegate(this);
return CHIP_NO_ERROR;
}

CHIP_ERROR DiscoveryCommands::TearDownDiscoveryCommands()
{
mDNSResolver.StopDiscovery();
mDNSResolver.SetOperationalDelegate(nullptr);
mDNSResolver.SetCommissioningDelegate(nullptr);
return CHIP_NO_ERROR;
}
Expand Down
6 changes: 1 addition & 5 deletions src/app/tests/suites/commands/discovery/DiscoveryCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <app-common/zap-generated/tests/simulated-cluster-objects.h>

class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate, public chip::Dnssd::OperationalResolveDelegate
class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate
{
public:
DiscoveryCommands(){};
Expand Down Expand Up @@ -64,10 +64,6 @@ class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate, publ
/////////// CommissioningDelegate Interface /////////
void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override;

/////////// OperationalDelegate Interface /////////
void OnOperationalNodeResolved(const chip::Dnssd::ResolvedNodeData & nodeData) override{};
void OnOperationalNodeResolutionFailed(const chip::PeerId & peerId, CHIP_ERROR error) override{};

private:
bool mReady = false;
chip::Dnssd::ResolverProxy mDNSResolver;
Expand Down
3 changes: 1 addition & 2 deletions src/controller/AbstractDnssdDiscoveryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ namespace Controller {
class DLL_EXPORT AbstractDnssdDiscoveryController : public Dnssd::CommissioningResolveDelegate
{
public:
AbstractDnssdDiscoveryController() {}
~AbstractDnssdDiscoveryController() override { mDNSResolver.Shutdown(); }
explicit AbstractDnssdDiscoveryController(Dnssd::Resolver * resolver = nullptr) : mDNSResolver(resolver) {}

void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override;
CHIP_ERROR StopDiscovery() { return mDNSResolver.StopDiscovery(); };
Expand Down
26 changes: 4 additions & 22 deletions src/controller/CHIPCommissionableNodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,12 @@ CHIP_ERROR CommissionableNodeController::DiscoverCommissioners(Dnssd::DiscoveryF
{
ReturnErrorOnFailure(SetUpNodeDiscovery());

if (mResolver == nullptr)
{
#if CONFIG_DEVICE_LAYER
mDNSResolver.Shutdown(); // reset if already inited
ReturnErrorOnFailure(mDNSResolver.Init(DeviceLayer::UDPEndPointManager()));
mDNSResolver.Shutdown(); // reset if already inited
ReturnErrorOnFailure(mDNSResolver.Init(DeviceLayer::UDPEndPointManager()));
#endif
mDNSResolver.SetCommissioningDelegate(this);
return mDNSResolver.DiscoverCommissioners(discoveryFilter);
}

#if CONFIG_DEVICE_LAYER
ReturnErrorOnFailure(mResolver->Init(DeviceLayer::UDPEndPointManager()));
#endif
return mResolver->DiscoverCommissioners(discoveryFilter);
}

CHIP_ERROR CommissionableNodeController::StopDiscovery()
{
if (mResolver == nullptr)
{
return AbstractDnssdDiscoveryController::StopDiscovery();
}

return mResolver->StopDiscovery();
mDNSResolver.SetCommissioningDelegate(this);
return mDNSResolver.DiscoverCommissioners(discoveryFilter);
}

CommissionableNodeController::~CommissionableNodeController()
Expand Down
5 changes: 1 addition & 4 deletions src/controller/CHIPCommissionableNodeController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ namespace Controller {
class DLL_EXPORT CommissionableNodeController : public AbstractDnssdDiscoveryController
{
public:
CommissionableNodeController(chip::Dnssd::Resolver * resolver = nullptr) : mResolver(resolver) {}
CommissionableNodeController(chip::Dnssd::Resolver * resolver = nullptr) : AbstractDnssdDiscoveryController(resolver) {}
~CommissionableNodeController() override;

void RegisterDeviceDiscoveryDelegate(DeviceDiscoveryDelegate * delegate) { mDeviceDiscoveryDelegate = delegate; }
CHIP_ERROR DiscoverCommissioners(Dnssd::DiscoveryFilter discoveryFilter = Dnssd::DiscoveryFilter());

CHIP_ERROR StopDiscovery();

/**
* @return
* Pointer to DiscoveredNodeData at index idx in the list of commissioners discovered
Expand All @@ -57,7 +55,6 @@ class DLL_EXPORT CommissionableNodeController : public AbstractDnssdDiscoveryCon
DiscoveredNodeList GetDiscoveredNodes() override { return DiscoveredNodeList(mDiscoveredCommissioners); }

private:
Dnssd::Resolver * mResolver = nullptr;
Dnssd::DiscoveredNodeData mDiscoveredCommissioners[CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES];
};

Expand Down
7 changes: 3 additions & 4 deletions src/controller/tests/TestCommissionableNodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ class MockResolver : public Resolver
bool IsInitialized() override { return true; }
void Shutdown() override {}
void SetOperationalDelegate(OperationalResolveDelegate * delegate) override {}
void SetCommissioningDelegate(CommissioningResolveDelegate * delegate) override {}
CHIP_ERROR ResolveNodeId(const PeerId & peerId) override { return ResolveNodeIdStatus; }
void NodeIdResolutionNoLongerNeeded(const PeerId & peerId) override {}
CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override { return DiscoverCommissionersStatus; }
CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override
CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext &) override { return DiscoverCommissionersStatus; }
CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext &) override
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR StopDiscovery() override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR StopDiscovery(DiscoveryContext &) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override
{
return CHIP_ERROR_NOT_IMPLEMENTED;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/dnssd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static_library("dnssd") {
"IPAddressSorter.cpp",
"IPAddressSorter.h",
"Resolver.h",
"ResolverProxy.cpp",
"ResolverProxy.h",
"ServiceNaming.cpp",
"ServiceNaming.h",
"TxtFields.cpp",
Expand Down
Loading
Loading