Skip to content

Commit

Permalink
Remove SecureSessionMgr::mLocalNodeId (#8700)
Browse files Browse the repository at this point in the history
Now local node id is in the FabricTable
  • Loading branch information
kghost authored Jul 29, 2021
1 parent 71c9d95 commit 1d420e1
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 54 deletions.
6 changes: 2 additions & 4 deletions examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ void StartPinging(streamer_t * stream, char * destination)
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
if (gPingArguments.IsUsingTCP())
{
err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &gFabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&DeviceLayer::SystemLayer, &gTCPManager, &gFabrics, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand All @@ -321,8 +320,7 @@ void StartPinging(streamer_t * stream, char * destination)
else
#endif
{
err = gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &gFabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&DeviceLayer::SystemLayer, &gUDPManager, &gFabrics, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand Down
6 changes: 2 additions & 4 deletions examples/shell/shell_common/cmd_send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,15 @@ void ProcessCommand(streamer_t * stream, char * destination)
{
peerAddress = Transport::PeerAddress::TCP(gDestAddr, gSendArguments.GetPort());

err =
gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gTCPManager, &fabrics, &gMessageCounterManager);
err = gSessionManager.Init(&DeviceLayer::SystemLayer, &gTCPManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);
}
else
#endif
{
peerAddress = Transport::PeerAddress::UDP(gDestAddr, gSendArguments.GetPort(), INET_NULL_INTERFACEID);

err =
gSessionManager.Init(kTestControllerNodeId, &DeviceLayer::SystemLayer, &gUDPManager, &fabrics, &gMessageCounterManager);
err = gSessionManager.Init(&DeviceLayer::SystemLayer, &gUDPManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ void InitServer(AppDelegate * delegate)

SuccessOrExit(err);

err = gSessions.Init(chip::kTestDeviceNodeId, &DeviceLayer::SystemLayer, &gTransports, &gFabrics, &gMessageCounterManager);
err = gSessions.Init(&DeviceLayer::SystemLayer, &gTransports, &gFabrics, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeMgr.Init(&gSessions);
Expand Down
3 changes: 1 addition & 2 deletions src/app/tests/TestCommandInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ void InitializeChip(nlTestSuite * apSuite)

chip::gSystemLayer.Init();

err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &fabrics,
&chip::gMessageCounterManager);
err = chip::gSessionManager.Init(&chip::gSystemLayer, &chip::gTransportManager, &fabrics, &chip::gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gExchangeManager.Init(&chip::gSessionManager);
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestEventLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void InitializeChip(nlTestSuite * apSuite)

gSystemLayer.Init();

err = gSessionManager.Init(kTestDeviceNodeId1, &gSystemLayer, &gTransportManager, &fabrics, &gMessageCounterManager);
err = gSessionManager.Init(&gSystemLayer, &gTransportManager, &fabrics, &gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = gExchangeManager.Init(&gSessionManager);
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestInteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void InitializeChip(nlTestSuite * apSuite)

gSystemLayer.Init();

err = gSessionManager.Init(chip::kTestDeviceNodeId, &gSystemLayer, &gTransportManager, &fabrics, &gMessageCounterManager);
err = gSessionManager.Init(&gSystemLayer, &gTransportManager, &fabrics, &gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = gExchangeManager.Init(&gSessionManager);
Expand Down
3 changes: 1 addition & 2 deletions src/app/tests/TestReportingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ void InitializeChip(nlTestSuite * apSuite)

chip::gSystemLayer.Init();

err = chip::gSessionManager.Init(chip::kTestDeviceNodeId, &chip::gSystemLayer, &chip::gTransportManager, &fabrics,
&chip::gMessageCounterManager);
err = chip::gSessionManager.Init(&chip::gSystemLayer, &chip::gTransportManager, &fabrics, &chip::gMessageCounterManager);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = chip::gExchangeManager.Init(&chip::gSessionManager);
Expand Down
3 changes: 1 addition & 2 deletions src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ int main(int argc, char * argv[])
.SetListenPort(IM_CLIENT_PORT));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestControllerNodeId, &chip::DeviceLayer::SystemLayer, &gTransportManager, &fabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer, &gTransportManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand Down
3 changes: 1 addition & 2 deletions src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ int main(int argc, char * argv[])
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv4));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestDeviceNodeId, &chip::DeviceLayer::SystemLayer, &gTransportManager, &fabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer, &gTransportManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ CHIP_ERROR DeviceController::Init(NodeId localDeviceId, ControllerInitParams par

ReturnErrorOnFailure(mFabrics.LoadFromStorage(mFabricIndex));

ReturnErrorOnFailure(mSessionMgr->Init(localDeviceId, mSystemLayer, mTransportMgr, &mFabrics, mMessageCounterManager));
ReturnErrorOnFailure(mSessionMgr->Init(mSystemLayer, mTransportMgr, &mFabrics, mMessageCounterManager));

ReturnErrorOnFailure(mExchangeMgr->Init(mSessionMgr));

Expand Down
3 changes: 1 addition & 2 deletions src/messaging/tests/MessagingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ CHIP_ERROR MessagingContext::Init(nlTestSuite * suite, TransportMgrBase * transp
chip::Transport::FabricInfo * destNodeFabric = mFabrics.AssignFabricIndex(mDestFabricIndex, GetDestinationNodeId());
VerifyOrReturnError(destNodeFabric != nullptr, CHIP_ERROR_NO_MEMORY);

ReturnErrorOnFailure(
mSecureSessionMgr.Init(GetSourceNodeId(), &GetSystemLayer(), transport, &mFabrics, &mMessageCounterManager));
ReturnErrorOnFailure(mSecureSessionMgr.Init(&GetSystemLayer(), transport, &mFabrics, &mMessageCounterManager));

ReturnErrorOnFailure(mExchangeManager.Init(&mSecureSessionMgr));
ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager));
Expand Down
6 changes: 2 additions & 4 deletions src/messaging/tests/echo/echo_requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ int main(int argc, char * argv[])
.SetListenPort(ECHO_CLIENT_PORT));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestControllerNodeId, &chip::DeviceLayer::SystemLayer, &gTCPManager, &fabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer, &gTCPManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);
}
else
Expand All @@ -249,8 +248,7 @@ int main(int argc, char * argv[])
.SetListenPort(ECHO_CLIENT_PORT));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestControllerNodeId, &chip::DeviceLayer::SystemLayer, &gUDPManager, &fabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer, &gUDPManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);
}

