Skip to content

Commit

Permalink
Select least peer active session
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Jan 9, 2025
1 parent 62b2437 commit 2b3f4b6
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 @@ -1057,9 +1057,9 @@ Optional<SessionHandle> SessionManager::FindSecureSessionForNode(ScopedNodeId pe
(!type.HasValue() || type.Value() == session->GetSecureSessionType()))
{
//
// Select the active session with the most recent activity to return back to the caller.
// Select the active session with the most recent activity of peer to return back to the caller.
//
if ((found == nullptr) || (found->GetLastActivityTime() < session->GetLastActivityTime()))
if ((found == nullptr) || (found->GetLastPeerActivityTime() < session->GetLastPeerActivityTime()))
{
found = 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 @@ -1029,19 +1029,19 @@ static void TestFindSecureSessionForNode(nlTestSuite * inSuite, void * inContext
CHIP_ERROR err = sessionManager.InjectCaseSessionWithTestKey(aliceToBobSession, 2, 1, aliceNodeId, bobNodeId, aliceFabricIndex,
peer, CryptoContext::SessionRole::kInitiator);
NL_TEST_ASSERT(inSuite, 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);
NL_TEST_ASSERT(inSuite, 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 2b3f4b6

Please sign in to comment.