relay_msg_st.h (1564B)
1 /* Copyright (c) 2023, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 /** 5 * @file relay_msg_st.h 6 * @brief A relay message which contains a relay command and parameters, 7 * if any, that is from a relay cell. 8 **/ 9 10 #ifndef TOR_RELAY_MSG_ST_H 11 #define TOR_RELAY_MSG_ST_H 12 13 #include "core/or/or.h" 14 15 /** A relay message object which contains pointers to the header and payload. 16 * 17 * One acquires a relay message through the use of an iterator. Once you get a 18 * reference, the getters MUST be used to access data. 19 * 20 * This CAN NOT be made opaque so to avoid heap allocation in the fast path. */ 21 typedef struct relay_msg_t { 22 /* Relay command of a message. */ 23 uint8_t command; 24 /* Length of the message body. 25 * 26 * This value MUST always be less than or equal to the lower of: 27 * - the number of bytes available in `body`. 28 * - relay_cell_max_format(_, command). 29 * 30 * (These bounds on the length field are guaranteed by all message decoding 31 * functions, and enforced by all message encoding functions.) 32 */ 33 uint16_t length; 34 /* Optional routing header: stream ID of a message or 0. */ 35 streamid_t stream_id; 36 /* Indicate if this is a message from a relay early cell. */ 37 bool is_relay_early; 38 /* Message body of a relay message. 39 * 40 * Code MUST NOT access any part of `body` beyond the first `length` bytes. 41 * 42 * NOTE that this struct does not own the body; instead, this is a pointer 43 * into a different object. */ 44 const uint8_t *body; 45 } relay_msg_t; 46 47 #endif /* !defined(TOR_RELAY_MSG_ST_H) */