From: Nick Mathewson Date: Thu, 17 Apr 2025 20:47:39 +0000 (-0400) Subject: Fold relay_cell.h into relay_msg.h X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdc9df82d05c62355d05325f6b55d1cf8c5f8653;p=thirdparty%2Ftor.git Fold relay_cell.h into relay_msg.h It no longer needs an independent existence. --- diff --git a/src/core/or/include.am b/src/core/or/include.am index 0b9323b909..9b8f295297 100644 --- a/src/core/or/include.am +++ b/src/core/or/include.am @@ -105,7 +105,6 @@ noinst_HEADERS += \ src/core/or/protover.h \ src/core/or/reasons.h \ src/core/or/relay.h \ - src/core/or/relay_cell.h \ src/core/or/relay_crypto_st.h \ src/core/or/relay_msg.h \ src/core/or/relay_msg_st.h \ diff --git a/src/core/or/relay.c b/src/core/or/relay.c index a32416b314..1f2ef34fdd 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -85,7 +85,6 @@ #include "core/or/scheduler.h" #include "feature/hs/hs_metrics.h" #include "feature/stats/rephist.h" -#include "core/or/relay_cell.h" #include "core/or/relay_msg.h" #include "core/or/cell_st.h" diff --git a/src/core/or/relay_cell.h b/src/core/or/relay_cell.h deleted file mode 100644 index ca3db7aa00..0000000000 --- a/src/core/or/relay_cell.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (c) 2023, The Tor Project, Inc. */ -/* See LICENSE for licensing information */ - -/** - * \file relay_cell.h - * \brief Header file for relay_cell.c. - **/ - -#ifndef TOR_RELAY_CELL_H -#define TOR_RELAY_CELL_H - -#include "core/or/or.h" - -#include "core/or/cell_st.h" - -/* TODO #41051: Fold this file into relay_msg.h */ - -/* - * NOTE: The following are inlined for performance reasons. These values are - * accessed everywhere and so, even if not expensive, we avoid a function call. - */ - -/** Return true iff 'cmd' uses a stream ID when using - * the v1 relay message format. */ -static bool -relay_cmd_expects_streamid_in_v1(uint8_t relay_command) -{ - switch (relay_command) { - case RELAY_COMMAND_BEGIN: - case RELAY_COMMAND_BEGIN_DIR: - case RELAY_COMMAND_CONNECTED: - case RELAY_COMMAND_DATA: - case RELAY_COMMAND_END: - case RELAY_COMMAND_RESOLVE: - case RELAY_COMMAND_RESOLVED: - case RELAY_COMMAND_XOFF: - case RELAY_COMMAND_XON: - return true; - default: - return false; - } -} - -/** Return the size of the relay cell payload for the given relay - * cell format. */ -static inline size_t -relay_cell_max_payload_size(relay_cell_fmt_t format, - uint8_t relay_command) -{ - switch (format) { - case RELAY_CELL_FORMAT_V0: - return CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V0; - case RELAY_CELL_FORMAT_V1: { - if (relay_cmd_expects_streamid_in_v1(relay_command)) { - return CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V1_WITH_STREAM_ID; - } else { - return CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V1_NO_STREAM_ID; - } - } - default: - tor_fragile_assert(); - return 0; - } -} - -#ifdef RELAY_CELL_PRIVATE - -#endif /* RELAY_CELL_PRIVATE */ - -#endif /* TOR_RELAY_CELL_H */ diff --git a/src/core/or/relay_msg.c b/src/core/or/relay_msg.c index 97091dcd59..5b40a68057 100644 --- a/src/core/or/relay_msg.c +++ b/src/core/or/relay_msg.c @@ -13,9 +13,7 @@ #include "core/or/cell_st.h" #include "core/or/circuitlist.h" #include "core/or/relay.h" -#include "core/or/relay_cell.h" #include "core/or/relay_msg.h" -#include "core/or/relay_cell.h" #include "lib/crypt_ops/crypto_rand.h" #include "core/or/cell_st.h" diff --git a/src/core/or/relay_msg.h b/src/core/or/relay_msg.h index cec56d6b28..4943ab0090 100644 --- a/src/core/or/relay_msg.h +++ b/src/core/or/relay_msg.h @@ -35,8 +35,53 @@ relay_msg_t *relay_msg_decode_cell( relay_cell_fmt_t relay_msg_get_format(const circuit_t *circ, const crypt_path_t *cpath); -/* Helpers. */ -void relay_msg_free_messages(smartlist_t *messages); +/* + * NOTE: The following are inlined for performance reasons. These values are + * accessed everywhere and so, even if not expensive, we avoid a function call. + */ + +/** Return true iff 'cmd' uses a stream ID when using + * the v1 relay message format. */ +static bool +relay_cmd_expects_streamid_in_v1(uint8_t relay_command) +{ + switch (relay_command) { + case RELAY_COMMAND_BEGIN: + case RELAY_COMMAND_BEGIN_DIR: + case RELAY_COMMAND_CONNECTED: + case RELAY_COMMAND_DATA: + case RELAY_COMMAND_END: + case RELAY_COMMAND_RESOLVE: + case RELAY_COMMAND_RESOLVED: + case RELAY_COMMAND_XOFF: + case RELAY_COMMAND_XON: + return true; + default: + return false; + } +} + +/** Return the size of the relay cell payload for the given relay + * cell format. */ +static inline size_t +relay_cell_max_payload_size(relay_cell_fmt_t format, + uint8_t relay_command) +{ + switch (format) { + case RELAY_CELL_FORMAT_V0: + return CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V0; + case RELAY_CELL_FORMAT_V1: { + if (relay_cmd_expects_streamid_in_v1(relay_command)) { + return CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V1_WITH_STREAM_ID; + } else { + return CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V1_NO_STREAM_ID; + } + } + default: + tor_fragile_assert(); + return 0; + } +} #ifdef RELAY_MSG_PRIVATE diff --git a/src/feature/client/circpathbias.c b/src/feature/client/circpathbias.c index c7b42ecfae..e388c55125 100644 --- a/src/feature/client/circpathbias.c +++ b/src/feature/client/circpathbias.c @@ -34,7 +34,6 @@ #include "feature/client/entrynodes.h" #include "feature/nodelist/networkstatus.h" #include "core/or/relay.h" -#include "core/or/relay_cell.h" #include "core/or/relay_msg.h" #include "lib/math/fp.h" #include "lib/math/laplace.h" diff --git a/src/test/test_sendme.c b/src/test/test_sendme.c index 7ece88c2cc..93a828643b 100644 --- a/src/test/test_sendme.c +++ b/src/test/test_sendme.c @@ -14,7 +14,6 @@ #include "core/or/origin_circuit_st.h" #include "core/or/circuitlist.h" #include "core/or/relay.h" -#include "core/or/relay_cell.h" #include "core/or/sendme.h" #include "feature/nodelist/networkstatus.h"