From 1d4d7d5c07443fccfd4283b588ce9fc4b79f2739 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 11 Feb 2021 11:25:26 -0800 Subject: [PATCH] Rename SecureChannelMgr to MessageCounterSyncMgr --- src/messaging/BUILD.gn | 4 +-- src/messaging/ExchangeMgr.cpp | 5 +-- src/messaging/ExchangeMgr.h | 6 ++-- ...eChannelMgr.cpp => MessageCounterSync.cpp} | 33 +++++++++---------- ...ecureChannelMgr.h => MessageCounterSync.h} | 10 +++--- src/messaging/tests/BUILD.gn | 4 +-- ...lMgr.cpp => TestMessageCounterSyncMgr.cpp} | 12 +++---- ...pp => TestMessageCounterSyncMgrDriver.cpp} | 0 8 files changed, 34 insertions(+), 40 deletions(-) rename src/messaging/{SecureChannelMgr.cpp => MessageCounterSync.cpp} (86%) rename src/messaging/{SecureChannelMgr.h => MessageCounterSync.h} (93%) rename src/messaging/tests/{TestSecureChannelMgr.cpp => TestMessageCounterSyncMgr.cpp} (94%) rename src/messaging/tests/{TestSecureChannelMgrDriver.cpp => TestMessageCounterSyncMgrDriver.cpp} (100%) diff --git a/src/messaging/BUILD.gn b/src/messaging/BUILD.gn index b3c126a962abd4..b16c92d2bbc633 100644 --- a/src/messaging/BUILD.gn +++ b/src/messaging/BUILD.gn @@ -26,13 +26,13 @@ static_library("messaging") { "ExchangeMgr.cpp", "ExchangeMgr.h", "Flags.h", + "MessageCounterSync.cpp", + "MessageCounterSync.h", "ReliableMessageContext.cpp", "ReliableMessageContext.h", "ReliableMessageMgr.cpp", "ReliableMessageMgr.h", "ReliableMessageProtocolConfig.h", - "SecureChannelMgr.cpp", - "SecureChannelMgr.h", ] cflags = [ "-Wconversion" ] diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index 199ffe769589e5..d421287e6190e1 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -94,11 +94,8 @@ CHIP_ERROR ExchangeManager::Init(SecureSessionMgr * sessionMgr) CHIP_ERROR ExchangeManager::Shutdown() { -<<<<<<< HEAD - mReliableMessageMgr.Shutdown(); -======= mSecureChannelMgr.Shutdown(); ->>>>>>> Implement Message Counter Synchronization Protocol (MCSP) part + mReliableMessageMgr.Shutdown(); if (mSessionMgr != nullptr) { diff --git a/src/messaging/ExchangeMgr.h b/src/messaging/ExchangeMgr.h index b62427e2f4537c..37dea4f74446a6 100644 --- a/src/messaging/ExchangeMgr.h +++ b/src/messaging/ExchangeMgr.h @@ -27,8 +27,8 @@ #include #include +#include #include -#include #include #include @@ -178,7 +178,7 @@ class DLL_EXPORT ExchangeManager : public SecureSessionMgrDelegate ReliableMessageMgr * GetReliableMessageMgr() { return &mReliableMessageMgr; }; - Protocols::SecureChannel::SecureChannelMgr * GetSecureChannelMgr() { return &mSecureChannelMgr; }; + MessageCounterSyncMgr * GetSecureChannelMgr() { return &mSecureChannelMgr; }; size_t GetContextsInUse() const { return mContextsInUse; } @@ -200,7 +200,7 @@ class DLL_EXPORT ExchangeManager : public SecureSessionMgrDelegate State mState; SecureSessionMgr * mSessionMgr; ReliableMessageMgr mReliableMessageMgr; - Protocols::SecureChannel::SecureChannelMgr mSecureChannelMgr; + MessageCounterSyncMgr mSecureChannelMgr; std::array mContextPool; size_t mContextsInUse; diff --git a/src/messaging/SecureChannelMgr.cpp b/src/messaging/MessageCounterSync.cpp similarity index 86% rename from src/messaging/SecureChannelMgr.cpp rename to src/messaging/MessageCounterSync.cpp index e2be22ae970657..e1d2097d174bbf 100644 --- a/src/messaging/SecureChannelMgr.cpp +++ b/src/messaging/MessageCounterSync.cpp @@ -27,17 +27,16 @@ #include #include #include -#include +#include #include #include #include #include namespace chip { -namespace Protocols { -namespace SecureChannel { +namespace Messaging { -CHIP_ERROR SecureChannelMgr::Init(Messaging::ExchangeManager * exchangeMgr) +CHIP_ERROR MessageCounterSyncMgr::Init(Messaging::ExchangeManager * exchangeMgr) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -53,7 +52,7 @@ CHIP_ERROR SecureChannelMgr::Init(Messaging::ExchangeManager * exchangeMgr) return err; } -void SecureChannelMgr::Shutdown() +void MessageCounterSyncMgr::Shutdown() { if (mExchangeMgr != nullptr) { @@ -62,8 +61,8 @@ void SecureChannelMgr::Shutdown() } } -void SecureChannelMgr::OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - const PayloadHeader & payloadHeader, System::PacketBufferHandle msgBuf) +void MessageCounterSyncMgr::OnMessageReceived(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + const PayloadHeader & payloadHeader, System::PacketBufferHandle msgBuf) { if (payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::MsgCounterSyncReq)) { @@ -75,7 +74,7 @@ void SecureChannelMgr::OnMessageReceived(Messaging::ExchangeContext * exchangeCo } } -void SecureChannelMgr::OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) +void MessageCounterSyncMgr::OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) { // Close the exchange if MsgCounterSyncRsp is not received before kMsgCounterSyncTimeout. if (exchangeContext != nullptr) @@ -83,7 +82,8 @@ void SecureChannelMgr::OnResponseTimeout(Messaging::ExchangeContext * exchangeCo } // Create and initialize new exchange for the message counter synchronization request/response messages. -CHIP_ERROR SecureChannelMgr::NewMsgCounterSyncExchange(SecureSessionHandle session, Messaging::ExchangeContext *& exchangeContext) +CHIP_ERROR MessageCounterSyncMgr::NewMsgCounterSyncExchange(SecureSessionHandle session, + Messaging::ExchangeContext *& exchangeContext) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -98,7 +98,7 @@ CHIP_ERROR SecureChannelMgr::NewMsgCounterSyncExchange(SecureSessionHandle sessi return err; } -CHIP_ERROR SecureChannelMgr::SendMsgCounterSyncReq(SecureSessionHandle session) +CHIP_ERROR MessageCounterSyncMgr::SendMsgCounterSyncReq(SecureSessionHandle session) { CHIP_ERROR err = CHIP_NO_ERROR; Messaging::ExchangeContext * exchangeContext = nullptr; @@ -143,7 +143,7 @@ CHIP_ERROR SecureChannelMgr::SendMsgCounterSyncReq(SecureSessionHandle session) return err; } -CHIP_ERROR SecureChannelMgr::SendMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, SecureSessionHandle session) +CHIP_ERROR MessageCounterSyncMgr::SendMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, SecureSessionHandle session) { CHIP_ERROR err = CHIP_NO_ERROR; Transport::PeerConnectionState * state = nullptr; @@ -188,8 +188,8 @@ CHIP_ERROR SecureChannelMgr::SendMsgCounterSyncResp(Messaging::ExchangeContext * return err; } -void SecureChannelMgr::HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - System::PacketBufferHandle msgBuf) +void MessageCounterSyncMgr::HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, + System::PacketBufferHandle msgBuf) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -221,8 +221,8 @@ void SecureChannelMgr::HandleMsgCounterSyncReq(Messaging::ExchangeContext * exch return; } -void SecureChannelMgr::HandleMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, const PacketHeader & packetHeader, - System::PacketBufferHandle msgBuf) +void MessageCounterSyncMgr::HandleMsgCounterSyncResp(Messaging::ExchangeContext * exchangeContext, + const PacketHeader & packetHeader, System::PacketBufferHandle msgBuf) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -263,6 +263,5 @@ void SecureChannelMgr::HandleMsgCounterSyncResp(Messaging::ExchangeContext * exc return; } -} // namespace SecureChannel -} // namespace Protocols +} // namespace Messaging } // namespace chip diff --git a/src/messaging/SecureChannelMgr.h b/src/messaging/MessageCounterSync.h similarity index 93% rename from src/messaging/SecureChannelMgr.h rename to src/messaging/MessageCounterSync.h index 194c332ae7b7af..edb1f8c5627e03 100644 --- a/src/messaging/SecureChannelMgr.h +++ b/src/messaging/MessageCounterSync.h @@ -25,8 +25,7 @@ #include namespace chip { -namespace Protocols { -namespace SecureChannel { +namespace Messaging { constexpr uint16_t kMsgCounterSyncRespMsgSize = 12; // The size of the message counter synchronization response message. constexpr uint32_t kMsgCounterSyncTimeout = 500; // The amount of time(in milliseconds) which a peer is given to respond @@ -34,10 +33,10 @@ constexpr uint32_t kMsgCounterSyncTimeout = 500; // The amount of time(in mi class ExchangeManager; -class SecureChannelMgr : public Messaging::ExchangeDelegate +class MessageCounterSyncMgr : public Messaging::ExchangeDelegate { public: - SecureChannelMgr() : mExchangeMgr(nullptr) {} + MessageCounterSyncMgr() : mExchangeMgr(nullptr) {} CHIP_ERROR Init(Messaging::ExchangeManager * exchangeMgr); void Shutdown(); @@ -75,6 +74,5 @@ class SecureChannelMgr : public Messaging::ExchangeDelegate void OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) override; }; -} // namespace SecureChannel -} // namespace Protocols +} // namespace Messaging } // namespace chip diff --git a/src/messaging/tests/BUILD.gn b/src/messaging/tests/BUILD.gn index bc6d76bc4bb663..b8975653459c95 100644 --- a/src/messaging/tests/BUILD.gn +++ b/src/messaging/tests/BUILD.gn @@ -26,9 +26,9 @@ chip_test_suite("tests") { "MessagingContext.cpp", "MessagingContext.h", "TestExchangeMgr.cpp", + "TestMessageCounterSyncMgr.cpp", "TestMessagingLayer.h", "TestReliableMessageProtocol.cpp", - "TestSecureChannelMgr.cpp", ] cflags = [ "-Wconversion" ] @@ -47,7 +47,7 @@ chip_test_suite("tests") { tests = [ "TestExchangeMgr", - "TestSecureChannelMgr", + "TestMessageCounterSyncMgr", "TestReliableMessageProtocol", ] } diff --git a/src/messaging/tests/TestSecureChannelMgr.cpp b/src/messaging/tests/TestMessageCounterSyncMgr.cpp similarity index 94% rename from src/messaging/tests/TestSecureChannelMgr.cpp rename to src/messaging/tests/TestMessageCounterSyncMgr.cpp index ce9f237e98bff7..55158e99a7c6b2 100644 --- a/src/messaging/tests/TestSecureChannelMgr.cpp +++ b/src/messaging/tests/TestMessageCounterSyncMgr.cpp @@ -18,7 +18,7 @@ /** * @file - * This file implements unit tests for the SecureChannelMgr implementation. + * This file implements unit tests for the MessageCounterSyncMgr implementation. */ #include "TestMessagingLayer.h" @@ -139,7 +139,7 @@ void CheckSendMsgCounterSyncReq(nlTestSuite * inSuite, void * inContext) testExchangeMgr.mSuite = inSuite; ctx.GetSecureSessionManager().SetDelegate(&testExchangeMgr); - chip::Protocols::SecureChannel::SecureChannelMgr * sm = ctx.GetExchangeManager().GetSecureChannelMgr(); + MessageCounterSyncMgr * sm = ctx.GetExchangeManager().GetSecureChannelMgr(); NL_TEST_ASSERT(inSuite, sm != nullptr); Optional peer(Transport::PeerAddress::UDP(addr, CHIP_PORT)); @@ -180,7 +180,7 @@ void CheckReceiveMsgCounterSyncReq(nlTestSuite * inSuite, void * inContext) mockAppDelegate.mSuite = inSuite; - chip::Protocols::SecureChannel::SecureChannelMgr * sm = ctx.GetExchangeManager().GetSecureChannelMgr(); + MessageCounterSyncMgr * sm = ctx.GetExchangeManager().GetSecureChannelMgr(); NL_TEST_ASSERT(inSuite, sm != nullptr); // Register to receive unsolicited Secure Channel Request messages from the exchange manager. @@ -217,8 +217,8 @@ void CheckReceiveMsgCounterSyncReq(nlTestSuite * inSuite, void * inContext) // clang-format off const nlTest sTests[] = { - NL_TEST_DEF("Test SecureChannelMgr::ReceiveMsgCounterSyncReq", CheckReceiveMsgCounterSyncReq), - NL_TEST_DEF("Test SecureChannelMgr::SendMsgCounterSyncReq", CheckSendMsgCounterSyncReq), + NL_TEST_DEF("Test MessageCounterSyncMgr::ReceiveMsgCounterSyncReq", CheckReceiveMsgCounterSyncReq), + NL_TEST_DEF("Test MessageCounterSyncMgr::SendMsgCounterSyncReq", CheckSendMsgCounterSyncReq), NL_TEST_SENTINEL() }; // clang-format on @@ -229,7 +229,7 @@ int Finalize(void * aContext); // clang-format off nlTestSuite sSuite = { - "Test-SecureChannelMgr", + "Test-MessageCounterSyncMgr", &sTests[0], Initialize, Finalize diff --git a/src/messaging/tests/TestSecureChannelMgrDriver.cpp b/src/messaging/tests/TestMessageCounterSyncMgrDriver.cpp similarity index 100% rename from src/messaging/tests/TestSecureChannelMgrDriver.cpp rename to src/messaging/tests/TestMessageCounterSyncMgrDriver.cpp