Expand Down
6 changes: 2 additions & 4 deletions src/messaging/tests/echo/echo_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ int main(int argc, char * argv[])
chip::Transport::TcpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv4));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestDeviceNodeId, &chip::DeviceLayer::SystemLayer, &gTCPManager, &fabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer, &gTCPManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);
}
else
Expand All @@ -103,8 +102,7 @@ int main(int argc, char * argv[])
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer).SetAddressType(chip::Inet::kIPAddressType_IPv4));
SuccessOrExit(err);

err = gSessionManager.Init(chip::kTestDeviceNodeId, &chip::DeviceLayer::SystemLayer, &gUDPManager, &fabrics,
&gMessageCounterManager);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer, &gUDPManager, &fabrics, &gMessageCounterManager);
SuccessOrExit(err);
}

Expand Down
7 changes: 1 addition & 6 deletions src/transport/SecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,20 @@ SecureSessionMgr::~SecureSessionMgr()
CancelExpiryTimer();
}

CHIP_ERROR SecureSessionMgr::Init(NodeId localNodeId, System::Layer * systemLayer, TransportMgrBase * transportMgr,
Transport::FabricTable * fabrics,
CHIP_ERROR SecureSessionMgr::Init(System::Layer * systemLayer, TransportMgrBase * transportMgr, Transport::FabricTable * fabrics,
Transport::MessageCounterManagerInterface * messageCounterManager)
{
VerifyOrReturnError(mState == State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(transportMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

mState = State::kInitialized;
mLocalNodeId = localNodeId;
mSystemLayer = systemLayer;
mTransportMgr = transportMgr;
mFabrics = fabrics;
mMessageCounterManager = messageCounterManager;

mGlobalEncryptedMessageCounter.Init();

ChipLogProgress(Inet, "local node id is 0x" ChipLogFormatX64, ChipLogValueX64(mLocalNodeId));

ScheduleExpiryTimer();

mTransportMgr->SetSecureSessionMgr(this);
Expand All @@ -103,7 +99,6 @@ void SecureSessionMgr::Shutdown()
mMessageCounterManager = nullptr;

mState = State::kNotReady;
mLocalNodeId = kUndefinedNodeId;
mSystemLayer = nullptr;
mTransportMgr = nullptr;
mFabrics = nullptr;
Expand Down
16 changes: 2 additions & 14 deletions src/transport/SecureSessionMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,13 @@ class DLL_EXPORT SecureSessionMgr : public TransportMgrDelegate
* @brief
* Initialize a Secure Session Manager
*
* @param localNodeId Node id for the current node
* @param systemLayer System, layer to use
* @param transportMgr Transport to use
* @param fabrics A table of device administrators
* @param messageCounterManager The message counter manager
*/
CHIP_ERROR Init(NodeId localNodeId, System::Layer * systemLayer, TransportMgrBase * transportMgr,
Transport::FabricTable * fabrics, Transport::MessageCounterManagerInterface * messageCounterManager);
CHIP_ERROR Init(System::Layer * systemLayer, TransportMgrBase * transportMgr, Transport::FabricTable * fabrics,
Transport::MessageCounterManagerInterface * messageCounterManager);

/**
* @brief
Expand All @@ -252,16 +251,6 @@ class DLL_EXPORT SecureSessionMgr : public TransportMgrDelegate
*/
void Shutdown();

/**
* @brief
* Set local node ID
*
* @param nodeId Node id for the current node
*/
void SetLocalNodeId(NodeId nodeId) { mLocalNodeId = nodeId; }

NodeId GetLocalNodeId() { return mLocalNodeId; }

TransportMgrBase * GetTransportManager() const { return mTransportMgr; }

/**
Expand Down Expand Up @@ -290,7 +279,6 @@ class DLL_EXPORT SecureSessionMgr : public TransportMgrDelegate
};

System::Layer * mSystemLayer = nullptr;
NodeId mLocalNodeId; // < Id of the current node
Transport::PeerConnections<CHIP_CONFIG_PEER_CONNECTION_POOL_SIZE> mPeerConnections; // < Active connections to other peers
State mState; // < Initialization state of the object

Expand Down
8 changes: 4 additions & 4 deletions src/transport/tests/TestSecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

Transport::FabricTable fabrics;
err = secureSessionMgr.Init(kSourceNodeId, ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
err = secureSessionMgr.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

Transport::FabricTable fabrics;
err = secureSessionMgr.Init(kSourceNodeId, ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
err = secureSessionMgr.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

callback.mSuite = inSuite;
Expand Down Expand Up @@ -251,7 +251,7 @@ void SendEncryptedPacketTest(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

Transport::FabricTable fabrics;
err = secureSessionMgr.Init(kSourceNodeId, ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
err = secureSessionMgr.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

callback.mSuite = inSuite;
Expand Down Expand Up @@ -333,7 +333,7 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

Transport::FabricTable fabrics;
err = secureSessionMgr.Init(kSourceNodeId, ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
err = secureSessionMgr.Init(ctx.GetInetLayer().SystemLayer(), &transportMgr, &fabrics, &gMessageCounterManager);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

callback.mSuite = inSuite;
Expand Down

0 comments on commit 1d420e1

Please sign in to comment.