summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArchit Aggarwal <architag@amazon.com>2020-11-30 11:12:07 -0800
committerGitHub <noreply@github.com>2020-11-30 11:12:07 -0800
commit682447445befbe01278328174a1aa507a00ec669 (patch)
tree518f80089ae93e364c462d3ef162999be8e95fff
parent220dd5cc1c388220171c0f38afda978d50b39c29 (diff)
downloadfreertos-git-682447445befbe01278328174a1aa507a00ec669.tar.gz
Bump backoffAlgorithm submodule for API change and update demos (#426)
The API of FreeRTOS/backoffAlgorithm library has changed to remove dependency on random number generator; instead require the caller to generate the random number and pass it to the BackoffAlgorithm_GetNextBackoff API for backoff period calculation. This PR updates the submodule pointer commit, and updates the demos and tests to use the simplied library API
-rwxr-xr-xFreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c17
-rw-r--r--FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/Common/http_demo_utils.c36
-rw-r--r--FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Basic_TLS/DemoTasks/BasicTLSMQTTExample.c59
-rw-r--r--FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Keep_Alive/DemoTasks/KeepAliveMQTTExample.c62
-rw-r--r--FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/MultitaskMQTTExample.c46
-rw-r--r--FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c62
-rw-r--r--FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/PlaintextMQTTExample.c62
-rw-r--r--FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Serializer/DemoTasks/SerializerMQTTExample.c62
m---------FreeRTOS-Plus/Source/Utilities/backoff_algorithm0
9 files changed, 120 insertions, 286 deletions
diff --git a/FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c b/FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c
index 20c3b3e11..a2751e88b 100755
--- a/FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c
+++ b/FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c
@@ -359,15 +359,11 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
#endif
xNetworkCredentials.pAlpnProtos = pcAlpnProtocols;
- /* Initialize reconnect attempts and interval.
- * Note: This utility uses a pseudo random number generator for use with the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ /* Initialize reconnect attempts and interval.*/
BackoffAlgorithm_InitializeParams( &xReconnectParams,
RETRY_BACKOFF_BASE_MS,
RETRY_MAX_BACKOFF_DELAY_MS,
- RETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ RETRY_MAX_ATTEMPTS );
/* Attempt to connect to MQTT broker. If connection fails, retry after
* a timeout. Timeout value will exponentially increase until maximum
@@ -390,9 +386,12 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
if( xNetworkStatus != TLS_TRANSPORT_SUCCESS )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/Common/http_demo_utils.c b/FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/Common/http_demo_utils.c
index 7ae825c7e..bbbbef353 100644
--- a/FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/Common/http_demo_utils.c
+++ b/FreeRTOS-Plus/Demo/coreHTTP_Windows_Simulator/Common/http_demo_utils.c
@@ -59,31 +59,6 @@
extern UBaseType_t uxRand();
/*-----------------------------------------------------------*/
-
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
-
-/*-----------------------------------------------------------*/
-
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
BaseType_t connectToServerWithBackoffRetries( TransportConnect_t connectFunction,
NetworkContext_t * pxNetworkContext )
{
@@ -100,8 +75,7 @@ BaseType_t connectToServerWithBackoffRetries( TransportConnect_t connectFunction
BackoffAlgorithm_InitializeParams( &xReconnectParams,
RETRY_BACKOFF_BASE_MS,
RETRY_MAX_BACKOFF_DELAY_MS,
- RETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ RETRY_MAX_ATTEMPTS );
/* Attempt to connect to the HTTP server. If connection fails, retry after a
* timeout. The timeout value will exponentially increase until either the
@@ -118,7 +92,13 @@ BaseType_t connectToServerWithBackoffRetries( TransportConnect_t connectFunction
LogInfo( ( "Retry attempt %lu out of maximum retry attempts %lu.",
( xReconnectParams.attemptsDone + 1 ),
RETRY_MAX_ATTEMPTS ) );
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextBackoff );
+
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextBackoff );
}
} while( ( xReturn == pdFAIL ) && ( xBackoffAlgStatus == BackoffAlgorithmSuccess ) );
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Basic_TLS/DemoTasks/BasicTLSMQTTExample.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Basic_TLS/DemoTasks/BasicTLSMQTTExample.c
index d797f2743..473f5b2ec 100644
--- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Basic_TLS/DemoTasks/BasicTLSMQTTExample.c
+++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Basic_TLS/DemoTasks/BasicTLSMQTTExample.c
@@ -1,5 +1,5 @@
/*
- * FreeRTOS Kernel V10.3.0
+ * FreeRTOS V202011.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -193,21 +193,6 @@
*/
static void prvMQTTDemoTask( void * pvParameters );
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
/**
* @brief Connect to MQTT broker with reconnection retries.
@@ -508,13 +493,6 @@ static void prvMQTTDemoTask( void * pvParameters )
}
/*-----------------------------------------------------------*/
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
-
static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredentials_t * pxNetworkCredentials,
NetworkContext_t * pxNetworkContext )
{
@@ -528,15 +506,11 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
pxNetworkCredentials->rootCaSize = sizeof( democonfigROOT_CA_PEM );
pxNetworkCredentials->disableSni = democonfigDISABLE_SNI;
- /* Initialize reconnect attempts and interval.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ /* Initialize reconnect attempts and interval.*/
BackoffAlgorithm_InitializeParams( &xReconnectParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNum );
+ mqttexampleRETRY_MAX_ATTEMPTS );
/* Attempt to connect to the MQTT broker. If connection fails, retry after
* a timeout. Timeout value will exponentially increase until maximum
@@ -560,9 +534,9 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
if( xNetworkStatus != TLS_TRANSPORT_SUCCESS )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
@@ -678,15 +652,11 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
xMQTTSubscription[ 0 ].pTopicFilter = mqttexampleTOPIC;
xMQTTSubscription[ 0 ].topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );
- /* Initialize context for backoff retry attempts if SUBSCRIBE request fails.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying network operations. */
+ /* Initialize context for backoff retry attempts if SUBSCRIBE request fails. */
BackoffAlgorithm_InitializeParams( &xRetryParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNum );
+ mqttexampleRETRY_MAX_ATTEMPTS );
do
{
@@ -729,9 +699,12 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
{
xFailedSubscribeToTopic = true;
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Keep_Alive/DemoTasks/KeepAliveMQTTExample.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Keep_Alive/DemoTasks/KeepAliveMQTTExample.c
index aade4aece..5e1673fca 100644
--- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Keep_Alive/DemoTasks/KeepAliveMQTTExample.c
+++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Keep_Alive/DemoTasks/KeepAliveMQTTExample.c
@@ -1,5 +1,5 @@
/*
- * FreeRTOS Kernel V10.3.0
+ * FreeRTOS V202011.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -215,21 +215,6 @@
*/
static void prvMQTTDemoTask( void * pvParameters );
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
/**
* @brief Connect to MQTT broker with reconnection retries.
@@ -634,13 +619,6 @@ static void prvMQTTDemoTask( void * pvParameters )
}
/*-----------------------------------------------------------*/
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
-
static PlaintextTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext_t * pxNetworkContext )
{
PlaintextTransportStatus_t xNetworkStatus;
@@ -648,15 +626,11 @@ static PlaintextTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkC
BackoffAlgorithmContext_t xReconnectParams;
uint16_t usNextRetryBackOff = 0U;
- /* Initialize reconnect attempts and interval.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ /* Initialize reconnect attempts and interval. */
BackoffAlgorithm_InitializeParams( &xReconnectParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
/* Attempt to connect to MQTT broker. If connection fails, retry after
* a timeout. Timeout value will exponentially increase till maximum
@@ -678,9 +652,12 @@ static PlaintextTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkC
if( xNetworkStatus != PLAINTEXT_TRANSPORT_SUCCESS )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
@@ -796,15 +773,11 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
xMQTTSubscription[ 0 ].pTopicFilter = mqttexampleTOPIC;
xMQTTSubscription[ 0 ].topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );
- /* Initialize context for backoff retry attempts if SUBSCRIBE request fails.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying network operations. */
+ /* Initialize context for backoff retry attempts if SUBSCRIBE request fails. */
BackoffAlgorithm_InitializeParams( &xRetryParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
do
{
@@ -864,9 +837,12 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
{
xFailedSubscribeToTopic = true;
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/MultitaskMQTTExample.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/MultitaskMQTTExample.c
index d4cd4f96b..afabdeeb7 100644
--- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/MultitaskMQTTExample.c
+++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/MultitaskMQTTExample.c
@@ -1,5 +1,5 @@
/*
- * FreeRTOS Kernel V10.3.0
+ * FreeRTOS V202011.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -19,8 +19,9 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
+ *
*/
/*
@@ -409,21 +410,6 @@ static MQTTStatus_t prvMQTTConnect( MQTTContext_t * pxMQTTContext,
*/
static MQTTStatus_t prvResumeSession( bool xSessionPresent );
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
/**
* @brief Form a TCP connection to a server.
@@ -988,13 +974,6 @@ static MQTTStatus_t prvResumeSession( bool xSessionPresent )
/*-----------------------------------------------------------*/
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
-
static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
{
BaseType_t xConnected = pdFAIL;
@@ -1037,15 +1016,11 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
#endif /* if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) */
/* We will use a retry mechanism with an exponential backoff mechanism and
- * jitter. We initialize the context required for backoff period calculation here.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ * jitter. We initialize the context required for backoff period calculation here. */
BackoffAlgorithm_InitializeParams( &xReconnectParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
/* Attempt to connect to MQTT broker. If connection fails, retry after a
* timeout. Timeout value will exponentially increase until the maximum
@@ -1081,9 +1056,12 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
if( !xConnected )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c
index 785b52c2d..ddc94a2b8 100644
--- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c
+++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c
@@ -1,5 +1,5 @@
/*
- * FreeRTOS Kernel V10.3.0
+ * FreeRTOS V202011.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -282,21 +282,6 @@
*/
static void prvMQTTDemoTask( void * pvParameters );
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
/**
* @brief Connect to MQTT broker with reconnection retries.
@@ -590,13 +575,6 @@ static void prvMQTTDemoTask( void * pvParameters )
}
/*-----------------------------------------------------------*/
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
-
static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredentials_t * pxNetworkCredentials,
NetworkContext_t * pxNetworkContext )
{
@@ -632,15 +610,11 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
pxNetworkCredentials->privateKeySize = sizeof( democonfigCLIENT_PRIVATE_KEY_PEM );
#endif
- /* Initialize reconnect attempts and interval.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ /* Initialize reconnect attempts and interval. */
BackoffAlgorithm_InitializeParams( &xReconnectParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
/* Attempt to connect to MQTT broker. If connection fails, retry after
* a timeout. Timeout value will exponentially increase till maximum
@@ -664,9 +638,12 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
if( xNetworkStatus != TLS_TRANSPORT_SUCCESS )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
@@ -805,15 +782,11 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
xMQTTSubscription[ 0 ].pTopicFilter = mqttexampleTOPIC;
xMQTTSubscription[ 0 ].topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );
- /* Initialize context for backoff retry attempts if SUBSCRIBE request fails.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying network operations. */
+ /* Initialize context for backoff retry attempts if SUBSCRIBE request fails. */
BackoffAlgorithm_InitializeParams( &xRetryParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
do
{
@@ -856,9 +829,12 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
{
xFailedSubscribeToTopic = true;
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/PlaintextMQTTExample.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/PlaintextMQTTExample.c
index da3975c76..a9f8fb95c 100644
--- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/PlaintextMQTTExample.c
+++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/PlaintextMQTTExample.c
@@ -1,5 +1,5 @@
/*
- * FreeRTOS Kernel V10.3.0
+ * FreeRTOS V202011.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -184,21 +184,6 @@
*/
static void prvMQTTDemoTask( void * pvParameters );
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
/**
* @brief Connect to MQTT broker with reconnection retries.
@@ -468,13 +453,6 @@ static void prvMQTTDemoTask( void * pvParameters )
}
/*-----------------------------------------------------------*/
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
-
static PlaintextTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext_t * pxNetworkContext )
{
PlaintextTransportStatus_t xNetworkStatus;
@@ -482,15 +460,11 @@ static PlaintextTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkC
BackoffAlgorithmContext_t xReconnectParams;
uint16_t usNextRetryBackOff = 0U;
- /* Initialize reconnect attempts and interval.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ /* Initialize reconnect attempts and interval.*/
BackoffAlgorithm_InitializeParams( &xReconnectParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
/* Attempt to connect to MQTT broker. If connection fails, retry after
* a timeout. Timeout value will exponentially increase till maximum
@@ -512,9 +486,12 @@ static PlaintextTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkC
if( xNetworkStatus != PLAINTEXT_TRANSPORT_SUCCESS )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
@@ -628,15 +605,11 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
xMQTTSubscription[ 0 ].pTopicFilter = mqttexampleTOPIC;
xMQTTSubscription[ 0 ].topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );
- /* Initialize context for backoff retry attempts if SUBSCRIBE request fails.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying network operations. */
+ /* Initialize context for backoff retry attempts if SUBSCRIBE request fails. */
BackoffAlgorithm_InitializeParams( &xRetryParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
do
{
@@ -679,9 +652,12 @@ static void prvMQTTSubscribeWithBackoffRetries( MQTTContext_t * pxMQTTContext )
{
xFailedSubscribeToTopic = true;
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Serializer/DemoTasks/SerializerMQTTExample.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Serializer/DemoTasks/SerializerMQTTExample.c
index b705eb5b8..1ea4eebec 100644
--- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Serializer/DemoTasks/SerializerMQTTExample.c
+++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Serializer/DemoTasks/SerializerMQTTExample.c
@@ -1,5 +1,5 @@
/*
- * FreeRTOS Kernel V10.3.0
+ * FreeRTOS V202011.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * http://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -189,21 +189,6 @@ static void prvMQTTDemoTask( void * pvParameters );
*/
static Socket_t prvCreateTCPConnectionToBroker( void );
-/**
- * @brief A wrapper to the "uxRand()" random number generator so that it
- * can be passed to the backoffAlgorithm library for retry logic.
- *
- * This function implements the #BackoffAlgorithm_RNG_T type interface
- * in the backoffAlgorithm library API.
- *
- * @note The "uxRand" function represents a pseudo random number generator.
- * However, it is recommended to use a True Randon Number Generator (TRNG)
- * for generating unique device-specific random values to avoid possibility
- * of network collisions from multiple devices retrying network operations.
- *
- * @return The generated randon number. This function ALWAYS succeeds.
- */
-static int32_t prvGenerateRandomNumber();
/**
* @brief Connect to MQTT broker with reconnection retries.
@@ -643,13 +628,6 @@ static Socket_t prvCreateTCPConnectionToBroker( void )
}
/*-----------------------------------------------------------*/
-static int32_t prvGenerateRandomNumber()
-{
- return( uxRand() & INT32_MAX );
-}
-
-/*-----------------------------------------------------------*/
-
static Socket_t prvConnectToServerWithBackoffRetries()
{
Socket_t xSocket;
@@ -657,15 +635,11 @@ static Socket_t prvConnectToServerWithBackoffRetries()
BackoffAlgorithmContext_t xReconnectParams;
uint16_t usNextRetryBackOff = 0U;
- /* Initialize reconnect attempts and interval.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying connection. */
+ /* Initialize reconnect attempts and interval.*/
BackoffAlgorithm_InitializeParams( &xReconnectParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
/* Attempt to connect to MQTT broker. If connection fails, retry after
* a timeout. Timeout value will exponentially increase till maximum
@@ -683,9 +657,12 @@ static Socket_t prvConnectToServerWithBackoffRetries()
if( xSocket == FREERTOS_INVALID_SOCKET )
{
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xReconnectParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
@@ -870,15 +847,11 @@ static void prvMQTTSubscribeWithBackoffRetries( Socket_t xMQTTSocket )
uint16_t usNextRetryBackOff = 0U;
bool xFailedSubscribeToTopic = false;
- /* Initialize context for backoff retry attempts if SUBSCRIBE request fails.
- * Note: This demo is using pseudo random number generator for the backoff
- * algorithm. However, it is recommended to use a True Random Number generator to
- * avoid possibility of collisions between multiple devices retrying network operations. */
+ /* Initialize context for backoff retry attempts if SUBSCRIBE request fails. */
BackoffAlgorithm_InitializeParams( &xRetryParams,
mqttexampleRETRY_BACKOFF_BASE_MS,
mqttexampleRETRY_MAX_BACKOFF_DELAY_MS,
- mqttexampleRETRY_MAX_ATTEMPTS,
- prvGenerateRandomNumber );
+ mqttexampleRETRY_MAX_ATTEMPTS );
do
{
@@ -916,9 +889,12 @@ static void prvMQTTSubscribeWithBackoffRetries( Socket_t xMQTTSocket )
{
xFailedSubscribeToTopic = true;
- /* Get back-off value (in milliseconds) for the next connection retry. */
- xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, &usNextRetryBackOff );
- configASSERT( xBackoffAlgStatus != BackoffAlgorithmRngFailure );
+ /* Generate a random number and calculate backoff value (in milliseconds) for
+ * the next connection retry.
+ * Note: It is recommended to seed the random number generator with a device-specific
+ * entropy source so that possibility of multiple devices retrying failed network operations
+ * at similar intervals can be avoided. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( &xRetryParams, uxRand(), &usNextRetryBackOff );
if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
{
diff --git a/FreeRTOS-Plus/Source/Utilities/backoff_algorithm b/FreeRTOS-Plus/Source/Utilities/backoff_algorithm
-Subproject bc5ce2ed93ac063d75a4d3661e5253477c4e4fe
+Subproject 8a9a6654296a3b478785eb5de4025b6d073a1ec