Skip to content

Commit f0176df

Browse files
authored
Rename files and API (#3)
* Rename files from "retry_utils" to "backoff_algorithm" * Rename API * Change "BackOff" to "Backoff" in API function name
1 parent caed843 commit f0176df

File tree

10 files changed

+162
-162
lines changed

10 files changed

+162
-162
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ jobs:
7272
- name: Clone This Repo
7373
uses: actions/checkout@v2
7474
with:
75-
path: libraries/standard/retry-utils
75+
path: libraries/standard/backoff-algorithm
7676
- name: Install spell
7777
run: |
7878
sudo apt-get install spell
7979
sudo apt-get install util-linux
8080
- name: Check spelling
8181
run: |
8282
PATH=$PATH:$PWD/tools/spell
83-
for lexfile in `find libraries/standard/retry-utils -name lexicon.txt`
83+
for lexfile in `find libraries/standard/backoff-algorithm -name lexicon.txt`
8484
do dir=${lexfile%/lexicon.txt}
8585
echo $dir
8686
find-unknown-comment-words --directory $dir

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Include file path configuration for retry utils library.
2-
include(retryUtilsFilePaths.cmake)
1+
# Include file path configuration for backoff algorithm library.
2+
include(BackoffAlgorithmFilePaths.cmake)
33

4-
# Library target for retry utils.
5-
add_library( retry_utils
6-
${RETRY_UTILS_SOURCES} )
4+
# Library target for backoff algorithm.
5+
add_library( backoff_algorithm
6+
${BACKOFF_ALGORITHM_SOURCES} )
77

8-
target_include_directories( retry_utils
8+
target_include_directories( backoff_algorithm
99
PUBLIC
10-
${RETRY_UTILS_INCLUDE_PUBLIC_DIRS} )
10+
${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} )
1111

1212
# Include unit tests.
1313
if(BUILD_TESTS)

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ More information about the algorithm can be seen in the [Exponential Backoff and
1010
The example below shows how to use the backoffAlgorithm library to retry a DNS resolution query for `amazon.com`.
1111

1212
```c
13-
#include "retry_utils.h"
13+
#include "backoff_algorithm.h"
1414
#include <stdlib.h>
1515
#include <string.h>
1616
#include <netdb.h>
@@ -49,8 +49,8 @@ static int32_t pseudoRng()
4949
int main()
5050
{
5151
/* Variables used in this example. */
52-
RetryUtilsStatus_t retryStatus = RetryUtilsSuccess;
53-
RetryUtilsContext_t retryParams;
52+
BackoffAlgorithmStatus_t retryStatus = BackoffAlgorithmSuccess;
53+
BackoffAlgorithmContext_t retryParams;
5454
char serverAddress[] = "amazon.com";
5555
uint16_t nextRetryBackOff = 0;
5656

@@ -68,7 +68,7 @@ int main()
6868
hints.ai_protocol = IPPROTO_TCP;
6969

7070
/* Initialize reconnect attempts and interval. */
71-
RetryUtils_InitializeParams( &retryParams,
71+
BackoffAlgorithm_InitializeParams( &retryParams,
7272
RETRY_BACKOFF_BASE_MS,
7373
RETRY_MAX_BACKOFF_DELAY_MS,
7474
RETRY_MAX_ATTEMPTS,
@@ -83,9 +83,9 @@ int main()
8383
if( dnsStatus != 0 )
8484
{
8585
/* Get back-off value (in milliseconds) for the next retry. */
86-
retryStatus = RetryUtils_GetNextBackOff( &retryParams, &nextRetryBackOff );
86+
retryStatus = BackoffAlgorithm_GetNextBackoff( &retryParams, &nextRetryBackOff );
8787
}
88-
} while( ( dnsStatus != 0 ) && ( retryStatus != RetryUtilsRetriesExhausted ) );
88+
} while( ( dnsStatus != 0 ) && ( retryStatus != BackoffAlgorithmRetriesExhausted ) );
8989

9090
return dnsStatus;
9191
}
@@ -97,13 +97,13 @@ A compiler that supports **C89 or later** such as *gcc* is required to build the
9797

9898
For instance, if the example above is copied to a file named `example.c`, *gcc* can be used like so:
9999
```bash
100-
gcc -I source/include example.c source/retry_utils.c -o example
100+
gcc -I source/include example.c source/backoff_algorithm.c -o example
101101
./example
102102
```
103103

104104
*gcc* can also produce an output file to be linked:
105105
```bash
106-
gcc -I source/include -c source/retry_utils.c
106+
gcc -I source/include -c source/backoff_algorithm.c
107107
```
108108

109109
## Building unit tests

backoffAlgorithmFilePaths.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# Files specific to the repository such as test runner, platform tests
66
# are not added to the variables.
77

8-
# Retry Utils library source files.
9-
set( RETRY_UTILS_SOURCES
10-
"${CMAKE_CURRENT_LIST_DIR}/source/retry_utils.c" )
8+
# Backoff Algorithm library source files.
9+
set( BACKOFF_ALGORITHM_SOURCES
10+
"${CMAKE_CURRENT_LIST_DIR}/source/backoff_algorithm.c" )
1111

12-
# Retry Utils library Public Include directories.
13-
set( RETRY_UTILS_INCLUDE_PUBLIC_DIRS
12+
# Backoff Algorithm library Public Include directories.
13+
set( BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS
1414
"${CMAKE_CURRENT_LIST_DIR}/source/include" )

lexicon.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ pnextbackoff
2525
pretrycontext
2626
pretryparams
2727
prng
28-
retryutilsretriesexhausted
29-
retryutilsrngfailure
30-
retryutilssuccess
28+
backoffalgorithmretriesexhausted
29+
backoffalgorithmrngfailure
30+
backoffalgorithmsuccess
3131
rng
3232
sdk
3333
shouldn

source/retry_utils.c renamed to source/backoff_algorithm.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222

2323
/**
24-
* @file retry_utils.c
25-
* @brief Implementation of the retry utils API for a "Full Jitter" exponential backoff
24+
* @file backoff_algorithm.c
25+
* @brief Implementation of the backoff algorithm API for a "Full Jitter" exponential backoff
2626
* with jitter strategy.
2727
*/
2828

@@ -31,29 +31,29 @@
3131
#include <assert.h>
3232

3333
/* Include API header. */
34-
#include "retry_utils.h"
34+
#include "backoff_algorithm.h"
3535

3636
/*-----------------------------------------------------------*/
3737

38-
RetryUtilsStatus_t RetryUtils_GetNextBackOff( RetryUtilsContext_t * pRetryContext,
39-
uint16_t * pNextBackOff )
38+
BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContext_t * pRetryContext,
39+
uint16_t * pNextBackOff )
4040
{
41-
RetryUtilsStatus_t status = RetryUtilsSuccess;
41+
BackoffAlgorithmStatus_t status = BackoffAlgorithmSuccess;
4242
int32_t randomVal = 0;
4343

4444
assert( pRetryContext != NULL );
4545
assert( pNextBackOff != NULL );
4646

47-
/* If RETRY_UTILS_RETRY_FOREVER is set to 0, try forever. */
47+
/* If BACKOFF_ALGORITHM_RETRY_FOREVER is set to 0, try forever. */
4848
if( ( pRetryContext->attemptsDone < pRetryContext->maxRetryAttempts ) ||
49-
( pRetryContext->maxRetryAttempts == RETRY_UTILS_RETRY_FOREVER ) )
49+
( pRetryContext->maxRetryAttempts == BACKOFF_ALGORITHM_RETRY_FOREVER ) )
5050
{
5151
/* Generate a random number. */
5252
randomVal = pRetryContext->pRng();
5353

5454
if( randomVal < 0 )
5555
{
56-
status = RetryUtilsRngFailure;
56+
status = BackoffAlgorithmRngFailure;
5757
}
5858
else
5959
{
@@ -81,21 +81,21 @@ RetryUtilsStatus_t RetryUtils_GetNextBackOff( RetryUtilsContext_t * pRetryContex
8181
else
8282
{
8383
/* When max retry attempts are exhausted, let application know by
84-
* returning RetryUtilsRetriesExhausted. Application may choose to
85-
* restart the retry process after calling RetryUtils_InitializeParams(). */
86-
status = RetryUtilsRetriesExhausted;
84+
* returning BackoffAlgorithmRetriesExhausted. Application may choose to
85+
* restart the retry process after calling BackoffAlgorithm_InitializeParams(). */
86+
status = BackoffAlgorithmRetriesExhausted;
8787
}
8888

8989
return status;
9090
}
9191

9292
/*-----------------------------------------------------------*/
9393

94-
void RetryUtils_InitializeParams( RetryUtilsContext_t * pContext,
95-
uint16_t backOffBase,
96-
uint16_t maxBackOff,
97-
uint32_t maxAttempts,
98-
RetryUtils_RNG_t pRng )
94+
void BackoffAlgorithm_InitializeParams( BackoffAlgorithmContext_t * pContext,
95+
uint16_t backOffBase,
96+
uint16_t maxBackOff,
97+
uint32_t maxAttempts,
98+
BackoffAlgorithm_RNG_t pRng )
9999
{
100100
assert( pContext != NULL );
101101

source/include/retry_utils.h renamed to source/include/backoff_algorithm.h

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
/**
24-
* @file retry_utils.h
24+
* @file backoff_algorithm.h
2525
* @brief Declaration of retry utility functions and constants for exponential backoff with
2626
* jitter strategy of retry attempts.
2727
* This library represents the "Full Jitter" backoff strategy explained in the
@@ -30,19 +30,19 @@
3030
*
3131
*/
3232

33-
#ifndef RETRY_UTILS_H_
34-
#define RETRY_UTILS_H_
33+
#ifndef BACKOFF_ALGORITHM_H_
34+
#define BACKOFF_ALGORITHM_H_
3535

3636
/* Standard include. */
3737
#include <stdint.h>
3838

3939
/**
40-
* @page retryutils_page Retry Utilities
41-
* @brief An abstraction of utilities for retrying with exponential back off and
42-
* jitter.
40+
* @page backoffalgorithm_page Backoff Algorithm
41+
* @brief Library for calculating backoff of retry attempts using exponential back off and
42+
* jitter algorithm.
4343
*
44-
* @section retryutils_overview Overview
45-
* The retry utilities are a set of APIs that aid in retrying with exponential
44+
* @section backoffalgorithm_overview Overview
45+
* The backoff algorithm library is a set of APIs that aid in retrying with exponential
4646
* backoff and jitter. Exponential backoff with jitter is strongly recommended
4747
* for retrying failed actions over the network with servers. Please see
4848
* https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ for
@@ -66,12 +66,12 @@
6666
/**
6767
* @brief Constant to represent unlimited number of retry attempts.
6868
*/
69-
#define RETRY_UTILS_RETRY_FOREVER 0
69+
#define BACKOFF_ALGORITHM_RETRY_FOREVER 0
7070

7171
/**
7272
* @brief Interface for a random number generator.
7373
* The user should supply the platform-specific random number generator to the
74-
* library through the @ref RetryUtils_InitializeParams API function.
74+
* library through the @ref BackoffAlgorithm_InitializeParams API function.
7575
*
7676
* @note It is recommended that a true random number generator is supplied
7777
* to the library. The random number generator should be seeded with an entropy
@@ -80,23 +80,23 @@
8080
* @return The random number if successful; otherwise a negative value to indicate
8181
* failure.
8282
*/
83-
typedef int32_t ( * RetryUtils_RNG_t )();
83+
typedef int32_t ( * BackoffAlgorithm_RNG_t )();
8484

8585
/**
86-
* @brief Status for @ref RetryUtils_GetNextBackOff.
86+
* @brief Status for @ref BackoffAlgorithm_GetNextBackoff.
8787
*/
88-
typedef enum RetryUtilsStatus
88+
typedef enum BackoffAlgorithmStatus
8989
{
90-
RetryUtilsSuccess = 0, /**< @brief The function successfully calculated the next back-off value. */
91-
RetryUtilsRngFailure = 1, /**< @brief The function encountered failure in generating random number. */
92-
RetryUtilsRetriesExhausted /**< @brief The function exhausted all retry attempts. */
93-
} RetryUtilsStatus_t;
90+
BackoffAlgorithmSuccess = 0, /**< @brief The function successfully calculated the next back-off value. */
91+
BackoffAlgorithmRngFailure = 1, /**< @brief The function encountered failure in generating random number. */
92+
BackoffAlgorithmRetriesExhausted /**< @brief The function exhausted all retry attempts. */
93+
} BackoffAlgorithmStatus_t;
9494

9595
/**
9696
* @brief Represents parameters required for calculating the back-off delay for the
9797
* next retry attempt.
9898
*/
99-
typedef struct RetryUtilsContext
99+
typedef struct BackoffAlgorithmContext
100100
{
101101
/**
102102
* @brief The maximum backoff delay (in milliseconds) between consecutive retry attempts.
@@ -105,7 +105,7 @@ typedef struct RetryUtilsContext
105105

106106
/**
107107
* @brief The total number of retry attempts completed.
108-
* This value is incremented on every call to #RetryUtils_GetNextBackOff API.
108+
* This value is incremented on every call to #BackoffAlgorithm_GetNextBackoff API.
109109
*/
110110
uint32_t attemptsDone;
111111

@@ -123,11 +123,11 @@ typedef struct RetryUtilsContext
123123
* @brief The random number generator function used for calculating the
124124
* backoff value for the next retry attempt.
125125
*/
126-
RetryUtils_RNG_t pRng;
127-
} RetryUtilsContext_t;
126+
BackoffAlgorithm_RNG_t pRng;
127+
} BackoffAlgorithmContext_t;
128128

129129
/**
130-
* @brief Initializes the context for using retry utils. The parameters
130+
* @brief Initializes the context for using backoff algorithm. The parameters
131131
* are required for calculating the next retry backoff delay.
132132
* This function must be called by the application before the first new retry attempt.
133133
*
@@ -138,17 +138,17 @@ typedef struct RetryUtilsContext
138138
* @param[in] backOffBase The base value (in milliseconds) of backoff delay to
139139
* use in the exponential backoff and jitter model.
140140
* @param[in] maxAttempts The maximum number of retry attempts. Set the value to
141-
* #RETRY_UTILS_RETRY_FOREVER to retry for ever.
141+
* #BACKOFF_ALGORITHM_RETRY_FOREVER to retry for ever.
142142
* @param[in] pRng The platform-specific function to use for random number generation.
143143
* The random number generator should be seeded before calling this function.
144144
*/
145-
/* @[define_retryutils_initializeparams] */
146-
void RetryUtils_InitializeParams( RetryUtilsContext_t * pContext,
147-
uint16_t backOffBase,
148-
uint16_t maxBackOff,
149-
uint32_t maxAttempts,
150-
RetryUtils_RNG_t pRng );
151-
/* @[define_retryutils_initializeparams] */
145+
/* @[define_backoffalgorithm_initializeparams] */
146+
void BackoffAlgorithm_InitializeParams( BackoffAlgorithmContext_t * pContext,
147+
uint16_t backOffBase,
148+
uint16_t maxBackOff,
149+
uint32_t maxAttempts,
150+
BackoffAlgorithm_RNG_t pRng );
151+
/* @[define_backoffalgorithm_initializeparams] */
152152

153153
/**
154154
* @brief Simple exponential backoff and jitter function that provides the
@@ -163,12 +163,12 @@ void RetryUtils_InitializeParams( RetryUtilsContext_t * pContext,
163163
* for the next retry attempt. The value does not exceed the maximum backoff delay
164164
* configured in the context.
165165
*
166-
* @return #RetryUtilsSuccess after a successful sleep, #RetryUtilsRngFailure for a failure
167-
* in random number generation, #RetryUtilsRetriesExhausted when all attempts are exhausted.
166+
* @return #BackoffAlgorithmSuccess after a successful sleep, #BackoffAlgorithmRngFailure for a failure
167+
* in random number generation, #BackoffAlgorithmRetriesExhausted when all attempts are exhausted.
168168
*/
169-
/* @[define_retryutils_getnextbackoff] */
170-
RetryUtilsStatus_t RetryUtils_GetNextBackOff( RetryUtilsContext_t * pRetryContext,
171-
uint16_t * pNextBackOff );
172-
/* @[define_retryutils_getnextbackoff] */
169+
/* @[define_BackoffAlgorithm_GetNextBackoff] */
170+
BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContext_t * pRetryContext,
171+
uint16_t * pNextBackOff );
172+
/* @[define_BackoffAlgorithm_GetNextBackoff] */
173173

174-
#endif /* ifndef RETRY_UTILS_H_ */
174+
#endif /* ifndef BACKOFF_ALGORITHM_H_ */

test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ include( ${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake )
3838

3939
# Target for Coverity analysis that builds the library.
4040
add_library( coverity_analysis
41-
${RETRY_UTILS_SOURCES} )
41+
${BACKOFF_ALGORITHM_SOURCES} )
4242

4343
# Backoff Algorithm library public include path.
4444
target_include_directories( coverity_analysis
4545
PUBLIC
46-
${RETRY_UTILS_INCLUDE_PUBLIC_DIRS} )
46+
${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} )
4747

4848
# ==================================== Unit Test Configuration ====================================
4949

@@ -82,6 +82,6 @@ add_subdirectory( unit-test )
8282
add_custom_target( coverage
8383
COMMAND ${CMAKE_COMMAND} -DUNITY_DIR=${UNITY_DIR}
8484
-P ${MODULE_ROOT_DIR}/tools/unity/coverage.cmake
85-
DEPENDS unity retry_utils_utest
85+
DEPENDS unity backoff_algorithm_utest
8686
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
8787
)

0 commit comments

Comments
 (0)