[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/main] cc: Export sendme_inc validation into public function



commit 02f4e7b42e2158039a138c9cb68211304a754a1d
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Thu Feb 3 22:43:58 2022 +0000

    cc: Export sendme_inc validation into public function
    
    This is needed for client validation of server descriptor value,
    before launching a rend/intro.
---
 src/core/or/congestion_control_common.c | 24 ++++++++++++++++++++++++
 src/core/or/congestion_control_common.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/src/core/or/congestion_control_common.c b/src/core/or/congestion_control_common.c
index e999f435ed..6d4f34cff8 100644
--- a/src/core/or/congestion_control_common.c
+++ b/src/core/or/congestion_control_common.c
@@ -1312,6 +1312,30 @@ congestion_control_build_ext_response(const circuit_params_t *our_params,
   return (int)ret;
 }
 
+/** Return true iff the given sendme increment is within the acceptable
+ * margins. */
+bool
+congestion_control_validate_sendme_increment(uint8_t sendme_inc)
+{
+  /* We will only accept this response (and this circuit) if sendme_inc
+   * is within a factor of 2 of our consensus value. We should not need
+   * to change cc_sendme_inc much, and if we do, we can spread out those
+   * changes over smaller increments once every 4 hours. Exits that
+   * violate this range should just not be used. */
+#define MAX_SENDME_INC_NEGOTIATE_FACTOR 2
+
+  if (sendme_inc == 0)
+    return false;
+
+  if (sendme_inc >
+      MAX_SENDME_INC_NEGOTIATE_FACTOR * congestion_control_sendme_inc() ||
+      sendme_inc <
+      congestion_control_sendme_inc() / MAX_SENDME_INC_NEGOTIATE_FACTOR) {
+    return false;
+  }
+  return true;
+}
+
 /** Return 1 if CC is enabled which also will set the SENDME increment into our
  * params_out. Return 0 if CC is disabled. Else, return -1 on error. */
 int
diff --git a/src/core/or/congestion_control_common.h b/src/core/or/congestion_control_common.h
index 21291983e0..936cb5887c 100644
--- a/src/core/or/congestion_control_common.h
+++ b/src/core/or/congestion_control_common.h
@@ -59,6 +59,7 @@ int congestion_control_build_ext_response(const circuit_params_t *our_params,
 int congestion_control_parse_ext_response(const uint8_t *msg,
                                           const size_t msg_len,
                                           circuit_params_t *params_out);
+bool congestion_control_validate_sendme_increment(uint8_t sendme_inc);
 
 /* Ugh, C.. these are private. Use the getter instead, when
  * external to the congestion control code. */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits