Skip to content

Commit

Permalink
Access FabricTable in SessionManager (#15774)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored and pull[bot] committed Feb 3, 2024
1 parent d7a6d3e commit 1051996
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 52 deletions.
7 changes: 5 additions & 2 deletions examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ void StartPinging(streamer_t * stream, char * destination)
ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
}

err = gFabricTable.Init(&gStorage);
SuccessOrExit(err);

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
err = gTCPManager.Init(Transport::TcpListenParameters(DeviceLayer::TCPEndPointManager())
.SetAddressType(gDestAddr.Type())
Expand All @@ -306,7 +309,7 @@ void StartPinging(streamer_t * stream, char * destination)
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
if (gPingArguments.IsUsingTCP())
{
err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage);
err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage, &gFabricTable);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand All @@ -315,7 +318,7 @@ void StartPinging(streamer_t * stream, char * destination)
else
#endif
{
err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager, &gStorage);
err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager, &gStorage, &gFabricTable);
SuccessOrExit(err);

err = gExchangeManager.Init(&gSessionManager);
Expand Down
7 changes: 5 additions & 2 deletions examples/shell/shell_common/cmd_send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ void ProcessCommand(streamer_t * stream, char * destination)
ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
}

err = gFabricTable.Init(&gStorage);
SuccessOrExit(err);

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
err = gTCPManager.Init(Transport::TcpListenParameters(DeviceLayer::TCPEndPointManager())
.SetAddressType(gDestAddr.Type())
Expand All @@ -227,15 +230,15 @@ void ProcessCommand(streamer_t * stream, char * destination)
{
peerAddress = Transport::PeerAddress::TCP(gDestAddr, gSendArguments.GetPort());

err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage);
err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage, &gFabricTable);
SuccessOrExit(err);
}
else
#endif
{
peerAddress = Transport::PeerAddress::UDP(gDestAddr, gSendArguments.GetPort(), chip::Inet::InterfaceId::Null());

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

Expand Down
1 change: 1 addition & 0 deletions examples/shell/shell_common/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <Globals.h>

chip::FabricTable gFabricTable;
chip::secure_channel::MessageCounterManager gMessageCounterManager;
chip::Messaging::ExchangeManager gExchangeManager;
chip::SessionManager gSessionManager;
Expand Down
2 changes: 2 additions & 0 deletions examples/shell/shell_common/include/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <credentials/FabricTable.h>
#include <lib/core/CHIPCore.h>
#include <lib/support/TestPersistentStorageDelegate.h>
#include <messaging/ExchangeMgr.h>
Expand All @@ -32,6 +33,7 @@ constexpr size_t kMaxTcpPendingPackets = 4;
#endif
constexpr chip::System::Clock::Timeout kResponseTimeOut = chip::System::Clock::Seconds16(1);

extern chip::FabricTable gFabricTable;
extern chip::secure_channel::MessageCounterManager gMessageCounterManager;
extern chip::Messaging::ExchangeManager gExchangeManager;
extern chip::SessionManager gSessionManager;
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 @@ -180,7 +180,7 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
#endif
SuccessOrExit(err);

err = mSessions.Init(&DeviceLayer::SystemLayer(), &mTransports, &mMessageCounterManager, &mDeviceStorage);
err = mSessions.Init(&DeviceLayer::SystemLayer(), &mTransports, &mMessageCounterManager, &mDeviceStorage, &GetFabricTable());
SuccessOrExit(err);

err = mExchangeMgr.Init(&mSessions);
Expand Down
6 changes: 5 additions & 1 deletion src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,16 @@ int main(int argc, char * argv[])

InitializeChip();

err = gFabricTable.Init(&gStorage);
SuccessOrExit(err);

err = gTransportManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager())
.SetAddressType(chip::Inet::IPAddressType::kIPv6)
.SetListenPort(IM_CLIENT_PORT));
SuccessOrExit(err);

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

