]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Turn orconn watermarks into consensus parameters.
authorMike Perry <mikeperry-git@torproject.org>
Tue, 28 Sep 2021 21:19:27 +0000 (21:19 +0000)
committerDavid Goulet <dgoulet@torproject.org>
Mon, 4 Oct 2021 14:45:46 +0000 (10:45 -0400)
Tuning these may reduce memory usage and latency.

src/app/main/main.c
src/core/or/channeltls.c
src/core/or/congestion_control_common.c
src/core/or/congestion_control_common.h
src/core/or/connection_or.c
src/core/or/or.h
src/feature/nodelist/networkstatus.c
src/test/test_channeltls.c

index 0742abe70a07a92ac3c3e24de206433106067ce5..6043b9589f6a7a6d36d634eed028f4911cf21d4a 100644 (file)
@@ -27,6 +27,7 @@
 #include "core/or/channel.h"
 #include "core/or/channelpadding.h"
 #include "core/or/circuitpadding.h"
+#include "core/or/congestion_control_common.h"
 #include "core/or/congestion_control_flow.h"
 #include "core/or/circuitlist.h"
 #include "core/or/command.h"
@@ -631,6 +632,7 @@ tor_init(int argc, char *argv[])
    * until we get a consensus */
   channelpadding_new_consensus_params(NULL);
   circpad_new_consensus_params(NULL);
+  congestion_control_new_consensus_params(NULL);
   flow_control_new_consensus_params(NULL);
 
   /* Initialize circuit padding to defaults+torrc until we get a consensus */
index 481dafef910d0b3c5983abf77fbe3ea480090206..9db8e2392dab70a7c235798e0f9bbb5f6d4a604e 100644 (file)
@@ -64,6 +64,7 @@
 #include "trunnel/netinfo.h"
 #include "core/or/channelpadding.h"
 #include "core/or/extendinfo.h"
+#include "core/or/congestion_control_common.h"
 
 #include "core/or/cell_st.h"
 #include "core/or/cell_queue_st.h"
@@ -793,7 +794,7 @@ channel_tls_num_cells_writeable_method(channel_t *chan)
   cell_network_size = get_cell_network_size(tlschan->conn->wide_circ_ids);
   outbuf_len = connection_get_outbuf_len(TO_CONN(tlschan->conn));
   /* Get the number of cells */
-  n = CEIL_DIV(OR_CONN_HIGHWATER - outbuf_len, cell_network_size);
+  n = CEIL_DIV(or_conn_highwatermark() - outbuf_len, cell_network_size);
   if (n < 0) n = 0;
 #if SIZEOF_SIZE_T > SIZEOF_INT
   if (n > INT_MAX) n = INT_MAX;
index 51691c106da9c74d8350c471a551d63ffe8899e3..393b79459de4dbd91898ac57fa9d57280d7d4896 100644 (file)
@@ -46,6 +46,9 @@
 
 #define BWE_SENDME_MIN_DFLT   5
 
