From 0d33404a9ab3b8099be9b582a5a01a3d698b0145 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Thu, 9 Jun 2022 01:38:23 +0800 Subject: [PATCH] Add API to invalid sessions/exchanges for UpdateNOC command --- src/messaging/ExchangeMgr.cpp | 11 +++++++++++ src/messaging/ExchangeMgr.h | 3 +++ src/transport/SessionManager.cpp | 11 +++++++++++ src/transport/SessionManager.h | 3 +++ 4 files changed, 28 insertions(+) diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index fc5bea10b83e22..369a3c977626cf 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -342,5 +342,16 @@ void ExchangeManager::CloseAllContextsForDelegate(const ExchangeDelegate * deleg }); } +void ExchangeManager::AbortExchangeForNodeExceptOne(const ScopedNodeId & node, ExchangeContext * stay) +{ + mContextPool.ForEachActiveObject([&](auto * ec) { + if (ec != stay && ec->HasSessionHandle() && ec->GetSessionHandle()->GetPeer() == node) + { + ec->Abort(); + } + return Loop::Continue; + }); +} + } // namespace Messaging } // namespace chip diff --git a/src/messaging/ExchangeMgr.h b/src/messaging/ExchangeMgr.h index 1c0a783703a343..9d08cd5587ab42 100644 --- a/src/messaging/ExchangeMgr.h +++ b/src/messaging/ExchangeMgr.h @@ -183,6 +183,9 @@ class DLL_EXPORT ExchangeManager : public SessionMessageDelegate */ void CloseAllContextsForDelegate(const ExchangeDelegate * delegate); + // This API is used by UpdateNOC command, to invalid all exchanges except the given one. + void AbortExchangeForNodeExceptOne(const ScopedNodeId & node, ExchangeContext * stay); + SessionManager * GetSessionManager() const { return mSessionManager; } ReliableMessageMgr * GetReliableMessageMgr() { return &mReliableMessageMgr; }; diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index f68ae57f535dae..8cb334619a185d 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -387,6 +387,17 @@ void SessionManager::ExpireAllPASEPairings() }); } +void SessionManager::ReleaseSessionForNodeExceptOne(const ScopedNodeId & node, const SessionHandle & stay) +{ + mSecureSessions.ForEachSession([&](auto session) { + if (session->GetPeer() == node && session != stay->AsSecureSession()) + { + session->MarkForRemoval(); + } + return Loop::Continue; + }); +} + Optional SessionManager::AllocateSession(SecureSession::Type secureSessionType) { return mSecureSessions.CreateNewSecureSession(secureSessionType); diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index a3ed1f5b440474..2d60d77e45a71f 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -171,6 +171,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate void ExpireAllPairingsForFabric(FabricIndex fabric); void ExpireAllPASEPairings(); + // This API is used by UpdateNOC command, to invalid all sessions except the given one. + void ReleaseSessionForNodeExceptOne(const ScopedNodeId & node, const SessionHandle & stay); + /** * @brief * Return the System Layer pointer used by current SessionManager.