[srp-client] apply short random jitter to lease renew time (#10473)

This commit updates `Srp::Client` to apply a short random jitter
(15 seconds) when calculating the lease renew time. The lease is
renewed close to its expiration, using a guard interval of 120
seconds (renewing 120 seconds before expiration). The jitter is added
to distribute client refreshes, in case many clients registered their
services around the same time.
This commit is contained in:
Abtin Keshavarzian
2024-07-05 12:40:00 -07:00
committed by GitHub
parent 71dd8a2d3a
commit 4c0d8f2e59
2 changed files with 9 additions and 4 deletions
+6 -4
View File
@@ -1857,12 +1857,14 @@ void Client::ProcessResponse(Message &aMessage)
// and the lease time. `kLeaseRenewGuardInterval` is used to // and the lease time. `kLeaseRenewGuardInterval` is used to
// ensure that we renew the lease before server expires it. In the // ensure that we renew the lease before server expires it. In the
// unlikely (but maybe useful for testing) case where the accepted // unlikely (but maybe useful for testing) case where the accepted
// lease interval is too short (shorter than the guard time) we // lease interval is too short (shorter than twice the guard time)
// just use half of the accepted lease interval. // we just use half of the accepted lease interval.
if (mLease > kLeaseRenewGuardInterval) if (mLease > 2 * kLeaseRenewGuardInterval)
{ {
mLeaseRenewTime += Time::SecToMsec(mLease - kLeaseRenewGuardInterval); uint32_t interval = Time::SecToMsec(mLease - kLeaseRenewGuardInterval);
mLeaseRenewTime += Random::NonCrypto::AddJitter(interval, kLeaseRenewJitter);
} }
else else
{ {
+3
View File
@@ -829,6 +829,9 @@ private:
// to renew the lease. Value is in seconds. // to renew the lease. Value is in seconds.
static constexpr uint32_t kLeaseRenewGuardInterval = OPENTHREAD_CONFIG_SRP_CLIENT_LEASE_RENEW_GUARD_INTERVAL; static constexpr uint32_t kLeaseRenewGuardInterval = OPENTHREAD_CONFIG_SRP_CLIENT_LEASE_RENEW_GUARD_INTERVAL;
// Lease renew time jitter (in msec).
static constexpr uint16_t kLeaseRenewJitter = 15 * 1000; // 15 second
// Max allowed lease time to avoid timer roll-over (~24.8 days). // Max allowed lease time to avoid timer roll-over (~24.8 days).
static constexpr uint32_t kMaxLease = (Timer::kMaxDelay / 1000) - 1; static constexpr uint32_t kMaxLease = (Timer::kMaxDelay / 1000) - 1;