Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Jun 17, 2022
1 parent 42049c5 commit ad2ea2e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ ExchangeContext::~ExchangeContext()
VerifyOrDie(mExchangeMgr != nullptr && GetReferenceCount() == 0);
VerifyOrDie(!IsAckPending());

if (IsAutoReleaseSession() && mSession)
if (ReleaseSessionOnDestruction() && mSession)
mSession->AsSecureSession()->MarkForRemoval();

#if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED
Expand Down
4 changes: 4 additions & 0 deletions src/messaging/ExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ void ExchangeManager::CloseAllContextsForDelegate(const ExchangeDelegate * deleg

void ExchangeManager::AbortExchangesForFabricExceptOne(FabricIndex fabricIndex, ExchangeContext * deferred)
{
VerifyOrDie(deferred->HasSessionHandle() && deferred->GetSessionHandle()->IsSecureSession());

mContextPool.ForEachActiveObject([&](auto * ec) {
if (ec->HasSessionHandle() && ec->GetSessionHandle()->GetFabricIndex() == fabricIndex)
{
Expand All @@ -388,6 +390,8 @@ void ExchangeManager::AbortExchangesForFabricExceptOne(FabricIndex fabricIndex,
}
return Loop::Continue;
});

mSessionManager->ReleaseSessionsForFabricExceptOne(fabricIndex, deferred->GetSessionHandle());
}

} // namespace Messaging
Expand Down
5 changes: 2 additions & 3 deletions src/messaging/ExchangeMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ class DLL_EXPORT ExchangeManager : public SessionMessageDelegate
*/
void CloseAllContextsForDelegate(const ExchangeDelegate * delegate);

// This API is used by commands that need to shut down all existing exchanges on
// a fabric but need to make sure the response to the command still goes out on the exchange
// the command came in on. This API flags that one exchange to shut down its session
// This API is used by commands that need to shut down all existing exchanges on a fabric but need to make sure the response to
// the command still goes out on the exchange the command came in on. This API flags that one exchange to shut down its session
// when it's done.
void AbortExchangesForFabricExceptOne(FabricIndex fabricIndex, ExchangeContext * deferred);

Expand Down
2 changes: 1 addition & 1 deletion src/messaging/ReliableMessageContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ inline void ReliableMessageContext::SetAutoReleaseSession()
mFlags.Set(Flags::kFlagAutoReleaseSession, true);
}

inline bool ReliableMessageContext::IsAutoReleaseSession()
inline bool ReliableMessageContext::ReleaseSessionOnDestruction()
{
return mFlags.Has(Flags::kFlagAutoReleaseSession);
}
Expand Down
4 changes: 2 additions & 2 deletions src/transport/SecureSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ void SecureSession::MarkForRemoval()
}
}

void SecureSession::MarkForInactive()
void SecureSession::MarkInactive()
{
ChipLogDetail(Inet, "SecureSession[%p]: MarkForInactive Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
ChipLogDetail(Inet, "SecureSession[%p]: MarkInactive Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
mLocalSessionId);
ReferenceCountedHandle<Transport::Session> ref(*this);
switch (mState)
Expand Down
4 changes: 2 additions & 2 deletions src/transport/SecureSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SecureSession : public Session, public ReferenceCounted<SecureSession, Sec
void MarkForRemoval();

// Used to prevent any new exchange created on the session while the existing exchanges finish their work.
void MarkForInactive();
void MarkInactive();

Session::SessionType GetSessionType() const override { return Session::SessionType::kSecure; }
#if CHIP_PROGRESS_LOGGING
Expand Down Expand Up @@ -254,7 +254,7 @@ class SecureSession : public Session, public ReferenceCounted<SecureSession, Sec
kPendingRemoval = 3,

// The session is still functional, but it can't yield any new exchanges,
// This is meant to be used in conjunction with
// This is meant to be used in conjunction with
// ExchangeManager::AbortExchangesForFabricExceptOne, with the one
// exceptional exchange handling moving this session out of this state when
// it finishes whatever it needs the session for.
Expand Down
7 changes: 5 additions & 2 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,14 @@ void SessionManager::ExpireAllPASEPairings()

void SessionManager::ReleaseSessionsForFabricExceptOne(FabricIndex fabricIndex, const SessionHandle & deferred)
{
VerifyOrDie(deferred->IsSecureSession());
SecureSession * deferredSecureSession = deferred->AsSecureSession();

mSecureSessions.ForEachSession([&](auto session) {
if (session->GetPeer().GetFabricIndex() == fabricIndex)
{
if (session == deferred->AsSecureSession())
session->MarkForInactive();
if (session == deferredSecureSession)
session->MarkInactive();
else
session->MarkForRemoval();
}
Expand Down
5 changes: 3 additions & 2 deletions src/transport/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
void ExpireAllPairingsForFabric(FabricIndex fabric);
void ExpireAllPASEPairings();

// This API is used by UpdateNOC command, to invalidate all sessions except the given one, whose release is deferred until
// UpdateNOC command finishing its work.
// This API is used by commands that need to release all existing sessions on a fabric but need to make sure the response to the
// command still goes out on the exchange the command came in on. This API flags that the release of the session used by the
// exchange is deferred until the exchange is done.
void ReleaseSessionsForFabricExceptOne(FabricIndex fabricIndex, const SessionHandle & deferred);

/**
Expand Down

0 comments on commit ad2ea2e

Please sign in to comment.