Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ICDClientStorage #30931

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/app/icd/client/DefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,23 +391,6 @@ CHIP_ERROR DefaultICDClientStorage::UpdateEntryCountForFabric(FabricIndex fabric
backingBuffer.Get(), static_cast<uint16_t>(len));
}

CHIP_ERROR DefaultICDClientStorage::GetEntry(const ScopedNodeId & peerNode, ICDClientInfo & clientInfo)
{
size_t clientInfoSize = 0;
std::vector<ICDClientInfo> clientInfoVector;
ReturnErrorOnFailure(Load(peerNode.GetFabricIndex(), clientInfoVector, clientInfoSize));
IgnoreUnusedVariable(clientInfoSize);
for (auto & info : clientInfoVector)
{
if (peerNode.GetNodeId() == info.peer_node.GetNodeId())
{
clientInfo = info;
return CHIP_NO_ERROR;
}
}
return CHIP_ERROR_NOT_FOUND;
}

CHIP_ERROR DefaultICDClientStorage::DeleteEntry(const ScopedNodeId & peerNode)
{
size_t clientInfoSize = 0;
Expand Down
22 changes: 18 additions & 4 deletions src/app/icd/client/DefaultICDClientStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <lib/core/DataModelTypes.h>
#include <lib/core/ScopedNodeId.h>
#include <lib/core/TLV.h>
#include <lib/support/CommonIterator.h>
#include <lib/support/Pool.h>
#include <vector>

Expand All @@ -50,11 +51,18 @@ namespace app {
class DefaultICDClientStorage : public ICDClientStorage
{
public:
using ICDClientInfoIterator = CommonIterator<ICDClientInfo>;

static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_ICD_CLIENTS_INFO_STORAGE_CONCURRENT_ITERATORS;

CHIP_ERROR Init(PersistentStorageDelegate * clientInfoStore, Crypto::SymmetricKeystore * keyStore);

ICDClientInfoIterator * IterateICDClientInfo() override;
/**
* Iterate through persisted ICD Client Info
*
* @return A valid iterator on success. Use CommonIterator accessor to retrieve ICDClientInfo
*/
ICDClientInfoIterator * IterateICDClientInfo();

/**
* When decrypting check-in messages, the system needs to iterate through all keys
Expand All @@ -75,11 +83,17 @@ class DefaultICDClientStorage : public ICDClientStorage

CHIP_ERROR StoreEntry(const ICDClientInfo & clientInfo) override;

CHIP_ERROR GetEntry(const ScopedNodeId & peerNode, ICDClientInfo & clientInfo) override;

CHIP_ERROR DeleteEntry(const ScopedNodeId & peerNode) override;

CHIP_ERROR DeleteAllEntries(FabricIndex fabricIndex) override;
/**
* Remove all ICDClient persistent information associated with the specified
* fabric index. If no entries for the fabric index exist, this is a no-op
* and is considered successful.
* When the whole fabric is removed, all entries from persistent storage in current fabric index are removed.
*
* @param[in] fabricIndex the index of the fabric for which to remove ICDClient persistent information
*/
CHIP_ERROR DeleteAllEntries(FabricIndex fabricIndex);

CHIP_ERROR ProcessCheckInPayload(const ByteSpan & payload, ICDClientInfo & clientInfo) override;

Expand Down
35 changes: 4 additions & 31 deletions src/app/icd/client/ICDClientStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <lib/core/DataModelTypes.h>
#include <lib/core/ScopedNodeId.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/CommonIterator.h>
#include <stddef.h>

namespace chip {
Expand All @@ -37,17 +36,8 @@ namespace app {
class ICDClientStorage
{
public:
using ICDClientInfoIterator = CommonIterator<ICDClientInfo>;

virtual ~ICDClientStorage() = default;

/**
* Iterate through persisted ICD Client Info
*
* @return A valid iterator on success. Use CommonIterator accessor to retrieve ICDClientInfo
*/
virtual ICDClientInfoIterator * IterateICDClientInfo() = 0;

/**
* Called during ICD device registration in commissioning, commissioner/controller
* provides raw key data, the shared key handle in clientInfo is updated based upon raw key data
Expand All @@ -66,37 +56,20 @@ class ICDClientStorage
virtual CHIP_ERROR StoreEntry(const ICDClientInfo & clientInfo) = 0;

/**
* Remove ICD key from clientInfo when ICD registration fails
*
* @param[inout] clientInfo the updated ICD Client Info.
* This function removes the ICD key from the provided clientInfo object in the event
* of a failed LIT ICD device registration attempt. If the key handle is not found within
* the Keystore, the function will not perform any operation.
* @param[inout] clientInfo The ICD Client Info to update with uninitialized key handle if key is removed successfully.
*/
virtual void RemoveKey(ICDClientInfo & clientInfo) = 0;

/**
* Get ICD ClientInfo from storage
* One user case is to retrieve UserActiveModeTriggerHint and inform how user how to wake up sleepy device.
* @param[in] peerNode scoped node with peer node id and fabric index
* @param[out] clientInfo the ICD Client Info.
*/
virtual CHIP_ERROR GetEntry(const ScopedNodeId & peerNode, ICDClientInfo & clientInfo) = 0;

/**
* Delete ICD Client persistent information associated with the specified scoped node Id.
* when ICD device is unpaired/removed, the corresponding entry in ICD storage is removed.
* @param peerNode scoped node with peer node id and fabric index
*/
virtual CHIP_ERROR DeleteEntry(const ScopedNodeId & peerNode) = 0;

/**
* Remove all ICDClient persistent information associated with the specified
* fabric index. If no entries for the fabric index exist, this is a no-op
* and is considered successful.
* When the whole fabric is removed, all entries from persistent storage in current fabric index are removed.
*
* @param[in] fabricIndex the index of the fabric for which to remove ICDClient persistent information
*/
virtual CHIP_ERROR DeleteAllEntries(FabricIndex fabricIndex) = 0;

/**
* Process received ICD Check-in message payload. The implementation needs to parse the payload,
* look for a key that allows successfully decrypting the payload, verify that the counter in the payload is valid,
Expand Down
4 changes: 0 additions & 4 deletions src/app/tests/TestDefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)
FabricIndex fabricId = 1;
NodeId nodeId1 = 6666;
NodeId nodeId2 = 6667;
NodeId unknownNodeId = 6668;
TestPersistentStorageDelegate clientInfoStorage;
TestSessionKeystoreImpl keystore;

Expand Down Expand Up @@ -90,9 +89,6 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

ICDClientInfo clientInfo;
manager.GetEntry(clientInfo3.peer_node, clientInfo);
NL_TEST_ASSERT(apSuite, clientInfo.peer_node.GetNodeId() == nodeId1);
NL_TEST_ASSERT(apSuite, CHIP_ERROR_NOT_FOUND == manager.GetEntry(ScopedNodeId(unknownNodeId, fabricId), clientInfo));
// Make sure iterator counts correctly
auto * iterator = manager.IterateICDClientInfo();
// same nodeId for clientInfo2 and clientInfo3, so the new one replace old one
Expand Down
Loading