Skip to content

Commit 2353f02

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 2353f02

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 21 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,22 @@ 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+
// Upper bound on the download timeout.
62+
constexpr System::Clock::Timeout kMaxDownloadTimeout = System::Clock::Seconds32(5 * 60);
63+
64+
static System::Clock::Timeout ComputeDownloadTimeout(const SessionHandle & session)
65+
{
66+
System::Clock::Timeout roundTrip = session->ComputeRoundTripTimeout(kExpectedProviderProcessingTime, true);
67+
System::Clock::Timeout timeout = std::min(roundTrip * kDownloadTimeoutRoundTrips, kMaxDownloadTimeout);
68+
69+
return timeout;
70+
}
5571

5672
static void LogQueryImageResponse(const QueryImageResponse::DecodableType & response)
5773
{
@@ -831,7 +847,9 @@ CHIP_ERROR DefaultOTARequestor::StartDownload(Messaging::ExchangeManager & excha
831847
mBdxDownloader->SetMessageDelegate(&mBdxMessenger);
832848
mBdxDownloader->SetStateDelegate(this);
833849

834-
CHIP_ERROR err = mBdxDownloader->SetBDXParams(initOptions, kDownloadTimeoutSec);
850+
const System::Clock::Timeout downloadTimeout = ComputeDownloadTimeout(sessionHandle);
851+
852+
CHIP_ERROR err = mBdxDownloader->SetBDXParams(initOptions, downloadTimeout);
835853
if (err == CHIP_NO_ERROR)
836854
{
837855
err = mBdxDownloader->BeginPrepareDownload();

0 commit comments

Comments
 (0)