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 76e86f2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/messaging/ExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,20 @@ 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)
{
if (ec == deferred)
ec->SetAutoReleaseSession();
ec->ReleaseSessionOnDestruction();
else
ec->Abort();
}
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
8 changes: 4 additions & 4 deletions src/messaging/ReliableMessageContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ class ReliableMessageContext
/// Determine whether this exchange is a EphemeralExchange for replying a StandaloneAck
bool IsEphemeralExchange() const;

// If SetAutoReleaseSession() is called, this exchange must be using a SecureSession, and should
// If ReleaseSessionOnDestruction() is called, this exchange must be using a SecureSession, and should
// evict it when the exchange is done with all its work (including any MRP traffic).
void SetAutoReleaseSession();
bool ReleaseSessionOnDestruction();
void ReleaseSessionOnDestruction();
bool IsAutoReleaseSession();

/**
* Get the reliable message manager that corresponds to this reliable
Expand Down Expand Up @@ -253,7 +253,7 @@ inline bool ReliableMessageContext::IsEphemeralExchange() const
return mFlags.Has(Flags::kFlagEphemeralExchange);
}

inline void ReliableMessageContext::SetAutoReleaseSession()
inline void ReliableMessageContext::ReleaseSessionOnDestruction()
{
mFlags.Set(Flags::kFlagAutoReleaseSession, true);
}
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 76e86f2

Please sign in to comment.