tor  0.4.0.1-alpha
relay.h
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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_RELAY_H
13 #define TOR_RELAY_H
14 
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 
19 void relay_consensus_has_changed(const networkstatus_t *ns);
21  cell_direction_t cell_direction);
22 size_t cell_queues_get_total_allocation(void);
23 
24 void relay_header_pack(uint8_t *dest, const relay_header_t *src);
25 void relay_header_unpack(relay_header_t *dest, const uint8_t *src);
26 MOCK_DECL(int,
27 relay_send_command_from_edge_,(streamid_t stream_id, circuit_t *circ,
28  uint8_t relay_command, const char *payload,
29  size_t payload_len, crypt_path_t *cpath_layer,
30  const char *filename, int lineno));
31 /* Indicates to relay_send_command_from_edge() that it is a control cell. */
32 #define CONTROL_CELL_ID 0
33 #define relay_send_command_from_edge(stream_id, circ, relay_command, payload, \
34  payload_len, cpath_layer) \
35  relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
36  (payload), (payload_len), (cpath_layer), \
37  __FILE__, __LINE__)
39  uint8_t relay_command, const char *payload,
40  size_t payload_len);
42  int package_partial,
43  int *max_cells);
45 
46 extern uint64_t stats_n_data_cells_packaged;
47 extern uint64_t stats_n_data_bytes_packaged;
48 extern uint64_t stats_n_data_cells_received;
49 extern uint64_t stats_n_data_bytes_received;
50 
51 void dump_cell_pool_usage(int severity);
52 size_t packed_cell_mem_cost(void);
53 
55 
56 /* For channeltls.c */
58 #define packed_cell_free(cell) \
59  FREE_AND_NULL(packed_cell_t, packed_cell_free_, (cell))
60 
61 void cell_queue_init(cell_queue_t *queue);
62 void cell_queue_clear(cell_queue_t *queue);
63 void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
65  int exitward, const cell_t *cell,
66  int wide_circ_ids, int use_stats);
67 
69  cell_t *cell, cell_direction_t direction,
70  streamid_t fromstream);
71 
75  circid_t circid,
76  uint8_t reason);
77 
78 void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out);
79 MOCK_DECL(int, channel_flush_from_first_active_circuit,
80  (channel_t *chan, int max));
81 MOCK_DECL(int, circuit_package_relay_cell, (cell_t *cell, circuit_t *circ,
82  cell_direction_t cell_direction,
83  crypt_path_t *layer_hint, streamid_t on_stream,
84  const char *filename, int lineno));
85 
87  const char *file, int lineno);
88 #define update_circuit_on_cmux(circ, direction) \
89  update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
90 
91 int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr);
92 const uint8_t *decode_address_from_payload(tor_addr_t *addr_out,
93  const uint8_t *payload,
94  int payload_len);
96 
97 void stream_choice_seed_weak_rng(void);
98 
99 circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
100 
101 #ifdef RELAY_PRIVATE
102 STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell,
103  tor_addr_t *addr_out, int *ttl_out);
105 typedef struct address_ttl_s {
106  tor_addr_t addr;
107  char *hostname;
108  int ttl;
109 } address_ttl_t;
110 STATIC void address_ttl_free_(address_ttl_t *addr);
111 #define address_ttl_free(addr) \
112  FREE_AND_NULL(address_ttl_t, address_ttl_free_, (addr))
113 STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh,
114  smartlist_t *addresses_out, int *errcode_out);
116  const cell_t *cell,
117  const relay_header_t *rh);
118 STATIC packed_cell_t *packed_cell_new(void);
121 STATIC int cell_queues_check_size(void);
122 STATIC int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ,
123  edge_connection_t *conn,
124  crypt_path_t *layer_hint);
125 
126 #endif /* defined(RELAY_PRIVATE) */
127 
128 #endif /* !defined(TOR_RELAY_H) */
129 
STATIC void address_ttl_free_(address_ttl_t *addr)
Definition: relay.c:1036
STATIC destroy_cell_t * destroy_cell_queue_pop(destroy_cell_queue_t *queue)
Definition: relay.c:2550
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:998
uint64_t stats_n_relay_cells_relayed
Definition: relay.c:128
const uint8_t * decode_address_from_payload(tor_addr_t *addr_out, const uint8_t *payload, int payload_len)
Definition: relay.c:3121
STATIC int cell_queues_check_size(void)
Definition: relay.c:2616
STATIC packed_cell_t * packed_cell_new(void)
Definition: relay.c:2422
uint64_t stats_n_circ_max_cell_reached
Definition: relay.c:135
uint64_t stats_n_data_cells_received
Definition: relay.c:1976
Definition: cell_st.h:12
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
Definition: relay.c:489
void cell_queue_init(cell_queue_t *queue)
Definition: relay.c:2494
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:3022
void packed_cell_free_(packed_cell_t *cell)
Definition: relay.c:2430
int connection_edge_send_command(edge_connection_t *fromconn, uint8_t relay_command, const char *payload, size_t payload_len)
Definition: relay.c:661
int connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial, int *max_cells)
Definition: relay.c:1993
void connection_edge_consider_sending_sendme(edge_connection_t *conn)
Definition: relay.c:2133
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:1447
void relay_header_pack(uint8_t *dest, const relay_header_t *src)
Definition: relay.c:476
size_t packed_cell_mem_cost(void)
Definition: relay.c:2595
void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell)
Definition: relay.c:2467
cell_direction_t
Definition: or.h:482
uint16_t streamid_t
Definition: or.h:610
uint64_t stats_n_data_bytes_received
Definition: relay.c:1980
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:2478
STATIC packed_cell_t * cell_queue_pop(cell_queue_t *queue)
Definition: relay.c:2516
void destroy_cell_queue_init(destroy_cell_queue_t *queue)
Definition: relay.c:2528
void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction, const char *file, int lineno)
Definition: relay.c:2673
uint64_t stats_n_data_cells_packaged
Definition: relay.c:1970
void destroy_cell_queue_clear(destroy_cell_queue_t *queue)
Definition: relay.c:2536
uint64_t stats_n_data_bytes_packaged
Definition: relay.c:1974
void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out)
Definition: relay.c:2718
void dump_cell_pool_usage(int severity)
Definition: relay.c:2440
uint64_t stats_n_relay_cells_delivered
Definition: relay.c:132
uint32_t circid_t
Definition: or.h:608
int have_been_under_memory_pressure(void)
Definition: relay.c:2662
STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn, const cell_t *cell, const relay_header_t *rh)
Definition: relay.c:1221
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh, smartlist_t *addresses_out, int *errcode_out)
Definition: relay.c:1050
void destroy_cell_queue_append(destroy_cell_queue_t *queue, circid_t circid, uint8_t reason)
Definition: relay.c:2562
void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan)
Definition: relay.c:3149
circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids)
Definition: relay.c:2795
int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr)
Definition: relay.c:3095
int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, cell_direction_t cell_direction)
Definition: relay.c:229
void cell_queue_clear(cell_queue_t *queue)
Definition: relay.c:2502