Skip to content

Commit

Permalink
ReadHandler changes for large payloads
Browse files Browse the repository at this point in the history
When sending reports, if the session established with the peer
supports large payloads, the ReadHandler will allocate a large
buffer to, potentially, fit more attribute and event data.
  • Loading branch information
pidarped committed Jun 8, 2024
1 parent 5ee4ef6 commit 9e4dac0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest
return Status::ResourceExhausted;
}

if (apExchangeContext->GetSessionHandle()->AllowsLargePayload())
{
handler->UseLargePayloadBuffer();
}

handler->OnInitialRequest(std::move(aPayload));

return Status::Success;
Expand Down
6 changes: 6 additions & 0 deletions src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ class ReadHandler : public Messaging::ExchangeDelegate
/// @param aFlag Flag to clear
void ClearStateFlag(ReadHandlerFlags aFlag);


void UseLargePayloadBuffer() { mUseLargePayloadBuffer = true; }
bool ShouldUseLargePayloadBuffer() { return mUseLargePayloadBuffer; }

AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr);

// The current generation of the reporting engine dirty set the last time we were notified that a path we're interested in was
Expand Down Expand Up @@ -572,6 +576,8 @@ class ReadHandler : public Messaging::ExchangeDelegate

// TODO (#27675): Merge all observers into one and that one will dispatch the callbacks to the right place.
Observer * mObserver = nullptr;

bool mUseLargePayloadBuffer = false;
};
} // namespace app
} // namespace chip
1 change: 1 addition & 0 deletions src/app/StatusResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace chip {
namespace app {
static constexpr size_t kMaxSecureSduLengthBytes = kMaxAppMessageLen + kMaxTagLen;
static constexpr size_t kMaxLargeSecureSduLengthBytes = kMaxLargeAppMessageLen + kMaxTagLen;

class StatusResponse
{
Expand Down
20 changes: 14 additions & 6 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,11 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
CHIP_ERROR err = CHIP_NO_ERROR;
chip::System::PacketBufferTLVWriter reportDataWriter;
ReportDataMessage::Builder reportDataBuilder;
chip::System::PacketBufferHandle bufHandle = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes);
uint16_t reservedSize = 0;
bool hasMoreChunks = false;
bool needCloseReadHandler = false;
size_t maxSduSize = chip::app::kMaxSecureSduLengthBytes;
chip::System::PacketBufferHandle bufHandle = nullptr;
uint16_t reservedSize = 0;
bool hasMoreChunks = false;
bool needCloseReadHandler = false;

// Reserved size for the MoreChunks boolean flag, which takes up 1 byte for the control tag and 1 byte for the context tag.
const uint32_t kReservedSizeForMoreChunksFlag = 1 + 1;
Expand All @@ -512,11 +513,18 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)

VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(apReadHandler->GetSession() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

if (apReadHandler->ShouldUseLargePayloadBuffer())
{
maxSduSize = chip::app::kMaxLargeSecureSduLengthBytes;
}

bufHandle = System::PacketBufferHandle::New(maxSduSize);
VerifyOrExit(!bufHandle.IsNull(), err = CHIP_ERROR_NO_MEMORY);

if (bufHandle->AvailableDataLength() > kMaxSecureSduLengthBytes)
if (bufHandle->AvailableDataLength() > maxSduSize)
{
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - kMaxSecureSduLengthBytes);
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - maxSduSize);
}

reportDataWriter.Init(std::move(bufHandle));
Expand Down

0 comments on commit 9e4dac0

Please sign in to comment.