Skip to content

Commit b0f4ca0

Browse files
Address comments and apply suggestions from code review
Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 5f31784 commit b0f4ca0

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/app/ReadHandler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,11 @@ void ReadHandler::ClearStateFlag(ReadHandlerFlags aFlag)
921921

922922
size_t ReadHandler::GetReportBufferMaxSize()
923923
{
924-
size_t maxBufSize = chip::app::kMaxSecureSduLengthBytes;
924+
size_t maxBufSize = kMaxSecureSduLengthBytes;
925925
Transport::SecureSession * session = GetSession();
926926
if (session && session->AllowsLargePayload())
927927
{
928-
maxBufSize = chip::app::kMaxLargeSecureSduLengthBytes;
928+
maxBufSize = kMaxLargeSecureSduLengthBytes;
929929
}
930930

931931
return maxBufSize;

src/app/ReadHandler.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ class ReadHandler : public Messaging::ExchangeDelegate
335335

336336
/*
337337
* Get the appropriate size of a packet buffer to allocate for encoding a Report message.
338-
* Depending on the underlying session, which may or may not support large
339-
* payloads, a buffer with the corresponding max size would be allocated.
338+
* This size might depend on the underlying session used by the ReadHandler.
340339
*
340+
* The size returned here is the size not including the various prepended headers
341+
* (what System::PacketBuffer calls the "available size").
341342
*/
342343
size_t GetReportBufferMaxSize();
343344

src/app/reporting/Engine.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
496496
uint16_t reservedSize = 0;
497497
bool hasMoreChunks = false;
498498
bool needCloseReadHandler = false;
499-
size_t maxSduSize = 0;
499+
size_t reportBufferMaxSize = 0;
500500

501501
// Reserved size for the MoreChunks boolean flag, which takes up 1 byte for the control tag and 1 byte for the context tag.
502502
const uint32_t kReservedSizeForMoreChunksFlag = 1 + 1;
@@ -514,16 +514,14 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
514514
VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
515515
VerifyOrExit(apReadHandler->GetSession() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
516516

517-
// Depending on whether the session supports large payload or not, the
518-
// appropriate max size would be returned for the Report buffer.
519-
maxSduSize = apReadHandler->GetReportBufferMaxSize();
517+
reportBufferMaxSize = apReadHandler->GetReportBufferMaxSize();
520518

521-
bufHandle = System::PacketBufferHandle::New(maxSduSize);
519+
bufHandle = System::PacketBufferHandle::New(reportBufferMaxSize);
522520
VerifyOrExit(!bufHandle.IsNull(), err = CHIP_ERROR_NO_MEMORY);
523521

524-
if (bufHandle->AvailableDataLength() > maxSduSize)
522+
if (bufHandle->AvailableDataLength() > reportBufferMaxSize)
525523
{
526-
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - maxSduSize);
524+
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - reportBufferMaxSize);
527525
}
528526

529527
reportDataWriter.Init(std::move(bufHandle));
@@ -532,8 +530,8 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
532530
reportDataWriter.ReserveBuffer(mReservedSize);
533531
#endif
534532

535-
// Always limit the size of the generated packet to fit within kMaxSecureSduLengthBytes regardless of the available buffer
536-
// capacity.
533+
// Always limit the size of the generated packet to fit within the max size returned by the ReadHandler regardless
534+
// of the available buffer capacity.
537535
// Also, we need to reserve some extra space for the MIC field.
538536
reportDataWriter.ReserveBuffer(static_cast<uint32_t>(reservedSize + chip::Crypto::CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES));
539537

0 commit comments

Comments
 (0)