From: David Goulet Date: Mon, 14 Aug 2023 18:27:46 +0000 (-0400) Subject: prop340: Add torrc option and consensus parameter X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67bc70c84eb6c2ac8dde5cac86125267e5546622;p=thirdparty%2Ftor.git prop340: Add torrc option and consensus parameter Signed-off-by: David Goulet --- diff --git a/src/app/config/config.c b/src/app/config/config.c index 102d1bbc04..0ab617d370 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -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), diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h index 624dc61bc5..d160aeec93 100644 --- a/src/app/config/or_options_st.h +++ b/src/app/config/or_options_st.h @@ -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. * diff --git a/src/core/or/include.am b/src/core/or/include.am index d0dffd5d3b..473ab84f77 100644 --- a/src/core/or/include.am +++ b/src/core/or/include.am @@ -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 \ diff --git a/src/core/or/protover.c b/src/core/or/protover.c index b084cb5f36..9943b28b35 100644 --- a/src/core/or/protover.c +++ b/src/core/or/protover.c @@ -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); diff --git a/src/core/or/relay.c b/src/core/or/relay.c index 0cda6e7bf7..36e94820fa 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -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 cell to the queue of circ writing to chan diff --git a/src/core/or/relay_msg.c b/src/core/or/relay_msg.c new file mode 100644 index 0000000000..3dad5322fd --- /dev/null +++ b/src/core/or/relay_msg.c @@ -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 index 0000000000..35b0990ba3 --- /dev/null +++ b/src/core/or/relay_msg.h @@ -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 */ +