Skip to content

Commit

Permalink
[mrp] Fix project-chip#15800 - Add start of peer active tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
turon committed Mar 30, 2022
1 parent cd79d33 commit fd359a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/transport/SecureSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class SecureSession : public Session
FabricIndex fabric, const ReliableMessageProtocolConfig & config) :
mSecureSessionType(secureSessionType),
mPeerNodeId(peerNodeId), mPeerCATs(peerCATs), mLocalSessionId(localSessionId), mPeerSessionId(peerSessionId),
mLastActivityTime(System::SystemClock().GetMonotonicTimestamp()), mMRPConfig(config)
mLastActivityTime(System::SystemClock().GetMonotonicTimestamp()),
mLastPeerActivityTime(System::SystemClock().GetMonotonicTimestamp()),
mMRPConfig(config)
{
SetFabricIndex(fabric);
}
Expand Down Expand Up @@ -134,7 +136,12 @@ class SecureSession : public Session
}

System::Clock::Timestamp GetLastActivityTime() const { return mLastActivityTime; }
System::Clock::Timestamp GetLastPeerActivityTime() const { return mLastPeerActivityTime; }
void MarkActive() { mLastActivityTime = System::SystemClock().GetMonotonicTimestamp(); }
void MarkActiveRx() {
mLastPeerActivityTime = System::SystemClock().GetMonotonicTimestamp();
MarkActive();
}

CryptoContext & GetCryptoContext() { return mCryptoContext; }

Expand All @@ -148,7 +155,8 @@ class SecureSession : public Session
const uint16_t mPeerSessionId;

PeerAddress mPeerAddress;
System::Clock::Timestamp mLastActivityTime;
System::Clock::Timestamp mLastActivityTime; ///< Timestamp of last tx or rx
System::Clock::Timestamp mLastPeerActivityTime; ///< Timestamp of last rx
ReliableMessageProtocolConfig mMRPConfig;
CryptoContext mCryptoContext;
SessionMessageCounter mSessionMessageCounter;
Expand Down
4 changes: 2 additions & 2 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void SessionManager::UnauthenticatedMessageDispatch(const PacketHeader & packetH
unsecuredSession->SetPeerAddress(peerAddress);
SessionMessageDelegate::DuplicateMessage isDuplicate = SessionMessageDelegate::DuplicateMessage::No;

unsecuredSession->MarkActive();
unsecuredSession->MarkActiveRx();

PayloadHeader payloadHeader;
ReturnOnFailure(payloadHeader.DecodeAndConsume(msg));
Expand Down Expand Up @@ -612,7 +612,7 @@ void SessionManager::SecureUnicastMessageDispatch(const PacketHeader & packetHea
return;
}

secureSession->MarkActive();
secureSession->MarkActiveRx();

if (isDuplicate == SessionMessageDelegate::DuplicateMessage::Yes && !payloadHeader.NeedsAck())
{
Expand Down
11 changes: 9 additions & 2 deletions src/transport/UnauthenticatedSessionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class UnauthenticatedSession : public Session, public ReferenceCounted<Unauthent

UnauthenticatedSession(SessionRole sessionRole, NodeId ephemeralInitiatorNodeID, const ReliableMessageProtocolConfig & config) :
mEphemeralInitiatorNodeId(ephemeralInitiatorNodeID), mSessionRole(sessionRole),
mLastActivityTime(System::SystemClock().GetMonotonicTimestamp()), mMRPConfig(config)
mLastActivityTime(System::SystemClock().GetMonotonicTimestamp()),
mLastPeerActivityTime(System::SystemClock().GetMonotonicTimestamp()),
mMRPConfig(config)
{}
~UnauthenticatedSession() override { NotifySessionReleased(); }

Expand All @@ -65,6 +67,10 @@ class UnauthenticatedSession : public Session, public ReferenceCounted<Unauthent

System::Clock::Timestamp GetLastActivityTime() const { return mLastActivityTime; }
void MarkActive() { mLastActivityTime = System::SystemClock().GetMonotonicTimestamp(); }
void MarkActiveRx() {
mLastPeerActivityTime = System::SystemClock().GetMonotonicTimestamp();
MarkActive();
}

Session::SessionType GetSessionType() const override { return Session::SessionType::kUnauthenticated; }
#if CHIP_PROGRESS_LOGGING
Expand Down Expand Up @@ -122,7 +128,8 @@ class UnauthenticatedSession : public Session, public ReferenceCounted<Unauthent
const NodeId mEphemeralInitiatorNodeId;
const SessionRole mSessionRole;
PeerAddress mPeerAddress;
System::Clock::Timestamp mLastActivityTime;
System::Clock::Timestamp mLastActivityTime; ///< Timestamp of last tx or rx
System::Clock::Timestamp mLastPeerActivityTime; ///< Timestamp of last rx
ReliableMessageProtocolConfig mMRPConfig;
PeerMessageCounter mPeerMessageCounter;
};
Expand Down

0 comments on commit fd359a8

Please sign in to comment.