+#define OR_CONN_HIGHWATER_DFLT (32*1024)
+#define OR_CONN_LOWWATER_DFLT (16*1024)
+
 static uint64_t congestion_control_update_circuit_rtt(congestion_control_t *,
                                                       uint64_t);
 static bool congestion_control_update_circuit_bdp(congestion_control_t *,
@@ -53,6 +56,34 @@ static bool congestion_control_update_circuit_bdp(congestion_control_t *,
                                                   const crypt_path_t *,
                                                   uint64_t, uint64_t);
 
+static uint32_t cwnd_max = CWND_MAX_DFLT;
+uint32_t or_conn_highwater = OR_CONN_HIGHWATER_DFLT;
+uint32_t or_conn_lowwater = OR_CONN_LOWWATER_DFLT;
+
+/**
+ * Update global congestion control related consensus parameter values,
+ * every consensus update.
+ */
+void
+congestion_control_new_consensus_params(const networkstatus_t *ns)
+{
+#define OR_CONN_HIGHWATER_MIN (CELL_PAYLOAD_SIZE)
+#define OR_CONN_HIGHWATER_MAX (INT32_MAX)
+  or_conn_highwater =
+    networkstatus_get_param(ns, "orconn_high",
+        OR_CONN_HIGHWATER_DFLT,
+        OR_CONN_HIGHWATER_MIN,
+        OR_CONN_HIGHWATER_MAX);
+
+#define OR_CONN_LOWWATER_MIN (CELL_PAYLOAD_SIZE)
+#define OR_CONN_LOWWATER_MAX (INT32_MAX)
+  or_conn_lowwater =
+    networkstatus_get_param(ns, "orconn_low",
+        OR_CONN_LOWWATER_DFLT,
+        OR_CONN_LOWWATER_MIN,
+        OR_CONN_LOWWATER_MAX);
+}
+
 /**
  * Set congestion control parameters on a circuit's congestion
  * control object based on values from the consensus.
index e8b9681ac622fbc3ac2fad466c3469ff2de71d8b..02fee78013f6dece04e7f0b27fad9bb924ebf405 100644 (file)
@@ -41,6 +41,27 @@ 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);
 
+void congestion_control_new_consensus_params(const networkstatus_t *ns);
+
+/* Ugh, C.. these two are private. Use the getter instead, when
+ * external to the congestion control code. */
+extern uint32_t or_conn_highwater;
+extern uint32_t or_conn_lowwater;
+
+/** Stop writing on an orconn when its outbuf is this large */
+static inline uint32_t
+or_conn_highwatermark(void)
+{
+  return or_conn_highwater;
+}
+
+/** Resume writing on an orconn when its outbuf is less than this */
+static inline uint32_t
+or_conn_lowwatermark(void)
+{
+  return or_conn_lowwater;
+}
+
 /**
  * Compute an N-count EWMA, aka N-EWMA. N-EWMA is defined as:
  *  EWMA = alpha*value + (1-alpha)*EWMA_prev
index dd31638eb3c4188a422941e6b2e70082280fdb40..db9f93e6f6453b0ea09e1c666757b4bc5fbe10c5 100644 (file)
@@ -65,6 +65,7 @@
 #include "core/or/scheduler.h"
 #include "feature/nodelist/torcert.h"
 #include "core/or/channelpadding.h"
+#include "core/or/congestion_control_common.h"
 #include "feature/dirauth/authmode.h"
 #include "feature/hs/hs_service.h"
 
@@ -636,7 +637,7 @@ connection_or_flushed_some(or_connection_t *conn)
   /* If we're under the low water mark, add cells until we're just over the
    * high water mark. */
   datalen = connection_get_outbuf_len(TO_CONN(conn));
-  if (datalen < OR_CONN_LOWWATER) {
+  if (datalen < or_conn_lowwatermark()) {
     /* Let the scheduler know */
     scheduler_channel_wants_writes(TLS_CHAN_TO_BASE(conn->chan));
   }
@@ -660,9 +661,9 @@ connection_or_num_cells_writeable(or_connection_t *conn)
    * used to trigger when to start writing after we've stopped.
    */
   datalen = connection_get_outbuf_len(TO_CONN(conn));
-  if (datalen < OR_CONN_HIGHWATER) {
+  if (datalen < or_conn_highwatermark()) {
     cell_network_size = get_cell_network_size(conn->wide_circ_ids);
-    n = CEIL_DIV(OR_CONN_HIGHWATER - datalen, cell_network_size);
+    n = CEIL_DIV(or_conn_highwatermark() - datalen, cell_network_size);
   }
 
   return n;
index ad82130301ca888139629be29d64916418330768..392a848ee788f0c79c0b4bcdea55782ed79529ab 100644 (file)
@@ -594,18 +594,6 @@ typedef struct or_handshake_state_t or_handshake_state_t;
 
 /** Length of Extended ORPort connection identifier. */
 #define EXT_OR_CONN_ID_LEN DIGEST_LEN /* 20 */
-/*
- * OR_CONN_HIGHWATER and OR_CONN_LOWWATER moved from connection_or.c so
- * channeltls.c can see them too.
- */
-
-/** When adding cells to an OR connection's outbuf, keep adding until the
- * outbuf is at least this long, or we run out of cells. */
-#define OR_CONN_HIGHWATER (32*1024)
-
-/** Add cells to an OR connection's outbuf whenever the outbuf's data length
- * drops below this size. */
-#define OR_CONN_LOWWATER (16*1024)
 
 typedef struct connection_t connection_t;
 typedef struct control_connection_t control_connection_t;
index 0138dff0331051c72441ca1d0162f2d0aabd081f..6867d8c98e50295c9e911b8de0e38579e4dd4475 100644 (file)
@@ -45,6 +45,7 @@
 #include "core/or/channel.h"
 #include "core/or/channelpadding.h"
 #include "core/or/circuitpadding.h"
+#include "core/or/congestion_control_common.h"
 #include "core/or/congestion_control_flow.h"
 #include "core/or/circuitmux.h"
 #include "core/or/circuitmux_ewma.h"
@@ -1700,6 +1701,7 @@ notify_after_networkstatus_changes(void)
   channelpadding_new_consensus_params(c);
   circpad_new_consensus_params(c);
   router_new_consensus_params(c);
+  congestion_control_new_consensus_params(c);
   flow_control_new_consensus_params(c);
 
   /* Maintenance of our L2 guard list */
index 5219c86097098dfd839ea73496d3717be97eaa9f..ca7fee2c5316e3cb782e70c713cc1e70171ca015 100644 (file)
@@ -20,6 +20,7 @@
 #include "lib/tls/tortls.h"
 
 #include "core/or/or_connection_st.h"
+#include "core/or/congestion_control_common.h"
 
 /* Test suite stuff */
 #include "test/test.h"
@@ -155,7 +156,7 @@ test_channeltls_num_bytes_queued(void *arg)
    * - 2 cells.
    */
   n = ch->num_cells_writeable(ch);
-  tt_int_op(n, OP_EQ, CEIL_DIV(OR_CONN_HIGHWATER, 512) - 2);
+  tt_int_op(n, OP_EQ, CEIL_DIV(or_conn_highwatermark(), 512) - 2);
   UNMOCK(buf_datalen);
   tlschan_buf_datalen_mock_target = NULL;
   tlschan_buf_datalen_mock_size = 0;