err = gExchangeManager.Init(&gSessionManager);
Expand Down
6 changes: 5 additions & 1 deletion src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ int main(int argc, char * argv[])

InitializeChip();

err = gFabricTable.Init(&gStorage);
SuccessOrExit(err);

err = gTransportManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager())
.SetAddressType(chip::Inet::IPAddressType::kIPv6));
SuccessOrExit(err);

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

err = gExchangeManager.Init(&gSessionManager);
Expand Down
1 change: 1 addition & 0 deletions src/app/tests/integration/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <lib/support/logging/Constants.h>
#include <platform/CHIPDeviceLayer.h>

chip::FabricTable gFabricTable;
chip::Messaging::ExchangeManager gExchangeManager;
chip::SessionManager gSessionManager;
chip::secure_channel::MessageCounterManager gMessageCounterManager;
Expand Down
2 changes: 2 additions & 0 deletions src/app/tests/integration/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <app/util/basic-types.h>
#include <credentials/FabricTable.h>
#include <lib/support/TestPersistentStorageDelegate.h>
#include <messaging/ExchangeMgr.h>
#include <protocols/secure_channel/MessageCounterManager.h>
Expand All @@ -33,6 +34,7 @@
#define MAX_MESSAGE_SOURCE_STR_LENGTH (100)
#define NETWORK_SLEEP_TIME_MSECS (100 * 1000)

extern chip::FabricTable gFabricTable;
extern chip::Messaging::ExchangeManager gExchangeManager;
extern chip::SessionManager gSessionManager;
extern chip::secure_channel::MessageCounterManager gMessageCounterManager;
Expand Down
3 changes: 2 additions & 1 deletion src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
ReturnErrorOnFailure(stateParams.fabricTable->Init(mFabricStorage));

ReturnErrorOnFailure(stateParams.sessionMgr->Init(stateParams.systemLayer, stateParams.transportMgr,
stateParams.messageCounterManager, params.fabricIndependentStorage));
stateParams.messageCounterManager, params.fabricIndependentStorage,
stateParams.fabricTable));
ReturnErrorOnFailure(stateParams.exchangeMgr->Init(stateParams.sessionMgr));
ReturnErrorOnFailure(stateParams.messageCounterManager->Init(stateParams.exchangeMgr));

Expand Down
3 changes: 2 additions & 1 deletion src/messaging/tests/MessagingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ CHIP_ERROR MessagingContext::Init(TransportMgrBase * transport, IOContext * ioCo
mTransport = transport;

ReturnErrorOnFailure(PlatformMemoryUser::Init());
ReturnErrorOnFailure(mSessionManager.Init(&GetSystemLayer(), transport, &mMessageCounterManager, &mStorage));
ReturnErrorOnFailure(mFabricTable.Init(&mStorage));
ReturnErrorOnFailure(mSessionManager.Init(&GetSystemLayer(), transport, &mMessageCounterManager, &mStorage, &mFabricTable));

ReturnErrorOnFailure(mExchangeManager.Init(&mSessionManager));
ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager));
Expand Down
1 change: 1 addition & 0 deletions src/messaging/tests/MessagingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class MessagingContext : public PlatformMemoryUser

private:
bool mInitialized;
FabricTable mFabricTable;
SessionManager mSessionManager;
Messaging::ExchangeManager mExchangeManager;
secure_channel::MessageCounterManager mMessageCounterManager;
Expand Down
1 change: 1 addition & 0 deletions src/messaging/tests/echo/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <platform/CHIPDeviceLayer.h>
#include <protocols/secure_channel/MessageCounterManager.h>

chip::FabricTable gFabricTable;
chip::SessionManager gSessionManager;
chip::Messaging::ExchangeManager gExchangeManager;
chip::secure_channel::MessageCounterManager gMessageCounterManager;
Expand Down
2 changes: 2 additions & 0 deletions src/messaging/tests/echo/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#pragma once

#include <credentials/FabricTable.h>
#include <lib/support/TestPersistentStorageDelegate.h>
#include <messaging/ExchangeMgr.h>
#include <protocols/secure_channel/MessageCounterManager.h>
Expand All @@ -33,6 +34,7 @@ constexpr size_t kMaxTcpActiveConnectionCount = 4;
constexpr size_t kMaxTcpPendingPackets = 4;
constexpr size_t kNetworkSleepTimeMsecs = (100 * 1000);

extern chip::FabricTable gFabricTable;
extern chip::SessionManager gSessionManager;
extern chip::Messaging::ExchangeManager gExchangeManager;
extern chip::secure_channel::MessageCounterManager gMessageCounterManager;
Expand Down
9 changes: 7 additions & 2 deletions src/messaging/tests/echo/echo_requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,18 @@ int main(int argc, char * argv[])

InitializeChip();

err = gFabricTable.Init(&gStorage);
SuccessOrExit(err);

if (gUseTCP)
{
err = gTCPManager.Init(chip::Transport::TcpListenParameters(chip::DeviceLayer::TCPEndPointManager())
.SetAddressType(chip::Inet::IPAddressType::kIPv6)
.SetListenPort(ECHO_CLIENT_PORT));
SuccessOrExit(err);

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

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

Expand Down
9 changes: 7 additions & 2 deletions src/messaging/tests/echo/echo_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ int main(int argc, char * argv[])

InitializeChip();

err = gFabricTable.Init(&gStorage);
SuccessOrExit(err);

if (useTCP)
{
err = gTCPManager.Init(chip::Transport::TcpListenParameters(chip::DeviceLayer::TCPEndPointManager())
Expand All @@ -93,7 +96,8 @@ int main(int argc, char * argv[])
);
SuccessOrExit(err);

err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage);
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage,
&gFabricTable);
SuccessOrExit(err);
}
else
Expand All @@ -102,7 +106,8 @@ int main(int argc, char * argv[])
.SetAddressType(chip::Inet::IPAddressType::kIPv6));
SuccessOrExit(err);

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

Expand Down
4 changes: 3 additions & 1 deletion src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,18 @@ SessionManager::~SessionManager() {}

CHIP_ERROR SessionManager::Init(System::Layer * systemLayer, TransportMgrBase * transportMgr,
Transport::MessageCounterManagerInterface * messageCounterManager,
chip::PersistentStorageDelegate * storageDelegate)
chip::PersistentStorageDelegate * storageDelegate, FabricTable * fabricTable)
{
VerifyOrReturnError(mState == State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(transportMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(storageDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(fabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

mState = State::kInitialized;
mSystemLayer = systemLayer;
mTransportMgr = transportMgr;
mMessageCounterManager = messageCounterManager;
mFabricTable = fabricTable;

// TODO: Handle error from mGlobalEncryptedMessageCounter! Unit tests currently crash if you do!
(void) mGlobalEncryptedMessageCounter.Init();
Expand Down
3 changes: 2 additions & 1 deletion src/transport/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
*/
CHIP_ERROR Init(System::Layer * systemLayer, TransportMgrBase * transportMgr,
Transport::MessageCounterManagerInterface * messageCounterManager,
chip::PersistentStorageDelegate * storageDelegate);
chip::PersistentStorageDelegate * storageDelegate, FabricTable * fabricTable);

/**
* @brief
Expand Down Expand Up @@ -244,6 +244,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
};

System::Layer * mSystemLayer = nullptr;
FabricTable * mFabricTable = nullptr;
Transport::UnauthenticatedSessionTable<CHIP_CONFIG_UNAUTHENTICATED_CONNECTION_POOL_SIZE> mUnauthenticatedSessions;
Transport::SecureSessionTable<CHIP_CONFIG_PEER_CONNECTION_POOL_SIZE> mSecureSessions;
State mState; // < Initialization state of the object
Expand Down
Loading

0 comments on commit 1051996

Please sign in to comment.