From 64e6149c2e680ed9f0121269f96f149d84a3d470 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Fri, 10 Jun 2022 04:53:13 +0800 Subject: [PATCH] Add purge all fabric API --- src/messaging/ExchangeMgr.cpp | 14 ++++++++++++++ src/messaging/ExchangeMgr.h | 5 +++-- src/transport/SessionManager.cpp | 14 ++++++++++++++ src/transport/SessionManager.h | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index fcfc460286cbe1..69dab9102b319d 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -342,6 +342,20 @@ void ExchangeManager::CloseAllContextsForDelegate(const ExchangeDelegate * deleg }); } +void ExchangeManager::AbortExchangeForFabricExceptOne(FabricIndex fabricIndex, ExchangeContext * exception) +{ + mContextPool.ForEachActiveObject([&](auto * ec) { + if (ec->HasSessionHandle() && ec->GetSessionHandle()->GetPeer().GetFabricIndex() == fabricIndex) + { + if (ec == exception) + ec->SetAutoReleaseSession(); + else + ec->Abort(); + } + return Loop::Continue; + }); +} + void ExchangeManager::AbortExchangeForNodeExceptOne(const ScopedNodeId & node, ExchangeContext * exception) { mContextPool.ForEachActiveObject([&](auto * ec) { diff --git a/src/messaging/ExchangeMgr.h b/src/messaging/ExchangeMgr.h index 9d08cd5587ab42..2a51a8ae171e2a 100644 --- a/src/messaging/ExchangeMgr.h +++ b/src/messaging/ExchangeMgr.h @@ -183,8 +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); + // This 2 APIs are used by UpdateNOC command, to invalid all exchanges except the given one. + void AbortExchangeForFabricExceptOne(FabricIndex fabricIndex, ExchangeContext * exception); + void AbortExchangeForNodeExceptOne(const ScopedNodeId & node, ExchangeContext * exception); SessionManager * GetSessionManager() const { return mSessionManager; } diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index 45214d4b163ed9..076a636d2362d3 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -387,6 +387,20 @@ void SessionManager::ExpireAllPASEPairings() }); } +void SessionManager::ReleaseSessionForFabricExceptOne(FabricIndex fabricIndex, const SessionHandle & exception) +{ + mSecureSessions.ForEachSession([&](auto session) { + if (session->GetPeer().GetFabricIndex() == fabricIndex) + { + if (session == exception->AsSecureSession()) + session->MarkForInactive(); + else + session->MarkForRemoval(); + } + return Loop::Continue; + }); +} + void SessionManager::ReleaseSessionForNodeExceptOne(const ScopedNodeId & node, const SessionHandle & exception) { mSecureSessions.ForEachSession([&](auto session) { diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index 2d60d77e45a71f..0f626d0ed5a94b 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -172,7 +172,8 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate 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); + void ReleaseSessionForFabricExceptOne(FabricIndex fabricIndex, const SessionHandle & exception); + void ReleaseSessionForNodeExceptOne(const ScopedNodeId & node, const SessionHandle & exception); /** * @brief