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 \
src/core/or/scheduler.h \
src/core/or/sendme.h \
src/core/or/congestion_control_flow.h \
--- /dev/null
+/* 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 "core/or/relay_msg.h"
+
+/*
+ * Public API
+ */
+
+/** 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);
+}
+
+/** Free the given relay message. */
+void
+relay_msg_free_(relay_msg_t *msg)
+{
+ if (!msg) {
+ return;
+ }
+ tor_free(msg->body);
+ tor_free(msg);
+}
+
+/** Clear a relay message as in free its content and reset all fields to 0.
+ * This is useful for stack allocated memory. */
+void
+relay_msg_clear(relay_msg_t *msg)
+{
+ tor_assert(msg);
+ tor_free(msg->body);
+ memset(msg, 0, sizeof(*msg));
+}
--- /dev/null
+/* 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"
+
+#include "core/or/relay_msg_st.h"
+
+/* Relay message */
+void relay_msg_free_(relay_msg_t *msg);
+void relay_msg_clear(relay_msg_t *msg);
+
+#define relay_msg_free(msg) \
+ FREE_AND_NULL(relay_msg_t, relay_msg_free_, (msg))
+
+#ifdef RELAY_MSG_PRIVATE
+
+#endif /* RELAY_MSG_PRIVATE */
+
+#endif /* TOR_RELAY_MSG_H */
--- /dev/null
+/* Copyright (c) 2023, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * @file relay_msg_st.h
+ * @brief A relay message which contains a relay command and parameters,
+ * if any, that is from a relay cell.
+ **/
+
+#ifndef TOR_RELAY_MSG_ST_H
+#define TOR_RELAY_MSG_ST_H
+
+#include "core/or/or.h"
+
+/** A relay message object which contains pointers to the header and payload.
+ *
+ * One acquires a relay message through the use of an iterator. Once you get a
+ * reference, the getters MUST be used to access data.
+ *
+ * This CAN NOT be made opaque so to avoid heap allocation in the fast path. */
+typedef struct relay_msg_t {
+ /* Relay cell protocol version of this message. */
+ uint8_t relay_cell_proto;
+ /* Relay command of a message. */
+ uint8_t command;
+ /* Length of payload. */
+ uint16_t length;
+ /* Optional routing header: stream ID of a message or 0. */
+ streamid_t stream_id;
+ /* Indicate if this is a message from a relay early cell. */
+ bool is_relay_early;
+ /* Message body of a relay message. */
+ // TODO #41051: This is an owned copy of the body.
+ // It might be better to turn this into a non-owned pointer into
+ // the cell body, if we can, to save a copy.
+ uint8_t *body;
+} relay_msg_t;
+
+#endif /* !defined(TOR_RELAY_MSG_ST_H) */