From 3632d9ae1cfe4d773cfea4dcc24d868992a91f17 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Tue, 7 Dec 2021 13:42:20 -0500 Subject: [PATCH 1/4] [Inet] Remove InetLayer class #### Problem After PR #12291, `InetLayer` merely holds pointers to TCP and UDP `EndPointManager`. Almost all uses are of `UDPEndPointManager` only, so `InetLayer` is an unnecessary indirection. Part of #7715 _Virtualize System and Inet interfaces_ #### Change overview Remove the `InetLayer` class and pass or store `UDPEndPointManager` and/or `TCPEndPointManager` directly. (This was not included in #12291 because it touches a large number of files with trivial changes.) #### Testing CI; no change to external functionality. --- examples/all-clusters-app/esp32/main/main.cpp | 2 +- .../chip-tool/commands/discover/Commands.h | 2 +- examples/minimal-mdns/advertiser.cpp | 2 +- examples/minimal-mdns/client.cpp | 2 +- examples/minimal-mdns/server.cpp | 2 +- examples/shell/shell_common/cmd_ping.cpp | 4 +- examples/shell/shell_common/cmd_send.cpp | 4 +- src/app/server/Dnssd.cpp | 4 +- src/app/server/Server.cpp | 16 +++-- src/app/tests/TestOperationalDeviceProxy.cpp | 9 ++- .../tests/integration/chip_im_initiator.cpp | 2 +- .../tests/integration/chip_im_responder.cpp | 4 +- src/app/util/chip-message-send.cpp | 1 - .../AbstractDnssdDiscoveryController.cpp | 2 +- src/controller/CHIPDeviceController.cpp | 24 +++---- .../CHIPDeviceControllerFactory.cpp | 38 +++++----- src/controller/CHIPDeviceControllerFactory.h | 9 +-- .../CHIPDeviceControllerSystemState.h | 23 +++--- src/controller/CommissioneeDeviceProxy.cpp | 6 +- src/controller/CommissioneeDeviceProxy.h | 26 +++---- .../java/AndroidDeviceControllerWrapper.cpp | 25 ++++--- .../java/AndroidDeviceControllerWrapper.h | 4 +- .../java/CHIPDeviceController-JNI.cpp | 5 +- .../python/chip/discovery/NodeResolution.cpp | 2 +- .../TestCommissionableNodeController.cpp | 2 +- src/controller/tests/TestDevice.cpp | 26 +++---- src/include/platform/CHIPDeviceLayer.h | 2 - .../internal/GenericPlatformManagerImpl.cpp | 8 +-- src/inet/BUILD.gn | 1 - src/inet/InetLayer.h | 72 ++++--------------- src/inet/tests/TestInetCommon.h | 4 +- src/inet/tests/TestInetCommonOptions.h | 1 - src/inet/tests/TestInetCommonPosix.cpp | 9 ++- src/inet/tests/TestInetEndPoint.cpp | 31 ++++---- src/inet/tests/TestInetLayer.cpp | 12 ++-- src/inet/tests/TestInetLayerCommon.cpp | 2 - src/inet/tests/TestLwIPDNS.cpp | 1 - src/lib/core/CHIPCore.h | 10 ++- src/lib/dnssd/Advertiser.h | 3 +- src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp | 6 +- src/lib/dnssd/Advertiser_ImplNone.cpp | 2 +- src/lib/dnssd/Discovery_ImplPlatform.h | 2 +- src/lib/dnssd/DnssdCache.h | 1 - src/lib/dnssd/MinimalMdnsServer.cpp | 5 +- src/lib/dnssd/MinimalMdnsServer.h | 4 +- src/lib/dnssd/Resolver.h | 4 +- src/lib/dnssd/Resolver_ImplMinimalMdns.cpp | 11 ++- src/lib/dnssd/Resolver_ImplNone.cpp | 2 +- src/lib/dnssd/minimal_mdns/ResponseSender.h | 1 - src/lib/dnssd/minimal_mdns/Server.cpp | 7 +- src/lib/dnssd/minimal_mdns/Server.h | 4 +- .../minimal_mdns/responders/QueryResponder.h | 2 +- .../minimal_mdns/tests/TestAdvertiser.cpp | 2 +- src/lib/dnssd/platform/tests/TestPlatform.cpp | 6 +- src/lib/dnssd/tests/TestDnssdCache.cpp | 1 - src/lib/shell/commands/Dns.cpp | 2 +- src/messaging/ReliableMessageContext.h | 3 +- src/messaging/tests/echo/common.cpp | 2 +- src/messaging/tests/echo/echo_requester.cpp | 4 +- src/messaging/tests/echo/echo_responder.cpp | 6 +- src/platform/Globals.cpp | 8 +-- src/platform/mbed/PlatformManagerImpl.cpp | 1 - src/transport/raw/TCP.cpp | 1 - src/transport/raw/TCP.h | 2 +- src/transport/raw/UDP.h | 2 +- .../raw/tests/NetworkTestHelpers.cpp | 5 +- src/transport/raw/tests/NetworkTestHelpers.h | 11 +-- src/transport/raw/tests/TestTCP.cpp | 4 +- src/transport/raw/tests/TestUDP.cpp | 4 +- src/transport/tests/TestSessionManager.cpp | 10 +-- 70 files changed, 253 insertions(+), 274 deletions(-) diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index d6d8cf49d51aeb..9c9126002c0604 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -363,7 +363,7 @@ class MdnsDebugListModel : public ActionListModel private: void DoReinit() { - CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(&DeviceLayer::InetLayer()); + CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(DeviceLayer::UDPEndPointManager()); if (err != CHIP_NO_ERROR) { ESP_LOGE(TAG, "Error initializing: %s", err.AsString()); diff --git a/examples/chip-tool/commands/discover/Commands.h b/examples/chip-tool/commands/discover/Commands.h index cbcdf2e27bd938..4a74a3a4d0e8c7 100644 --- a/examples/chip-tool/commands/discover/Commands.h +++ b/examples/chip-tool/commands/discover/Commands.h @@ -32,7 +32,7 @@ class Resolve : public DiscoverCommand, public chip::Dnssd::ResolverDelegate /////////// DiscoverCommand Interface ///////// CHIP_ERROR RunCommand(NodeId remoteId, uint64_t fabricId) override { - ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(&chip::DeviceLayer::InetLayer())); + ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(chip::DeviceLayer::UDPEndPointManager())); chip::Dnssd::Resolver::Instance().SetResolverDelegate(this); ChipLogProgress(chipTool, "Dnssd: Searching for NodeId: %" PRIx64 " FabricId: %" PRIx64 " ...", remoteId, fabricId); return chip::Dnssd::Resolver::Instance().ResolveNodeId(chip::PeerId().SetNodeId(remoteId).SetCompressedFabricId(fabricId), diff --git a/examples/minimal-mdns/advertiser.cpp b/examples/minimal-mdns/advertiser.cpp index ff267044ac39f8..dc20c195537a7b 100644 --- a/examples/minimal-mdns/advertiser.cpp +++ b/examples/minimal-mdns/advertiser.cpp @@ -255,7 +255,7 @@ int main(int argc, char ** args) return 1; } - if (chip::Dnssd::ServiceAdvertiser::Instance().Init(&DeviceLayer::InetLayer()) != CHIP_NO_ERROR) + if (chip::Dnssd::ServiceAdvertiser::Instance().Init(DeviceLayer::UDPEndPointManager()) != CHIP_NO_ERROR) { fprintf(stderr, "FAILED to start MDNS advertisement\n"); return 1; diff --git a/examples/minimal-mdns/client.cpp b/examples/minimal-mdns/client.cpp index dcfef3f987e40d..246a97252e6009 100644 --- a/examples/minimal-mdns/client.cpp +++ b/examples/minimal-mdns/client.cpp @@ -334,7 +334,7 @@ int main(int argc, char ** args) MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4); - err = mdnsServer.Listen(&chip::DeviceLayer::InetLayer(), &allInterfaces, gOptions.listenPort); + err = mdnsServer.Listen(chip::DeviceLayer::UDPEndPointManager(), &allInterfaces, gOptions.listenPort); if (err != CHIP_NO_ERROR) { printf("Server failed to listen on all interfaces: %s\n", chip::ErrorStr(err)); diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index 1d310b9618851b..afc84b75261716 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -258,7 +258,7 @@ int main(int argc, char ** args) { MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4); - if (mdnsServer.Listen(&DeviceLayer::InetLayer(), &allInterfaces, gOptions.listenPort) != CHIP_NO_ERROR) + if (mdnsServer.Listen(DeviceLayer::UDPEndPointManager(), &allInterfaces, gOptions.listenPort) != CHIP_NO_ERROR) { printf("Server failed to listen on all interfaces\n"); return 1; diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp index 4bda418cc559ed..bbae46e2a3a65e 100644 --- a/examples/shell/shell_common/cmd_ping.cpp +++ b/examples/shell/shell_common/cmd_ping.cpp @@ -292,13 +292,13 @@ void StartPinging(streamer_t * stream, char * destination) } #if INET_CONFIG_ENABLE_TCP_ENDPOINT - err = gTCPManager.Init(Transport::TcpListenParameters(&DeviceLayer::InetLayer()) + err = gTCPManager.Init(Transport::TcpListenParameters(DeviceLayer::TCPEndPointManager()) .SetAddressType(gDestAddr.Type()) .SetListenPort(gPingArguments.GetEchoPort() + 1)); VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init TCP manager error: %s\n", ErrorStr(err))); #endif - err = gUDPManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer()) + err = gUDPManager.Init(Transport::UdpListenParameters(DeviceLayer::UDPEndPointManager()) .SetAddressType(gDestAddr.Type()) .SetListenPort(gPingArguments.GetEchoPort() + 1)); VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init UDP manager error: %s\n", ErrorStr(err))); diff --git a/examples/shell/shell_common/cmd_send.cpp b/examples/shell/shell_common/cmd_send.cpp index 26363ebdc8a10c..f01e0cfde60548 100644 --- a/examples/shell/shell_common/cmd_send.cpp +++ b/examples/shell/shell_common/cmd_send.cpp @@ -211,13 +211,13 @@ void ProcessCommand(streamer_t * stream, char * destination) } #if INET_CONFIG_ENABLE_TCP_ENDPOINT - err = gTCPManager.Init(Transport::TcpListenParameters(&DeviceLayer::InetLayer()) + err = gTCPManager.Init(Transport::TcpListenParameters(DeviceLayer::TCPEndPointManager()) .SetAddressType(gDestAddr.Type()) .SetListenPort(gSendArguments.GetPort() + 1)); VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init TCP manager error: %s\n", ErrorStr(err))); #endif - err = gUDPManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer()) + err = gUDPManager.Init(Transport::UdpListenParameters(DeviceLayer::UDPEndPointManager()) .SetAddressType(gDestAddr.Type()) .SetListenPort(gSendArguments.GetPort() + 1)); VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init UDP manager error: %s\n", ErrorStr(err))); diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index f4faaa79536840..d16c3fa19ff6a0 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -146,7 +146,7 @@ bool DnssdServer::OnExpiration(System::Clock::Timestamp expirationMs) ChipLogDetail(Discovery, "OnExpiration - valid time out"); - CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(&chip::DeviceLayer::InetLayer()); + CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(chip::DeviceLayer::UDPEndPointManager()); if (err != CHIP_NO_ERROR) { ChipLogError(Discovery, "Failed to initialize advertiser: %s", chip::ErrorStr(err)); @@ -410,7 +410,7 @@ void DnssdServer::StartServer(chip::Dnssd::CommissioningMode mode) DeviceLayer::PlatformMgr().AddEventHandler(OnPlatformEventWrapper, 0); - CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(&chip::DeviceLayer::InetLayer()); + CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(chip::DeviceLayer::UDPEndPointManager()); if (err != CHIP_NO_ERROR) { ChipLogError(Discovery, "Failed to initialize advertiser: %s", chip::ErrorStr(err)); diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 1c9af3eb3a9ceb..7876bfd1ec0b0f 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -111,16 +110,19 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint SetGroupDataProvider(&mGroupsProvider); // Init transport before operations with secure session mgr. - err = mTransports.Init( - UdpListenParameters(&DeviceLayer::InetLayer()).SetAddressType(IPAddressType::kIPv6).SetListenPort(mSecuredServicePort) + err = mTransports.Init(UdpListenParameters(DeviceLayer::UDPEndPointManager()) + .SetAddressType(IPAddressType::kIPv6) + .SetListenPort(mSecuredServicePort) #if INET_CONFIG_ENABLE_IPV4 - , - UdpListenParameters(&DeviceLayer::InetLayer()).SetAddressType(IPAddressType::kIPv4).SetListenPort(mSecuredServicePort) + , + UdpListenParameters(DeviceLayer::UDPEndPointManager()) + .SetAddressType(IPAddressType::kIPv4) + .SetListenPort(mSecuredServicePort) #endif #if CONFIG_NETWORK_LAYER_BLE - , - BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer()) + , + BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer()) #endif ); diff --git a/src/app/tests/TestOperationalDeviceProxy.cpp b/src/app/tests/TestOperationalDeviceProxy.cpp index fb1d0936bed521..8b6101deabfecf 100644 --- a/src/app/tests/TestOperationalDeviceProxy.cpp +++ b/src/app/tests/TestOperationalDeviceProxy.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -44,7 +43,7 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite, TestTransportMgr transportMgr; SessionManager sessionManager; ExchangeManager exchangeMgr; - Inet::InetLayer inetLayer; + Inet::UDPEndPointManagerImpl udpEndPointManager; System::LayerImpl systemLayer; // Heap-allocate the fairly large FabricTable so we don't end up with a huge // stack. @@ -54,8 +53,8 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite, SessionIDAllocator idAllocator; systemLayer.Init(); - inetLayer.Init(systemLayer, nullptr); - transportMgr.Init(UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT)); + udpEndPointManager.Init(systemLayer); + transportMgr.Init(UdpListenParameters(udpEndPointManager).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT)); sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager); exchangeMgr.Init(&sessionManager); messageCounterManager.Init(&exchangeMgr); @@ -81,7 +80,7 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite, sessionManager.Shutdown(); Platform::Delete(fabrics); transportMgr.Close(); - inetLayer.Shutdown(); + udpEndPointManager.Shutdown(); systemLayer.Shutdown(); Platform::MemoryShutdown(); } diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index 44b9ed4f4479ff..d36066851c437d 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -685,7 +685,7 @@ int main(int argc, char * argv[]) InitializeChip(); - err = gTransportManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer()) + err = gTransportManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager()) .SetAddressType(chip::Inet::IPAddressType::kIPv6) .SetListenPort(IM_CLIENT_PORT)); SuccessOrExit(err); diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index 84ff6566b7e84a..2bd75f77f8aa02 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -194,8 +194,8 @@ int main(int argc, char * argv[]) InitializeChip(); - err = gTransportManager.Init( - chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer()).SetAddressType(chip::Inet::IPAddressType::kIPv6)); + err = gTransportManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager()) + .SetAddressType(chip::Inet::IPAddressType::kIPv6)); SuccessOrExit(err); err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager); diff --git a/src/app/util/chip-message-send.cpp b/src/app/util/chip-message-send.cpp index 2b2f5584f31712..ea3eafb506e3d3 100644 --- a/src/app/util/chip-message-send.cpp +++ b/src/app/util/chip-message-send.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include diff --git a/src/controller/AbstractDnssdDiscoveryController.cpp b/src/controller/AbstractDnssdDiscoveryController.cpp index 8d34292df1bb02..5dc8707218a780 100644 --- a/src/controller/AbstractDnssdDiscoveryController.cpp +++ b/src/controller/AbstractDnssdDiscoveryController.cpp @@ -67,7 +67,7 @@ void AbstractDnssdDiscoveryController::OnNodeDiscoveryComplete(const chip::Dnssd CHIP_ERROR AbstractDnssdDiscoveryController::SetUpNodeDiscovery() { #if CONFIG_DEVICE_LAYER - ReturnErrorOnFailure(mResolver->Init(&DeviceLayer::InetLayer())); + ReturnErrorOnFailure(mResolver->Init(DeviceLayer::UDPEndPointManager())); #endif mResolver->SetResolverDelegate(this); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 365dd0472c0008..6e9bd508e647e3 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -122,7 +122,7 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params) VerifyOrReturnError(params.systemState != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(params.systemState->SystemLayer() != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(params.systemState->InetLayer() != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(params.systemState->UDPEndPointManager() != nullptr, CHIP_ERROR_INVALID_ARGUMENT); mStorageDelegate = params.storageDelegate; #if CONFIG_NETWORK_LAYER_BLE @@ -132,7 +132,7 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params) VerifyOrReturnError(params.systemState->TransportMgr() != nullptr, CHIP_ERROR_INVALID_ARGUMENT); #if CHIP_DEVICE_CONFIG_ENABLE_DNSSD - Dnssd::Resolver::Instance().Init(params.systemState->InetLayer()); + Dnssd::Resolver::Instance().Init(params.systemState->UDPEndPointManager()); Dnssd::Resolver::Instance().SetResolverDelegate(this); RegisterDeviceAddressUpdateDelegate(params.deviceAddressUpdateDelegate); RegisterDeviceDiscoveryDelegate(params.deviceDiscoveryDelegate); @@ -585,14 +585,14 @@ void DeviceController::OnNodeIdResolutionFailed(const chip::PeerId & peer, CHIP_ ControllerDeviceInitParams DeviceController::GetControllerDeviceInitParams() { return ControllerDeviceInitParams{ - .transportMgr = mSystemState->TransportMgr(), - .sessionManager = mSystemState->SessionMgr(), - .exchangeMgr = mSystemState->ExchangeMgr(), - .inetLayer = mSystemState->InetLayer(), - .storageDelegate = mStorageDelegate, - .idAllocator = &mIDAllocator, - .fabricsTable = mSystemState->Fabrics(), - .imDelegate = mSystemState->IMDelegate(), + .transportMgr = mSystemState->TransportMgr(), + .sessionManager = mSystemState->SessionMgr(), + .exchangeMgr = mSystemState->ExchangeMgr(), + .udpEndPointManager = mSystemState->UDPEndPointManager(), + .storageDelegate = mStorageDelegate, + .idAllocator = &mIDAllocator, + .fabricsTable = mSystemState->Fabrics(), + .imDelegate = mSystemState->IMDelegate(), }; } @@ -631,12 +631,12 @@ CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params) #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable mUdcTransportMgr = chip::Platform::New(); - ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(mSystemState->InetLayer()) + ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(mSystemState->UDPEndPointManager()) .SetAddressType(Inet::IPAddressType::kIPv6) .SetListenPort((uint16_t)(mUdcListenPort)) #if INET_CONFIG_ENABLE_IPV4 , - Transport::UdpListenParameters(mSystemState->InetLayer()) + Transport::UdpListenParameters(mSystemState->UDPEndPointManager()) .SetAddressType(Inet::IPAddressType::kIPv4) .SetListenPort((uint16_t)(mUdcListenPort)) #endif // INET_CONFIG_ENABLE_IPV4 diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index 95bb7f69a1de97..ef87c3f09bf998 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -62,8 +62,9 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState() FactoryInitParams params; if (mSystemState != nullptr) { - params.systemLayer = mSystemState->SystemLayer(); - params.inetLayer = mSystemState->InetLayer(); + params.systemLayer = mSystemState->SystemLayer(); + params.tcpEndPointManager = mSystemState->TCPEndPointManager(); + params.udpEndPointManager = mSystemState->UDPEndPointManager(); #if CONFIG_NETWORK_LAYER_BLE params.bleLayer = mSystemState->BleLayer(); #endif @@ -90,16 +91,18 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) #if CONFIG_DEVICE_LAYER ReturnErrorOnFailure(DeviceLayer::PlatformMgr().InitChipStack()); - stateParams.systemLayer = &DeviceLayer::SystemLayer(); - stateParams.inetLayer = &DeviceLayer::InetLayer(); + stateParams.systemLayer = &DeviceLayer::SystemLayer(); + stateParams.tcpEndPointManager = DeviceLayer::TCPEndPointManager(); + stateParams.udpEndPointManager = DeviceLayer::UDPEndPointManager(); #else - stateParams.systemLayer = params.systemLayer; - stateParams.inetLayer = params.inetLayer; + stateParams.systemLayer = params.systemLayer; + stateParams.tcpEndPointManager = params.tcpEndPointManager; + stateParams.udpEndPointManager = params.udpEndPointManager; ChipLogError(Controller, "Warning: Device Controller Factory should be with a CHIP Device Layer..."); #endif // CONFIG_DEVICE_LAYER VerifyOrReturnError(stateParams.systemLayer != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(stateParams.inetLayer != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(stateParams.udpEndPointManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); #if CONFIG_NETWORK_LAYER_BLE #if CONFIG_DEVICE_LAYER @@ -112,17 +115,20 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) stateParams.transportMgr = chip::Platform::New(); - ReturnErrorOnFailure(stateParams.transportMgr->Init( - Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(mListenPort) + ReturnErrorOnFailure(stateParams.transportMgr->Init(Transport::UdpListenParameters(stateParams.udpEndPointManager) + .SetAddressType(Inet::IPAddressType::kIPv6) + .SetListenPort(mListenPort) #if INET_CONFIG_ENABLE_IPV4 - , - Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(mListenPort) + , + Transport::UdpListenParameters(stateParams.udpEndPointManager) + .SetAddressType(Inet::IPAddressType::kIPv4) + .SetListenPort(mListenPort) #endif #if CONFIG_NETWORK_LAYER_BLE - , - Transport::BleListenParameters(stateParams.bleLayer) + , + Transport::BleListenParameters(stateParams.bleLayer) #endif - )); + )); if (params.imDelegate == nullptr) { @@ -254,8 +260,8 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown() mSessionMgr->Shutdown(); } - mSystemLayer = nullptr; - mInetLayer = nullptr; + mSystemLayer = nullptr; + mUDPEndPointManager = nullptr; if (mMessageCounterManager != nullptr) { diff --git a/src/controller/CHIPDeviceControllerFactory.h b/src/controller/CHIPDeviceControllerFactory.h index 3f07c85103e07c..115c2caf04c670 100644 --- a/src/controller/CHIPDeviceControllerFactory.h +++ b/src/controller/CHIPDeviceControllerFactory.h @@ -67,10 +67,11 @@ struct SetupParams // We're blocked because of the need to support !CHIP_DEVICE_LAYER struct FactoryInitParams { - FabricStorage * fabricStorage = nullptr; - System::Layer * systemLayer = nullptr; - Inet::InetLayer * inetLayer = nullptr; - DeviceControllerInteractionModelDelegate * imDelegate = nullptr; + FabricStorage * fabricStorage = nullptr; + System::Layer * systemLayer = nullptr; + Inet::EndPointManager * tcpEndPointManager = nullptr; + Inet::EndPointManager * udpEndPointManager = nullptr; + DeviceControllerInteractionModelDelegate * imDelegate = nullptr; #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer * bleLayer = nullptr; #endif diff --git a/src/controller/CHIPDeviceControllerSystemState.h b/src/controller/CHIPDeviceControllerSystemState.h index 02862ab816ebea..88507214a819b1 100644 --- a/src/controller/CHIPDeviceControllerSystemState.h +++ b/src/controller/CHIPDeviceControllerSystemState.h @@ -62,8 +62,9 @@ namespace Controller { struct DeviceControllerSystemStateParams { - System::Layer * systemLayer = nullptr; - Inet::InetLayer * inetLayer = nullptr; + System::Layer * systemLayer = nullptr; + Inet::EndPointManager * tcpEndPointManager = nullptr; + Inet::EndPointManager * udpEndPointManager = nullptr; #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer * bleLayer = nullptr; #endif @@ -83,9 +84,11 @@ class DeviceControllerSystemState public: ~DeviceControllerSystemState(){}; DeviceControllerSystemState(DeviceControllerSystemStateParams params) : - mSystemLayer(params.systemLayer), mInetLayer(params.inetLayer), mTransportMgr(params.transportMgr), - mSessionMgr(params.sessionMgr), mExchangeMgr(params.exchangeMgr), mMessageCounterManager(params.messageCounterManager), - mFabrics(params.fabricTable), mIMDelegate(params.imDelegate) + mSystemLayer(params.systemLayer), + mTCPEndPointManager(params.tcpEndPointManager), + mUDPEndPointManager(params.udpEndPointManager), mTransportMgr(params.transportMgr), mSessionMgr(params.sessionMgr), + mExchangeMgr(params.exchangeMgr), mMessageCounterManager(params.messageCounterManager), mFabrics(params.fabricTable), + mIMDelegate(params.imDelegate) { #if CONFIG_NETWORK_LAYER_BLE mBleLayer = params.bleLayer; @@ -122,12 +125,13 @@ class DeviceControllerSystemState }; bool IsInitialized() { - return mSystemLayer != nullptr && mInetLayer != nullptr && mTransportMgr != nullptr && mSessionMgr != nullptr && + return mSystemLayer != nullptr && mUDPEndPointManager != nullptr && mTransportMgr != nullptr && mSessionMgr != nullptr && mExchangeMgr != nullptr && mMessageCounterManager != nullptr && mFabrics != nullptr; }; System::Layer * SystemLayer() { return mSystemLayer; }; - Inet::InetLayer * InetLayer() { return mInetLayer; }; + Inet::EndPointManager * TCPEndPointManager() { return mTCPEndPointManager; }; + Inet::EndPointManager * UDPEndPointManager() { return mUDPEndPointManager; }; DeviceTransportMgr * TransportMgr() { return mTransportMgr; }; SessionManager * SessionMgr() { return mSessionMgr; }; Messaging::ExchangeManager * ExchangeMgr() { return mExchangeMgr; } @@ -141,8 +145,9 @@ class DeviceControllerSystemState private: DeviceControllerSystemState(){}; - System::Layer * mSystemLayer = nullptr; - Inet::InetLayer * mInetLayer = nullptr; + System::Layer * mSystemLayer = nullptr; + Inet::EndPointManager * mTCPEndPointManager = nullptr; + Inet::EndPointManager * mUDPEndPointManager = nullptr; #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer * mBleLayer = nullptr; #endif diff --git a/src/controller/CommissioneeDeviceProxy.cpp b/src/controller/CommissioneeDeviceProxy.cpp index 04465221303797..1014cb67e127c4 100644 --- a/src/controller/CommissioneeDeviceProxy.cpp +++ b/src/controller/CommissioneeDeviceProxy.cpp @@ -146,9 +146,9 @@ void CommissioneeDeviceProxy::Reset() { SetActive(false); - mState = ConnectionState::NotConnected; - mSessionManager = nullptr; - mInetLayer = nullptr; + mState = ConnectionState::NotConnected; + mSessionManager = nullptr; + mUDPEndPointManager = nullptr; #if CONFIG_NETWORK_LAYER_BLE mBleLayer = nullptr; #endif diff --git a/src/controller/CommissioneeDeviceProxy.h b/src/controller/CommissioneeDeviceProxy.h index b092224e0c9a8d..7867cea6eb7de4 100644 --- a/src/controller/CommissioneeDeviceProxy.h +++ b/src/controller/CommissioneeDeviceProxy.h @@ -65,12 +65,12 @@ using DeviceIPTransportMgr = TransportMgr * udpEndPointManager = nullptr; + PersistentStorageDelegate * storageDelegate = nullptr; + SessionIDAllocator * idAllocator = nullptr; #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer * bleLayer = nullptr; #endif @@ -119,12 +119,12 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegat */ void Init(ControllerDeviceInitParams params, FabricIndex fabric) { - mSessionManager = params.sessionManager; - mExchangeMgr = params.exchangeMgr; - mInetLayer = params.inetLayer; - mFabricIndex = fabric; - mIDAllocator = params.idAllocator; - mpIMDelegate = params.imDelegate; + mSessionManager = params.sessionManager; + mExchangeMgr = params.exchangeMgr; + mUDPEndPointManager = params.udpEndPointManager; + mFabricIndex = fabric; + mIDAllocator = params.idAllocator; + mpIMDelegate = params.imDelegate; #if CONFIG_NETWORK_LAYER_BLE mBleLayer = params.bleLayer; #endif @@ -289,7 +289,7 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegat */ Transport::PeerAddress mDeviceAddress = Transport::PeerAddress::UDP(Inet::IPAddress::Any); - Inet::InetLayer * mInetLayer = nullptr; + Inet::EndPointManager * mUDPEndPointManager = nullptr; bool mActive = false; ConnectionState mState = ConnectionState::NotConnected; diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 4f961e0a0dec97..b194804831c081 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -167,10 +167,10 @@ CHIP_ERROR AndroidDeviceControllerWrapper::GenerateNOCChain(const ByteSpan & csr return CHIP_NO_ERROR; } -AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(JavaVM * vm, jobject deviceControllerObj, - chip::NodeId nodeId, chip::System::Layer * systemLayer, - chip::Inet::InetLayer * inetLayer, - CHIP_ERROR * errInfoOnFailure) +AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( + JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::System::Layer * systemLayer, + chip::Inet::EndPointManager * tcpEndPointManager, + chip::Inet::EndPointManager * udpEndPointManager, CHIP_ERROR * errInfoOnFailure) { if (errInfoOnFailure == nullptr) { @@ -183,9 +183,15 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(Jav *errInfoOnFailure = CHIP_ERROR_INVALID_ARGUMENT; return nullptr; } - if (inetLayer == nullptr) + if (tcpEndPointManager == nullptr) { - ChipLogError(Controller, "Missing inet layer"); + ChipLogError(Controller, "Missing TCP layer"); + *errInfoOnFailure = CHIP_ERROR_INVALID_ARGUMENT; + return nullptr; + } + if (udpEndPointManager == nullptr) + { + ChipLogError(Controller, "Missing UDP layer"); *errInfoOnFailure = CHIP_ERROR_INVALID_ARGUMENT; return nullptr; } @@ -211,9 +217,10 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(Jav chip::Controller::FactoryInitParams initParams; chip::Controller::SetupParams setupParams; - initParams.systemLayer = systemLayer; - initParams.inetLayer = inetLayer; - initParams.fabricStorage = wrapper.get(); + initParams.systemLayer = systemLayer; + initParams.tcpEndPointManager = tcpEndPointManager; + initParams.udpEndPointManager = udpEndPointManager; + initParams.fabricStorage = wrapper.get(); // move bleLayer into platform/android to share with app server #if CONFIG_NETWORK_LAYER_BLE initParams.bleLayer = DeviceLayer::ConnectivityMgr().GetBleLayer(); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index 7580062f72967e..3ab37f7dd06ce5 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -85,7 +85,9 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel } static AndroidDeviceControllerWrapper * AllocateNew(JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, - chip::System::Layer * systemLayer, chip::Inet::InetLayer * inetLayer, + chip::System::Layer * systemLayer, + chip::Inet::EndPointManager * tcpEndPointManager, + chip::Inet::EndPointManager * udpEndPointManager, CHIP_ERROR * errInfoOnFailure); CHIP_ERROR GenerateNOCChainAfterValidation(chip::NodeId nodeId, chip::FabricId fabricId, diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 5364aceebd9698..144d091e4a943e 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -146,8 +146,9 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self) ChipLogProgress(Controller, "newDeviceController() called"); - wrapper = AndroidDeviceControllerWrapper::AllocateNew(sJVM, self, kLocalDeviceId, &DeviceLayer::SystemLayer(), - &DeviceLayer::InetLayer(), &err); + wrapper = + AndroidDeviceControllerWrapper::AllocateNew(sJVM, self, kLocalDeviceId, &DeviceLayer::SystemLayer(), + DeviceLayer::TCPEndPointManager(), DeviceLayer::UDPEndPointManager(), &err); SuccessOrExit(err); // Create and start the IO thread. Must be called after Controller()->Init diff --git a/src/controller/python/chip/discovery/NodeResolution.cpp b/src/controller/python/chip/discovery/NodeResolution.cpp index 301b384d5dd88d..7e794b77c8981c 100644 --- a/src/controller/python/chip/discovery/NodeResolution.cpp +++ b/src/controller/python/chip/discovery/NodeResolution.cpp @@ -95,7 +95,7 @@ extern "C" ChipError::StorageType pychip_discovery_resolve(uint64_t fabricId, ui CHIP_ERROR result = CHIP_NO_ERROR; chip::python::ChipMainThreadScheduleAndWait([&] { - result = Resolver::Instance().Init(&chip::DeviceLayer::InetLayer()); + result = Resolver::Instance().Init(chip::DeviceLayer::UDPEndPointManager()); ReturnOnFailure(result); Resolver::Instance().SetResolverDelegate(&gPythonResolverDelegate); diff --git a/src/controller/tests/TestCommissionableNodeController.cpp b/src/controller/tests/TestCommissionableNodeController.cpp index c1101eca7ebb97..4907b5997a1a5d 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -31,7 +31,7 @@ namespace { class MockResolver : public Resolver { public: - CHIP_ERROR Init(chip::Inet::InetLayer * inetLayer) override { return InitStatus; } + CHIP_ERROR Init(chip::Inet::EndPointManager * udpEndPointManager) override { return InitStatus; } void Shutdown() override {} void SetResolverDelegate(ResolverDelegate *) override {} CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type, Resolver::CacheBypass dnssdCacheBypass) override diff --git a/src/controller/tests/TestDevice.cpp b/src/controller/tests/TestDevice.cpp index fe4cd909a0efe6..16018a603c497e 100644 --- a/src/controller/tests/TestDevice.cpp +++ b/src/controller/tests/TestDevice.cpp @@ -20,7 +20,7 @@ #endif // CONFIG_NETWORK_LAYER_BLE #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext DeviceTransportMgr transportMgr; SessionManager sessionManager; ExchangeManager exchangeMgr; - Inet::InetLayer inetLayer; + Inet::UDPEndPointManagerImpl udpEndPointManager; System::LayerImpl systemLayer; #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer blelayer; @@ -61,11 +61,11 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext SessionIDAllocator idAllocator; systemLayer.Init(); - inetLayer.Init(systemLayer, nullptr); - transportMgr.Init(UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(CHIP_PORT) + udpEndPointManager.Init(systemLayer); + transportMgr.Init(UdpListenParameters(udpEndPointManager).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(CHIP_PORT) #if INET_CONFIG_ENABLE_IPV4 , - UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT) + UdpListenParameters(udpEndPointManager).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT) #endif #if CONFIG_NETWORK_LAYER_BLE , @@ -77,13 +77,13 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext messageCounterManager.Init(&exchangeMgr); ControllerDeviceInitParams params = { - .transportMgr = &transportMgr, - .sessionManager = &sessionManager, - .exchangeMgr = &exchangeMgr, - .inetLayer = &inetLayer, - .storageDelegate = nullptr, - .idAllocator = &idAllocator, - .fabricsTable = fabrics, + .transportMgr = &transportMgr, + .sessionManager = &sessionManager, + .exchangeMgr = &exchangeMgr, + .udpEndPointManager = &udpEndPointManager, + .storageDelegate = nullptr, + .idAllocator = &idAllocator, + .fabricsTable = fabrics, }; CommissioneeDeviceProxy device; NodeId mockNodeId = 1; @@ -102,7 +102,7 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext sessionManager.Shutdown(); Platform::Delete(fabrics); transportMgr.Close(); - inetLayer.Shutdown(); + udpEndPointManager.Shutdown(); systemLayer.Shutdown(); Platform::MemoryShutdown(); } diff --git a/src/include/platform/CHIPDeviceLayer.h b/src/include/platform/CHIPDeviceLayer.h index fd61b902588e69..8d6fab3f7248c7 100644 --- a/src/include/platform/CHIPDeviceLayer.h +++ b/src/include/platform/CHIPDeviceLayer.h @@ -23,7 +23,6 @@ #if !CHIP_DEVICE_LAYER_NONE #include -#include #include #include #include @@ -46,7 +45,6 @@ namespace DeviceLayer { void SetSystemLayerForTesting(System::LayerImpl * layer); // These functions are defined in src/platform/Globals.cpp -chip::Inet::InetLayer & InetLayer(); chip::Inet::EndPointManager * UDPEndPointManager(); chip::Inet::EndPointManager * TCPEndPointManager(); chip::System::Layer & SystemLayer(); diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.cpp b/src/include/platform/internal/GenericPlatformManagerImpl.cpp index bb6f1f5407eff7..5caf2a7aa38531 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.cpp @@ -80,11 +80,11 @@ CHIP_ERROR GenericPlatformManagerImpl::_InitChipStack() } SuccessOrExit(err); - // Initialize the CHIP Inet layer. - err = InetLayer().Init(SystemLayer(), UDPEndPointManager()); + // Initialize the CHIP UDP layer. + err = UDPEndPointManager()->Init(SystemLayer()); if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "InetLayer initialization failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "UDP initialization failed: %s", ErrorStr(err)); } SuccessOrExit(err); @@ -131,7 +131,7 @@ CHIP_ERROR GenericPlatformManagerImpl::_Shutdown() { CHIP_ERROR err; ChipLogError(DeviceLayer, "Inet Layer shutdown"); - err = InetLayer().Shutdown(); + err = UDPEndPointManager()->Shutdown(); #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE ChipLogError(DeviceLayer, "BLE shutdown"); diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index 7dfe6ac5441ac6..fc94850e7e7f8d 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -89,7 +89,6 @@ static_library("inet") { "InetFaultInjection.h", "InetInterface.cpp", "InetInterface.h", - "InetLayer.cpp", "InetLayer.h", "arpa-inet-compatibility.h", ] diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index cace73625b104f..8f2405545d5915 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -22,6 +22,8 @@ #pragma once +#include +#include #include #include #include @@ -58,17 +60,27 @@ class EndPointManager CHIP_ERROR Init(System::Layer & systemLayer) { + RegisterLayerErrorFormatter(); + VerifyOrReturnError(mLayerState.SetInitializing(), CHIP_ERROR_INCORRECT_STATE); mSystemLayer = &systemLayer; + mLayerState.SetInitialized(); return CHIP_NO_ERROR; } - CHIP_ERROR Shutdown() { return CHIP_NO_ERROR; } + CHIP_ERROR Shutdown() + { + // Return to uninitialized state to permit re-initialization. + VerifyOrReturnError(mLayerState.ResetFromInitialized(), CHIP_ERROR_INCORRECT_STATE); + mSystemLayer = nullptr; + return CHIP_NO_ERROR; + } System::Layer & SystemLayer() const { return *mSystemLayer; } CHIP_ERROR NewEndPoint(EndPoint ** retEndPoint) { assertChipStackLockedByCurrentThread(); + VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE); *retEndPoint = CreateEndPoint(); if (*retEndPoint == nullptr) @@ -87,6 +99,7 @@ class EndPointManager virtual Loop ForEachEndPoint(const EndPointVisitor visitor) = 0; private: + ObjectLifeCycle mLayerState; System::Layer * mSystemLayer; }; @@ -114,62 +127,5 @@ class EndPointManagerImplPool : public EndPointManager. - * This function will initialize the EndPointManager. - * - * @retval #CHIP_ERROR_INCORRECT_STATE If the InetLayer is in an incorrect state. - * @retval #CHIP_NO_ERROR On success. - * - */ - CHIP_ERROR Init(System::Layer & aSystemLayer, EndPointManager * udpEndPointManager); - - /** - * This is the InetLayer explicit deinitializer and should be called - * prior to disposing of an instantiated InetLayer instance. - * - * Must be called before System::Layer::Shutdown(), since this holds a pointer to that. - * - * @return #CHIP_NO_ERROR on success; otherwise, a specific error indicating - * the reason for shutdown failure. - * - */ - CHIP_ERROR Shutdown(); - - EndPointManager * GetUDPEndPointManager() const { return mUDPEndPointManager; } - - // Initialize the TCP EndPointManager. Must be called after Init() if the appication uses TCP. - CHIP_ERROR InitTCP(EndPointManager * tcpEndPointManager); - // Shut down the TCP EndPointManager. Must be called before Shutdown() if the appication uses TCP. - CHIP_ERROR ShutdownTCP(); - EndPointManager * GetTCPEndPointManager() const { return mTCPEndPointManager; } - - chip::System::Layer * SystemLayer() const { return mSystemLayer; } - -private: - ObjectLifeCycle mLayerState; - System::Layer * mSystemLayer; - EndPointManager * mTCPEndPointManager; - EndPointManager * mUDPEndPointManager; -}; - } // namespace Inet } // namespace chip diff --git a/src/inet/tests/TestInetCommon.h b/src/inet/tests/TestInetCommon.h index 0e1d7ab474c1e0..6c4d1dc33578d0 100644 --- a/src/inet/tests/TestInetCommon.h +++ b/src/inet/tests/TestInetCommon.h @@ -39,7 +39,6 @@ #include -#include #include #include #include @@ -55,7 +54,8 @@ extern chip::System::LayerImpl gSystemLayer; -extern chip::Inet::InetLayer gInet; +extern chip::Inet::TCPEndPointManagerImpl gTCP; +extern chip::Inet::UDPEndPointManagerImpl gUDP; extern bool gDone; diff --git a/src/inet/tests/TestInetCommonOptions.h b/src/inet/tests/TestInetCommonOptions.h index 801aa7a62583e1..9b3cd2e59b4f3b 100644 --- a/src/inet/tests/TestInetCommonOptions.h +++ b/src/inet/tests/TestInetCommonOptions.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include diff --git a/src/inet/tests/TestInetCommonPosix.cpp b/src/inet/tests/TestInetCommonPosix.cpp index fa32cd780e31e5..5da8e44d7253ee 100644 --- a/src/inet/tests/TestInetCommonPosix.cpp +++ b/src/inet/tests/TestInetCommonPosix.cpp @@ -80,7 +80,6 @@ using namespace chip::Inet; System::LayerImpl gSystemLayer; -Inet::InetLayer gInet; Inet::UDPEndPointManagerImpl gUDP; Inet::TCPEndPointManagerImpl gTCP; @@ -420,8 +419,8 @@ void InitNetwork() #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - gInet.Init(gSystemLayer, &gUDP); - gInet.InitTCP(&gTCP); + gTCP.Init(gSystemLayer); + gUDP.Init(gSystemLayer); } void ServiceEvents(uint32_t aSleepTimeMilliseconds) @@ -504,8 +503,8 @@ static void OnLwIPInitComplete(void * arg) void ShutdownNetwork() { - gInet.ShutdownTCP(); - gInet.Shutdown(); + gTCP.Shutdown(); + gUDP.Shutdown(); #if CHIP_SYSTEM_CONFIG_USE_LWIP ReleaseLwIP(); #endif diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index f6aacc3fbce7d3..1809f1c1104542 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -20,7 +20,7 @@ /** * @file - * This file implements a unit test suite for InetLayer EndPoint related features + * This file implements a unit test suite for Inet EndPoint related features * */ @@ -35,9 +35,8 @@ #include -#include #include -#include +#include #include #include @@ -82,6 +81,12 @@ void HandleTimer(Layer * aLayer, void * aAppState) // Test before init network, Inet is not initialized static void TestInetPre(nlTestSuite * inSuite, void * inContext) { +#if INET_CONFIG_ENABLE_UDP_ENDPOINT + UDPEndPoint * testUDPEP = nullptr; +#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT +#if INET_CONFIG_ENABLE_TCP_ENDPOINT + TCPEndPoint * testTCPEP = nullptr; +#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT CHIP_ERROR err = CHIP_NO_ERROR; // Deinit system layer and network @@ -92,13 +97,13 @@ static void TestInetPre(nlTestSuite * inSuite, void * inContext) } #if INET_CONFIG_ENABLE_UDP_ENDPOINT - EndPointManager * udpEndPointManager = gInet.GetUDPEndPointManager(); - NL_TEST_ASSERT(inSuite, udpEndPointManager == nullptr); + err = gUDP.NewEndPoint(&testUDPEP); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT #if INET_CONFIG_ENABLE_TCP_ENDPOINT - EndPointManager * tcpEndPointManager = gInet.GetTCPEndPointManager(); - NL_TEST_ASSERT(inSuite, tcpEndPointManager == nullptr); + err = gTCP.NewEndPoint(&testTCPEP); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT err = gSystemLayer.StartTimer(10_ms32, HandleTimer, nullptr); @@ -250,10 +255,10 @@ static void TestInetEndPointInternal(nlTestSuite * inSuite, void * inContext) PacketBufferHandle buf = PacketBufferHandle::New(PacketBuffer::kMaxSize); // init all the EndPoints - err = gInet.GetUDPEndPointManager()->NewEndPoint(&testUDPEP); + err = gUDP.NewEndPoint(&testUDPEP); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = gInet.GetTCPEndPointManager()->NewEndPoint(&testTCPEP1); + err = gTCP.NewEndPoint(&testTCPEP1); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); err = InterfaceId::Null().GetLinkLocalAddr(&addr); @@ -290,7 +295,7 @@ static void TestInetEndPointInternal(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); testUDPEP->Free(); - err = gInet.GetUDPEndPointManager()->NewEndPoint(&testUDPEP); + err = gUDP.NewEndPoint(&testUDPEP); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); #if INET_CONFIG_ENABLE_IPV4 err = testUDPEP->Bind(IPAddressType::kIPv4, addr_v4, 3000, intId); @@ -340,7 +345,7 @@ static void TestInetEndPointInternal(nlTestSuite * inSuite, void * inContext) } #if !CHIP_SYSTEM_CONFIG_POOL_USE_HEAP -// Test the InetLayer resource limitation +// Test the Inet resource limitations. static void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext) { UDPEndPoint * testUDPEP[INET_CONFIG_NUM_UDP_ENDPOINTS + 1] = { nullptr }; @@ -350,13 +355,13 @@ static void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext) for (int i = INET_CONFIG_NUM_UDP_ENDPOINTS; i >= 0; --i) { - err = gInet.GetUDPEndPointManager()->NewEndPoint(&testUDPEP[i]); + err = gUDP.NewEndPoint(&testUDPEP[i]); NL_TEST_ASSERT(inSuite, err == (i ? CHIP_NO_ERROR : CHIP_ERROR_ENDPOINT_POOL_FULL)); } for (int i = INET_CONFIG_NUM_TCP_ENDPOINTS; i >= 0; --i) { - err = gInet.GetTCPEndPointManager()->NewEndPoint(&testTCPEP[i]); + err = gTCP.NewEndPoint(&testTCPEP[i]); NL_TEST_ASSERT(inSuite, err == (i ? CHIP_NO_ERROR : CHIP_ERROR_ENDPOINT_POOL_FULL)); } diff --git a/src/inet/tests/TestInetLayer.cpp b/src/inet/tests/TestInetLayer.cpp index 9b295e70f9de38..82f3f35091d0fd 100644 --- a/src/inet/tests/TestInetLayer.cpp +++ b/src/inet/tests/TestInetLayer.cpp @@ -692,8 +692,8 @@ static CHIP_ERROR PrepareTransportForSend() { if (sTCPIPEndPoint == nullptr) { - lStatus = gInet.GetTCPEndPointManager()->NewEndPoint(&sTCPIPEndPoint); - INET_FAIL_ERROR(lStatus, "InetLayer::GetTCPEndPointManager()->NewEndPoint failed"); + lStatus = gTCP.NewEndPoint(&sTCPIPEndPoint); + INET_FAIL_ERROR(lStatus, "TCP NewEndPoint failed"); sTCPIPEndPoint->OnConnectComplete = HandleTCPConnectionComplete; sTCPIPEndPoint->OnConnectionClosed = HandleTCPConnectionClosed; @@ -820,8 +820,8 @@ static void StartTest() if (gOptFlags & kOptFlagUseUDPIP) { - lStatus = gInet.GetUDPEndPointManager()->NewEndPoint(&sUDPIPEndPoint); - INET_FAIL_ERROR(lStatus, "InetLayer::GetUDPEndPointManager()->NewEndPoint failed"); + lStatus = gUDP.NewEndPoint(&sUDPIPEndPoint); + INET_FAIL_ERROR(lStatus, "UDP NewEndPoint failed"); if (gInterfaceId.IsPresent()) { @@ -845,8 +845,8 @@ static void StartTest() const uint16_t lConnectionBacklogMax = 1; const bool lReuseAddress = true; - lStatus = gInet.GetTCPEndPointManager()->NewEndPoint(&sTCPIPListenEndPoint); - INET_FAIL_ERROR(lStatus, "InetLayer::GetTCPEndPointManager()->NewEndPoint failed"); + lStatus = gTCP.NewEndPoint(&sTCPIPListenEndPoint); + INET_FAIL_ERROR(lStatus, "TCP NewEndPoint failed"); sTCPIPListenEndPoint->OnConnectionReceived = HandleTCPConnectionReceived; sTCPIPListenEndPoint->OnAcceptError = HandleTCPAcceptError; diff --git a/src/inet/tests/TestInetLayerCommon.cpp b/src/inet/tests/TestInetLayerCommon.cpp index 516f57a839a5ab..fbb3fa4cf68c20 100644 --- a/src/inet/tests/TestInetLayerCommon.cpp +++ b/src/inet/tests/TestInetLayerCommon.cpp @@ -34,8 +34,6 @@ #include #include -#include - #include #include "TestInetCommon.h" diff --git a/src/inet/tests/TestLwIPDNS.cpp b/src/inet/tests/TestLwIPDNS.cpp index 0d97d6e6f8cae0..41576dada9e3f8 100644 --- a/src/inet/tests/TestLwIPDNS.cpp +++ b/src/inet/tests/TestLwIPDNS.cpp @@ -39,7 +39,6 @@ #include #include -#include #include "TestInetCommon.h" #include "TestInetCommonOptions.h" diff --git a/src/lib/core/CHIPCore.h b/src/lib/core/CHIPCore.h index 4d63975b6b2145..332978d881b2ca 100644 --- a/src/lib/core/CHIPCore.h +++ b/src/lib/core/CHIPCore.h @@ -31,12 +31,18 @@ #include +#if INET_CONFIG_ENABLE_TCP_ENDPOINT +#include +#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT + +#if INET_CONFIG_ENABLE_UDP_ENDPOINT +#include +#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT + #if CONFIG_NETWORK_LAYER_BLE #include #endif // CONFIG_NETWORK_LAYER_BLE -#include - #define CHIP_CORE_IDENTITY "chip-core" #define CHIP_CORE_PREFIX CHIP_CORE_IDENTITY ": " diff --git a/src/lib/dnssd/Advertiser.h b/src/lib/dnssd/Advertiser.h index 59047049b8cff3..9cc067d5a94fcc 100644 --- a/src/lib/dnssd/Advertiser.h +++ b/src/lib/dnssd/Advertiser.h @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -287,7 +286,7 @@ class ServiceAdvertiser * The method must be called before other methods of this class. * If the advertiser has already been initialized, the method exits immediately with no error. */ - virtual CHIP_ERROR Init(chip::Inet::InetLayer * inetLayer) = 0; + virtual CHIP_ERROR Init(chip::Inet::EndPointManager * udpEndPointManager) = 0; /** * Shuts down the advertiser. diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index 4bcfd8fa699612..ee6612c82093f0 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -116,7 +116,7 @@ class AdvertiserMinMdns : public ServiceAdvertiser, ~AdvertiserMinMdns() {} // Service advertiser - CHIP_ERROR Init(chip::Inet::InetLayer * inetLayer) override; + CHIP_ERROR Init(chip::Inet::EndPointManager * udpEndPointManager) override; void Shutdown() override; CHIP_ERROR RemoveServices() override; CHIP_ERROR Advertise(const OperationalAdvertisingParameters & params) override; @@ -274,7 +274,7 @@ void AdvertiserMinMdns::OnQuery(const QueryData & data) } } -CHIP_ERROR AdvertiserMinMdns::Init(chip::Inet::InetLayer * inetLayer) +CHIP_ERROR AdvertiserMinMdns::Init(chip::Inet::EndPointManager * udpEndPointManager) { GlobalMinimalMdnsServer::Server().Shutdown(); @@ -285,7 +285,7 @@ CHIP_ERROR AdvertiserMinMdns::Init(chip::Inet::InetLayer * inetLayer) // GlobalMinimalMdnsServer (used for testing). mResponseSender.SetServer(&GlobalMinimalMdnsServer::Server()); - ReturnErrorOnFailure(GlobalMinimalMdnsServer::Instance().StartServer(inetLayer, kMdnsPort)); + ReturnErrorOnFailure(GlobalMinimalMdnsServer::Instance().StartServer(udpEndPointManager, kMdnsPort)); ChipLogProgress(Discovery, "CHIP minimal mDNS started advertising."); diff --git a/src/lib/dnssd/Advertiser_ImplNone.cpp b/src/lib/dnssd/Advertiser_ImplNone.cpp index 59f205e783a559..503366ab033d7e 100644 --- a/src/lib/dnssd/Advertiser_ImplNone.cpp +++ b/src/lib/dnssd/Advertiser_ImplNone.cpp @@ -26,7 +26,7 @@ namespace { class NoneAdvertiser : public ServiceAdvertiser { public: - CHIP_ERROR Init(chip::Inet::InetLayer * inetLayet) override + CHIP_ERROR Init(chip::Inet::EndPointManager * inetLayet) override { ChipLogError(Discovery, "DNS-SD advertising not available. DNS-SD init disabled."); return CHIP_ERROR_NOT_IMPLEMENTED; diff --git a/src/lib/dnssd/Discovery_ImplPlatform.h b/src/lib/dnssd/Discovery_ImplPlatform.h index 5ac1753493d6ca..8ca6155114c886 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.h +++ b/src/lib/dnssd/Discovery_ImplPlatform.h @@ -37,7 +37,7 @@ class DiscoveryImplPlatform : public ServiceAdvertiser, public Resolver { public: // Members that implement both ServiceAdveriser and Resolver interfaces. - CHIP_ERROR Init(Inet::InetLayer *) override { return InitImpl(); } + CHIP_ERROR Init(Inet::EndPointManager *) override { return InitImpl(); } void Shutdown() override; // Members that implement ServiceAdvertiser interface. diff --git a/src/lib/dnssd/DnssdCache.h b/src/lib/dnssd/DnssdCache.h index a55136d087b4de..bdc3d1a69bdaa8 100644 --- a/src/lib/dnssd/DnssdCache.h +++ b/src/lib/dnssd/DnssdCache.h @@ -21,7 +21,6 @@ #include #include -#include #include #include #include diff --git a/src/lib/dnssd/MinimalMdnsServer.cpp b/src/lib/dnssd/MinimalMdnsServer.cpp index 45d5ce1f7519a7..042dc08303973e 100644 --- a/src/lib/dnssd/MinimalMdnsServer.cpp +++ b/src/lib/dnssd/MinimalMdnsServer.cpp @@ -98,11 +98,12 @@ GlobalMinimalMdnsServer & GlobalMinimalMdnsServer::Instance() return _instance; } -CHIP_ERROR GlobalMinimalMdnsServer::StartServer(chip::Inet::InetLayer * inetLayer, uint16_t port) +CHIP_ERROR GlobalMinimalMdnsServer::StartServer(chip::Inet::EndPointManager * udpEndPointManager, + uint16_t port) { GlobalMinimalMdnsServer::Server().Shutdown(); AllInterfaces allInterfaces; - return GlobalMinimalMdnsServer::Server().Listen(inetLayer, &allInterfaces, port); + return GlobalMinimalMdnsServer::Server().Listen(udpEndPointManager, &allInterfaces, port); } void GlobalMinimalMdnsServer::ShutdownServer() diff --git a/src/lib/dnssd/MinimalMdnsServer.h b/src/lib/dnssd/MinimalMdnsServer.h index 8f80d0f1960732..e956fa017d9cf7 100644 --- a/src/lib/dnssd/MinimalMdnsServer.h +++ b/src/lib/dnssd/MinimalMdnsServer.h @@ -15,6 +15,8 @@ * limitations under the License. */ #pragma once + +#include #include namespace chip { @@ -89,7 +91,7 @@ class GlobalMinimalMdnsServer : public mdns::Minimal::ServerDelegate } /// Calls Server().Listen() on all available interfaces - CHIP_ERROR StartServer(chip::Inet::InetLayer * inetLayer, uint16_t port); + CHIP_ERROR StartServer(chip::Inet::EndPointManager * udpEndPointManager, uint16_t port); void ShutdownServer(); void SetQueryDelegate(MdnsPacketDelegate * delegate) { mQueryDelegate = delegate; } diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index 0e4873c2a76750..81161bf0b17b74 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -23,7 +23,7 @@ #include "lib/support/logging/CHIPLogging.h" #include #include -#include +#include #include #include #include @@ -289,7 +289,7 @@ class Resolver * The method must be called before other methods of this class. * If the resolver has already been initialized, the method exits immediately with no error. */ - virtual CHIP_ERROR Init(chip::Inet::InetLayer * inetLayer) = 0; + virtual CHIP_ERROR Init(chip::Inet::EndPointManager * endPointManager) = 0; /** * Shuts down the resolver if it has been initialized before. diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index 5252d51994fb4d..ef067c1932d061 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -20,7 +20,6 @@ #include -#include #include #include #include @@ -347,7 +346,7 @@ class MinMdnsResolver : public Resolver, public MdnsPacketDelegate void OnMdnsPacketData(const BytesRange & data, const chip::Inet::IPPacketInfo * info) override; ///// Resolver implementation - CHIP_ERROR Init(chip::Inet::InetLayer * inetLayer) override; + CHIP_ERROR Init(chip::Inet::EndPointManager * udpEndPointManager) override; void Shutdown() override; void SetResolverDelegate(ResolverDelegate * delegate) override { mDelegate = delegate; } CHIP_ERROR ResolveNodeId(const PeerId & peerId, Inet::IPAddressType type, Resolver::CacheBypass dnssdCacheBypass) override; @@ -404,18 +403,18 @@ void MinMdnsResolver::OnMdnsPacketData(const BytesRange & data, const chip::Inet } } -CHIP_ERROR MinMdnsResolver::Init(chip::Inet::InetLayer * inetLayer) +CHIP_ERROR MinMdnsResolver::Init(chip::Inet::EndPointManager * udpEndPointManager) { /// Note: we do not double-check the port as we assume the APP will always use - /// the same inetLayer and port for mDNS. - mSystemLayer = inetLayer->SystemLayer(); + /// the same udpEndPointManager and port for mDNS. + mSystemLayer = &udpEndPointManager->SystemLayer(); if (GlobalMinimalMdnsServer::Server().IsListening()) { return CHIP_NO_ERROR; } - return GlobalMinimalMdnsServer::Instance().StartServer(inetLayer, kMdnsPort); + return GlobalMinimalMdnsServer::Instance().StartServer(udpEndPointManager, kMdnsPort); } void MinMdnsResolver::Shutdown() diff --git a/src/lib/dnssd/Resolver_ImplNone.cpp b/src/lib/dnssd/Resolver_ImplNone.cpp index c3c28ac8d138b2..ed6049540475d6 100644 --- a/src/lib/dnssd/Resolver_ImplNone.cpp +++ b/src/lib/dnssd/Resolver_ImplNone.cpp @@ -26,7 +26,7 @@ namespace { class NoneResolver : public Resolver { public: - CHIP_ERROR Init(chip::Inet::InetLayer *) override { return CHIP_NO_ERROR; } + CHIP_ERROR Init(chip::Inet::EndPointManager *) override { return CHIP_NO_ERROR; } void Shutdown() override {} void SetResolverDelegate(ResolverDelegate *) override {} diff --git a/src/lib/dnssd/minimal_mdns/ResponseSender.h b/src/lib/dnssd/minimal_mdns/ResponseSender.h index ab7bb317dffa26..1a40bfaa5f8138 100644 --- a/src/lib/dnssd/minimal_mdns/ResponseSender.h +++ b/src/lib/dnssd/minimal_mdns/ResponseSender.h @@ -23,7 +23,6 @@ #include -#include #include namespace mdns { diff --git a/src/lib/dnssd/minimal_mdns/Server.cpp b/src/lib/dnssd/minimal_mdns/Server.cpp index 3b80d797d1de94..5cd0dd7db59a47 100644 --- a/src/lib/dnssd/minimal_mdns/Server.cpp +++ b/src/lib/dnssd/minimal_mdns/Server.cpp @@ -214,7 +214,8 @@ bool ServerBase::IsListening() const return listening; } -CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator * it, uint16_t port) +CHIP_ERROR ServerBase::Listen(chip::Inet::EndPointManager * udpEndPointManager, ListenIterator * it, + uint16_t port) { Shutdown(); // ensure everything starts fresh @@ -226,7 +227,7 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator while (it->Next(&interfaceId, &addressType)) { chip::Inet::UDPEndPoint * listenUdp; - ReturnErrorOnFailure(inetLayer->GetUDPEndPointManager()->NewEndPoint(&listenUdp)); + ReturnErrorOnFailure(udpEndPointManager->NewEndPoint(&listenUdp)); std::unique_ptr endPointHolder(listenUdp, {}); ReturnErrorOnFailure(listenUdp->Bind(addressType, chip::Inet::IPAddress::Any, port, interfaceId)); @@ -250,7 +251,7 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::InetLayer * inetLayer, ListenIterator // - has a *DRAWBACK* of unicast queries being considered LEGACY by mdns since they do // not originate from 5353 and the answers will include a query section. chip::Inet::UDPEndPoint * unicastQueryUdp; - ReturnErrorOnFailure(inetLayer->GetUDPEndPointManager()->NewEndPoint(&unicastQueryUdp)); + ReturnErrorOnFailure(udpEndPointManager->NewEndPoint(&unicastQueryUdp)); std::unique_ptr endPointHolderUnicast(unicastQueryUdp, {}); ReturnErrorOnFailure(unicastQueryUdp->Bind(addressType, chip::Inet::IPAddress::Any, 0, interfaceId)); ReturnErrorOnFailure(unicastQueryUdp->Listen(OnUdpPacketReceived, nullptr /*OnReceiveError*/, this)); diff --git a/src/lib/dnssd/minimal_mdns/Server.h b/src/lib/dnssd/minimal_mdns/Server.h index 22910c8cc1fb19..edcff644bb36eb 100644 --- a/src/lib/dnssd/minimal_mdns/Server.h +++ b/src/lib/dnssd/minimal_mdns/Server.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -166,7 +165,8 @@ class ServerBase /// /// Since mDNS uses link-local addresses, one generally wants to listen on all /// non-loopback interfaces. - CHIP_ERROR Listen(chip::Inet::InetLayer * inetLayer, ListenIterator * it, uint16_t port); + CHIP_ERROR Listen(chip::Inet::EndPointManager * udpEndPointManager, ListenIterator * it, + uint16_t port); /// Send the specified packet to a destination IP address over the specified address virtual CHIP_ERROR DirectSend(chip::System::PacketBufferHandle && data, const chip::Inet::IPAddress & addr, uint16_t port, diff --git a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.h b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.h index 356c238f11a86a..4ff359490ee19e 100644 --- a/src/lib/dnssd/minimal_mdns/responders/QueryResponder.h +++ b/src/lib/dnssd/minimal_mdns/responders/QueryResponder.h @@ -21,7 +21,7 @@ #include "ReplyFilter.h" #include "Responder.h" -#include +#include namespace mdns { namespace Minimal { diff --git a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp index c7dedc87cf7cb6..68364226a6ece1 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp @@ -555,7 +555,7 @@ int TestAdvertiser(void) CheckOnlyServer server(&theSuite); test::ServerSwapper swapper(&server); auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance(); - mdnsAdvertiser.Init(&context.GetInetLayer()); + mdnsAdvertiser.Init(context.GetUDPEndPointManager()); nlTestRunner(&theSuite, &server); server.Shutdown(); return nlTestRunnerStats(&theSuite); diff --git a/src/lib/dnssd/platform/tests/TestPlatform.cpp b/src/lib/dnssd/platform/tests/TestPlatform.cpp index 1e7ea27b1e23e9..e77c58799976b0 100644 --- a/src/lib/dnssd/platform/tests/TestPlatform.cpp +++ b/src/lib/dnssd/platform/tests/TestPlatform.cpp @@ -156,7 +156,7 @@ void TestStub(nlTestSuite * inSuite, void * inContext) // without an expected event. ChipLogError(Discovery, "Test platform returns error correctly"); DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance(); - NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(&DeviceLayer::InetLayer()) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR); OperationalAdvertisingParameters params; NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(params) == CHIP_ERROR_UNEXPECTED_EVENT); @@ -167,7 +167,7 @@ void TestOperational(nlTestSuite * inSuite, void * inContext) ChipLogError(Discovery, "Test operational"); test::Reset(); DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance(); - NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(&DeviceLayer::InetLayer()) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR); operationalCall1.callType = test::CallType::kStart; @@ -188,7 +188,7 @@ void TestCommissionableNode(nlTestSuite * inSuite, void * inContext) ChipLogError(Discovery, "Test commissionable"); test::Reset(); DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance(); - NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(&DeviceLayer::InetLayer()) == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR); commissionableSmall.callType = test::CallType::kStart; diff --git a/src/lib/dnssd/tests/TestDnssdCache.cpp b/src/lib/dnssd/tests/TestDnssdCache.cpp index 231dcf695021e4..34759eb4d9ffe8 100644 --- a/src/lib/dnssd/tests/TestDnssdCache.cpp +++ b/src/lib/dnssd/tests/TestDnssdCache.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 8f8bb31ffeb50d..06886462c4ba50 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -221,7 +221,7 @@ CHIP_ERROR DnsHandler(int argc, char ** argv) return CHIP_NO_ERROR; } - Dnssd::Resolver::Instance().Init(&DeviceLayer::InetLayer()); + Dnssd::Resolver::Instance().Init(DeviceLayer::UDPEndPointManager()); Dnssd::Resolver::Instance().SetResolverDelegate(&sDnsShellResolverDelegate); return sShellDnsSubcommands.ExecCommand(argc, argv); diff --git a/src/messaging/ReliableMessageContext.h b/src/messaging/ReliableMessageContext.h index b0999fec69d6d2..68e05979cac0d1 100644 --- a/src/messaging/ReliableMessageContext.h +++ b/src/messaging/ReliableMessageContext.h @@ -26,7 +26,8 @@ #include #include -#include +#include + #include #include #include diff --git a/src/messaging/tests/echo/common.cpp b/src/messaging/tests/echo/common.cpp index 75b73baad40ce7..d1f7c4df8ac7e5 100644 --- a/src/messaging/tests/echo/common.cpp +++ b/src/messaging/tests/echo/common.cpp @@ -49,7 +49,7 @@ void InitializeChip(void) SuccessOrExit(err); // Initialize TCP. - err = chip::DeviceLayer::InetLayer().InitTCP(chip::DeviceLayer::TCPEndPointManager()); + err = chip::DeviceLayer::TCPEndPointManager()->Init(chip::DeviceLayer::SystemLayer()); SuccessOrExit(err); exit: diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp index 8929fe3376d1ec..4dc5d7b3e241d0 100644 --- a/src/messaging/tests/echo/echo_requester.cpp +++ b/src/messaging/tests/echo/echo_requester.cpp @@ -228,7 +228,7 @@ int main(int argc, char * argv[]) if (gUseTCP) { - err = gTCPManager.Init(chip::Transport::TcpListenParameters(&chip::DeviceLayer::InetLayer()) + err = gTCPManager.Init(chip::Transport::TcpListenParameters(chip::DeviceLayer::TCPEndPointManager()) .SetAddressType(chip::Inet::IPAddressType::kIPv6) .SetListenPort(ECHO_CLIENT_PORT)); SuccessOrExit(err); @@ -238,7 +238,7 @@ int main(int argc, char * argv[]) } else { - err = gUDPManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer()) + err = gUDPManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager()) .SetAddressType(chip::Inet::IPAddressType::kIPv6) .SetListenPort(ECHO_CLIENT_PORT)); SuccessOrExit(err); diff --git a/src/messaging/tests/echo/echo_responder.cpp b/src/messaging/tests/echo/echo_responder.cpp index 9dc973f890fe18..0842d1b7d23104 100644 --- a/src/messaging/tests/echo/echo_responder.cpp +++ b/src/messaging/tests/echo/echo_responder.cpp @@ -83,7 +83,7 @@ int main(int argc, char * argv[]) if (useTCP) { - err = gTCPManager.Init(chip::Transport::TcpListenParameters(&chip::DeviceLayer::InetLayer()) + err = gTCPManager.Init(chip::Transport::TcpListenParameters(chip::DeviceLayer::TCPEndPointManager()) #if INET_CONFIG_ENABLE_IPV4 .SetAddressType(chip::Inet::IPAddressType::kIPv4) #else @@ -97,8 +97,8 @@ int main(int argc, char * argv[]) } else { - err = gUDPManager.Init( - chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer()).SetAddressType(chip::Inet::IPAddressType::kIPv6)); + err = gUDPManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager()) + .SetAddressType(chip::Inet::IPAddressType::kIPv6)); SuccessOrExit(err); err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager); diff --git a/src/platform/Globals.cpp b/src/platform/Globals.cpp index 23bfe7ca5c8f94..de9749f5e10681 100644 --- a/src/platform/Globals.cpp +++ b/src/platform/Globals.cpp @@ -27,18 +27,13 @@ namespace chip { namespace DeviceLayer { -chip::Inet::InetLayer & InetLayer() -{ - static chip::Inet::InetLayer gInetLayer; - return gInetLayer; -} - chip::Inet::EndPointManager * UDPEndPointManager() { static chip::Inet::UDPEndPointManagerImpl gUDPEndPointManager; return &gUDPEndPointManager; } +#if INET_CONFIG_ENABLE_TCP_ENDPOINT chip::Inet::EndPointManager * TCPEndPointManager() { #if INET_CONFIG_ENABLE_TCP_ENDPOINT @@ -48,6 +43,7 @@ chip::Inet::EndPointManager * TCPEndPointManager() return nullptr; #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT } +#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT chip::System::LayerImpl * gMockedSystemLayer = nullptr; diff --git a/src/platform/mbed/PlatformManagerImpl.cpp b/src/platform/mbed/PlatformManagerImpl.cpp index 740aeaf8826c88..892f0770aac771 100644 --- a/src/platform/mbed/PlatformManagerImpl.cpp +++ b/src/platform/mbed/PlatformManagerImpl.cpp @@ -2,7 +2,6 @@ #include "platform/internal/CHIPDeviceLayerInternal.h" -#include #include #include #include diff --git a/src/transport/raw/TCP.cpp b/src/transport/raw/TCP.cpp index d8db200488d718..70b7b8027b3ccf 100644 --- a/src/transport/raw/TCP.cpp +++ b/src/transport/raw/TCP.cpp @@ -80,7 +80,6 @@ CHIP_ERROR TCPBase::Init(TcpListenParameters & params) VerifyOrExit(mState == State::kNotReady, err = CHIP_ERROR_INCORRECT_STATE); #if INET_CONFIG_ENABLE_TCP_ENDPOINT - VerifyOrDieWithMsg(params.GetEndPointManager() != nullptr, Inet, "TCP not initialized"); err = params.GetEndPointManager()->NewEndPoint(&mListenSocket); #else err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; diff --git a/src/transport/raw/TCP.h b/src/transport/raw/TCP.h index e5295186c7b3a5..e2e257ba262d0b 100644 --- a/src/transport/raw/TCP.h +++ b/src/transport/raw/TCP.h @@ -43,7 +43,7 @@ namespace Transport { class TcpListenParameters { public: - explicit TcpListenParameters(Inet::InetLayer * inetLayer) : mEndPointManager(inetLayer->GetTCPEndPointManager()) {} + explicit TcpListenParameters(Inet::EndPointManager * endPointManager) : mEndPointManager(endPointManager) {} TcpListenParameters(const TcpListenParameters &) = default; TcpListenParameters(TcpListenParameters &&) = default; diff --git a/src/transport/raw/UDP.h b/src/transport/raw/UDP.h index 7aa554ffc6d6a1..2ea712cf64208e 100644 --- a/src/transport/raw/UDP.h +++ b/src/transport/raw/UDP.h @@ -41,7 +41,7 @@ namespace Transport { class UdpListenParameters { public: - explicit UdpListenParameters(Inet::InetLayer * inetLayer) : mEndPointManager(inetLayer->GetUDPEndPointManager()) {} + explicit UdpListenParameters(Inet::EndPointManager * endPointManager) : mEndPointManager(endPointManager) {} UdpListenParameters(const UdpListenParameters &) = default; UdpListenParameters(UdpListenParameters &&) = default; diff --git a/src/transport/raw/tests/NetworkTestHelpers.cpp b/src/transport/raw/tests/NetworkTestHelpers.cpp index 280cd6b84d0a75..02c08a7df72fe1 100644 --- a/src/transport/raw/tests/NetworkTestHelpers.cpp +++ b/src/transport/raw/tests/NetworkTestHelpers.cpp @@ -36,8 +36,9 @@ CHIP_ERROR IOContext::Init() InitNetwork(); - mSystemLayer = &gSystemLayer; - mInetLayer = &gInet; + mSystemLayer = &gSystemLayer; + mTCPEndPointManager = &gTCP; + mUDPEndPointManager = &gUDP; return err; } diff --git a/src/transport/raw/tests/NetworkTestHelpers.h b/src/transport/raw/tests/NetworkTestHelpers.h index b7e6b881c0f4b3..1cc57df34fa3ad 100644 --- a/src/transport/raw/tests/NetworkTestHelpers.h +++ b/src/transport/raw/tests/NetworkTestHelpers.h @@ -18,7 +18,8 @@ #include -#include +#include +#include #include #include #include @@ -51,11 +52,13 @@ class IOContext void DriveIOUntil(System::Clock::Timeout maxWait, std::function completionFunction); System::Layer & GetSystemLayer() { return *mSystemLayer; } - Inet::InetLayer & GetInetLayer() { return *mInetLayer; } + Inet::EndPointManager * GetTCPEndPointManager() { return mTCPEndPointManager; } + Inet::EndPointManager * GetUDPEndPointManager() { return mUDPEndPointManager; } private: - System::Layer * mSystemLayer = nullptr; - Inet::InetLayer * mInetLayer = nullptr; + System::Layer * mSystemLayer = nullptr; + Inet::EndPointManager * mTCPEndPointManager = nullptr; + Inet::EndPointManager * mUDPEndPointManager = nullptr; }; class LoopbackTransport : public Transport::Base diff --git a/src/transport/raw/tests/TestTCP.cpp b/src/transport/raw/tests/TestTCP.cpp index a49f2bc69b86e0..15f7d3cfdcd507 100644 --- a/src/transport/raw/tests/TestTCP.cpp +++ b/src/transport/raw/tests/TestTCP.cpp @@ -106,7 +106,7 @@ class MockTransportMgrDelegate : public chip::TransportMgrDelegate void InitializeMessageTest(TCPImpl & tcp, const IPAddress & addr) { - CHIP_ERROR err = tcp.Init(Transport::TcpListenParameters(&mContext.GetInetLayer()).SetAddressType(addr.Type())); + CHIP_ERROR err = tcp.Init(Transport::TcpListenParameters(mContext.GetTCPEndPointManager()).SetAddressType(addr.Type())); NL_TEST_ASSERT(mSuite, err == CHIP_NO_ERROR); mTransportMgrBase.SetSessionManager(this); @@ -172,7 +172,7 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext, Inet::IPAddres TCPImpl tcp; - CHIP_ERROR err = tcp.Init(Transport::TcpListenParameters(&ctx.GetInetLayer()).SetAddressType(type)); + CHIP_ERROR err = tcp.Init(Transport::TcpListenParameters(ctx.GetTCPEndPointManager()).SetAddressType(type)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } diff --git a/src/transport/raw/tests/TestUDP.cpp b/src/transport/raw/tests/TestUDP.cpp index 88057e6770809b..4652f4f5f6f963 100644 --- a/src/transport/raw/tests/TestUDP.cpp +++ b/src/transport/raw/tests/TestUDP.cpp @@ -90,7 +90,7 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext, Inet::IPAddres Transport::UDP udp; - CHIP_ERROR err = udp.Init(Transport::UdpListenParameters(&ctx.GetInetLayer()).SetAddressType(type).SetListenPort(0)); + CHIP_ERROR err = udp.Init(Transport::UdpListenParameters(ctx.GetUDPEndPointManager()).SetAddressType(type).SetListenPort(0)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } @@ -122,7 +122,7 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext, const IPAddress & Transport::UDP udp; - err = udp.Init(Transport::UdpListenParameters(&ctx.GetInetLayer()).SetAddressType(addr.Type()).SetListenPort(0)); + err = udp.Init(Transport::UdpListenParameters(ctx.GetUDPEndPointManager()).SetAddressType(addr.Type()).SetListenPort(0)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); MockTransportMgrDelegate gMockTransportMgrDelegate(inSuite); diff --git a/src/transport/tests/TestSessionManager.cpp b/src/transport/tests/TestSessionManager.cpp index b3270936132f87..ee29705a68fdc8 100644 --- a/src/transport/tests/TestSessionManager.cpp +++ b/src/transport/tests/TestSessionManager.cpp @@ -120,7 +120,7 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext) err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } @@ -147,7 +147,7 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext) err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); callback.mSuite = inSuite; @@ -236,7 +236,7 @@ void SendEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); callback.mSuite = inSuite; @@ -311,7 +311,7 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); callback.mSuite = inSuite; @@ -416,7 +416,7 @@ void StaleConnectionDropTest(nlTestSuite * inSuite, void * inContext) err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); TestSessMgrCallback callback; From 9860b37d4b2d36ee5226cc6f67b9c08a36216670 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Wed, 8 Dec 2021 09:23:36 -0500 Subject: [PATCH 2/4] restyle --- src/controller/CHIPDeviceControllerFactory.cpp | 4 ++-- src/controller/CHIPDeviceControllerSystemState.h | 3 +-- src/inet/tests/TestInetEndPoint.cpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index ef87c3f09bf998..102012fc2251e7 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -260,8 +260,8 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown() mSessionMgr->Shutdown(); } - mSystemLayer = nullptr; - mUDPEndPointManager = nullptr; + mSystemLayer = nullptr; + mUDPEndPointManager = nullptr; if (mMessageCounterManager != nullptr) { diff --git a/src/controller/CHIPDeviceControllerSystemState.h b/src/controller/CHIPDeviceControllerSystemState.h index 88507214a819b1..337f212bc65298 100644 --- a/src/controller/CHIPDeviceControllerSystemState.h +++ b/src/controller/CHIPDeviceControllerSystemState.h @@ -84,8 +84,7 @@ class DeviceControllerSystemState public: ~DeviceControllerSystemState(){}; DeviceControllerSystemState(DeviceControllerSystemStateParams params) : - mSystemLayer(params.systemLayer), - mTCPEndPointManager(params.tcpEndPointManager), + mSystemLayer(params.systemLayer), mTCPEndPointManager(params.tcpEndPointManager), mUDPEndPointManager(params.udpEndPointManager), mTransportMgr(params.transportMgr), mSessionMgr(params.sessionMgr), mExchangeMgr(params.exchangeMgr), mMessageCounterManager(params.messageCounterManager), mFabrics(params.fabricTable), mIMDelegate(params.imDelegate) diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index 1809f1c1104542..e281813851720a 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -35,8 +35,8 @@ #include -#include #include +#include #include #include From 6f55c1b2840063c61ff9136797584237a14ee020 Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Wed, 8 Dec 2021 09:25:41 -0500 Subject: [PATCH 3/4] remove src/inet/InetLayer.cpp --- src/inet/InetLayer.cpp | 84 ------------------------------------------ 1 file changed, 84 deletions(-) delete mode 100644 src/inet/InetLayer.cpp diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp deleted file mode 100644 index 57229256d50b5f..00000000000000 --- a/src/inet/InetLayer.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * Copyright (c) 2013-2017 Nest Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Provides access to UDP (and optionally TCP) EndPointManager. - */ - -#include - -#include -#include -#include -#include - -namespace chip { -namespace Inet { - -CHIP_ERROR InetLayer::Init(System::Layer & aSystemLayer, EndPointManager * udpEndPointManager) -{ - Inet::RegisterLayerErrorFormatter(); - VerifyOrReturnError(mLayerState.SetInitializing(), CHIP_ERROR_INCORRECT_STATE); - VerifyOrReturnError(udpEndPointManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - - mSystemLayer = &aSystemLayer; - ReturnErrorOnFailure(udpEndPointManager->Init(aSystemLayer)); - mUDPEndPointManager = udpEndPointManager; - - mLayerState.SetInitialized(); - return CHIP_NO_ERROR; -} - -CHIP_ERROR InetLayer::Shutdown() -{ - VerifyOrReturnError(mLayerState.SetShuttingDown(), CHIP_ERROR_INCORRECT_STATE); - VerifyOrReturnError(mTCPEndPointManager == nullptr, CHIP_ERROR_INCORRECT_STATE); - VerifyOrReturnError(mUDPEndPointManager != nullptr, CHIP_ERROR_INCORRECT_STATE); - ReturnErrorOnFailure(mUDPEndPointManager->Shutdown()); - mUDPEndPointManager = nullptr; - mSystemLayer = nullptr; - mLayerState.ResetFromShuttingDown(); // Return to uninitialized state to permit re-initialization. - return CHIP_NO_ERROR; -} - -CHIP_ERROR InetLayer::InitTCP(EndPointManager * tcpEndPointManager) -{ - VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE); -#if INET_CONFIG_ENABLE_TCP_ENDPOINT - VerifyOrReturnError(tcpEndPointManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - ReturnErrorOnFailure(tcpEndPointManager->Init(*mSystemLayer)); -#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT - mTCPEndPointManager = tcpEndPointManager; - return CHIP_NO_ERROR; -} - -CHIP_ERROR InetLayer::ShutdownTCP() -{ - VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE); -#if INET_CONFIG_ENABLE_TCP_ENDPOINT - if (mTCPEndPointManager != nullptr) - { - ReturnErrorOnFailure(mTCPEndPointManager->Shutdown()); - mTCPEndPointManager = nullptr; - } -#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT - return CHIP_NO_ERROR; -} - -} // namespace Inet -} // namespace chip From d4906a11e73cb12052be8179fb0f88631db081ec Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Thu, 9 Dec 2021 09:49:58 -0500 Subject: [PATCH 4/4] fix merge --- src/controller/CHIPCommissionableNodeController.cpp | 4 ++-- src/controller/CHIPDeviceControllerFactory.cpp | 2 +- src/lib/dnssd/ResolverProxy.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controller/CHIPCommissionableNodeController.cpp b/src/controller/CHIPCommissionableNodeController.cpp index d127e2abee050e..49ae43d14e30a4 100644 --- a/src/controller/CHIPCommissionableNodeController.cpp +++ b/src/controller/CHIPCommissionableNodeController.cpp @@ -35,7 +35,7 @@ CHIP_ERROR CommissionableNodeController::DiscoverCommissioners(Dnssd::DiscoveryF if (mResolver == nullptr) { #if CONFIG_DEVICE_LAYER - ReturnErrorOnFailure(mDNSResolver.Init(&DeviceLayer::InetLayer())); + ReturnErrorOnFailure(mDNSResolver.Init(DeviceLayer::UDPEndPointManager())); #endif mDNSResolver.SetResolverDelegate(this); return mDNSResolver.FindCommissioners(discoveryFilter); @@ -43,7 +43,7 @@ CHIP_ERROR CommissionableNodeController::DiscoverCommissioners(Dnssd::DiscoveryF else { #if CONFIG_DEVICE_LAYER - ReturnErrorOnFailure(mResolver->Init(&DeviceLayer::InetLayer())); + ReturnErrorOnFailure(mResolver->Init(DeviceLayer::UDPEndPointManager())); #endif return mResolver->FindCommissioners(discoveryFilter); } diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index 633a9445ef75e6..cabf6a4b89ecab 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -153,7 +153,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->Init(stateParams.exchangeMgr, stateParams.imDelegate)); #if CHIP_DEVICE_CONFIG_ENABLE_DNSSD - ReturnErrorOnFailure(Dnssd::Resolver::Instance().Init(stateParams.inetLayer)); + ReturnErrorOnFailure(Dnssd::Resolver::Instance().Init(stateParams.udpEndPointManager)); #endif // CHIP_DEVICE_CONFIG_ENABLE_DNSSD // store the system state diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h index 88ac1d407a1784..e7ce4fa10c408f 100644 --- a/src/lib/dnssd/ResolverProxy.h +++ b/src/lib/dnssd/ResolverProxy.h @@ -63,9 +63,9 @@ class ResolverProxy : public Resolver ResolverProxy() {} // Resolver interface. - CHIP_ERROR Init(Inet::InetLayer * inetLayer = nullptr) override + CHIP_ERROR Init(Inet::EndPointManager * udpEndPoint = nullptr) override { - ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(inetLayer)); + ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(udpEndPoint)); VerifyOrReturnError(mDelegate == nullptr, CHIP_ERROR_INCORRECT_STATE); mDelegate = chip::Platform::New(); return CHIP_NO_ERROR;