tor  0.4.2.0-alpha-dev
Macros | Functions | Variables
relay.h File Reference

Go to the source code of this file.

Macros

#define CONTROL_CELL_ID   0
 
#define relay_send_command_from_edge(stream_id, circ, relay_command, payload, payload_len, cpath_layer)
 
#define packed_cell_free(cell)   FREE_AND_NULL(packed_cell_t, packed_cell_free_, (cell))
 
#define update_circuit_on_cmux(circ, direction)   update_circuit_on_cmux_((circ), (direction), SHORT_FILE__, __LINE__)
 

Functions

void relay_consensus_has_changed (const networkstatus_t *ns)
 
int circuit_receive_relay_cell (cell_t *cell, circuit_t *circ, cell_direction_t cell_direction)
 
size_t cell_queues_get_total_allocation (void)
 
void relay_header_pack (uint8_t *dest, const relay_header_t *src)
 
void relay_header_unpack (relay_header_t *dest, const uint8_t *src)
 
 MOCK_DECL (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))
 
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, int package_partial, int *max_cells)
 
void connection_edge_consider_sending_sendme (edge_connection_t *conn)
 
void circuit_reset_sendme_randomness (circuit_t *circ)
 
void dump_cell_pool_usage (int severity)
 
size_t packed_cell_mem_cost (void)
 
int have_been_under_memory_pressure (void)
 
void packed_cell_free_ (packed_cell_t *cell)
 
void cell_queue_init (cell_queue_t *queue)
 
void cell_queue_clear (cell_queue_t *queue)
 
void cell_queue_append (cell_queue_t *queue, packed_cell_t *cell)
 
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)
 
void append_cell_to_circuit_queue (circuit_t *circ, channel_t *chan, cell_t *cell, cell_direction_t direction, streamid_t fromstream)
 
void destroy_cell_queue_init (destroy_cell_queue_t *queue)
 
void destroy_cell_queue_clear (destroy_cell_queue_t *queue)
 
void destroy_cell_queue_append (destroy_cell_queue_t *queue, circid_t circid, uint8_t reason)
 
void channel_unlink_all_circuits (channel_t *chan, smartlist_t *detached_out)
 
 MOCK_DECL (int, channel_flush_from_first_active_circuit,(channel_t *chan, int max))
 
 MOCK_DECL (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))
 
void update_circuit_on_cmux_ (circuit_t *circ, cell_direction_t direction, const char *file, int lineno)
 
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, int payload_len)
 
void circuit_clear_cell_queue (circuit_t *circ, channel_t *chan)
 
circid_t packed_cell_get_circid (const packed_cell_t *cell, int wide_circ_ids)
 
uint8_t packed_cell_get_command (const packed_cell_t *cell, int wide_circ_ids)
 

Variables

uint64_t stats_n_relay_cells_relayed
 
uint64_t stats_n_relay_cells_delivered
 
uint64_t stats_n_circ_max_cell_reached
 
uint64_t stats_n_data_cells_packaged
 
uint64_t stats_n_data_bytes_packaged
 
uint64_t stats_n_data_cells_received
 
uint64_t stats_n_data_bytes_received
 

Detailed Description

Header file for relay.c.

Definition in file relay.h.

Macro Definition Documentation

◆ relay_send_command_from_edge

#define relay_send_command_from_edge (   stream_id,
  circ,
  relay_command,
  payload,
  payload_len,
  cpath_layer 
)
Value:
relay_send_command_from_edge_((stream_id), (circ), (relay_command), \
(payload), (payload_len), (cpath_layer), \
__FILE__, __LINE__)

Definition at line 33 of file relay.h.

Function Documentation

◆ append_address_to_payload()

int append_address_to_payload ( uint8_t *  payload_out,
const tor_addr_t addr 
)

Append an encoded value of addr to payload_out, which must have at least 18 bytes of free space. The encoding is, as specified in tor-spec.txt: RESOLVED_TYPE_IPV4 or RESOLVED_TYPE_IPV6 [1 byte] LENGTH [1 byte] ADDRESS [length bytes] Return the number of bytes added, or -1 on error

Definition at line 3156 of file relay.c.

References tor_addr_family().

◆ append_cell_to_circuit_queue()

void append_cell_to_circuit_queue ( circuit_t circ,
channel_t chan,
cell_t cell,
cell_direction_t  direction,
streamid_t  fromstream 
)

Add cell to the queue of circ writing to chan transmitting in direction.

The given cell is copied onto the circuit queue so the caller must cleanup the memory.

This function is part of the fast path.

Definition at line 3083 of file relay.c.

References CELL_DIRECTION_OUT, circuit_t::marked_for_close, circuit_t::n_chan_cells, or_circuit_t::p_chan_cells, circuit_t::streams_blocked_on_n_chan, circuit_t::streams_blocked_on_p_chan, and TO_OR_CIRCUIT().

◆ cell_queue_append()

void cell_queue_append ( cell_queue_t queue,
packed_cell_t cell 
)

