Skip to content

Commit

Permalink
Add mDNS shutdown (#9621)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored Sep 13, 2021
1 parent b8e7596 commit 3da26cf
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ CHIP_ERROR DeviceController::Shutdown()
// manager.
app::InteractionModelEngine::GetInstance()->Shutdown();

#if CHIP_DEVICE_CONFIG_ENABLE_MDNS
Mdns::Resolver::Instance().ShutdownResolver();
#endif // CHIP_DEVICE_CONFIG_ENABLE_MDNS

// TODO(#6668): Some exchange has leak, shutting down ExchangeManager will cause a assert fail.
// if (mExchangeMgr != nullptr)
// {
Expand Down
1 change: 1 addition & 0 deletions src/controller/tests/TestCommissionableNodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MockResolver : public Resolver
public:
CHIP_ERROR SetResolverDelegate(ResolverDelegate *) override { return SetResolverDelegateStatus; }
CHIP_ERROR StartResolver(chip::Inet::InetLayer * inetLayer, uint16_t port) override { return StartResolverStatus; }
void ShutdownResolver() override {}
CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type) override { return ResolveNodeIdStatus; }
CHIP_ERROR FindCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override { return FindCommissionersStatus; }
CHIP_ERROR FindCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
Expand Down
1 change: 1 addition & 0 deletions src/lib/mdns/Discovery_ImplPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DiscoveryImplPlatform : public ServiceAdvertiser, public Resolver

/// Starts the service resolver if not yet started
CHIP_ERROR StartResolver(Inet::InetLayer * inetLayer, uint16_t port) override { return Init(); }
void ShutdownResolver() override { ChipMdnsShutdown(); }

/// Advertises the CHIP node as an operational node
CHIP_ERROR Advertise(const OperationalAdvertisingParameters & params) override;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/mdns/MinimalMdnsServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@ CHIP_ERROR GlobalMinimalMdnsServer::StartServer(chip::Inet::InetLayer * inetLaye
return GlobalMinimalMdnsServer::Server().Listen(inetLayer, &allInterfaces, port);
}

void GlobalMinimalMdnsServer::ShutdownServer()
{
GlobalMinimalMdnsServer::Server().Shutdown();
}

} // namespace Mdns
} // namespace chip
1 change: 1 addition & 0 deletions src/lib/mdns/MinimalMdnsServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class GlobalMinimalMdnsServer : public mdns::Minimal::ServerDelegate

/// Calls Server().Listen() on all available interfaces
CHIP_ERROR StartServer(chip::Inet::InetLayer * inetLayer, uint16_t port);
void ShutdownServer();

void SetQueryDelegate(MdnsPacketDelegate * delegate) { mQueryDelegate = delegate; }
void SetResponseDelegate(MdnsPacketDelegate * delegate) { mResponseDelegate = delegate; }
Expand Down
1 change: 1 addition & 0 deletions src/lib/mdns/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Resolver
///
/// Unsual name to allow base MDNS classes to implement both Advertiser and Resolver interfaces.
virtual CHIP_ERROR StartResolver(chip::Inet::InetLayer * inetLayer, uint16_t port) = 0;
virtual void ShutdownResolver() = 0;

/// Registers a resolver delegate if none has been registered before
virtual CHIP_ERROR SetResolverDelegate(ResolverDelegate * delegate) = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/mdns/Resolver_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class MinMdnsResolver : public Resolver, public MdnsPacketDelegate

///// Resolver implementation
CHIP_ERROR StartResolver(chip::Inet::InetLayer * inetLayer, uint16_t port) override;
void ShutdownResolver() override;
CHIP_ERROR SetResolverDelegate(ResolverDelegate * delegate) override;
CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type) override;
CHIP_ERROR FindCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override;
Expand Down Expand Up @@ -394,6 +395,11 @@ CHIP_ERROR MinMdnsResolver::StartResolver(chip::Inet::InetLayer * inetLayer, uin
return GlobalMinimalMdnsServer::Instance().StartServer(inetLayer, port);
}

void MinMdnsResolver::ShutdownResolver()
{
GlobalMinimalMdnsServer::Instance().ShutdownServer();
}

CHIP_ERROR MinMdnsResolver::SetResolverDelegate(ResolverDelegate * delegate)
{
mDelegate = delegate;
Expand Down
1 change: 1 addition & 0 deletions src/lib/mdns/Resolver_ImplNone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NoneResolver : public Resolver
CHIP_ERROR SetResolverDelegate(ResolverDelegate *) override { return CHIP_NO_ERROR; }

CHIP_ERROR StartResolver(chip::Inet::InetLayer * inetLayer, uint16_t port) override { return CHIP_NO_ERROR; }
void ShutdownResolver() override {}

CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type) override
{
Expand Down
5 changes: 5 additions & 0 deletions src/platform/fake/MdnsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ CHIP_ERROR ChipMdnsInit(MdnsAsyncReturnCallback initCallback, MdnsAsyncReturnCal
return CHIP_NO_ERROR;
}

CHIP_ERROR ChipMdnsShutdown()
{
return CHIP_NO_ERROR;
}

CHIP_ERROR ChipMdnsPublishService(const MdnsService * service)
{
return test::CheckExpected(test::CallType::kStart, service);
Expand Down

0 comments on commit 3da26cf

Please sign in to comment.