diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index d4d4dbb1597a7f..c819dc92809586 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -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 * diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index 0c39895322ec2c..ee723e33912562 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -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; } diff --git a/src/transport/SecureSession.cpp b/src/transport/SecureSession.cpp index 2902a9df5a9790..f2ec416c0ba9d6 100644 --- a/src/transport/SecureSession.cpp +++ b/src/transport/SecureSession.cpp @@ -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 ref(*this); switch (mState) @@ -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::Retain(); +} + +void SecureSession::Release() +{ +#if CHIP_CONFIG_SECURE_SESSION_REFCOUNT_LOGGING + ChipLogProgress(SecureChannel, "SecureSession[%p]: -- %d -> %d", this, GetReferenceCount(), GetReferenceCount() - 1); +#endif + + ReferenceCounted::Release(); +} + } // namespace Transport } // namespace chip diff --git a/src/transport/SecureSession.h b/src/transport/SecureSession.h index 85462c2c773014..47bee45412f0ca 100644 --- a/src/transport/SecureSession.h +++ b/src/transport/SecureSession.h @@ -75,7 +75,7 @@ class SecureSession : public Session, public ReferenceCounted::Retain(); } - void Release() override { ReferenceCounted::Release(); } + void Retain() override; + void Release() override; bool IsActiveSession() const override { return mState == State::kActive; } bool IsPairing() const { return mState == State::kPairing; }