Skip to content

Commit

Permalink
Rename SecureChannelMgr to MessageCounterSyncMgr
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Feb 12, 2021
1 parent 38aa301 commit 11dc138
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/messaging/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
5 changes: 1 addition & 4 deletions src/messaging/ExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/messaging/ExchangeMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <array>

#include <messaging/ExchangeContext.h>
#include <messaging/MessageCounterSync.h>
#include <messaging/ReliableMessageMgr.h>
#include <messaging/SecureChannelMgr.h>
#include <support/DLLUtil.h>
#include <transport/SecureSessionMgr.h>

Expand Down Expand Up @@ -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; }

Expand All @@ -200,7 +200,7 @@ class DLL_EXPORT ExchangeManager : public SecureSessionMgrDelegate
State mState;
SecureSessionMgr * mSessionMgr;
ReliableMessageMgr mReliableMessageMgr;
Protocols::SecureChannel::SecureChannelMgr mSecureChannelMgr;
MessageCounterSyncMgr mSecureChannelMgr;

std::array<ExchangeContext, CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS> mContextPool;
size_t mContextsInUse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
#include <messaging/ExchangeContext.h>
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <messaging/SecureChannelMgr.h>
#include <messaging/MessageCounterSync.h>
#include <protocols/Protocols.h>
#include <support/BufferWriter.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>

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;

Expand All @@ -53,7 +52,7 @@ CHIP_ERROR SecureChannelMgr::Init(Messaging::ExchangeManager * exchangeMgr)
return err;
}

void SecureChannelMgr::Shutdown()
void MessageCounterSyncMgr::Shutdown()
{
if (mExchangeMgr != nullptr)
{
Expand All @@ -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))
{
Expand All @@ -75,15 +74,16 @@ 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)
exchangeContext->Close();
}

// 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;

Expand All @@ -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;
Expand All @@ -111,7 +111,7 @@ CHIP_ERROR SecureChannelMgr::SendMsgCounterSyncReq(SecureSessionHandle session)
SuccessOrExit(err);

// Allocate a buffer for the null message.
msgBuf = System::PacketBufferHandle::New(kMsgCounterChallengeSize);
msgBuf = MessagePacketBuffer::New(kMsgCounterChallengeSize);
VerifyOrExit(!msgBuf.IsNull(), err = CHIP_ERROR_NO_MEMORY);

// Generate a 64-bit random number to uniquely identify the request.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -263,6 +263,5 @@ void SecureChannelMgr::HandleMsgCounterSyncResp(Messaging::ExchangeContext * exc
return;
}

} // namespace SecureChannel
} // namespace Protocols
} // namespace Messaging
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@

#pragma once

#include <system/SystemPacketBuffer.h>

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
// to a message counter synchronization request.

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();
Expand Down Expand Up @@ -75,6 +72,5 @@ class SecureChannelMgr : public Messaging::ExchangeDelegate
void OnResponseTimeout(Messaging::ExchangeContext * exchangeContext) override;
};

} // namespace SecureChannel
} // namespace Protocols
} // namespace Messaging
} // namespace chip
1 change: 0 additions & 1 deletion src/messaging/ReliableMessageMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <messaging/ReliableMessageMgr.h>

#include <core/CHIPKeyIds.h>
#include <messaging/ErrorCategory.h>
#include <messaging/Flags.h>
#include <messaging/ReliableMessageContext.h>
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ chip_test_suite("tests") {
"MessagingContext.cpp",
"MessagingContext.h",
"TestExchangeMgr.cpp",
"TestMessageCounterSyncMgr.cpp",
"TestMessagingLayer.h",
"TestReliableMessageProtocol.cpp",
"TestSecureChannelMgr.cpp",
]

cflags = [ "-Wconversion" ]
Expand All @@ -47,7 +47,7 @@ chip_test_suite("tests") {

tests = [
"TestExchangeMgr",
"TestSecureChannelMgr",
"TestMessageCounterSyncMgr",
"TestReliableMessageProtocol",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<Transport::PeerAddress> peer(Transport::PeerAddress::UDP(addr, CHIP_PORT));
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -229,7 +229,7 @@ int Finalize(void * aContext);
// clang-format off
nlTestSuite sSuite =
{
"Test-SecureChannelMgr",
"Test-MessageCounterSyncMgr",
&sTests[0],
Initialize,
Finalize
Expand Down Expand Up @@ -263,7 +263,7 @@ int Finalize(void * aContext)
/**
* Main
*/
int TestSecureChannelMgr()
int TestMessageCounterSyncMgr()
{
// Run test suit against one context
nlTestRunner(&sSuite, &sContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ int main()
// Generate machine-readable, comma-separated value (CSV) output.
nlTestSetOutputStyle(OUTPUT_CSV);

return (TestSecureChannelMgr());
return (TestMessageCounterSyncMgr());
}
2 changes: 1 addition & 1 deletion src/messaging/tests/TestMessagingLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
#endif

int TestExchangeMgr(void);
int TestSecureChannelMgr(void);
int TestMessageCounterSyncMgr(void);
int TestReliableMessageProtocol(void);

#ifdef __cplusplus
Expand Down

0 comments on commit 11dc138

Please sign in to comment.