From b4991f6bb6bc090ba1d3e5f9a80e4069b1068e71 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 2 Jun 2025 10:36:18 -0400 Subject: [PATCH] Use protovers to detect cgo support. --- src/core/or/or.h | 3 +++ src/core/or/protover.h | 8 ++++++++ src/core/or/versions.c | 9 +++++++++ src/feature/nodelist/nodelist.c | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/core/or/or.h b/src/core/or/or.h index 19836736ce..1f06574ecf 100644 --- a/src/core/or/or.h +++ b/src/core/or/or.h @@ -831,6 +831,9 @@ typedef struct protover_summary_flags_t { /** True iff this router supports conflux. */ unsigned int supports_conflux : 1; + + /** True iff this router supports CGO. */ + unsigned int supports_cgo : 1; } protover_summary_flags_t; typedef struct routerinfo_t routerinfo_t; diff --git a/src/core/or/protover.h b/src/core/or/protover.h index 9d8eb4dcc5..53e126ea34 100644 --- a/src/core/or/protover.h +++ b/src/core/or/protover.h @@ -58,6 +58,14 @@ struct smartlist_t; /** The protover that signals support for congestion control */ #define PROTOVER_FLOWCTRL_CC 2 +/** The protover required for negotiating protovers as part of the circuit + * extension handshake. */ +#define PROTOVER_RELAY_NEGOTIATE_SUBPROTO 5 + +/** The protover required for negotiating protovers as part of the circuit + * extension handshake. */ +#define PROTOVER_RELAY_CRYPT_CGO 6 + /** List of recognized subprotocols. */ /// C_RUST_COUPLED: src/rust/protover/ffi.rs `translate_to_rust` /// C_RUST_COUPLED: src/rust/protover/protover.rs `Proto` diff --git a/src/core/or/versions.c b/src/core/or/versions.c index 8f5503691e..782cdf4142 100644 --- a/src/core/or/versions.c +++ b/src/core/or/versions.c @@ -495,6 +495,15 @@ memoize_protover_summary(protover_summary_flags_t *out, protocol_list_supports_protocol(protocols, PRT_CONFLUX, PROTOVER_CONFLUX_V1); + /* CGO requires congestion control and subproto negotiation. */ + out->supports_cgo = + protocol_list_supports_protocol(protocols, PRT_FLOWCTRL, + PROTOVER_FLOWCTRL_CC) && + protocol_list_supports_protocol(protocols, PRT_RELAY, + PROTOVER_RELAY_NEGOTIATE_SUBPROTO) && + protocol_list_supports_protocol(protocols, PRT_RELAY, + PROTOVER_RELAY_CRYPT_CGO); + protover_summary_flags_t *new_cached = tor_memdup(out, sizeof(*out)); cached = strmap_set(protover_summary_map, protocols, new_cached); tor_assert(!cached); diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c index 250f4fc782..105368b728 100644 --- a/src/feature/nodelist/nodelist.c +++ b/src/feature/nodelist/nodelist.c @@ -1239,7 +1239,7 @@ node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id) /** Dummy object that should be unreturnable. Used to ensure that * node_get_protover_summary_flags() always returns non-NULL. */ static const protover_summary_flags_t zero_protover_flags = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; /** Return the protover_summary_flags for a given node. */ -- 2.47.2