Skip to content

Commit

Permalink
Adds refcount logging for SecureSessions. (#19257)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjerryjohns authored and pull[bot] committed Aug 10, 2023
1 parent 0f965d7 commit 1686524
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,17 @@
#define CHIP_CONFIG_PEER_CONNECTION_POOL_SIZE 16
#endif // CHIP_CONFIG_PEER_CONNECTION_POOL_SIZE

/**
* @def CHIP_CONFIG_SECURE_SESSION_REFCOUNT_LOGGING
*
* @brief This enables logging of changes to the underlying reference count of
* SecureSession objects.
*
*/
#ifndef CHIP_CONFIG_SECURE_SESSION_REFCOUNT_LOGGING
#define CHIP_CONFIG_SECURE_SESSION_REFCOUNT_LOGGING 0
#endif

/**
* @def CHIP_CONFIG_MAX_FABRICS
*
Expand Down
3 changes: 2 additions & 1 deletion src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ CASESession::ListenForSessionEstablishment(SessionManager & sessionManager, Fabr
mSessionResumptionStorage = sessionResumptionStorage;
mLocalMRPConfig = mrpConfig;

ChipLogDetail(SecureChannel, "Waiting for Sigma1 msg");
ChipLogDetail(SecureChannel, "Allocated SecureSession (%p) - waiting for Sigma1 msg",
mSecureSessionHolder.Get().Value()->AsSecureSession());

return CHIP_NO_ERROR;
}
Expand Down
20 changes: 19 additions & 1 deletion src/transport/SecureSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void SecureSessionDeleter::Release(SecureSession * entry)

void SecureSession::MarkForRemoval()
{
ChipLogDetail(Inet, "SecureSession MarkForRemoval %p Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
ChipLogDetail(Inet, "SecureSession[%p]: MarkForRemoval Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
mLocalSessionId);
ReferenceCountedHandle<Transport::Session> ref(*this);
switch (mState)
Expand Down Expand Up @@ -77,5 +77,23 @@ Access::SubjectDescriptor SecureSession::GetSubjectDescriptor() const
return subjectDescriptor;
}

void SecureSession::Retain()
{
#if CHIP_CONFIG_SECURE_SESSION_REFCOUNT_LOGGING
ChipLogProgress(SecureChannel, "SecureSession[%p]: ++ %d -> %d", this, GetReferenceCount(), GetReferenceCount() + 1);
#endif

ReferenceCounted<SecureSession, SecureSessionDeleter, 0, uint16_t>::Retain();
}

void SecureSession::Release()
{
#if CHIP_CONFIG_SECURE_SESSION_REFCOUNT_LOGGING
ChipLogProgress(SecureChannel, "SecureSession[%p]: -- %d -> %d", this, GetReferenceCount(), GetReferenceCount() - 1);
#endif

ReferenceCounted<SecureSession, SecureSessionDeleter, 0, uint16_t>::Release();
}

} // namespace Transport
} // namespace chip
15 changes: 9 additions & 6 deletions src/transport/SecureSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SecureSession : public Session, public ReferenceCounted<SecureSession, Sec
{
Retain(); // Put the test session in Active state
SetFabricIndex(fabric);
ChipLogDetail(Inet, "SecureSession Allocated for test %p Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
ChipLogDetail(Inet, "SecureSession[%p]: Allocated for Test Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
mLocalSessionId);
}

Expand All @@ -88,7 +88,8 @@ class SecureSession : public Session, public ReferenceCounted<SecureSession, Sec
SecureSession(SecureSessionTable & table, Type secureSessionType, uint16_t localSessionId) :
mTable(table), mState(State::kPairing), mSecureSessionType(secureSessionType), mLocalSessionId(localSessionId)
{
ChipLogDetail(Inet, "SecureSession Allocated %p Type:%d LSID:%d", this, to_underlying(mSecureSessionType), mLocalSessionId);
ChipLogDetail(Inet, "SecureSession[%p]: Allocated Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
mLocalSessionId);
}

/**
Expand Down Expand Up @@ -120,20 +121,22 @@ class SecureSession : public Session, public ReferenceCounted<SecureSession, Sec

Retain();
mState = State::kActive;
ChipLogDetail(Inet, "SecureSession Active %p Type:%d LSID:%d", this, to_underlying(mSecureSessionType), mLocalSessionId);
ChipLogDetail(Inet, "SecureSession[%p]: Activated - Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
mLocalSessionId);
}
~SecureSession() override
{
ChipLogDetail(Inet, "SecureSession Released %p Type:%d LSID:%d", this, to_underlying(mSecureSessionType), mLocalSessionId);
ChipLogDetail(Inet, "SecureSession[%p]: Released - Type:%d LSID:%d", this, to_underlying(mSecureSessionType),
mLocalSessionId);
}

SecureSession(SecureSession &&) = delete;
SecureSession(const SecureSession &) = delete;
SecureSession & operator=(const SecureSession &) = delete;
SecureSession & operator=(SecureSession &&) = delete;

void Retain() override { ReferenceCounted<SecureSession, SecureSessionDeleter, 0, uint16_t>::Retain(); }
void Release() override { ReferenceCounted<SecureSession, SecureSessionDeleter, 0, uint16_t>::Release(); }
void Retain() override;
void Release() override;

bool IsActiveSession() const override { return mState == State::kActive; }
bool IsPairing() const { return mState == State::kPairing; }
Expand Down

0 comments on commit 1686524

Please sign in to comment.