]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
prop340: Add torrc option and consensus parameter
authorDavid Goulet <dgoulet@torproject.org>
Mon, 14 Aug 2023 18:27:46 +0000 (14:27 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 31 Jan 2024 15:16:02 +0000 (10:16 -0500)
Signed-off-by: David Goulet <dgoulet@torproject.org>
src/app/config/config.c
src/app/config/or_options_st.h
src/core/or/include.am
src/core/or/protover.c
src/core/or/relay.c
src/core/or/relay_msg.c [new file with mode: 0644]
src/core/or/relay_msg.h [new file with mode: 0644]

index 102d1bbc04ea2b5a9e40d5e70914cb2fbb802581..0ab617d3708d0c4f6748675fe4cec400910fb53f 100644 (file)
@@ -692,6 +692,7 @@ static const config_var_t option_vars_[] = {
   V(VanguardsLiteEnabled,        AUTOBOOL, "auto"),
   V(UseMicrodescriptors,         AUTOBOOL, "auto"),
   OBSOLETE("UseNTorHandshake"),
+  V(UseRelayMessage,             AUTOBOOL, "auto"),
   VAR("__AlwaysCongestionControl",  BOOL, AlwaysCongestionControl, "0"),
   VAR("__SbwsExit",  BOOL, SbwsExit, "0"),
   V_IMMUTABLE(User,              STRING,   NULL),
index 624dc61bc5c1c797af4dec44bc9d93c7c220845e..d160aeec93dde44db33b4533d760281cfb3801d9 100644 (file)
@@ -1097,6 +1097,11 @@ struct or_options_t {
    * report bandwidth observations from this period? */
   int TestingMinTimeToReportBandwidth;
 
+  /** Autobool: true if we should use the relay message with relays supporting
+   * protocol version Relay=5. Set to -1 indicating that the consensus decide.
+   * Default to 0. */
+  int UseRelayMessage;
+
   /**
    * Configuration objects for individual modules.
    *
index d0dffd5d3b90260af4fbc7bba41f9e8f9dd731bc..473ab84f778f96e7fcaec1d45359afc6a574fc30 100644 (file)
@@ -30,6 +30,7 @@ LIBTOR_APP_A_SOURCES +=                               \
        src/core/or/protover.c                  \
        src/core/or/reasons.c                   \
        src/core/or/relay.c                     \
+       src/core/or/relay_msg.c                 \
        src/core/or/scheduler.c                 \
        src/core/or/scheduler_kist.c            \
        src/core/or/scheduler_vanilla.c         \
@@ -104,6 +105,8 @@ noinst_HEADERS +=                                   \
        src/core/or/protover.h                          \
        src/core/or/reasons.h                           \
        src/core/or/relay.h                             \
+       src/core/or/relay_msg.h                 \
+       src/core/or/relay_msg_st.h                      \
        src/core/or/relay_crypto_st.h                   \
        src/core/or/scheduler.h                         \
        src/core/or/sendme.h                            \
index b084cb5f3661eb1c90e8309c05e21b59a610f78a..9943b28b35b94ddcf87f10df86758f1af5d9103a 100644 (file)
@@ -26,6 +26,7 @@
 #include "core/or/congestion_control_common.h"
 #include "core/or/extend_info_st.h"
 #include "core/or/protover.h"
+#include "core/or/relay_msg.h"
 #include "core/or/versions.h"
 #include "lib/tls/tortls.h"
 
@@ -927,7 +928,7 @@ protover_build_ntor3_ext_request(const extend_info_t *ei)
     trn_ntorv3_ext_subproto_add_reqs(req, proto_req);
   }
   /* Build the RelayCell version request. */
-  if (ei->supports_relay_cell_proto) {
+  if (relay_msg_is_enabled() && ei->supports_relay_cell_proto) {
     trn_ntorv3_ext_subproto_req_t *proto_req =
       trn_ntorv3_ext_subproto_req_new();
     trn_ntorv3_ext_subproto_req_set_proto_id(proto_req, PRT_RELAY_CELL);
index 0cda6e7bf7c95cba5c481380d8780341e54f20c4..36e94820fa7113e2fd5417c582501274dc157866 100644 (file)
@@ -84,6 +84,7 @@
 #include "core/or/scheduler.h"
 #include "feature/hs/hs_metrics.h"
 #include "feature/stats/rephist.h"
+#include "core/or/relay_msg.h"
 
 #include "core/or/cell_st.h"
 #include "core/or/cell_queue_st.h"
@@ -3372,6 +3373,9 @@ relay_consensus_has_changed(const networkstatus_t *ns)
     get_param_max_circuit_cell_queue_size(ns);
   max_circuit_cell_queue_size_out =
     get_param_max_circuit_cell_queue_size_out(ns);
+
+  /* Inform our relay message library. */
+  relay_msg_consensus_has_changed(ns);
 }
 
 /** Add <b>cell</b> to the queue of <b>circ</b> writing to <b>chan</b>
diff --git a/src/core/or/relay_msg.c b/src/core/or/relay_msg.c
new file mode 100644 (file)
index 0000000..3dad532
--- /dev/null
@@ -0,0 +1,52 @@
+/* Copyright (c) 2023, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file relay_msg.c
+ * \brief XXX: Write a brief introduction to this module.
+ **/
+
+#define RELAY_MSG_PRIVATE
+
+#include "app/config/config.h"
+
+#include "core/or/relay_msg.h"
+
+#include "feature/nodelist/networkstatus.h"
+
+/* Consensus parameters. Updated when we get a new consensus. */
+static bool relay_msg_enabled = false;
+
+/** Return the UseRelayMessage value either from the configuration file or the
+ * consensus if not present. */
+static bool
+get_param_enabled(const networkstatus_t *ns)
+{
+#define RELAY_MSG_PARAM_ENABLED_DEFAULT (0)
+#define RELAY_MSG_PARAM_ENABLED_MIN (0)
+#define RELAY_MSG_PARAM_ENABLED_MAX (1)
+
+  if (get_options()->UseRelayMessage != -1) {
+    return get_options()->UseRelayMessage != 0;
+  }
+
+  return networkstatus_get_param(ns, "UseRelayMessage",
+                                 RELAY_MSG_PARAM_ENABLED_DEFAULT,
+                                 RELAY_MSG_PARAM_ENABLED_MIN,
+                                 RELAY_MSG_PARAM_ENABLED_MAX) != 0;
+}
+
+/** Return true iff the ability to use relay messages is enabled. */
+bool
+relay_msg_is_enabled(void)
+{
+  return relay_msg_enabled;
+}
+
+/** Called just before the consensus is changed with the given networkstatus_t
+ * object. */
+void
+relay_msg_consensus_has_changed(const networkstatus_t *ns)
+{
+  relay_msg_enabled = get_param_enabled(ns);
+}
diff --git a/src/core/or/relay_msg.h b/src/core/or/relay_msg.h
new file mode 100644 (file)
index 0000000..35b0990
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2023, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file relay_msg.h
+ * \brief Header file for relay_msg.c.
+ **/
+
+#ifndef TOR_RELAY_MSG_H
+#define TOR_RELAY_MSG_H
+
+#include "core/or/or.h"
+
+bool relay_msg_is_enabled(void);
+
+void relay_msg_consensus_has_changed(const networkstatus_t *ns);
+
+#ifdef RELAY_MSG_PRIVATE
+
+#endif /* RELAY_MSG_PRIVATE */
+
+#endif /* TOR_RELAY_MSG_H */
+