mirror of
https://github.com/espressif/openthread.git
synced 2026-08-17 16:09:51 +00:00
[srp-client] add random short delay before sending update message (#7863)
This commit updates the `Srp::Client` to add a randomly chosen short delay before delay wait time before sending an update message. This replaces the current model which was adding a fixed short delay. Selecting the delay randomly helps in situations where some common event triggers multiple SRP clients on Thread mesh to send an SRP update(e.g., new OMR prefix causing new addresses, or a server entry change on Thread Network Data).
This commit is contained in:
@@ -627,4 +627,9 @@
|
||||
#error "OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE was removed and no longer supported"
|
||||
#endif
|
||||
|
||||
#ifdef OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY
|
||||
#error "OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY was replaced with "\
|
||||
"OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY and OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY"
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_CORE_CONFIG_CHECK_H_
|
||||
|
||||
@@ -214,9 +214,11 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY
|
||||
* @def OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY
|
||||
*
|
||||
* Specifies the (short) delay (in msec) after an update is required before SRP client sends the update message.
|
||||
* Specifies the minimum value (in msec) for the short random delay wait time before sending an update message.
|
||||
*
|
||||
* The random delay is chosen uniformly from the min up to max value `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY`.
|
||||
*
|
||||
* When there is a change (e.g., a new service is added/removed) that requires an update, the SRP client will wait for
|
||||
* a short delay before preparing and sending an SRP update message to server. This allows user to provide more change
|
||||
@@ -225,8 +227,22 @@
|
||||
* delay timer.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY
|
||||
#define OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY 10
|
||||
#ifndef OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY
|
||||
#define OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY
|
||||
*
|
||||
* Specifies the maximum value (in msec) for the short random delay wait time before sending an update message.
|
||||
*
|
||||
* The random delay is chosen uniformly from the min `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY` up to max value.
|
||||
*
|
||||
* See `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY` for more details.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY
|
||||
#define OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY 700
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -690,7 +690,7 @@ void Client::SetState(State aState)
|
||||
break;
|
||||
|
||||
case kStateToUpdate:
|
||||
mTimer.Start(kUpdateTxDelay);
|
||||
mTimer.Start(Random::NonCrypto::GetUint32InRange(kUpdateTxMinDelay, kUpdateTxMaxDelay));
|
||||
break;
|
||||
|
||||
case kStateUpdating:
|
||||
|
||||
@@ -777,7 +777,8 @@ private:
|
||||
// delay as specified by `kUpdateTxDelay` before sending an SRP
|
||||
// update to server. This allows the user to provide more change
|
||||
// that are then all sent in same update message.
|
||||
static constexpr uint32_t kUpdateTxDelay = OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY; // in msec.
|
||||
static constexpr uint32_t kUpdateTxMinDelay = OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MIN_DELAY; // in msec.
|
||||
static constexpr uint32_t kUpdateTxMaxDelay = OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_MAX_DELAY; // in msec.
|
||||
|
||||
// -------------------------------
|
||||
// Retry related constants
|
||||
|
||||
Reference in New Issue
Block a user