Merge branch 'maint-0.3.0' into maint-0.3.1
[tor.git] / src / or / relay.h
blob9dc0b5d3a23feeff2e7977430d037b887dc838c7
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-2017, 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;
18 int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
19 cell_direction_t cell_direction);
21 void relay_header_pack(uint8_t *dest, const relay_header_t *src);
22 void relay_header_unpack(relay_header_t *dest, const uint8_t *src);
23 MOCK_DECL(int,
24 relay_send_command_from_edge_,(streamid_t stream_id, circuit_t *circ,
25 uint8_t relay_command, const char *payload,
26 size_t payload_len, crypt_path_t *cpath_layer,
27 const char *filename, int lineno));
28 /* Indicates to relay_send_command_from_edge() that it is a control cell. */
29 #define CONTROL_CELL_ID 0
30 #define relay_send_command_from_edge(stream_id, circ, relay_command, payload, \
31 payload_len, cpath_layer) \
32 relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
33 (payload), (payload_len), (cpath_layer), \
34 __FILE__, __LINE__)
35 int connection_edge_send_command(edge_connection_t *fromconn,
36 uint8_t relay_command, const char *payload,
37 size_t payload_len);
38 int connection_edge_package_raw_inbuf(edge_connection_t *conn,
39 int package_partial,
40 int *max_cells);
41 void connection_edge_consider_sending_sendme(edge_connection_t *conn);
43 extern uint64_t stats_n_data_cells_packaged;
44 extern uint64_t stats_n_data_bytes_packaged;
45 extern uint64_t stats_n_data_cells_received;
46 extern uint64_t stats_n_data_bytes_received;
48 void dump_cell_pool_usage(int severity);
49 size_t packed_cell_mem_cost(void);
51 int have_been_under_memory_pressure(void);
53 /* For channeltls.c */
54 void packed_cell_free(packed_cell_t *cell);
56 void cell_queue_init(cell_queue_t *queue);
57 void cell_queue_clear(cell_queue_t *queue);
58 void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
59 void cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue,
60 int exitward, const cell_t *cell,
61 int wide_circ_ids, int use_stats);
63 void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan,
64 cell_t *cell, cell_direction_t direction,
65 streamid_t fromstream);
67 void destroy_cell_queue_init(destroy_cell_queue_t *queue);
68 void destroy_cell_queue_clear(destroy_cell_queue_t *queue);
69 void destroy_cell_queue_append(destroy_cell_queue_t *queue,
70 circid_t circid,
71 uint8_t reason);
73 void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out);
74 MOCK_DECL(int, channel_flush_from_first_active_circuit,
75 (channel_t *chan, int max));
76 void assert_circuit_mux_okay(channel_t *chan);
77 void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction,
78 const char *file, int lineno);
79 #define update_circuit_on_cmux(circ, direction) \
80 update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
82 int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr);
83 const uint8_t *decode_address_from_payload(tor_addr_t *addr_out,
84 const uint8_t *payload,
85 int payload_len);
86 void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan);
88 void stream_choice_seed_weak_rng(void);
90 int relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
91 crypt_path_t **layer_hint, char *recognized);
93 circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
95 #ifdef RELAY_PRIVATE
96 STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell,
97 tor_addr_t *addr_out, int *ttl_out);
98 /** An address-and-ttl tuple as yielded by resolved_cell_parse */
99 typedef struct address_ttl_s {
100 tor_addr_t addr;
101 char *hostname;
102 int ttl;
103 } address_ttl_t;
104 STATIC void address_ttl_free(address_ttl_t *addr);
105 STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh,
106 smartlist_t *addresses_out, int *errcode_out);
107 STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn,
108 const cell_t *cell,
109 const relay_header_t *rh);
110 STATIC packed_cell_t *packed_cell_new(void);
111 STATIC packed_cell_t *cell_queue_pop(cell_queue_t *queue);
112 STATIC destroy_cell_t *destroy_cell_queue_pop(destroy_cell_queue_t *queue);
113 STATIC size_t cell_queues_get_total_allocation(void);
114 STATIC int cell_queues_check_size(void);
115 #endif
117 #endif