Append cell to the end of queue.

Definition at line 2528 of file relay.c.

References cell_queue_t::n.

Referenced by cell_queue_append_packed_copy().

◆ cell_queue_append_packed_copy()

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 
)

Append a newly allocated copy of cell to the end of the exitward (or app-ward) queue of circ. If use_stats is true, record statistics about the cell.

Definition at line 2539 of file relay.c.

References cell_queue_append(), packed_cell_t::inserted_timestamp, monotime_coarse_get_stamp(), and packed_cell_copy().

◆ cell_queue_clear()

void cell_queue_clear ( cell_queue_t queue)

Remove and free every cell in queue.

Definition at line 2563 of file relay.c.

References cell_queue_t::n, and packed_cell_free_unchecked().

Referenced by circuit_clear_cell_queue().

◆ cell_queue_init()

void cell_queue_init ( cell_queue_t queue)

Initialize queue as an empty cell queue.

Definition at line 2555 of file relay.c.

Referenced by init_circuit_base().

◆ channel_unlink_all_circuits()

void channel_unlink_all_circuits ( channel_t chan,
smartlist_t circuits_out 
)

Remove all circuits from the cmux on chan.

If circuits_out is non-NULL, add all detached circuits to circuits_out.

Definition at line 2779 of file relay.c.

References circuitmux_detach_all_circuits(), channel_s::cmux, channel_s::num_n_circuits, and tor_assert().

Referenced by circuit_unlink_all_from_channel().

◆ circuit_clear_cell_queue()

void circuit_clear_cell_queue ( circuit_t circ,
channel_t chan 
)

◆ circuit_receive_relay_cell()

int circuit_receive_relay_cell ( cell_t cell,
circuit_t circ,
cell_direction_t  cell_direction 
)

