]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Export the n_ewma function for flow control use.
authorMike Perry <mikeperry-git@torproject.org>
Sat, 21 Aug 2021 00:02:30 +0000 (00:02 +0000)
committerMike Perry <mikeperry-git@torproject.org>
Tue, 28 Sep 2021 21:39:36 +0000 (21:39 +0000)
src/core/or/congestion_control_common.c
src/core/or/congestion_control_common.h

index edb65d2b70b3de2329a77f5e430f4613b632d41c..fa603e8df8cf92b55ef6d7a124246f1fd40f83d5 100644 (file)
@@ -224,24 +224,6 @@ congestion_control_free_(congestion_control_t *cc)
   tor_free(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.
  */
index 12da0cb4e04f9b10844e6887f8758938d4d70d11..e8b9681ac622fbc3ac2fad466c3469ff2de71d8b 100644 (file)
@@ -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