commit 33d8974f4d6b3697f021ece1b9b12a9b8c69e4b5
parent 8f9cf1ec4341f23c6a09c4f8194eb0c546cdb187
Author: Mike Perry <mikeperry-git@torproject.org>
Date: Sat, 21 Aug 2021 00:02:30 +0000
Export the n_ewma function for flow control use.
Diffstat:
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
@@ -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
@@ -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