diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp index c043a03bf42536..31d9647433a25f 100644 --- a/examples/shell/shell_common/cmd_ping.cpp +++ b/examples/shell/shell_common/cmd_ping.cpp @@ -320,7 +320,7 @@ void StartPinging(streamer_t * stream, char * destination) err = EstablishSecureSession(stream, GetEchoPeerAddress()); SuccessOrExit(err); - err = gEchoClient.Init(&gExchangeManager, gSession.Get()); + err = gEchoClient.Init(&gExchangeManager, gSession.Get().Value()); SuccessOrExit(err); // Arrange to get a callback whenever an Echo Response is received. diff --git a/examples/shell/shell_common/cmd_send.cpp b/examples/shell/shell_common/cmd_send.cpp index a8417b966d2db4..f7cb24cb92cfe9 100644 --- a/examples/shell/shell_common/cmd_send.cpp +++ b/examples/shell/shell_common/cmd_send.cpp @@ -128,7 +128,7 @@ CHIP_ERROR SendMessage(streamer_t * stream) uint32_t payloadSize = gSendArguments.GetPayloadSize(); // Create a new exchange context. - auto * ec = gExchangeManager.NewContext(gSession.Get(), &gMockAppDelegate); + auto * ec = gExchangeManager.NewContext(gSession.Get().Value(), &gMockAppDelegate); VerifyOrExit(ec != nullptr, err = CHIP_ERROR_NO_MEMORY); payloadBuf = MessagePacketBuffer::New(payloadSize); diff --git a/src/app/OperationalDeviceProxy.cpp b/src/app/OperationalDeviceProxy.cpp index 3a6ffe69bb6b96..51f3afea749696 100644 --- a/src/app/OperationalDeviceProxy.cpp +++ b/src/app/OperationalDeviceProxy.cpp @@ -191,7 +191,7 @@ CHIP_ERROR OperationalDeviceProxy::UpdateDeviceData(const Transport::PeerAddress return CHIP_NO_ERROR; } - mSecureSession.Get()->AsSecureSession()->SetPeerAddress(addr); + mSecureSession.Get().Value()->AsSecureSession()->SetPeerAddress(addr); } return err; @@ -305,7 +305,7 @@ CHIP_ERROR OperationalDeviceProxy::Disconnect() ReturnErrorCodeIf(mState != State::SecureConnected, CHIP_ERROR_INCORRECT_STATE); if (mSecureSession) { - mInitParams.sessionManager->ExpirePairing(mSecureSession.Get()); + mInitParams.sessionManager->ExpirePairing(mSecureSession.Get().Value()); } MoveToState(State::Initialized); diff --git a/src/app/OperationalDeviceProxy.h b/src/app/OperationalDeviceProxy.h index 5f3b7adaf75ca3..a1623c17733810 100644 --- a/src/app/OperationalDeviceProxy.h +++ b/src/app/OperationalDeviceProxy.h @@ -182,7 +182,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy, Messaging::ExchangeManager * GetExchangeManager() const override { return mInitParams.exchangeMgr; } - chip::Optional GetSecureSession() const override { return mSecureSession.ToOptional(); } + chip::Optional GetSecureSession() const override { return mSecureSession.Get(); } Transport::PeerAddress GetPeerAddress() const { return mDeviceAddress; } diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 7e1ea4efa8aaf2..19ebc43e32a1c5 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -269,7 +269,9 @@ CHIP_ERROR ReadClient::SendReadRequest(ReadPrepareParams & aReadPrepareParams) ReturnErrorOnFailure(request.EndOfReadRequestMessage().GetError()); ReturnErrorOnFailure(writer.Finalize(&msgBuf)); - mpExchangeCtx = mpExchangeMgr->NewContext(aReadPrepareParams.mSessionHolder.Get(), this); + VerifyOrReturnError(aReadPrepareParams.mSessionHolder, CHIP_ERROR_MISSING_SECURE_SESSION); + + mpExchangeCtx = mpExchangeMgr->NewContext(aReadPrepareParams.mSessionHolder.Get().Value(), this); VerifyOrReturnError(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY); mpExchangeCtx->SetResponseTimeout(aReadPrepareParams.mTimeout); @@ -913,7 +915,9 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara ReturnErrorOnFailure(err = request.EndOfSubscribeRequestMessage().GetError()); ReturnErrorOnFailure(writer.Finalize(&msgBuf)); - mpExchangeCtx = mpExchangeMgr->NewContext(aReadPrepareParams.mSessionHolder.Get(), this); + VerifyOrReturnError(aReadPrepareParams.mSessionHolder, CHIP_ERROR_MISSING_SECURE_SESSION); + + mpExchangeCtx = mpExchangeMgr->NewContext(aReadPrepareParams.mSessionHolder.Get().Value(), this); VerifyOrReturnError(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY); mpExchangeCtx->SetResponseTimeout(kImMessageTimeout); diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 0b33746e68fa41..c02d9d222f6e1a 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -221,7 +221,7 @@ CHIP_ERROR ReadHandler::SendStatusReport(Protocols::InteractionModel::Status aSt { VerifyOrReturnLogError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnLogError(mSessionHandle, CHIP_ERROR_INCORRECT_STATE); - mpExchangeCtx = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get(), this); + mpExchangeCtx = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); } VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -240,7 +240,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b { VerifyOrReturnLogError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnLogError(mSessionHandle, CHIP_ERROR_INCORRECT_STATE); - mpExchangeCtx = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get(), this); + mpExchangeCtx = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); } VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE); diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index dd67a126962f25..12c78e36e23e4a 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -266,7 +266,7 @@ CHIP_ERROR SendCommandRequest(std::unique_ptr && comma err = commandSender->FinishCommand(); SuccessOrExit(err); - err = commandSender->SendCommandRequest(gSession.Get(), chip::MakeOptional(gMessageTimeout)); + err = commandSender->SendCommandRequest(gSession.Get().Value(), chip::MakeOptional(gMessageTimeout)); SuccessOrExit(err); gCommandCount++; @@ -302,7 +302,7 @@ CHIP_ERROR SendBadCommandRequest(std::unique_ptr && co err = commandSender->FinishCommand(); SuccessOrExit(err); - err = commandSender->SendCommandRequest(gSession.Get(), chip::MakeOptional(gMessageTimeout)); + err = commandSender->SendCommandRequest(gSession.Get().Value(), chip::MakeOptional(gMessageTimeout)); SuccessOrExit(err); gCommandCount++; commandSender.release(); @@ -330,7 +330,7 @@ CHIP_ERROR SendReadRequest() printf("\nSend read request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); - chip::app::ReadPrepareParams readPrepareParams(gSession.Get()); + chip::app::ReadPrepareParams readPrepareParams(gSession.Get().Value()); readPrepareParams.mTimeout = gMessageTimeout; readPrepareParams.mpAttributePathParamsList = &attributePathParams; readPrepareParams.mAttributePathParamsListSize = 1; @@ -367,7 +367,7 @@ CHIP_ERROR SendWriteRequest(chip::app::WriteClient & apWriteClient) SuccessOrExit(err = apWriteClient.EncodeAttribute( chip::app::AttributePathParams(2 /* endpoint */, 3 /* cluster */, 4 /* attribute */), true)); - SuccessOrExit(err = apWriteClient.SendWriteRequest(gSession.Get(), gMessageTimeout)); + SuccessOrExit(err = apWriteClient.SendWriteRequest(gSession.Get().Value(), gMessageTimeout)); gWriteCount++; @@ -384,7 +384,7 @@ CHIP_ERROR SendSubscribeRequest() CHIP_ERROR err = CHIP_NO_ERROR; gLastMessageTime = chip::System::SystemClock().GetMonotonicTimestamp(); - chip::app::ReadPrepareParams readPrepareParams(gSession.Get()); + chip::app::ReadPrepareParams readPrepareParams(gSession.Get().Value()); chip::app::EventPathParams * eventPathParams = new chip::app::EventPathParams[2]; chip::app::AttributePathParams * attributePathParams = new chip::app::AttributePathParams[1]; readPrepareParams.mpEventPathParamsList = eventPathParams; diff --git a/src/controller/CommissioneeDeviceProxy.cpp b/src/controller/CommissioneeDeviceProxy.cpp index 320e88eabe1bb2..90c6ab0a8379b0 100644 --- a/src/controller/CommissioneeDeviceProxy.cpp +++ b/src/controller/CommissioneeDeviceProxy.cpp @@ -47,7 +47,8 @@ CHIP_ERROR CommissioneeDeviceProxy::SendCommands(app::CommandSender * commandObj { VerifyOrReturnError(mSecureSession, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(commandObj != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - return commandObj->SendCommandRequest(mSecureSession.Get(), timeout); + VerifyOrReturnError(mSecureSession, CHIP_ERROR_MISSING_SECURE_SESSION); + return commandObj->SendCommandRequest(mSecureSession.Get().Value(), timeout); } void CommissioneeDeviceProxy::OnSessionReleased() @@ -60,7 +61,7 @@ CHIP_ERROR CommissioneeDeviceProxy::CloseSession() ReturnErrorCodeIf(mState != ConnectionState::SecureConnected, CHIP_ERROR_INCORRECT_STATE); if (mSecureSession) { - mSessionManager->ExpirePairing(mSecureSession.Get()); + mSessionManager->ExpirePairing(mSecureSession.Get().Value()); } mState = ConnectionState::NotConnected; mPairing.Clear(); @@ -87,7 +88,7 @@ CHIP_ERROR CommissioneeDeviceProxy::UpdateDeviceData(const Transport::PeerAddres return CHIP_NO_ERROR; } - Transport::SecureSession * secureSession = mSecureSession.Get()->AsSecureSession(); + Transport::SecureSession * secureSession = mSecureSession.Get().Value()->AsSecureSession(); secureSession->SetPeerAddress(addr); return CHIP_NO_ERROR; diff --git a/src/controller/CommissioneeDeviceProxy.h b/src/controller/CommissioneeDeviceProxy.h index 34cbfe7aeeb6f3..972497a060e3f2 100644 --- a/src/controller/CommissioneeDeviceProxy.h +++ b/src/controller/CommissioneeDeviceProxy.h @@ -137,7 +137,7 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionDelegate CHIP_ERROR SetPeerId(ByteSpan rcac, ByteSpan noc) override; const Transport::PeerAddress & GetPeerAddress() const { return mDeviceAddress; } - chip::Optional GetSecureSession() const override { return mSecureSession.ToOptional(); } + chip::Optional GetSecureSession() const override { return mSecureSession.Get(); } Messaging::ExchangeManager * GetExchangeManager() const override { return mExchangeMgr; } diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp index c260cb94ce4cc5..16cee29f58740d 100644 --- a/src/controller/python/chip/clusters/attribute.cpp +++ b/src/controller/python/chip/clusters/attribute.cpp @@ -85,7 +85,7 @@ OnReportBeginCallback gOnReportEndCallback = nullptr; void PythonResubscribePolicy(uint32_t aNumCumulativeRetries, uint32_t & aNextSubscriptionIntervalMsec, bool & aShouldResubscribe) { - aShouldResubscribe = false; + aShouldResubscribe = true; } class ReadClientCallback : public ReadClient::Callback diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index 785ee0b7af07e9..8b7fb3ec87b40a 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -206,6 +206,9 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_TLV_TAG_NOT_FOUND.AsInteger(): desc = "TLV tag not found"; break; + case CHIP_ERROR_MISSING_SECURE_SESSION.AsInteger(): + desc = "Missing secure session"; + break; case CHIP_ERROR_INVALID_PATH_LIST.AsInteger(): desc = "Invalid TLV path list"; break; diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index 732d1f60d4241d..1f87ab631f1526 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -1500,7 +1500,14 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_TLV_TAG_NOT_FOUND CHIP_CORE_ERROR(0x76) -// unused CHIP_CORE_ERROR(0x77) +/** + * @def CHIP_ERROR_MISSING_SECURE_SESSION + * + * @brief + * + * A secure session is needed to do work, but is missing/is not present. + */ +#define CHIP_ERROR_MISSING_SECURE_SESSION CHIP_CORE_ERROR(0x77) // unused CHIP_CORE_ERROR(0x78) @@ -2388,10 +2395,6 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_IM_MALFORMED_STATUS_RESPONSE_MESSAGE CHIP_CORE_ERROR(0xe1) -/** - * @} - */ - // clang-format on // !!!!! IMPORTANT !!!!! If you add new CHIP errors, please update the translation diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 28592c19457d06..507f2711b768fd 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -183,10 +183,24 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp return CHIP_ERROR_INTERNAL; } + // + // It is possible that we might have evicted a session as a side-effect of processing an inbound message on this exchange. + // We cannot proceed any further sending a message since we don't have an attached session, so let's error out. + // + // This should not happen to well-behaved logic attempting to sending messages on exchanges, so let's print out a warning + // to ensure it alerts someone to fixing their logic... + // + if (!mSession) + { + ChipLogError(ExchangeManager, + "WARNING: We shouldn't be sending a message on an exchange that has no attached session..."); + return CHIP_ERROR_MISSING_SECURE_SESSION; + } + // Create a new scope for `err`, to avoid shadowing warning previous `err`. - CHIP_ERROR err = mDispatch.SendMessage(GetExchangeMgr()->GetSessionManager(), mSession.Get(), mExchangeId, IsInitiator(), - GetReliableMessageContext(), reliableTransmissionRequested, protocolId, msgType, - std::move(msgBuf)); + CHIP_ERROR err = mDispatch.SendMessage(GetExchangeMgr()->GetSessionManager(), mSession.Get().Value(), mExchangeId, + IsInitiator(), GetReliableMessageContext(), reliableTransmissionRequested, + protocolId, msgType, std::move(msgBuf)); if (err != CHIP_NO_ERROR && IsResponseExpected()) { CancelResponseTimer(); diff --git a/src/messaging/ExchangeContext.h b/src/messaging/ExchangeContext.h index c0211c857384e4..bd45b65df86d3b 100644 --- a/src/messaging/ExchangeContext.h +++ b/src/messaging/ExchangeContext.h @@ -156,7 +156,13 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, ExchangeMessageDispatch & GetMessageDispatch() { return mDispatch; } - SessionHandle GetSessionHandle() const { return mSession.Get(); } + SessionHandle GetSessionHandle() const + { + VerifyOrDie(mSession); + auto sessionHandle = mSession.Get(); + return std::move(sessionHandle.Value()); + } + bool HasSessionHandle() const { return mSession; } uint16_t GetExchangeId() const { return mExchangeId; } diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp index b8c22b1c891d0c..40b7f04a4b78dc 100644 --- a/src/messaging/tests/MessagingContext.cpp +++ b/src/messaging/tests/MessagingContext.cpp @@ -107,12 +107,14 @@ CHIP_ERROR MessagingContext::CreateSessionBobToFriends() SessionHandle MessagingContext::GetSessionBobToAlice() { - return mSessionBobToAlice.Get(); + auto sessionHandle = mSessionBobToAlice.Get(); + return std::move(sessionHandle.Value()); } SessionHandle MessagingContext::GetSessionAliceToBob() { - return mSessionAliceToBob.Get(); + auto sessionHandle = mSessionAliceToBob.Get(); + return std::move(sessionHandle.Value()); } SessionHandle MessagingContext::GetSessionBobToFriends() @@ -122,12 +124,18 @@ SessionHandle MessagingContext::GetSessionBobToFriends() void MessagingContext::ExpireSessionBobToAlice() { - mSessionManager.ExpirePairing(mSessionBobToAlice.Get()); + if (mSessionBobToAlice) + { + mSessionManager.ExpirePairing(mSessionBobToAlice.Get().Value()); + } } void MessagingContext::ExpireSessionAliceToBob() { - mSessionManager.ExpirePairing(mSessionAliceToBob.Get()); + if (mSessionAliceToBob) + { + mSessionManager.ExpirePairing(mSessionAliceToBob.Get().Value()); + } } void MessagingContext::ExpireSessionBobToFriends() diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp index ac9db8eeb4f7ca..4ac8b59994fece 100644 --- a/src/messaging/tests/echo/echo_requester.cpp +++ b/src/messaging/tests/echo/echo_requester.cpp @@ -255,7 +255,7 @@ int main(int argc, char * argv[]) err = EstablishSecureSession(); SuccessOrExit(err); - err = gEchoClient.Init(&gExchangeManager, gSession.Get()); + err = gEchoClient.Init(&gExchangeManager, gSession.Get().Value()); SuccessOrExit(err); // Arrange to get a callback whenever an Echo Response is received. diff --git a/src/protocols/echo/EchoClient.cpp b/src/protocols/echo/EchoClient.cpp index 6805dabb67a995..ee546d4db449d5 100644 --- a/src/protocols/echo/EchoClient.cpp +++ b/src/protocols/echo/EchoClient.cpp @@ -70,8 +70,10 @@ CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload, Me mExchangeCtx = nullptr; } + VerifyOrReturnError(mSecureSession, CHIP_ERROR_INVALID_MESSAGE_TYPE); + // Create a new exchange context. - mExchangeCtx = mExchangeMgr->NewContext(mSecureSession.Get(), this); + mExchangeCtx = mExchangeMgr->NewContext(mSecureSession.Get().Value(), this); if (mExchangeCtx == nullptr) { return CHIP_ERROR_NO_MEMORY; diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index 01c428020464b3..0ab53dc06e6a07 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -67,7 +67,8 @@ void PairingSession::Finish() CHIP_ERROR err = ActivateSecureSession(address); if (err == CHIP_NO_ERROR) { - mDelegate->OnSessionEstablished(mSecureSessionHolder.Get()); + VerifyOrDie(mSecureSessionHolder); + mDelegate->OnSessionEstablished(mSecureSessionHolder.Get().Value()); } else { @@ -155,14 +156,14 @@ void PairingSession::Clear() if (mSecureSessionHolder) { - SessionHandle session = mSecureSessionHolder.Get(); + auto session = mSecureSessionHolder.Get(); // Call Release before ExpirePairing because we don't want to receive OnSessionReleased() event here mSecureSessionHolder.Release(); - if (!session->AsSecureSession()->IsActiveSession() && mSessionManager != nullptr) + if (!session.Value()->AsSecureSession()->IsActiveSession() && mSessionManager != nullptr) { // Make sure to clean up our pending session, since we're the only // ones who have access to it do do so. - mSessionManager->ExpirePairing(session); + mSessionManager->ExpirePairing(session.Value()); } } diff --git a/src/transport/SessionHolder.h b/src/transport/SessionHolder.h index 28321d9e71c2e9..2a10a4ca4aa291 100644 --- a/src/transport/SessionHolder.h +++ b/src/transport/SessionHolder.h @@ -51,10 +51,16 @@ class SessionHolder : public SessionDelegate, public IntrusiveListNodeBase void Release(); operator bool() const { return mSession.HasValue(); } - SessionHandle Get() const { return SessionHandle{ mSession.Value().Get() }; } - Optional ToOptional() const + Optional Get() const { - return mSession.HasValue() ? chip::MakeOptional(Get()) : chip::Optional::Missing(); + // + // We cannot return mSession directly even if Optional is internally composed of the same bits, + // since they are not actually equivalent type-wise, and SessionHandle does not permit copy-construction. + // + // So, construct a new Optional from the underlying Transport::Session reference. + // + return mSession.HasValue() ? chip::MakeOptional(mSession.Value().Get()) + : chip::Optional::Missing(); } Transport::Session * operator->() const { return &mSession.Value().Get(); } diff --git a/src/transport/tests/TestSessionManager.cpp b/src/transport/tests/TestSessionManager.cpp index 13170c707187b1..fbfe727f2d2e2b 100644 --- a/src/transport/tests/TestSessionManager.cpp +++ b/src/transport/tests/TestSessionManager.cpp @@ -177,10 +177,10 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext) payloadHeader.SetMessageType(chip::Protocols::Echo::MsgType::EchoRequest); EncryptedPacketBufferHandle preparedMessage; - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -192,10 +192,10 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext) callback.LargeMessageSent = true; - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(large_buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(large_buffer), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -209,7 +209,8 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext) callback.LargeMessageSent = true; - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(extra_large_buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(extra_large_buffer), + preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_MESSAGE_TOO_LONG); sessionManager.Shutdown(); @@ -286,20 +287,20 @@ void SendEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) payloadHeader.SetInitiator(true); - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); NL_TEST_ASSERT(inSuite, callback.ReceiveHandlerCallCount == 1); // Reset receive side message counter, or duplicated message will be denied. - Transport::SecureSession * session = bobToAliceSession.Get()->AsSecureSession(); + Transport::SecureSession * session = bobToAliceSession.Get().Value()->AsSecureSession(); session->GetSessionMessageCounter().GetPeerMessageCounter().SetCounter(1); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -379,10 +380,10 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) payloadHeader.SetInitiator(true); - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -390,7 +391,7 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) /* -------------------------------------------------------------------------------------------*/ // Reset receive side message counter, or duplicated message will be denied. - Transport::SecureSession * session = bobToAliceSession.Get()->AsSecureSession(); + Transport::SecureSession * session = bobToAliceSession.Get().Value()->AsSecureSession(); session->GetSessionMessageCounter().GetPeerMessageCounter().SetCounter(1); PacketHeader packetHeader; @@ -403,7 +404,7 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) packetHeader.SetMessageCounter(messageCounter + 1); NL_TEST_ASSERT(inSuite, badMessageCounterMsg.InsertPacketHeader(packetHeader) == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), badMessageCounterMsg); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), badMessageCounterMsg); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -420,7 +421,7 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) packetHeader.SetSessionId(3); NL_TEST_ASSERT(inSuite, badKeyIdMsg.InsertPacketHeader(packetHeader) == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), badKeyIdMsg); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), badKeyIdMsg); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -430,7 +431,7 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) session->GetSessionMessageCounter().GetPeerMessageCounter().SetCounter(1); // Send the correct encrypted msg - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -509,10 +510,10 @@ void SendPacketWithOldCounterTest(nlTestSuite * inSuite, void * inContext) payloadHeader.SetInitiator(true); - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -525,11 +526,11 @@ void SendPacketWithOldCounterTest(nlTestSuite * inSuite, void * inContext) buffer = chip::MessagePacketBuffer::NewWithData(PAYLOAD, payload_len); NL_TEST_ASSERT(inSuite, !buffer.IsNull()); - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), newMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), newMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), newMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), newMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -537,7 +538,7 @@ void SendPacketWithOldCounterTest(nlTestSuite * inSuite, void * inContext) // Now resend our original message. It should be rejected as a duplicate. - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -616,10 +617,10 @@ void SendPacketWithTooOldCounterTest(nlTestSuite * inSuite, void * inContext) payloadHeader.SetInitiator(true); - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), preparedMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -634,11 +635,11 @@ void SendPacketWithTooOldCounterTest(nlTestSuite * inSuite, void * inContext) buffer = chip::MessagePacketBuffer::NewWithData(PAYLOAD, payload_len); NL_TEST_ASSERT(inSuite, !buffer.IsNull()); - err = sessionManager.PrepareMessage(aliceToBobSession.Get(), payloadHeader, std::move(buffer), newMessage); + err = sessionManager.PrepareMessage(aliceToBobSession.Get().Value(), payloadHeader, std::move(buffer), newMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), newMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), newMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -646,7 +647,7 @@ void SendPacketWithTooOldCounterTest(nlTestSuite * inSuite, void * inContext) // Now resend our original message. It should be rejected as a duplicate. - err = sessionManager.SendPreparedMessage(aliceToBobSession.Get(), preparedMessage); + err = sessionManager.SendPreparedMessage(aliceToBobSession.Get().Value(), preparedMessage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO();