Skip to content

Commit

Permalink
Add mDNS shutdown (project-chip#9621)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Sep 14, 2021
1 parent 64d8f13 commit 158a0a5
Show file tree
Hide file tree
Showing 10 changed files with 30 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 @@ -267,6 +267,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/Tizen/MdnsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ CHIP_ERROR ChipMdnsInit(MdnsAsyncReturnCallback successCallback, MdnsAsyncReturn
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ChipMdnsShutdown()
{
return CHIP_NO_ERROR;
}

CHIP_ERROR ChipMdnsSetHostname(const char * hostname)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
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 158a0a5

Please sign in to comment.