Receive a relay cell:

  • Crypt it (encrypt if headed toward the origin or if we are the origin; decrypt if we're headed toward the exit).
  • Check if recognized (if exitward).
  • If recognized and the digest checks out, then find if there's a stream that the cell is intended for, and deliver it to the right connection_edge.
  • If not recognized, then we need to relay it: append it to the appropriate cell_queue on circ.

Return -reason on failure.

Definition at line 223 of file relay.c.

References CELL_DIRECTION_IN, CELL_DIRECTION_OUT, log_fn, circuit_t::marked_for_close, and tor_assert().

◆ circuit_reset_sendme_randomness()

void circuit_reset_sendme_randomness ( circuit_t circ)

Called when initializing a circuit, or when we have reached the end of the window in which we need to send some randomness so that incoming sendme cells will be unpredictable. Resets the flags and picks a new window.

Definition at line 2040 of file relay.c.

References CIRCWINDOW_INCREMENT, crypto_fast_rng_get_uint(), get_thread_fast_rng(), circuit_t::have_sent_sufficiently_random_cell, and circuit_t::send_randomness_after_n_cells.

Referenced by init_circuit_base().

◆ connection_edge_package_raw_inbuf()

int connection_edge_package_raw_inbuf ( edge_connection_t conn,
int  package_partial,
int *  max_cells 
)

If conn has an entire relay payload of bytes on its inbuf (or package_partial is true), and the appropriate package windows aren't empty, grab a cell and send it down the circuit.

If *max_cells is given, package no more than max_cells. Decrement *max_cells by the number of cells packaged.

Return -1 (and send a RELAY_COMMAND_END cell if necessary) if conn should be marked for close, else return 0.

Definition at line 2123 of file relay.c.

References CELL_PAYLOAD_SIZE, CONN_TYPE_AP, LD_APP, and connection_t::type.

◆ connection_edge_send_command()

int connection_edge_send_command ( edge_connection_t fromconn,
uint8_t  relay_command,
const char *  payload,
size_t  payload_len 
)

Make a relay cell out of relay_command and payload, and send it onto the open circuit circ. fromconn is the stream that's sending the relay cell, or NULL if it's a control cell. cpath_layer is NULL for OR->OP cells, or the destination hop for OP->OR cells.

If you can't send the cell, mark the circuit for close and return -1. Else return 0.

Definition at line 728 of file relay.c.

References edge_connection_t::cpath_layer, connection_t::marked_for_close, edge_connection_t::on_circuit, and tor_assert().

◆ decode_address_from_payload()

const uint8_t* decode_address_from_payload ( tor_addr_t addr_out,
const uint8_t *  payload,
int  payload_len 
)

Given payload_len bytes at payload, starting with an address encoded as by append_address_to_payload(), try to decode the address into *addr_out. Return the next byte in the payload after the address on success, or NULL on failure.

Definition at line 3182 of file relay.c.

◆ destroy_cell_queue_append()

void destroy_cell_queue_append ( destroy_cell_queue_t queue,
circid_t  circid,
uint8_t  reason 
)

Append a destroy cell for circid to queue.

Definition at line 2623 of file relay.c.

◆ destroy_cell_queue_clear()

void destroy_cell_queue_clear ( destroy_cell_queue_t queue)

Remove and free every cell in queue.

Definition at line 2597 of file relay.c.

References destroy_cell_queue_t::n, and tor_free.

◆ destroy_cell_queue_init()

void destroy_cell_queue_init ( destroy_cell_queue_t queue)

Initialize queue as an empty cell queue.

Definition at line 2589 of file relay.c.

◆ dump_cell_pool_usage()

void dump_cell_pool_usage ( int  severity)

Log current statistics for cell pool allocation at log level severity.

Definition at line 2501 of file relay.c.

References CIRCUIT_IS_ORIGIN, cell_queue_t::n, or_circuit_t::p_chan_cells, SMARTLIST_FOREACH_BEGIN, and TO_OR_CIRCUIT().

Referenced by dumpmemusage().

◆ have_been_under_memory_pressure()

int have_been_under_memory_pressure ( void  )

Return true if we've been under memory pressure in the last MEMORY_PRESSURE_INTERVAL seconds.

Definition at line 2723 of file relay.c.

References approx_time(), last_time_under_memory_pressure, and MEMORY_PRESSURE_INTERVAL.

◆ packed_cell_free_()

void packed_cell_free_ ( packed_cell_t cell)

Return a packed cell used outside by channel_t lower layer

Definition at line 2491 of file relay.c.

References packed_cell_free_unchecked().

◆ packed_cell_get_circid()

circid_t packed_cell_get_circid ( const packed_cell_t cell,
int  wide_circ_ids 
)

Extract the circuit ID from a packed cell.

Definition at line 2856 of file relay.c.

References packed_cell_t::body, get_uint16(), and get_uint32().

◆ packed_cell_get_command()

uint8_t packed_cell_get_command ( const packed_cell_t cell,
int  wide_circ_ids 
)

Extract the command from a packed cell.

Definition at line 2845 of file relay.c.

Referenced by write_packed_cell().

◆ packed_cell_mem_cost()

size_t packed_cell_mem_cost ( void  )

Return the total number of bytes used for each packed_cell in a queue. Approximate.

Definition at line 2656 of file relay.c.

◆ relay_header_pack()

void relay_header_pack ( uint8_t *  dest,
const relay_header_t src 
)

Pack the relay_header_t host-order structure src into network-order in the buffer dest. See tor-spec.txt for details about the wire format.

Definition at line 474 of file relay.c.

◆ relay_header_unpack()

void relay_header_unpack ( relay_header_t dest,
const uint8_t *  src 
)

Unpack the network-order buffer src into a host-order relay_header_t structure dest.

Definition at line 487 of file relay.c.

References relay_header_t::command.

Referenced by connection_exit_begin_conn(), connection_exit_begin_resolve(), pathbias_check_probe_response(), pathbias_count_valid_cells(), and relay_lookup_conn().

◆ update_circuit_on_cmux_()

void update_circuit_on_cmux_ ( circuit_t circ,
cell_direction_t  direction,
const char *  file,
int  lineno 
)

Update the number of cells available on the circuit's n_chan or p_chan's circuit mux.

Definition at line 2734 of file relay.c.

References CELL_DIRECTION_OUT, circuitmux_is_circuit_attached(), channel_s::cmux, circuit_t::n_chan, or_circuit_t::p_chan, TO_OR_CIRCUIT(), and tor_assert().

Variable Documentation

◆ stats_n_circ_max_cell_reached

uint64_t stats_n_circ_max_cell_reached

Stats: how many circuits have we closed due to the cell queue limit being reached (see append_cell_to_circuit_queue())

Definition at line 132 of file relay.c.

◆ stats_n_data_bytes_packaged

uint64_t stats_n_data_bytes_packaged

How many bytes of data have we put in relay_data cells have we built, ever? This would be RELAY_PAYLOAD_SIZE*stats_n_data_cells_packaged if every relay cell we ever sent were completely full of data.

Definition at line 2026 of file relay.c.

◆ stats_n_data_bytes_received

uint64_t stats_n_data_bytes_received

How many bytes of data have we received relay_data cells, ever? This would be RELAY_PAYLOAD_SIZE*stats_n_data_cells_packaged if every relay cell we ever received were completely full of data.

Definition at line 2032 of file relay.c.

◆ stats_n_data_cells_packaged

uint64_t stats_n_data_cells_packaged

How many relay_data cells have we built, ever?

Definition at line 2022 of file relay.c.

◆ stats_n_data_cells_received

uint64_t stats_n_data_cells_received

How many relay_data cells have we received, ever?

Definition at line 2028 of file relay.c.

◆ stats_n_relay_cells_delivered

uint64_t stats_n_relay_cells_delivered

Stats: how many relay cells have been delivered to streams at this hop?

Definition at line 129 of file relay.c.

◆ stats_n_relay_cells_relayed

uint64_t stats_n_relay_cells_relayed

Stats: how many relay cells have originated at this hop, or have been relayed onward (not recognized at this hop)?

Definition at line 125 of file relay.c.