diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index c8acb4d4da29ac..44612eeed3df81 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -82,6 +82,8 @@ CHIP_ERROR CommandHandler::SendCommandResponse() ReturnErrorOnFailure(Finalize(commandPacket)); ReturnErrorOnFailure( mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::InvokeCommandResponse, std::move(commandPacket))); + // The ExchangeContext is automatically freed here, and it makes mpExchangeCtx be temporarily dangling, but in + // all cases, we are going to call Close immediately after this function, which nulls out mpExchangeCtx. MoveToState(CommandState::CommandSent); diff --git a/src/app/CommandSender.cpp b/src/app/CommandSender.cpp index 6c67b3c5fa787f..c400caeac7a38c 100644 --- a/src/app/CommandSender.cpp +++ b/src/app/CommandSender.cpp @@ -36,8 +36,7 @@ CommandSender::CommandSender(Callback * apCallback, Messaging::ExchangeManager * mpCallback(apCallback), mpExchangeMgr(apExchangeMgr) {} -CHIP_ERROR CommandSender::SendCommandRequest(NodeId aNodeId, FabricIndex aFabricIndex, Optional secureSession, - System::Clock::Timeout timeout) +CHIP_ERROR CommandSender::SendCommandRequest(SessionHandle session, System::Clock::Timeout timeout) { CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferHandle commandPacket; @@ -48,7 +47,7 @@ CHIP_ERROR CommandSender::SendCommandRequest(NodeId aNodeId, FabricIndex aFabric SuccessOrExit(err); // Create a new exchange context. - mpExchangeCtx = mpExchangeMgr->NewContext(secureSession.ValueOr(SessionHandle(aNodeId, 1, 1, aFabricIndex)), this); + mpExchangeCtx = mpExchangeMgr->NewContext(session, this); VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY); mpExchangeCtx->SetResponseTimeout(timeout); diff --git a/src/app/CommandSender.h b/src/app/CommandSender.h index 4049798dffede8..656f0a4e64333d 100644 --- a/src/app/CommandSender.h +++ b/src/app/CommandSender.h @@ -137,8 +137,6 @@ class CommandSender final : public Command, public Messaging::ExchangeDelegate return FinishCommand(/* aEndDataStruct = */ false); } - // TODO: issue #6792 - the secure session parameter should be made non-optional and passed by reference. - // // Sends a queued up command request to the target encapsulated by the secureSession handle. // // Upon successful return from this call, all subsequent errors that occur during this interaction @@ -155,8 +153,7 @@ class CommandSender final : public Command, public Messaging::ExchangeDelegate // Client can specify the maximum time to wait for response (in milliseconds) via timeout parameter. // Default timeout value will be used otherwise. // - CHIP_ERROR SendCommandRequest(NodeId aNodeId, FabricIndex aFabricIndex, Optional secureSession, - System::Clock::Timeout timeout = kImMessageTimeout); + CHIP_ERROR SendCommandRequest(SessionHandle session, System::Clock::Timeout timeout = kImMessageTimeout); private: // ExchangeDelegate interface implementation. Private so people won't diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index f6411c55dea896..2735bd1be5d174 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -242,8 +242,7 @@ void WriteClient::ClearState() MoveToState(State::Uninitialized); } -CHIP_ERROR WriteClient::SendWriteRequest(NodeId aNodeId, FabricIndex aFabricIndex, Optional apSecureSession, - System::Clock::Timeout timeout) +CHIP_ERROR WriteClient::SendWriteRequest(SessionHandle session, System::Clock::Timeout timeout) { CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferHandle packet; @@ -258,7 +257,7 @@ CHIP_ERROR WriteClient::SendWriteRequest(NodeId aNodeId, FabricIndex aFabricInde ClearExistingExchangeContext(); // Create a new exchange context. - mpExchangeCtx = mpExchangeMgr->NewContext(apSecureSession.ValueOr(SessionHandle(aNodeId, 1, 1, aFabricIndex)), this); + mpExchangeCtx = mpExchangeMgr->NewContext(session, this); VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY); mpExchangeCtx->SetResponseTimeout(timeout); @@ -372,10 +371,9 @@ CHIP_ERROR WriteClient::ProcessAttributeStatusIB(AttributeStatusIB::Parser & aAt return err; } -CHIP_ERROR WriteClientHandle::SendWriteRequest(NodeId aNodeId, FabricIndex aFabricIndex, Optional apSecureSession, - System::Clock::Timeout timeout) +CHIP_ERROR WriteClientHandle::SendWriteRequest(SessionHandle session, System::Clock::Timeout timeout) { - CHIP_ERROR err = mpWriteClient->SendWriteRequest(aNodeId, aFabricIndex, apSecureSession, timeout); + CHIP_ERROR err = mpWriteClient->SendWriteRequest(session, timeout); if (err == CHIP_NO_ERROR) { diff --git a/src/app/WriteClient.h b/src/app/WriteClient.h index b0ffec92eae2f0..fa85904ac50606 100644 --- a/src/app/WriteClient.h +++ b/src/app/WriteClient.h @@ -143,8 +143,7 @@ class WriteClient : public Messaging::ExchangeDelegate * If SendWriteRequest is never called, or the call fails, the API * consumer is responsible for calling Shutdown on the WriteClient. */ - CHIP_ERROR SendWriteRequest(NodeId aNodeId, FabricIndex aFabricIndex, Optional apSecureSession, - System::Clock::Timeout timeout); + CHIP_ERROR SendWriteRequest(SessionHandle session, System::Clock::Timeout timeout); /** * Initialize the client object. Within the lifetime @@ -225,8 +224,7 @@ class WriteClientHandle * Finalize the message and send it to the desired node. The underlying write object will always be released, and the user * should not use this object after calling this function. */ - CHIP_ERROR SendWriteRequest(NodeId aNodeId, FabricIndex aFabricIndex, Optional apSecureSession, - System::Clock::Timeout timeout = kImMessageTimeout); + CHIP_ERROR SendWriteRequest(SessionHandle session, System::Clock::Timeout timeout = kImMessageTimeout); /** * Encode an attribute value that can be directly encoded using TLVWriter::Put diff --git a/src/app/tests/TestCommandInteraction.cpp b/src/app/tests/TestCommandInteraction.cpp index 181f9d71e8df26..3586e30541b2b8 100644 --- a/src/app/tests/TestCommandInteraction.cpp +++ b/src/app/tests/TestCommandInteraction.cpp @@ -49,7 +49,6 @@ using TestContext = chip::Test::AppContext; namespace chip { namespace { -FabricIndex gFabricIndex = 0; bool isCommandDispatched = false; bool sendResponse = true; @@ -288,7 +287,7 @@ void TestCommandInteraction::TestCommandSenderWithWrongState(nlTestSuite * apSui app::CommandSender commandSender(&mockCommandSenderDelegate, &ctx.GetExchangeManager()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = commandSender.SendCommandRequest(kTestDeviceNodeId, gFabricIndex, Optional::Missing()); + err = commandSender.SendCommandRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_INCORRECT_STATE); } @@ -303,11 +302,9 @@ void TestCommandInteraction::TestCommandHandlerWithWrongState(nlTestSuite * apSu err = commandHandler.PrepareCommand(commandPathParams); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - auto exchangeCtx = ctx.GetExchangeManager().NewContext(SessionHandle(0, 0, 0, 0), nullptr); - commandHandler.mpExchangeCtx = exchangeCtx; TestExchangeDelegate delegate; - commandHandler.mpExchangeCtx->SetDelegate(&delegate); - err = commandHandler.SendCommandResponse(); + commandHandler.mpExchangeCtx = ctx.NewExchangeToAlice(&delegate); + err = commandHandler.SendCommandResponse(); NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_INCORRECT_STATE); } @@ -322,8 +319,7 @@ void TestCommandInteraction::TestCommandSenderWithSendCommand(nlTestSuite * apSu System::PacketBufferHandle buf = System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize); AddCommandDataIB(apSuite, apContext, &commandSender, false); - err = - commandSender.SendCommandRequest(0 /* nodeid */, 0 /* fabricindex */, Optional(ctx.GetSessionBobToAlice())); + err = commandSender.SendCommandRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); GenerateReceivedCommand(apSuite, apContext, buf, true /*aNeedCommandData*/); @@ -340,17 +336,15 @@ void TestCommandInteraction::TestCommandHandlerWithSendEmptyCommand(nlTestSuite app::CommandHandler commandHandler(&mockCommandHandlerDelegate); System::PacketBufferHandle commandDatabuf = System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize); - auto exchangeCtx = ctx.GetExchangeManager().NewContext(SessionHandle(0, 0, 0, 0), nullptr); - commandHandler.mpExchangeCtx = exchangeCtx; - TestExchangeDelegate delegate; - commandHandler.mpExchangeCtx->SetDelegate(&delegate); - err = commandHandler.PrepareCommand(commandPathParams); + commandHandler.mpExchangeCtx = ctx.NewExchangeToAlice(&delegate); + err = commandHandler.PrepareCommand(commandPathParams); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); err = commandHandler.FinishCommand(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); err = commandHandler.SendCommandResponse(); - NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_NOT_CONNECTED); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); + commandHandler.Close(); } void TestCommandInteraction::TestCommandSenderWithProcessReceivedMsg(nlTestSuite * apSuite, void * apContext) @@ -374,11 +368,8 @@ void TestCommandInteraction::ValidateCommandHandlerWithSendCommand(nlTestSuite * app::CommandHandler commandHandler(&mockCommandHandlerDelegate); System::PacketBufferHandle commandPacket; - auto exchangeCtx = ctx.GetExchangeManager().NewContext(SessionHandle(0, 0, 0, 0), nullptr); - - commandHandler.mpExchangeCtx = exchangeCtx; TestExchangeDelegate delegate; - commandHandler.mpExchangeCtx->SetDelegate(&delegate); + commandHandler.mpExchangeCtx = ctx.NewExchangeToAlice(&delegate); AddCommandDataIB(apSuite, apContext, &commandHandler, aNeedStatusCode); err = commandHandler.Finalize(commandPacket); @@ -422,9 +413,8 @@ void TestCommandInteraction::TestCommandHandlerCommandDataEncoding(nlTestSuite * app::CommandHandler commandHandler(nullptr); System::PacketBufferHandle commandPacket; - commandHandler.mpExchangeCtx = ctx.GetExchangeManager().NewContext(SessionHandle(0, 0, 0, 0), nullptr); TestExchangeDelegate delegate; - commandHandler.mpExchangeCtx->SetDelegate(&delegate); + commandHandler.mpExchangeCtx = ctx.NewExchangeToAlice(&delegate); auto path = MakeTestCommandPath(); @@ -503,7 +493,7 @@ void TestCommandInteraction::TestCommandSenderCommandSuccessResponseFlow(nlTestS app::CommandSender commandSender(&mockCommandSenderDelegate, &ctx.GetExchangeManager()); AddCommandDataIB(apSuite, apContext, &commandSender, false); - err = commandSender.SendCommandRequest(0, 0, Optional(ctx.GetSessionBobToAlice())); + err = commandSender.SendCommandRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, mockCommandSenderDelegate.onResponseCalledTimes == 1 && mockCommandSenderDelegate.onFinalCalledTimes == 1 && @@ -522,7 +512,7 @@ void TestCommandInteraction::TestCommandSenderCommandSpecificResponseFlow(nlTest app::CommandSender commandSender(&mockCommandSenderDelegate, &ctx.GetExchangeManager()); AddCommandDataIB(apSuite, apContext, &commandSender, false, kTestCommandIdCommandSpecificResponse); - err = commandSender.SendCommandRequest(0, 0, Optional(ctx.GetSessionBobToAlice())); + err = commandSender.SendCommandRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, mockCommandSenderDelegate.onResponseCalledTimes == 1 && mockCommandSenderDelegate.onFinalCalledTimes == 1 && @@ -541,7 +531,7 @@ void TestCommandInteraction::TestCommandSenderCommandFailureResponseFlow(nlTestS app::CommandSender commandSender(&mockCommandSenderDelegate, &ctx.GetExchangeManager()); AddCommandDataIB(apSuite, apContext, &commandSender, false, kTestNonExistCommandId); - err = commandSender.SendCommandRequest(0, 0, Optional(ctx.GetSessionBobToAlice())); + err = commandSender.SendCommandRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, mockCommandSenderDelegate.onResponseCalledTimes == 0 && mockCommandSenderDelegate.onFinalCalledTimes == 1 && @@ -568,7 +558,7 @@ void TestCommandInteraction::TestCommandSenderAbruptDestruction(nlTestSuite * ap app::CommandSender commandSender(&mockCommandSenderDelegate, &ctx.GetExchangeManager()); AddCommandDataIB(apSuite, apContext, &commandSender, false, kTestCommandIdCommandSpecificResponse); - err = commandSender.SendCommandRequest(0, 0, Optional(ctx.GetSessionBobToAlice())); + err = commandSender.SendCommandRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); // diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index e63647a2effc89..46df2f2a0b09d9 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -224,8 +224,7 @@ void TestWriteInteraction::TestWriteClient(nlTestSuite * apSuite, void * apConte NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); AddAttributeDataElement(apSuite, apContext, writeClientHandle); - SessionHandle session = ctx.GetSessionBobToAlice(); - err = writeClientHandle.SendWriteRequest(ctx.GetAliceNodeId(), ctx.GetFabricIndex(), Optional::Value(session)); + err = writeClientHandle.SendWriteRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); // The internal WriteClient should be nullptr once we SendWriteRequest. NL_TEST_ASSERT(apSuite, nullptr == writeClientHandle.mpWriteClient); @@ -317,9 +316,7 @@ void TestWriteInteraction::TestWriteRoundtripWithClusterObjects(nlTestSuite * ap NL_TEST_ASSERT(apSuite, callback.mOnSuccessCalled == 0); - SessionHandle session = ctx.GetSessionBobToAlice(); - - err = writeClient.SendWriteRequest(ctx.GetAliceNodeId(), ctx.GetFabricIndex(), Optional::Value(session)); + err = writeClient.SendWriteRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, callback.mOnSuccessCalled == 1); @@ -370,9 +367,7 @@ void TestWriteInteraction::TestWriteRoundtrip(nlTestSuite * apSuite, void * apCo NL_TEST_ASSERT(apSuite, callback.mOnSuccessCalled == 0 && callback.mOnErrorCalled == 0 && callback.mOnDoneCalled == 0); - SessionHandle session = ctx.GetSessionBobToAlice(); - - err = writeClient.SendWriteRequest(ctx.GetAliceNodeId(), ctx.GetFabricIndex(), Optional::Value(session)); + err = writeClient.SendWriteRequest(ctx.GetSessionBobToAlice()); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(apSuite, callback.mOnSuccessCalled == 1 && callback.mOnErrorCalled == 0 && callback.mOnDoneCalled == 1); diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index 61d7e209f85241..bd1d7ce307e4ac 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -247,8 +247,7 @@ CHIP_ERROR SendCommandRequest(std::unique_ptr && comma err = commandSender->FinishCommand(); SuccessOrExit(err); - err = commandSender->SendCommandRequest(chip::kTestDeviceNodeId, gFabricIndex, chip::Optional::Missing(), - gMessageTimeout); + err = commandSender->SendCommandRequest(gSessionManager.FindSecureSessionForNode(chip::kTestDeviceNodeId), gMessageTimeout); SuccessOrExit(err); gCommandCount++; @@ -284,8 +283,7 @@ CHIP_ERROR SendBadCommandRequest(std::unique_ptr && co err = commandSender->FinishCommand(); SuccessOrExit(err); - err = commandSender->SendCommandRequest(chip::kTestDeviceNodeId, gFabricIndex, chip::Optional::Missing(), - gMessageTimeout); + err = commandSender->SendCommandRequest(gSessionManager.FindSecureSessionForNode(chip::kTestDeviceNodeId), gMessageTimeout); SuccessOrExit(err); gCommandCount++; commandSender.release(); @@ -359,8 +357,8 @@ CHIP_ERROR SendWriteRequest(chip::app::WriteClientHandle & apWriteClient) SuccessOrExit(err = writer->PutBoolean(chip::TLV::ContextTag(chip::app::AttributeDataElement::kCsTag_Data), true)); SuccessOrExit(err = apWriteClient->FinishAttribute()); - SuccessOrExit(err = apWriteClient.SendWriteRequest(chip::kTestDeviceNodeId, gFabricIndex, - chip::Optional::Missing(), gMessageTimeout)); + SuccessOrExit( + err = apWriteClient.SendWriteRequest(gSessionManager.FindSecureSessionForNode(chip::kTestDeviceNodeId), gMessageTimeout)); gWriteCount++; diff --git a/src/controller/CHIPDevice.cpp b/src/controller/CHIPDevice.cpp index a3f345f7083841..1fd3fa66204e1b 100644 --- a/src/controller/CHIPDevice.cpp +++ b/src/controller/CHIPDevice.cpp @@ -100,8 +100,10 @@ CHIP_ERROR Device::SendCommands(app::CommandSender * commandObj) { bool loadedSecureSession = false; ReturnErrorOnFailure(LoadSecureSessionParametersIfNeeded(loadedSecureSession)); + VerifyOrReturnError(mState == ConnectionState::SecureConnected, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(GetSecureSession().HasValue(), CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(commandObj != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - return commandObj->SendCommandRequest(mDeviceId, mFabricIndex, mSecureSession); + return commandObj->SendCommandRequest(mSecureSession.Value()); } CHIP_ERROR Device::Serialize(SerializedDevice & output) @@ -761,6 +763,8 @@ CHIP_ERROR Device::SendReadAttributeRequest(app::AttributePathParams aPath, Call aPath.mNodeId = GetDeviceId(); ReturnErrorOnFailure(LoadSecureSessionParametersIfNeeded(loadedSecureSession)); + VerifyOrReturnError(mState == ConnectionState::SecureConnected, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(GetSecureSession().HasValue(), CHIP_ERROR_INCORRECT_STATE); if (onSuccessCallback != nullptr || onFailureCallback != nullptr) { @@ -828,6 +832,8 @@ CHIP_ERROR Device::SendWriteAttributeRequest(app::WriteClientHandle aHandle, Cal CHIP_ERROR err = CHIP_NO_ERROR; ReturnErrorOnFailure(LoadSecureSessionParametersIfNeeded(loadedSecureSession)); + VerifyOrReturnError(mState == ConnectionState::SecureConnected, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(GetSecureSession().HasValue(), CHIP_ERROR_INCORRECT_STATE); app::WriteClient * writeClient = aHandle.Get(); @@ -835,7 +841,7 @@ CHIP_ERROR Device::SendWriteAttributeRequest(app::WriteClientHandle aHandle, Cal { AddIMResponseHandler(writeClient, onSuccessCallback, onFailureCallback); } - if ((err = aHandle.SendWriteRequest(GetDeviceId(), 0, mSecureSession)) != CHIP_NO_ERROR) + if ((err = aHandle.SendWriteRequest(mSecureSession.Value())) != CHIP_NO_ERROR) { CancelIMResponseHandler(writeClient); } diff --git a/src/controller/InvokeInteraction.h b/src/controller/InvokeInteraction.h index dc10117ed2dae6..30d8d58e20d718 100644 --- a/src/controller/InvokeInteraction.h +++ b/src/controller/InvokeInteraction.h @@ -70,8 +70,7 @@ CHIP_ERROR InvokeCommandRequest(Messaging::ExchangeManager * aExchangeMgr, Sessi VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_NO_MEMORY); ReturnErrorOnFailure(commandSender->AddRequestData(commandPath, requestCommandData)); - ReturnErrorOnFailure(commandSender->SendCommandRequest(sessionHandle.GetPeerNodeId(), sessionHandle.GetFabricIndex(), - Optional(sessionHandle))); + ReturnErrorOnFailure(commandSender->SendCommandRequest(sessionHandle)); // // We've effectively transfered ownership of the above allocated objects to CommandSender, and we need to wait for it to call us diff --git a/src/controller/WriteInteraction.h b/src/controller/WriteInteraction.h index 20722264616dec..f16ea085b4dbbc 100644 --- a/src/controller/WriteInteraction.h +++ b/src/controller/WriteInteraction.h @@ -94,8 +94,7 @@ CHIP_ERROR WriteAttribute(Messaging::ExchangeManager * aExchangeMgr, SessionHand ReturnErrorOnFailure(handle.EncodeAttributeWritePayload( chip::app::AttributePathParams(endpointId, AttributeInfo::GetClusterId(), AttributeInfo::GetAttributeId()), requestCommandData)); - ReturnErrorOnFailure(handle.SendWriteRequest(sessionHandle.GetPeerNodeId(), sessionHandle.GetFabricIndex(), - chip::Optional(sessionHandle))); + ReturnErrorOnFailure(handle.SendWriteRequest(sessionHandle)); callback.release(); return CHIP_NO_ERROR; diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index fb6508c0c30d32..285170c3c5c759 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -592,4 +592,12 @@ SecureSession * SessionManager::GetSecureSession(SessionHandle session) } } +SessionHandle SessionManager::FindSecureSessionForNode(NodeId peerNodeId) +{ + SecureSession * session = mPeerConnections.FindSecureSession(peerNodeId, nullptr); + VerifyOrDie(session != nullptr); + return SessionHandle(session->GetPeerNodeId(), session->GetLocalSessionId(), session->GetPeerSessionId(), + session->GetFabricIndex()); +} + } // namespace chip diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index d0d3795b41858a..dd76f6ebe8d1c0 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -269,6 +269,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate return session.HasValue() ? MakeOptional(session.Value()) : NullOptional; } + // TODO: this is a temporary solution for legacy tests which use nodeId to send packets + SessionHandle FindSecureSessionForNode(NodeId peerNodeId); + private: /** * The State of a secure transport object.