Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
relay_msg.h
Go to the documentation of this file.
1/* Copyright (c) 2023, The Tor Project, Inc. */
2/* See LICENSE for licensing information */
3
4/**
5 * \file relay_msg.h
6 * \brief Header file for relay_msg.c.
7 **/
8
9#ifndef TOR_RELAY_MSG_H
10#define TOR_RELAY_MSG_H
11
12#include "core/or/or.h"
13
15
16/* Relay message */
20
22 const relay_msg_t *msg,
23 cell_t *cell_out) ATTR_WUR;
25 const cell_t *cell,
26 relay_msg_t *msg_out) ATTR_WUR;
28 relay_cell_fmt_t format,
29 const cell_t *cell) ATTR_WUR;
30
31#define relay_msg_free(msg) \
32 FREE_AND_NULL(relay_msg_t, relay_msg_free_, (msg))
33
34/* Getters */
35
36/*
37 * NOTE: The following are inlined for performance reasons. These values are
38 * accessed everywhere and so, even if not expensive, we avoid a function call.
39 */
40
41/** Return true iff 'cmd' uses a stream ID when using
42 * the v1 relay message format. */
43static bool
45{
46 switch (relay_command) {
47 case RELAY_COMMAND_BEGIN:
48 case RELAY_COMMAND_BEGIN_DIR:
49 case RELAY_COMMAND_CONNECTED:
50 case RELAY_COMMAND_DATA:
51 case RELAY_COMMAND_END:
52 case RELAY_COMMAND_RESOLVE:
53 case RELAY_COMMAND_RESOLVED:
54 case RELAY_COMMAND_XOFF:
55 case RELAY_COMMAND_XON:
56 return true;
57 default:
58 return false;
59 }
60}
61
62/** Return the size of the relay cell payload for the given relay
63 * cell format. */
64static inline size_t
66 uint8_t relay_command)
67{
68 switch (format) {
72 if (relay_cmd_expects_streamid_in_v1(relay_command)) {
74 } else {
76 }
77 }
78 default:
80 return 0;
81 }
82}
83
84#ifdef RELAY_MSG_PRIVATE
85
86#endif /* RELAY_MSG_PRIVATE */
87
88#endif /* TOR_RELAY_MSG_H */
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
Definition: or.h:520
#define RELAY_HEADER_SIZE_V1_NO_STREAM_ID
Definition: or.h:557
#define RELAY_HEADER_SIZE_V0
Definition: or.h:554
#define RELAY_HEADER_SIZE_V1_WITH_STREAM_ID
Definition: or.h:560
relay_cell_fmt_t
Definition: or.h:529
@ RELAY_CELL_FORMAT_V1
Definition: or.h:533
@ RELAY_CELL_FORMAT_V0
Definition: or.h:531
void relay_msg_clear(relay_msg_t *msg)
Definition: relay_msg.c:41
relay_msg_t * relay_msg_copy(const relay_msg_t *msg)
Definition: relay_msg.c:68
int relay_msg_decode_cell_in_place(relay_cell_fmt_t format, const cell_t *cell, relay_msg_t *msg_out) ATTR_WUR
Definition: relay_msg.c:254
static bool relay_cmd_expects_streamid_in_v1(uint8_t relay_command)
Definition: relay_msg.h:44
relay_msg_t * relay_msg_decode_cell(relay_cell_fmt_t format, const cell_t *cell) ATTR_WUR
Definition: relay_msg.c:276
void relay_msg_free_(relay_msg_t *msg)
Definition: relay_msg.c:30
int relay_msg_encode_cell(relay_cell_fmt_t format, const relay_msg_t *msg, cell_t *cell_out) ATTR_WUR
Definition: relay_msg.c:225
static size_t relay_cell_max_payload_size(relay_cell_fmt_t format, uint8_t relay_command)
Definition: relay_msg.h:65
A relay message which contains a relay command and parameters, if any, that is from a relay cell.
Definition: cell_st.h:17
#define tor_fragile_assert()
Definition: util_bug.h:278