summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-02-03 22:43:58 +0000
committerMike Perry <mikeperry-git@torproject.org>2022-02-22 19:28:34 +0000
commit02f4e7b42e2158039a138c9cb68211304a754a1d (patch)
treed13724dc77a4d4c06acf3a5a8f9c6ec0e0dfc09c
parentbbf160d31199ffe75fac5b8921da904dbd45e2fb (diff)
downloadtor-02f4e7b42e2158039a138c9cb68211304a754a1d.tar.gz
tor-02f4e7b42e2158039a138c9cb68211304a754a1d.zip
cc: Export sendme_inc validation into public function
This is needed for client validation of server descriptor value, before launching a rend/intro.
-rw-r--r--src/core/or/congestion_control_common.c24
-rw-r--r--src/core/or/congestion_control_common.h1
2 files changed, 25 insertions, 0 deletions
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. */