Skip to content

Commit

Permalink
add session ID allocator to session manager
Browse files Browse the repository at this point in the history
  • Loading branch information
msandstedt committed Dec 9, 2021
1 parent eed472e commit 9c2a5e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/controller/CHIPDeviceControllerSystemState.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <app/DeviceControllerInteractionModelDelegate.h>
#include <credentials/FabricTable.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/SessionIDAllocator.h>
#include <transport/TransportMgr.h>
#include <transport/raw/UDP.h>
#if CONFIG_DEVICE_LAYER
Expand Down Expand Up @@ -131,7 +130,6 @@ class DeviceControllerSystemState
Inet::InetLayer * InetLayer() { return mInetLayer; };
DeviceTransportMgr * TransportMgr() { return mTransportMgr; };
SessionManager * SessionMgr() { return mSessionMgr; };
SessionIDAllocator * GetSessionIDAllocator() { return mIDAllocator; };
Messaging::ExchangeManager * ExchangeMgr() { return mExchangeMgr; }
secure_channel::MessageCounterManager * MessageCounterManager() { return mMessageCounterManager; };
FabricTable * Fabrics() { return mFabrics; };
Expand All @@ -150,7 +148,6 @@ class DeviceControllerSystemState
#endif
DeviceTransportMgr * mTransportMgr = nullptr;
SessionManager * mSessionMgr = nullptr;
SessionIDAllocator * mIDAllocator = nullptr;
Messaging::ExchangeManager * mExchangeMgr = nullptr;
secure_channel::MessageCounterManager * mMessageCounterManager = nullptr;
FabricTable * mFabrics = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions src/controller/CommissioningStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ struct SessionEstablishment : Base<TEvent>, SessionEstablishmentDelegate
VerifyOrExit(session.HasValue(), err = CHIP_ERROR_NO_MEMORY);
exchangeCtxt = this->mSystemState->ExchangeMgr()->NewContext(session.Value(), this->mPairing.get());
VerifyOrExit(exchangeCtxt != nullptr, err = CHIP_ERROR_INTERNAL);
err = this->mSystemState->GetSessionIDAllocator()->Allocate(sessionId);
err = this->mSystemState->SessionMgr()->GetSessionIDAllocator()->Allocate(sessionId);
SuccessOrExit(err);
err = mPairing.get()->Pair(mParams.GetPeerAddress(), mParams.GetSetupPINCode(), sessionId, Optional<ReliableMessageProtocolConfig>::Value(mParams.GetMRPConfig()), exchangeCtxt, this);
SuccessOrExit(err);
Expand All @@ -280,7 +280,8 @@ struct SessionEstablishment : Base<TEvent>, SessionEstablishmentDelegate
void Exit() {}

//////////// SessionEstablishmentDelegate Implementation ///////////////
void OnSessionEstablishmentError(CHIP_ERROR error) override { this->mCtx.Dispatch(TEvent::template Create<Failure>()); }
void OnSessionEstablishmentError(CHIP_ERROR error) override {
this->mCtx.Dispatch(TEvent::template Create<Failure>()); }
void OnSessionEstablished() override
{
this->mCtx.Dispatch(TEvent::template Create<Platform::SharedPtr<PASESession>>(mPairing));
Expand Down
9 changes: 9 additions & 0 deletions src/transport/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <transport/raw/Base.h>
#include <transport/raw/PeerAddress.h>
#include <transport/raw/Tuple.h>
#include <protocols/secure_channel/SessionIDAllocator.h>

namespace chip {

Expand Down Expand Up @@ -277,6 +278,12 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
// TODO: this is a temporary solution for legacy tests which use nodeId to send packets
SessionHandle FindSecureSessionForNode(NodeId peerNodeId);

/**
* @brief
* Return the session ID allocator for this session manager instance.
*/
SessionIDAllocator *GetSessionIDAllocator() { return &mIDAllocator; }

private:
/**
* The State of a secure transport object.
Expand All @@ -293,6 +300,8 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
kPayloadIsUnencrypted,
};

SessionIDAllocator mIDAllocator;

System::Layer * mSystemLayer = nullptr;
Transport::UnauthenticatedSessionTable<CHIP_CONFIG_UNAUTHENTICATED_CONNECTION_POOL_SIZE> mUnauthenticatedSessions;
Transport::SecureSessionTable<CHIP_CONFIG_PEER_CONNECTION_POOL_SIZE> mSecureSessions; // < Active connections to other peers
Expand Down

0 comments on commit 9c2a5e4

Please sign in to comment.