From 22d55e324900d34c970038fbd4e792f1e3d774d0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 17 Apr 2025 13:24:44 -0400 Subject: [PATCH] Add relay cell format field to circuits For client circuits, it is a per-hop field; for OR circuits, it is a per-circuit field. --- src/core/mainloop/cpuworker.c | 3 +++ src/core/or/crypt_path.c | 3 +++ src/core/or/crypt_path_st.h | 3 +++ src/core/or/or_circuit_st.h | 4 ++++ src/feature/hs/hs_circuit.c | 3 +++ 5 files changed, 16 insertions(+) diff --git a/src/core/mainloop/cpuworker.c b/src/core/mainloop/cpuworker.c index 602ebda228..9f8a88b6de 100644 --- a/src/core/mainloop/cpuworker.c +++ b/src/core/mainloop/cpuworker.c @@ -451,6 +451,9 @@ cpuworker_onion_handshake_replyfn(void *work_) } } + // TODO CGO: Initialize this from a real handshake. + circ->relay_cell_format = RELAY_CELL_FORMAT_V0; + if (onionskin_answer(circ, &rpl.created_cell, (const char*)rpl.keys, sizeof(rpl.keys), diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index 7673bc306f..f12bd964e3 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -71,6 +71,9 @@ cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) hop->package_window = circuit_initial_package_window(); hop->deliver_window = CIRCWINDOW_START; + // TODO CGO: Initialize this from a real decision. + hop->relay_cell_format = RELAY_CELL_FORMAT_V0; + return 0; } diff --git a/src/core/or/crypt_path_st.h b/src/core/or/crypt_path_st.h index fc6391f2f8..5f023e9f4f 100644 --- a/src/core/or/crypt_path_st.h +++ b/src/core/or/crypt_path_st.h @@ -87,6 +87,9 @@ struct crypt_path_t { /** Congestion control info */ struct congestion_control_t *ccontrol; + /** Format to use when exchanging relay cells with this relay. */ + relay_cell_fmt_t relay_cell_format; + /*********************** Private members ****************************/ /** Private member: Cryptographic state used for encrypting and diff --git a/src/core/or/or_circuit_st.h b/src/core/or/or_circuit_st.h index 28e357338a..0497d2058f 100644 --- a/src/core/or/or_circuit_st.h +++ b/src/core/or/or_circuit_st.h @@ -106,6 +106,10 @@ struct or_circuit_t { /** RELAY_BEGIN and RELAY_RESOLVE cell bucket controlling how much can go on * this circuit. Only used if this is the end of a circuit on an exit node.*/ token_bucket_ctr_t stream_limiter; + + /** Format to use when exchanging relay cells with the client + * who built this circuit. */ + relay_cell_fmt_t relay_cell_format; }; #endif /* !defined(OR_CIRCUIT_ST_H) */ diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c index 43b563b48a..306550f99c 100644 --- a/src/feature/hs/hs_circuit.c +++ b/src/feature/hs/hs_circuit.c @@ -110,6 +110,9 @@ create_rend_cpath(const uint8_t *ntor_key_seed, size_t seed_len, cpath = tor_malloc_zero(sizeof(crypt_path_t)); cpath->magic = CRYPT_PATH_MAGIC; + // TODO CGO: Pick relay cell format based on capabilities. + cpath->relay_cell_format = RELAY_CELL_FORMAT_V0; + if (cpath_init_circuit_crypto(cpath, (char*)keys, sizeof(keys), is_service_side, 1) < 0) { tor_free(cpath); -- 2.47.2