Skip to content

Commit

Permalink
Store fewer things as part of the fabric table. (#15840)
Browse files Browse the repository at this point in the history
The node id and fabric id are part of the NOC, so we don't need to
store them seaparately.

And the fabric index is 8-bit; there's no need to store a 16-bit
quantity for it.
  • Loading branch information
bzbarsky-apple authored Mar 4, 2022
1 parent 8fce49d commit 5ade766
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 5 additions & 10 deletions src/credentials/FabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ CHIP_ERROR FabricInfo::CommitToStorage(FabricStorage * storage)
StorableFabricInfo * info = chip::Platform::New<StorableFabricInfo>();
ReturnErrorCodeIf(info == nullptr, CHIP_ERROR_NO_MEMORY);

info->mNodeId = Encoding::LittleEndian::HostSwap64(mOperationalId.GetNodeId());
info->mFabric = Encoding::LittleEndian::HostSwap16(mFabric);
info->mVendorId = Encoding::LittleEndian::HostSwap16(mVendorId);

info->mFabricId = Encoding::LittleEndian::HostSwap64(mFabricId);
info->mFabricIndex = mFabric;
info->mVendorId = Encoding::LittleEndian::HostSwap16(mVendorId);

size_t stringLength = strnlen(mFabricLabel, kFabricLabelMaxLengthInBytes);
memcpy(info->mFabricLabel, mFabricLabel, stringLength);
Expand Down Expand Up @@ -130,17 +127,14 @@ CHIP_ERROR FabricInfo::LoadFromStorage(FabricStorage * storage)

uint16_t infoSize = sizeof(StorableFabricInfo);

uint16_t id;
FabricIndex id;
uint16_t rootCertLen, icaCertLen, nocCertLen;
size_t stringLength;

NodeId nodeId;

SuccessOrExit(err = storage->SyncLoad(mFabric, key, info, infoSize));

mFabricId = Encoding::LittleEndian::HostSwap64(info->mFabricId);
nodeId = Encoding::LittleEndian::HostSwap64(info->mNodeId);
id = Encoding::LittleEndian::HostSwap16(info->mFabric);
id = info->mFabricIndex;
mVendorId = Encoding::LittleEndian::HostSwap16(info->mVendorId);
rootCertLen = Encoding::LittleEndian::HostSwap16(info->mRootCertLen);
icaCertLen = Encoding::LittleEndian::HostSwap16(info->mICACertLen);
Expand Down Expand Up @@ -174,6 +168,7 @@ CHIP_ERROR FabricInfo::LoadFromStorage(FabricStorage * storage)
// The compressed fabric ID doesn't change for a fabric over time.
// Computing it here will save computational overhead when it's accessed by other
// parts of the code.
SuccessOrExit(err = ExtractNodeIdFabricIdFromOpCert(ByteSpan(info->mNOCCert, nocCertLen), &nodeId, &mFabricId));
SuccessOrExit(err = GetCompressedId(mFabricId, nodeId, &mOperationalId));

SuccessOrExit(err = SetICACert(ByteSpan(info->mICACert, icaCertLen)));
Expand Down
4 changes: 1 addition & 3 deletions src/credentials/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ class DLL_EXPORT FabricInfo

struct StorableFabricInfo
{
uint16_t mFabric; /* This field is serialized in LittleEndian byte order */
uint64_t mNodeId; /* This field is serialized in LittleEndian byte order */
uint64_t mFabricId; /* This field is serialized in LittleEndian byte order */
uint8_t mFabricIndex;
uint16_t mVendorId; /* This field is serialized in LittleEndian byte order */

uint16_t mRootCertLen; /* This field is serialized in LittleEndian byte order */
Expand Down

0 comments on commit 5ade766

Please sign in to comment.