]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
cc: Export sendme_inc validation into public function
authorDavid Goulet <dgoulet@torproject.org>
Thu, 3 Feb 2022 22:43:58 +0000 (22:43 +0000)
committerMike Perry <mikeperry-git@torproject.org>
Tue, 22 Feb 2022 19:28:34 +0000 (19:28 +0000)
This is needed for client validation of server descriptor value,
before launching a rend/intro.

src/core/or/congestion_control_common.c
src/core/or/congestion_control_common.h

index e999f435edba3b9cf4612ac625f5161d0d5a0518..6d4f34cff85a644552937f2254e9deab7f78d136 100644 (file)
@@ -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
index 21291983e060712cea2e6d2d86227cced52506b7..936cb5887c791ecf4139ad56daf18860228f14f9 100644 (file)
@@ -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. */