diff options
author | Mike Perry <mikeperry-git@torproject.org> | 2021-08-21 00:02:30 +0000 |
---|---|---|
committer | Mike Perry <mikeperry-git@torproject.org> | 2021-09-28 21:39:36 +0000 |
commit | 33d8974f4d6b3697f021ece1b9b12a9b8c69e4b5 (patch) | |
tree | 276c41af143963786532fdb9aae5d8e941a9bcfe | |
parent | 8f9cf1ec4341f23c6a09c4f8194eb0c546cdb187 (diff) | |
download | tor-33d8974f4d6b3697f021ece1b9b12a9b8c69e4b5.tar.gz tor-33d8974f4d6b3697f021ece1b9b12a9b8c69e4b5.zip |
Export the n_ewma function for flow control use.
-rw-r--r-- | src/core/or/congestion_control_common.c | 18 | ||||
-rw-r--r-- | src/core/or/congestion_control_common.h | 18 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/core/or/congestion_control_common.c b/src/core/or/congestion_control_common.c index edb65d2b70..fa603e8df8 100644 --- a/src/core/or/congestion_control_common.c +++ b/src/core/or/congestion_control_common.c @@ -225,24 +225,6 @@ congestion_control_free_(congestion_control_t *cc) } /** - * Compute an N-count EWMA, aka N-EWMA. N-EWMA is defined as: - * EWMA = alpha*value + (1-alpha)*EWMA_prev - * with alpha = 2/(N+1). - * - * This works out to: - * EWMA = value*2/(N+1) + EMA_prev*(N-1)/(N+1) - * = (value*2 + EWMA_prev*(N-1))/(N+1) - */ -static inline uint64_t -n_count_ewma(uint64_t curr, uint64_t prev, uint64_t N) -{ - if (prev == 0) - return curr; - else - return (2*curr + (N-1)*prev)/(N+1); -} - -/** * Enqueue a u64 timestamp to the end of a queue of timestamps. */ static inline void diff --git a/src/core/or/congestion_control_common.h b/src/core/or/congestion_control_common.h index 12da0cb4e0..e8b9681ac6 100644 --- a/src/core/or/congestion_control_common.h +++ b/src/core/or/congestion_control_common.h @@ -41,6 +41,24 @@ int sendme_get_inc_count(const circuit_t *, const crypt_path_t *); bool circuit_sent_cell_for_sendme(const circuit_t *, const crypt_path_t *); bool is_monotime_clock_reliable(void); +/** + * Compute an N-count EWMA, aka N-EWMA. N-EWMA is defined as: + * EWMA = alpha*value + (1-alpha)*EWMA_prev + * with alpha = 2/(N+1). + * + * This works out to: + * EWMA = value*2/(N+1) + EMA_prev*(N-1)/(N+1) + * = (value*2 + EWMA_prev*(N-1))/(N+1) + */ +static inline uint64_t +n_count_ewma(uint64_t curr, uint64_t prev, uint64_t N) +{ + if (prev == 0) + return curr; + else + return (2*curr + (N-1)*prev)/(N+1); +} + /* Private section starts. */ #ifdef TOR_CONGESTION_CONTROL_PRIVATE |