Skip to content

Commit

Permalink
Select least peer active session (project-chip#36936)
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen authored and Alami-Amine committed Jan 12, 2025
1 parent 8c07924 commit ad6f490
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,15 +1297,15 @@ Optional<SessionHandle> SessionManager::FindSecureSessionForNode(ScopedNodeId pe
{
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
// Set up a TCP transport based session as standby
if ((tcpSession == nullptr || tcpSession->GetLastActivityTime() < session->GetLastActivityTime()) &&
if ((tcpSession == nullptr || tcpSession->GetLastPeerActivityTime() < session->GetLastPeerActivityTime()) &&
session->GetTCPConnection() != nullptr)
{
tcpSession = session;
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
}

if ((mrpSession == nullptr) || (mrpSession->GetLastActivityTime() < session->GetLastActivityTime()))
if ((mrpSession == nullptr) || (mrpSession->GetLastPeerActivityTime() < session->GetLastPeerActivityTime()))
{
mrpSession = session;
}
Expand Down
6 changes: 3 additions & 3 deletions src/transport/tests/TestSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,19 +998,19 @@ TEST_F(TestSessionManager, TestFindSecureSessionForNode)
CHIP_ERROR err = sessionManager.InjectCaseSessionWithTestKey(aliceToBobSession, 2, 1, aliceNodeId, bobNodeId, aliceFabricIndex,
peer, CryptoContext::SessionRole::kInitiator);
EXPECT_EQ(err, CHIP_NO_ERROR);
aliceToBobSession->AsSecureSession()->MarkActive();
aliceToBobSession->AsSecureSession()->MarkActiveRx();

SessionHolder newAliceToBobSession;
err = sessionManager.InjectCaseSessionWithTestKey(newAliceToBobSession, 3, 4, aliceNodeId, bobNodeId, aliceFabricIndex, peer,
CryptoContext::SessionRole::kInitiator);
EXPECT_EQ(err, CHIP_NO_ERROR);

while (System::SystemClock().GetMonotonicTimestamp() <= aliceToBobSession->AsSecureSession()->GetLastActivityTime())
while (System::SystemClock().GetMonotonicTimestamp() <= aliceToBobSession->AsSecureSession()->GetLastPeerActivityTime())
{
// Wait for the clock to advance so the new session is
// more-recently-active.
}
newAliceToBobSession->AsSecureSession()->MarkActive();
newAliceToBobSession->AsSecureSession()->MarkActiveRx();

auto foundSession = sessionManager.FindSecureSessionForNode(ScopedNodeId(bobNodeId, aliceFabricIndex),
MakeOptional(SecureSession::Type::kCASE));
Expand Down

0 comments on commit ad6f490

Please sign in to comment.