Skip to content

Commit d92ebd4

Browse files
[nrf toup] Derive BDX download timeout from session round trip
The OTA requestor used a fixed five-minute BDX download timeout, which is far too long for sessions with short retransmission intervals and does not adapt to the peer's advertised session parameters. Compute the timeout from the session round trip time plus the expected provider processing time. Signed-off-by: Dominik Michalczyk <dominik.michalczyk@nordicsemi.no>
1 parent 9775b2c commit d92ebd4

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

‎src/app/clusters/ota-requestor/DefaultOTARequestor.cpp‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "BDXDownloader.h"
3232
#include "DefaultOTARequestor.h"
3333

34+
#include <algorithm>
35+
3436
namespace chip {
3537

3638
using namespace app;
@@ -50,8 +52,26 @@ OTARequestorInterface * globalOTARequestorInstance = nullptr;
5052
// Global callback to call when globalOTARequestorInstance is set.
5153
void (*gInternalOnSetRequestorInstance)(OTARequestorInterface * instance) = nullptr;
5254

53-
// Abort the QueryImage download request if there's been no progress for 5 minutes
54-
static constexpr System::Clock::Timeout kDownloadTimeoutSec = chip::System::Clock::Seconds32(5 * 60);
55+
// Maximum expected time for the provider to produce a BDX block.
56+
constexpr System::Clock::Timeout kExpectedProviderProcessingTime = System::Clock::Seconds16(2);
57+
58+
// Number of round trips without any BDX progress that is treated as a stalled download.
59+
constexpr uint32_t kDownloadTimeoutRoundTrips = 2;
60+
61+
// Lower bound on the download timeout.
62+
constexpr System::Clock::Timeout kMinDownloadTimeout = System::Clock::Seconds16(10);
63+
64+
// Upper bound on the download timeout.
65+
constexpr System::Clock::Timeout kMaxDownloadTimeout = System::Clock::Seconds32(5 * 60);
66+
67+
static System::Clock::Timeout ComputeDownloadTimeout(const SessionHandle & session)
68+
{
69+
System::Clock::Timeout roundTrip = session->ComputeRoundTripTimeout(kExpectedProviderProcessingTime, true);
70+
System::Clock::Timeout timeout =
71+
std::clamp(roundTrip * kDownloadTimeoutRoundTrips, kMinDownloadTimeout, kMaxDownloadTimeout);
72+
73+
return timeout;
74+
}
5575

5676
static void LogQueryImageResponse(const QueryImageResponse::DecodableType & response)
5777
{
@@ -831,7 +851,9 @@ CHIP_ERROR DefaultOTARequestor::StartDownload(Messaging::ExchangeManager & excha
831851
mBdxDownloader->SetMessageDelegate(&mBdxMessenger);
832852
mBdxDownloader->SetStateDelegate(this);
833853

834-
CHIP_ERROR err = mBdxDownloader->SetBDXParams(initOptions, kDownloadTimeoutSec);
854+
const System::Clock::Timeout downloadTimeout = ComputeDownloadTimeout(sessionHandle);
855+
856+
CHIP_ERROR err = mBdxDownloader->SetBDXParams(initOptions, downloadTimeout);
835857
if (err == CHIP_NO_ERROR)
836858
{
837859
err = mBdxDownloader->BeginPrepareDownload();

0 commit comments

Comments
 (0)