From c85512cd5dd025ddad72e6ed453711cf7b47ee4f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 17 Apr 2025 19:46:30 -0400 Subject: [PATCH] Move circuit accessors to relay.c --- src/core/or/relay.c | 29 +++++++++++++++++++++++++++++ src/core/or/relay.h | 6 ++++++ src/core/or/relay_msg.c | 29 ----------------------------- src/core/or/relay_msg.h | 5 ----- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/core/or/relay.c b/src/core/or/relay.c index e174f339e1..aa8c64f1e2 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -3540,3 +3540,32 @@ circuit_queue_streams_are_blocked(circuit_t *circ) return circ->circuit_blocked_on_p_chan; } } + +/** Return the format to use. + * + * NULL can be passed but not for both. */ +relay_cell_fmt_t +circuit_get_relay_format(const circuit_t *circ, const crypt_path_t *cpath) +{ + if (circ && CIRCUIT_IS_ORCIRC(circ)) { + return CONST_TO_OR_CIRCUIT(circ)->relay_cell_format; + } else if (cpath) { + return cpath->relay_cell_format; + } else { + /* We end up here when both params are NULL, which is not allowed, or when + * only an origin circuit is given (which again is not allowed). */ + tor_assert_unreached(); + } +} + +/** + * Return the maximum relay payload that can be sent to the chosen + * point, with the specified command. + */ +size_t +circuit_max_relay_payload(const circuit_t *circ, const crypt_path_t *cpath, + uint8_t relay_command) +{ + relay_cell_fmt_t fmt = circuit_get_relay_format(circ, cpath); + return relay_cell_max_payload_size(fmt, relay_command); +} diff --git a/src/core/or/relay.h b/src/core/or/relay.h index 47dbd18ca4..13716946a3 100644 --- a/src/core/or/relay.h +++ b/src/core/or/relay.h @@ -113,6 +113,12 @@ void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan); circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids); uint8_t packed_cell_get_command(const packed_cell_t *cell, int wide_circ_ids); +relay_cell_fmt_t circuit_get_relay_format(const circuit_t *circ, + const crypt_path_t *cpath); +size_t circuit_max_relay_payload(const circuit_t *circ, + const crypt_path_t *cpath, + uint8_t relay_command); + #ifdef RELAY_PRIVATE STATIC int handle_relay_msg(const relay_msg_t *msg, circuit_t *circ, diff --git a/src/core/or/relay_msg.c b/src/core/or/relay_msg.c index d5634a304b..f69f6b2667 100644 --- a/src/core/or/relay_msg.c +++ b/src/core/or/relay_msg.c @@ -283,32 +283,3 @@ relay_msg_decode_cell(relay_cell_fmt_t format, return NULL; } } - -/** Return the format to use. - * - * NULL can be passed but not for both. */ -relay_cell_fmt_t -circuit_get_relay_format(const circuit_t *circ, const crypt_path_t *cpath) -{ - if (circ && CIRCUIT_IS_ORCIRC(circ)) { - return CONST_TO_OR_CIRCUIT(circ)->relay_cell_format; - } else if (cpath) { - return cpath->relay_cell_format; - } else { - /* We end up here when both params are NULL, which is not allowed, or when - * only an origin circuit is given (which again is not allowed). */ - tor_assert_unreached(); - } -} - -/** - * Return the maximum relay payload that can be sent to the chosen - * point, with the specified command. - */ -size_t -circuit_get_max_relay_payload(const circuit_t *circ, const crypt_path_t *cpath, - uint8_t relay_command) -{ - relay_cell_fmt_t fmt = circuit_get_relay_format(circ, cpath); - return relay_cell_max_payload_size(fmt, relay_command); -} diff --git a/src/core/or/relay_msg.h b/src/core/or/relay_msg.h index 941c8896ef..3670bc5e92 100644 --- a/src/core/or/relay_msg.h +++ b/src/core/or/relay_msg.h @@ -32,11 +32,6 @@ relay_msg_t *relay_msg_decode_cell( FREE_AND_NULL(relay_msg_t, relay_msg_free_, (msg)) /* Getters */ -relay_cell_fmt_t circuit_get_relay_format(const circuit_t *circ, - const crypt_path_t *cpath); -size_t circuit_get_max_relay_payload(const circuit_t *circ, - const crypt_path_t *cpath, - uint8_t relay_command); /* * NOTE: The following are inlined for performance reasons. These values are -- 2.47.2