Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8  * \file relay.h
9  * \brief Header file for relay.c.
10  **/
12 #ifndef TOR_RELAY_H
13 #define TOR_RELAY_H
15 extern uint64_t stats_n_relay_cells_relayed;
16 extern uint64_t stats_n_relay_cells_delivered;
17 extern uint64_t stats_n_circ_max_cell_reached;
18 extern uint64_t stats_n_circ_max_cell_outq_reached;
20 const char *relay_command_to_string(uint8_t command);
22 void relay_consensus_has_changed(const networkstatus_t *ns);
23 uint32_t relay_get_param_max_circuit_cell_queue_size(
24  const networkstatus_t *ns);
26  cell_direction_t cell_direction);
27 size_t cell_queues_get_total_allocation(void);
29 void relay_header_pack(uint8_t *dest, const relay_header_t *src);
30 void relay_header_unpack(relay_header_t *dest, const uint8_t *src);
31 MOCK_DECL(int,
33  uint8_t relay_command, const char *payload,
34  size_t payload_len, crypt_path_t *cpath_layer,
35  const char *filename, int lineno));
36 /* Indicates to relay_send_command_from_edge() that it is a control cell. */
37 #define CONTROL_CELL_ID 0
38 #define relay_send_command_from_edge(stream_id, circ, relay_command, payload, \
39  payload_len, cpath_layer) \
40  relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
41  (payload), (payload_len), (cpath_layer), \
42  __FILE__, __LINE__)
44  uint8_t relay_command, const char *payload,
45  size_t payload_len);
47  int package_partial,
48  int *max_cells);
49 void connection_edge_consider_sending_sendme(edge_connection_t *conn);
52 extern uint64_t stats_n_data_cells_packaged;
53 extern uint64_t stats_n_data_bytes_packaged;
54 extern uint64_t stats_n_data_cells_received;
55 extern uint64_t stats_n_data_bytes_received;
57 extern uint64_t oom_stats_n_bytes_removed_dns;
58 extern uint64_t oom_stats_n_bytes_removed_cell;
59 extern uint64_t oom_stats_n_bytes_removed_geoip;
60 extern uint64_t oom_stats_n_bytes_removed_hsdir;
62 void dump_cell_pool_usage(int severity);
63 size_t packed_cell_mem_cost(void);
67 /* For channeltls.c */
69 #define packed_cell_free(cell) \
70  FREE_AND_NULL(packed_cell_t, packed_cell_free_, (cell))
72 void cell_queue_init(cell_queue_t *queue);
73 void cell_queue_clear(cell_queue_t *queue);
74 void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
76  int exitward, const cell_t *cell,
77  int wide_circ_ids, int use_stats);
80  cell_t *cell, cell_direction_t direction,
81  streamid_t fromstream);
86  circid_t circid,
87  uint8_t reason);
89 void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out);
91  (channel_t *chan, int max));
93  cell_direction_t cell_direction,
94  crypt_path_t *layer_hint, streamid_t on_stream,
95  const char *filename, int lineno));
98  const char *file, int lineno);
99 #define update_circuit_on_cmux(circ, direction) \
100  update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
102 int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr);
103 const uint8_t *decode_address_from_payload(tor_addr_t *addr_out,
104  const uint8_t *payload,
105  int payload_len);
106 void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan);
108 circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
109 uint8_t packed_cell_get_command(const packed_cell_t *cell, int wide_circ_ids);
111 #ifdef RELAY_PRIVATE
112 STATIC int
114  edge_connection_t *conn, crypt_path_t *layer_hint,
115  relay_header_t *rh, int optimistic_data);
117 STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell,
118  tor_addr_t *addr_out, int *ttl_out);
119 /** An address-and-ttl tuple as yielded by resolved_cell_parse */
120 typedef struct address_ttl_t {
121  tor_addr_t addr;
122  char *hostname;
123  int ttl;
124 } address_ttl_t;
125 STATIC void address_ttl_free_(address_ttl_t *addr);
126 #define address_ttl_free(addr) \
127  FREE_AND_NULL(address_ttl_t, address_ttl_free_, (addr))
128 STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh,
129  smartlist_t *addresses_out, int *errcode_out);
131  const cell_t *cell,
132  const relay_header_t *rh);
138  edge_connection_t *conn,
139  crypt_path_t *layer_hint);
140 STATIC size_t get_pad_cell_offset(size_t payload_len);
141 STATIC size_t connection_edge_get_inbuf_bytes_to_package(size_t n_available,
142  int package_partial,
143  circuit_t *on_circuit);
145 #endif /* defined(RELAY_PRIVATE) */
147 #endif /* !defined(TOR_RELAY_H) */
tor_cmdline_mode_t command
Definition: config.c:2449
uint32_t circid_t
Definition: or.h:488
uint16_t streamid_t
Definition: or.h:490
Definition: or.h:366
STATIC size_t connection_edge_get_inbuf_bytes_to_package(size_t n_available, int package_partial, circuit_t *on_circuit)
Definition: relay.c:2155
STATIC size_t get_pad_cell_offset(size_t data_len)
Definition: relay.c:561
STATIC int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, edge_connection_t *conn, crypt_path_t *layer_hint)
Definition: relay.c:2047
STATIC packed_cell_t * packed_cell_new(void)
Definition: relay.c:2582
STATIC destroy_cell_t * destroy_cell_queue_pop(destroy_cell_queue_t *queue)
Definition: relay.c:2710
STATIC packed_cell_t * cell_queue_pop(cell_queue_t *queue)
Definition: relay.c:2676
STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell, tor_addr_t *addr_out, int *ttl_out)
Definition: relay.c:1074
STATIC int cell_queues_check_size(void)
Definition: relay.c:2782
STATIC int handle_relay_cell_command(cell_t *cell, circuit_t *circ, edge_connection_t *conn, crypt_path_t *layer_hint, relay_header_t *rh, int optimistic_data)
Definition: relay.c:1617
STATIC void address_ttl_free_(address_ttl_t *addr)
Definition: relay.c:1112
STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh, smartlist_t *addresses_out, int *errcode_out)
Definition: relay.c:1126
STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn, const cell_t *cell, const relay_header_t *rh)
Definition: relay.c:1297
int channel_flush_from_first_active_circuit(channel_t *chan, int max)
Definition: relay.c:2986
void destroy_cell_queue_init(destroy_cell_queue_t *queue)
Definition: relay.c:2688
int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr)
Definition: relay.c:3324
uint64_t stats_n_data_cells_received
Definition: relay.c:2123
void packed_cell_free_(packed_cell_t *cell)
Definition: relay.c:2590
void destroy_cell_queue_clear(destroy_cell_queue_t *queue)
Definition: relay.c:2696
void destroy_cell_queue_append(destroy_cell_queue_t *queue, circid_t circid, uint8_t reason)
Definition: relay.c:2722
void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out)
Definition: relay.c:2895
void cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue, int exitward, const cell_t *cell, int wide_circ_ids, int use_stats)
Definition: relay.c:2638
uint64_t oom_stats_n_bytes_removed_dns
Definition: relay.c:2774
void dump_cell_pool_usage(int severity)
Definition: relay.c:2600
void circuit_reset_sendme_randomness(circuit_t *circ)
Definition: relay.c:2135
const uint8_t * decode_address_from_payload(tor_addr_t *addr_out, const uint8_t *payload, int payload_len)
Definition: relay.c:3350
uint64_t stats_n_relay_cells_relayed
Definition: relay.c:123
uint64_t stats_n_circ_max_cell_reached
Definition: relay.c:130
uint64_t stats_n_data_cells_packaged
Definition: relay.c:2117
void cell_queue_clear(cell_queue_t *queue)
Definition: relay.c:2662
void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan)
Definition: relay.c:3378
void cell_queue_init(cell_queue_t *queue)
Definition: relay.c:2654
int circuit_package_relay_cell(cell_t *cell, circuit_t *circ, cell_direction_t cell_direction, crypt_path_t *layer_hint, streamid_t on_stream, const char *filename, int lineno)
Definition: relay.c:369
int have_been_under_memory_pressure(void)
Definition: relay.c:2839
uint64_t stats_n_data_bytes_received
Definition: relay.c:2127
void relay_header_pack(uint8_t *dest, const relay_header_t *src)
Definition: relay.c:483
circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids)
Definition: relay.c:2972
void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction, const char *file, int lineno)
Definition: relay.c:2850
void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan, cell_t *cell, cell_direction_t direction, streamid_t fromstream)
Definition: relay.c:3241
int relay_send_command_from_edge_(streamid_t stream_id, circuit_t *circ, uint8_t relay_command, const char *payload, size_t payload_len, crypt_path_t *cpath_layer, const char *filename, int lineno)
Definition: relay.c:616
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
Definition: relay.c:496
const char * relay_command_to_string(uint8_t command)
Definition: relay.c:507
uint8_t packed_cell_get_command(const packed_cell_t *cell, int wide_circ_ids)
Definition: relay.c:2961
uint64_t stats_n_relay_cells_delivered
Definition: relay.c:127
void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell)
Definition: relay.c:2627
int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, cell_direction_t cell_direction)
Definition: relay.c:222
int connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial, int *max_cells)
Definition: relay.c:2219
int connection_edge_send_command(edge_connection_t *fromconn, uint8_t relay_command, const char *payload, size_t payload_len)
Definition: relay.c:737
uint64_t stats_n_data_bytes_packaged
Definition: relay.c:2121
size_t packed_cell_mem_cost(void)
Definition: relay.c:2755
Definition: cell_st.h:17
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127