Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 460c826

Browse files
author
Jay Logue
authored
Merge pull request #505 from openweave/issue/session-restore-fix
Fixed bug in WeaveFabricState::RestoreSession()
2 parents e0c3a21 + 6c01f7d commit 460c826

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/lib/core/WeaveFabricState.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,12 +762,24 @@ WEAVE_ERROR WeaveFabricState::RestoreSession(uint8_t * serializedSession, uint16
762762
err = reader.Get(peerNodeId);
763763
SuccessOrExit(err);
764764
765-
// Look for or create a session key entry for the given key id and peer node.
765+
// Look for / create a session key entry for the given key id and peer node.
766766
err = FindSessionKey(keyId, peerNodeId, true, sessionKey);
767767
SuccessOrExit(err);
768-
769-
// If the key id / peer node matched an existing session key, fail with an error.
770-
VerifyOrExit(!sessionKey->IsKeySet(), err = WEAVE_ERROR_DUPLICATE_KEY_ID);
768+
if (!sessionKey->IsAllocated())
769+
{
770+
sessionKey->MsgEncKey.KeyId = keyId;
771+
sessionKey->NodeId = peerNodeId;
772+
sessionKey->BoundCon = NULL;
773+
sessionKey->ReserveCount = 0;
774+
sessionKey->Flags = 0;
775+
}
776+
else
777+
{
778+
// If the key id / peer node matches an existing session that is NOT suspended, fail with an error.
779+
VerifyOrExit(sessionKey->IsSuspended(), err = WEAVE_ERROR_DUPLICATE_KEY_ID);
780+
}
781+
sessionKey->SetRemoveOnIdle(true);
782+
sessionKey->MarkRecentlyActive();
771783
772784
// After this point, if an error occurs, remove the session key.
773785
removeSessionOnError = true;

src/test-apps/weave-ping.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ void DriveSending()
671671
}
672672

673673
// If the --test-session-suspend option has been enabled, suspend and restore
674-
// the CASE session every 4 echo requests.
674+
// the CASE session every 4 echo requests. Every 8th echo request, remove the
675+
// suspended session before attempting to restore it.
675676
if (TestSessionSuspend && gWeaveSecurityMode.SecurityMode == WeaveSecurityMode::kCASE)
676677
{
677678
if (EchoCount > 0 && (EchoCount % 4) == 0)
@@ -680,16 +681,25 @@ void DriveSending()
680681
uint16_t serializedKeyLen;
681682

682683
printf("Suspending CASE session\n");
683-
684684
err = FabricState.SuspendSession(EchoClient.KeyId, DestNodeId, buf, sizeof(buf), serializedKeyLen);
685685
if (err != WEAVE_NO_ERROR)
686686
{
687687
printf("FabricState.SuspendSession() failed: %s\n", ErrorStr(err));
688688
}
689-
else
689+
690+
if (err == WEAVE_NO_ERROR && (EchoCount % 8) == 0)
690691
{
691-
printf("Restoring CASE session\n");
692+
printf("Removing suspended CASE session\n");
693+
err = FabricState.RemoveSessionKey(EchoClient.KeyId, DestNodeId);
694+
if (err != WEAVE_NO_ERROR)
695+
{
696+
printf("FabricState.RemoveSessionKey() failed: %s\n", ErrorStr(err));
697+
}
698+
}
692699

700+
if (err == WEAVE_NO_ERROR)
701+
{
702+
printf("Restoring suspended CASE session\n");
693703
err = FabricState.RestoreSession(buf, serializedKeyLen);
694704
if (err != WEAVE_NO_ERROR)
695705
{

0 commit comments

Comments
 (0)