2010-07-23 21:53:11 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2015-01-02 20:27:39 +01:00
|
|
|
* Copyright (c) 2007-2015, The Tor Project, Inc. */
|
2010-07-23 21:53:11 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file relay.h
|
|
|
|
* \brief Header file for relay.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_RELAY_H
|
|
|
|
#define TOR_RELAY_H
|
2010-07-23 21:53:11 +02:00
|
|
|
|
|
|
|
extern uint64_t stats_n_relay_cells_relayed;
|
|
|
|
extern uint64_t stats_n_relay_cells_delivered;
|
|
|
|
|
|
|
|
int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
|
|
|
|
cell_direction_t cell_direction);
|
|
|
|
|
2010-12-16 04:47:28 +01:00
|
|
|
void relay_header_pack(uint8_t *dest, const relay_header_t *src);
|
|
|
|
void relay_header_unpack(relay_header_t *dest, const uint8_t *src);
|
2013-03-19 22:00:40 +01:00
|
|
|
int relay_send_command_from_edge_(streamid_t stream_id, circuit_t *circ,
|
2010-07-23 21:53:11 +02:00
|
|
|
uint8_t relay_command, const char *payload,
|
2013-03-19 22:00:40 +01:00
|
|
|
size_t payload_len, crypt_path_t *cpath_layer,
|
|
|
|
const char *filename, int lineno);
|
|
|
|
#define relay_send_command_from_edge(stream_id, circ, relay_command, payload, \
|
|
|
|
payload_len, cpath_layer) \
|
|
|
|
relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
|
|
|
|
(payload), (payload_len), (cpath_layer), \
|
|
|
|
__FILE__, __LINE__)
|
2010-07-23 21:53:11 +02:00
|
|
|
int connection_edge_send_command(edge_connection_t *fromconn,
|
|
|
|
uint8_t relay_command, const char *payload,
|
|
|
|
size_t payload_len);
|
|
|
|
int connection_edge_package_raw_inbuf(edge_connection_t *conn,
|
2010-09-13 22:05:22 +02:00
|
|
|
int package_partial,
|
|
|
|
int *max_cells);
|
2010-07-23 21:53:11 +02:00
|
|
|
void connection_edge_consider_sending_sendme(edge_connection_t *conn);
|
|
|
|
|
|
|
|
extern uint64_t stats_n_data_cells_packaged;
|
|
|
|
extern uint64_t stats_n_data_bytes_packaged;
|
|
|
|
extern uint64_t stats_n_data_cells_received;
|
|
|
|
extern uint64_t stats_n_data_bytes_received;
|
|
|
|
|
2014-05-13 03:23:34 +02:00
|
|
|
#ifdef ENABLE_MEMPOOLS
|
2010-07-23 21:53:11 +02:00
|
|
|
void init_cell_pool(void);
|
|
|
|
void free_cell_pool(void);
|
|
|
|
void clean_cell_pool(void);
|
2014-05-13 03:23:34 +02:00
|
|
|
#endif /* ENABLE_MEMPOOLS */
|
2010-07-23 21:53:11 +02:00
|
|
|
void dump_cell_pool_usage(int severity);
|
2013-06-16 15:55:44 +02:00
|
|
|
size_t packed_cell_mem_cost(void);
|
2010-07-23 21:53:11 +02:00
|
|
|
|
2014-11-17 17:43:50 +01:00
|
|
|
int have_been_under_memory_pressure(void);
|
|
|
|
|
2012-08-25 23:30:01 +02:00
|
|
|
/* For channeltls.c */
|
|
|
|
void packed_cell_free(packed_cell_t *cell);
|
|
|
|
|
2013-03-22 19:25:34 +01:00
|
|
|
void cell_queue_init(cell_queue_t *queue);
|
2010-07-23 21:53:11 +02:00
|
|
|
void cell_queue_clear(cell_queue_t *queue);
|
|
|
|
void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
|
2013-02-06 14:37:38 +01:00
|
|
|
void cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue,
|
2013-05-24 12:29:42 +02:00
|
|
|
int exitward, const cell_t *cell,
|
2013-03-21 19:51:27 +01:00
|
|
|
int wide_circ_ids, int use_stats);
|
2010-07-23 21:53:11 +02:00
|
|
|
|
2012-08-08 15:02:47 +02:00
|
|
|
void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan,
|
2010-09-02 21:26:17 +02:00
|
|
|
cell_t *cell, cell_direction_t direction,
|
2010-09-08 16:53:19 +02:00
|
|
|
streamid_t fromstream);
|
2013-09-09 19:48:44 +02:00
|
|
|
void channel_unlink_all_circuits(channel_t *chan, smartlist_t *detached_out);
|
2014-01-22 10:04:39 +01:00
|
|
|
MOCK_DECL(int, channel_flush_from_first_active_circuit,
|
|
|
|
(channel_t *chan, int max));
|
2012-09-21 23:46:22 +02:00
|
|
|
void assert_circuit_mux_okay(channel_t *chan);
|
2012-11-12 04:20:59 +01:00
|
|
|
void update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction,
|
|
|
|
const char *file, int lineno);
|
|
|
|
#define update_circuit_on_cmux(circ, direction) \
|
|
|
|
update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
|
2010-07-23 21:53:11 +02:00
|
|
|
|
2010-12-16 04:47:28 +01:00
|
|
|
int append_address_to_payload(uint8_t *payload_out, const tor_addr_t *addr);
|
|
|
|
const uint8_t *decode_address_from_payload(tor_addr_t *addr_out,
|
|
|
|
const uint8_t *payload,
|
2010-07-23 21:53:11 +02:00
|
|
|
int payload_len);
|
2012-08-08 15:02:47 +02:00
|
|
|
void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan);
|
2010-07-23 21:53:11 +02:00
|
|
|
|
2013-02-08 22:28:05 +01:00
|
|
|
void stream_choice_seed_weak_rng(void);
|
|
|
|
|
2011-11-11 19:06:17 +01:00
|
|
|
int relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
|
|
|
|
crypt_path_t **layer_hint, char *recognized);
|
2013-06-06 23:58:28 +02:00
|
|
|
|
2014-06-10 19:35:45 +02:00
|
|
|
circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
|
|
|
|
|
2013-06-06 23:58:28 +02:00
|
|
|
#ifdef RELAY_PRIVATE
|
|
|
|
STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell,
|
2012-10-31 23:27:48 +01:00
|
|
|
tor_addr_t *addr_out, int *ttl_out);
|
2014-03-28 03:24:48 +01:00
|
|
|
/** An address-and-ttl tuple as yielded by resolved_cell_parse */
|
|
|
|
typedef struct address_ttl_s {
|
|
|
|
tor_addr_t addr;
|
|
|
|
char *hostname;
|
|
|
|
int ttl;
|
|
|
|
} address_ttl_t;
|
|
|
|
STATIC void address_ttl_free(address_ttl_t *addr);
|
|
|
|
STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh,
|
|
|
|
smartlist_t *addresses_out, int *errcode_out);
|
2014-04-02 19:38:50 +02:00
|
|
|
STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn,
|
|
|
|
const cell_t *cell,
|
|
|
|
const relay_header_t *rh);
|
2013-07-18 17:02:36 +02:00
|
|
|
STATIC packed_cell_t *packed_cell_new(void);
|
|
|
|
STATIC packed_cell_t *cell_queue_pop(cell_queue_t *queue);
|
2014-01-13 15:52:07 +01:00
|
|
|
STATIC size_t cell_queues_get_total_allocation(void);
|
|
|
|
STATIC int cell_queues_check_size(void);
|
2011-11-11 19:06:17 +01:00
|
|
|
#endif
|
|
|
|
|
2010-07-23 21:53:11 +02:00
|
|
|
#endif
|
|
|
|
|