#include <math.h>
#include "or.h"
#include "mempool.h"
#define CELL_QUEUE_HIGHWATER_SIZE 256 |
Stop reading on edge connections when we have this many cells waiting on the appropriate queue.
Referenced by append_cell_to_circuit_queue().
#define CELL_QUEUE_LOWWATER_SIZE 64 |
Start reading from edge connections again when we get down to this many cells.
Referenced by connection_or_flush_from_first_active_circuit().
#define EWMA_DEFAULT_HALFLIFE 0.0 |
The default per-tick scale factor, if it hasn't been overridden by a consensus or a configuration setting. zero means "disabled".
Referenced by cell_ewma_set_scale_factor().
#define EWMA_TICK_LEN 10 |
How long does a tick last (seconds)?
Referenced by cell_ewma_get_tick(), cell_ewma_set_scale_factor(), and cell_ewma_tick_from_timeval().
#define MAX_RESOLVE_FAILURES 3 |
How many times will I retry a stream that fails due to DNS resolve failure or misc error?
Referenced by connection_ap_process_end_not_open().
static void add_cell_ewma_to_conn | ( | or_connection_t * | conn, | |
cell_ewma_t * | ewma | |||
) | [static] |
Rescale ewma to the same scale as conn, and add it to conn's priority queue of active circuits
References or_connection_t::active_circuit_pqueue, or_connection_t::active_circuit_pqueue_last_recalibrated, compare_cell_ewma_counts(), cell_ewma_t::heap_index, scale_single_cell_ewma(), smartlist_pqueue_add(), STRUCT_OFFSET, and tor_assert.
Referenced by connection_or_flush_from_first_active_circuit(), and make_circuit_active_on_conn().
int append_address_to_payload | ( | char * | 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
References tor_addr_family(), and tor_addr_to_ipv4n().
Referenced by connection_or_send_netinfo().
void append_cell_to_circuit_queue | ( | circuit_t * | circ, | |
or_connection_t * | orconn, | |||
cell_t * | cell, | |||
cell_direction_t | direction | |||
) |
Add cell to the queue of circ writing to orconn transmitting in direction.
References or_connection_t::_base, approx_time(), buf_datalen(), CELL_DIRECTION_OUT, cell_queue_append_packed_copy(), CELL_QUEUE_HIGHWATER_SIZE, cell_t::command, connection_or_flush_from_first_active_circuit(), LD_GENERAL, or_connection_t::link_proto, make_circuit_active_on_conn(), cell_queue_t::n, circuit_t::n_conn_cells, connection_t::outbuf, or_circuit_t::p_conn_cells, set_streams_blocked_on_circ(), circuit_t::streams_blocked_on_n_conn, circuit_t::streams_blocked_on_p_conn, and TO_OR_CIRCUIT().
Referenced by circuit_deliver_create_cell(), circuit_package_relay_cell(), circuit_receive_relay_cell(), and onionskin_answer().
void assert_active_circuits_ok | ( | or_connection_t * | orconn | ) |
Fail with an assert if the active circuits ring on orconn is corrupt.
References or_connection_t::active_circuit_pqueue, or_connection_t::active_circuits, cell_ewma_t::heap_index, cell_ewma_t::is_for_p_conn, circuit_t::n_cell_ewma, circuit_t::n_conn, next_circ_on_conn_p(), or_circuit_t::p_cell_ewma, prev_circ_on_conn_p(), TO_OR_CIRCUIT(), and tor_assert.
unsigned cell_ewma_get_tick | ( | void | ) |
Compute and return the current cell_ewma tick.
References approx_time(), and EWMA_TICK_LEN.
Referenced by init_circuit_base(), or_circuit_new(), and or_connection_new().
void cell_ewma_set_scale_factor | ( | or_options_t * | options, | |
networkstatus_t * | consensus | |||
) |
Adjust the global cell scale factor based on options
References or_options_t::CircuitPriorityHalflife, EWMA_DEFAULT_HALFLIFE, EWMA_TICK_LEN, LD_OR, and networkstatus_get_param().
Referenced by networkstatus_set_current_consensus(), and options_act().
static unsigned cell_ewma_tick_from_timeval | ( | const struct timeval * | now, | |
double * | remainder_out | |||
) | [static] |
Given a timeval now, compute the cell_ewma tick in which it occurs and the fraction of the tick that has elapsed between the start of the tick and now. Return the former and store the latter in *remainder_out.
These tick values are not meant to be shared between Tor instances, or used for other purposes.
References EWMA_TICK_LEN.
Referenced by connection_or_flush_from_first_active_circuit().
static circuit_t* cell_ewma_to_circuit | ( | cell_ewma_t * | ewma | ) | [static] |
Given a cell_ewma_t, return a pointer to the circuit containing it.
References cell_ewma_t::is_for_p_conn, SUBTYPE_P, and TO_CIRCUIT.
Referenced by connection_or_flush_from_first_active_circuit().
void cell_queue_append | ( | cell_queue_t * | queue, | |
packed_cell_t * | cell | |||
) |
Append cell to the end of queue.
References cell_queue_t::head, cell_queue_t::n, packed_cell_t::next, cell_queue_t::tail, and tor_assert.
Referenced by cell_queue_append_packed_copy().
void cell_queue_append_packed_copy | ( | cell_queue_t * | queue, | |
const cell_t * | cell | |||
) |
Append a newly allocated copy of cell to the end of queue
References cell_queue_append(), insertion_time_elem_t::counter, insertion_time_queue_t::first, get_options(), insertion_time_elem_t::insertion_time, cell_queue_t::insertion_times, insertion_time_queue_t::last, insertion_time_elem_t::next, and packed_cell_copy().
Referenced by append_cell_to_circuit_queue().
void cell_queue_clear | ( | cell_queue_t * | queue | ) |
Remove and free every cell in queue.
References insertion_time_queue_t::first, cell_queue_t::head, cell_queue_t::insertion_times, cell_queue_t::n, insertion_time_elem_t::next, packed_cell_t::next, packed_cell_free_unchecked(), cell_queue_t::tail, and tor_free.
Referenced by circuit_free().
static INLINE packed_cell_t* cell_queue_pop | ( | cell_queue_t * | queue | ) | [static] |
Extract and return the cell at the head of queue; return NULL if queue is empty.
References cell_queue_t::head, cell_queue_t::n, packed_cell_t::next, cell_queue_t::tail, and tor_assert.
Referenced by connection_or_flush_from_first_active_circuit().
static void circuit_consider_sending_sendme | ( | circuit_t * | circ, | |
crypt_path_t * | layer_hint | |||
) | [static] |
Check if the deliver_window for circuit circ (at hop layer_hint if it's defined) is low enough that we should send a circuit-level sendme back down the circuit. If so, send enough sendmes that the window would be overfull if we sent any more.
References CIRCWINDOW_INCREMENT, CIRCWINDOW_START, circuit_t::deliver_window, crypt_path_t::deliver_window, LD_CIRC, and relay_send_command_from_edge().
Referenced by connection_edge_process_relay_cell().
static int circuit_consider_stop_edge_reading | ( | circuit_t * | circ, | |
crypt_path_t * | layer_hint | |||
) | [static] |
Check if the package window for circ is empty (at hop layer_hint if it's defined).
If yes, tell edge streams to stop reading and return 1. Else return 0.
References connection_stop_reading(), edge_connection_t::cpath_layer, LD_APP, or_circuit_t::n_streams, edge_connection_t::next_stream, crypt_path_t::package_window, circuit_t::package_window, TO_CONN, TO_OR_CIRCUIT(), and TO_ORIGIN_CIRCUIT().
Referenced by circuit_resume_edge_reading_helper(), and connection_edge_package_raw_inbuf().
static int circuit_package_relay_cell | ( | cell_t * | cell, | |
circuit_t * | circ, | |||
cell_direction_t | cell_direction, | |||
crypt_path_t * | layer_hint | |||
) | [static] |
Package a relay cell from an edge:
References append_cell_to_circuit_queue(), assert_circuit_ok(), CELL_DIRECTION_OUT, CIRCUIT_IS_ORIGIN, crypt_path_t::f_crypto, crypt_path_t::f_digest, LD_BUG, LD_OR, circuit_t::n_conn, or_circuit_t::p_conn, or_circuit_t::p_crypto, or_circuit_t::p_digest, cell_t::payload, crypt_path_t::prev, relay_crypt_one_payload(), relay_set_digest(), TO_OR_CIRCUIT(), TO_ORIGIN_CIRCUIT(), and tor_assert.
Referenced by relay_send_command_from_edge().
int circuit_receive_relay_cell | ( | cell_t * | cell, | |
circuit_t * | circ, | |||
cell_direction_t | cell_direction | |||
) |
Receive a relay cell:
Return -reason on failure.
References or_circuit_t::_base, append_cell_to_circuit_queue(), CELL_DIRECTION_IN, CELL_DIRECTION_OUT, cell_t::circ_id, CIRCUIT_IS_ORIGIN, CIRCUIT_PURPOSE_REND_ESTABLISHED, circuit_receive_relay_cell(), cell_t::command, connection_edge_process_relay_cell(), LD_BUG, LD_OR, LD_PROTOCOL, LD_REND, circuit_t::marked_for_close, circuit_t::n_circ_id, circuit_t::n_conn, or_circuit_t::p_circ_id, or_circuit_t::p_conn, circuit_t::purpose, relay_crypt(), relay_lookup_conn(), or_circuit_t::rend_splice, TO_CIRCUIT, TO_OR_CIRCUIT(), and tor_assert.
Referenced by circuit_receive_relay_cell(), and command_process_relay_cell().
static void circuit_resume_edge_reading | ( | circuit_t * | circ, | |
crypt_path_t * | layer_hint | |||
) | [static] |
The circuit circ has received a circuit-level sendme (on hop layer_hint, if we're the OP). Go through all the attached streams and let them resume reading and packaging, if their stream windows allow it.
References CIRCUIT_IS_ORIGIN, circuit_resume_edge_reading_helper(), LD_APP, TO_OR_CIRCUIT(), and TO_ORIGIN_CIRCUIT().
Referenced by connection_edge_process_relay_cell().
static int circuit_resume_edge_reading_helper | ( | edge_connection_t * | conn, | |
circuit_t * | circ, | |||
crypt_path_t * | layer_hint | |||
) | [static] |
A helper function for circuit_resume_edge_reading() above. The arguments are the same, except that conn is the head of a linked list of edge streams that should each be considered.
References edge_connection_t::_base, circuit_consider_stop_edge_reading(), connection_edge_package_raw_inbuf(), connection_start_reading(), edge_connection_t::cpath_layer, connection_t::marked_for_close, edge_connection_t::next_stream, edge_connection_t::package_window, and TO_CONN.
Referenced by circuit_resume_edge_reading().
void clean_cell_pool | ( | void | ) |
static int compare_cell_ewma_counts | ( | const void * | p1, | |
const void * | p2 | |||
) | [static] |
Helper for sorting cell_ewma_t values in their priority queue.
References cell_ewma_t::cell_count.
Referenced by add_cell_ewma_to_conn(), pop_first_cell_ewma_from_conn(), and remove_cell_ewma_from_conn().
static int connection_ap_process_end_not_open | ( | relay_header_t * | rh, | |
cell_t * | cell, | |||
origin_circuit_t * | circ, | |||
edge_connection_t * | conn, | |||
crypt_path_t * | layer_hint | |||
) | [static] |
Called when we receive an END cell on a stream that isn't open yet, from the client side. Arguments are as for connection_edge_process_relay_cell().
References edge_connection_t::_base, origin_circuit_t::_base, socks_request_t::address, addressmap_rewrite(), origin_circuit_t::build_state, cpath_build_state_t::chosen_exit, edge_connection_t::chosen_exit_name, edge_connection_t::chosen_exit_optional, edge_connection_t::chosen_exit_retries, circuit_log_path(), client_dns_clear_failures(), client_dns_incr_failures(), client_dns_set_addressmap(), or_options_t::ClientDNSRejectInternalAddresses, connection_ap_detach_retriable(), connection_edge_is_rendezvous_stream(), control_event_stream_status(), edge_reason_is_retriable(), END_STREAM_REASON_FLAG_REMOTE, get_options(), get_uint32(), extend_info_t::identity_digest, is_internal_IP(), LD_APP, relay_header_t::length, connection_t::marked_for_close, MAX_RESOLVE_FAILURES, or_options_t::MaxCircuitDirtiness, cell_t::payload, policies_set_router_exitpolicy_to_reject_all(), RELAY_HEADER_SIZE, router_get_by_digest(), safe_str(), edge_connection_t::socks_request, stream_end_reason_to_string(), circuit_t::timestamp_dirty, tor_assert, tor_free, and tor_inet_aton().
Referenced by connection_edge_process_relay_cell_not_open().
void connection_edge_consider_sending_sendme | ( | edge_connection_t * | conn | ) |
Called when we've just received a relay data cell, or when we've just finished flushing all bytes to stream conn.
If conn->outbuf is not too full, and our deliver window is low, send back a suitable number of stream-level sendme cells.
References edge_connection_t::_base, circuit_get_by_edge_conn(), connection_edge_send_command(), connection_outbuf_too_full(), edge_connection_t::cpath_layer, edge_connection_t::deliver_window, LD_APP, connection_t::outbuf_flushlen, STREAMWINDOW_INCREMENT, STREAMWINDOW_START, and TO_CONN.
Referenced by connection_edge_finished_flushing(), and connection_edge_process_relay_cell().
int connection_edge_package_raw_inbuf | ( | edge_connection_t * | conn, | |
int | package_partial | |||
) |
While conn->inbuf has an entire relay payload of bytes on it, and the appropriate package windows aren't empty, grab a cell and send it down the circuit.
Return -1 (and send a RELAY_COMMAND_END cell if necessary) if conn should be marked for close, else return 0.
References edge_connection_t::_base, buf_datalen(), CELL_PAYLOAD_SIZE, circuit_consider_stop_edge_reading(), circuit_get_by_edge_conn(), connection_edge_send_command(), connection_fetch_from_buf(), connection_stop_reading(), edge_connection_t::cpath_layer, edge_connection_t::end_reason, END_STREAM_REASON_CANT_ATTACH, connection_t::inbuf, LD_APP, LD_BUG, connection_t::marked_for_close, connection_t::marked_for_close_file, crypt_path_t::package_window, circuit_t::package_window, edge_connection_t::package_window, RELAY_PAYLOAD_SIZE, connection_t::s, TO_CONN, and tor_assert.
Referenced by circuit_resume_edge_reading_helper(), connection_edge_process_inbuf(), connection_edge_process_relay_cell(), and connection_edge_process_relay_cell_not_open().
static int connection_edge_process_relay_cell | ( | cell_t * | cell, | |
circuit_t * | circ, | |||
edge_connection_t * | conn, | |||
crypt_path_t * | layer_hint | |||
) | [static] |
An incoming relay cell has arrived on circuit circ. If conn is NULL this is a control cell, else cell is destined for conn.
If layer_hint is defined, then we're the origin of the circuit, and it specifies the hop that packaged cell.
Return -reason if you want to warn and tear down the circuit, else 0.
References edge_connection_t::_base, circuit_consider_sending_sendme(), circuit_extend(), circuit_finish_handshake(), CIRCUIT_PURPOSE_OR, CIRCUIT_PURPOSE_S_REND_JOINED, circuit_resume_edge_reading(), circuit_send_next_onion_skin(), circuit_set_n_circid_orconn(), circuit_truncated(), CIRCWINDOW_INCREMENT, relay_header_t::command, connection_edge_consider_sending_sendme(), connection_edge_end(), connection_edge_package_raw_inbuf(), connection_edge_process_relay_cell_not_open(), connection_exit_begin_conn(), connection_exit_begin_resolve(), connection_or_send_destroy(), connection_start_reading(), connection_state_is_open(), edge_connection_t::deliver_window, circuit_t::deliver_window, crypt_path_t::deliver_window, circuit_t::dirreq_id, edge_connection_t::edge_has_sent_end, edge_connection_t::end_reason, END_STREAM_REASON_FLAG_REMOTE, socks_request_t::has_finished, connection_t::hold_open_until_flushed, LD_APP, LD_BUG, LD_PROTOCOL, relay_header_t::length, connection_t::marked_for_close, circuit_t::n_circ_id, circuit_t::n_conn, edge_connection_t::package_window, circuit_t::package_window, crypt_path_t::package_window, cell_t::payload, circuit_t::purpose, RELAY_HEADER_SIZE, relay_header_unpack(), RELAY_PAYLOAD_SIZE, relay_send_command_from_edge(), rend_process_relay_cell(), connection_t::s, edge_connection_t::socks_request, stats_n_data_bytes_received, stats_n_data_cells_received, stream_end_reason_to_string(), edge_connection_t::stream_id, relay_header_t::stream_id, STREAMWINDOW_INCREMENT, TO_CONN, TO_OR_CIRCUIT(), TO_ORIGIN_CIRCUIT(), and tor_assert.
Referenced by circuit_receive_relay_cell().
static int connection_edge_process_relay_cell_not_open | ( | relay_header_t * | rh, | |
cell_t * | cell, | |||
circuit_t * | circ, | |||
edge_connection_t * | conn, | |||
crypt_path_t * | layer_hint | |||
) | [static] |
An incoming relay cell has arrived from circuit circ to stream conn.
The arguments here are the same as in connection_edge_process_relay_cell() below; this function is called from there when conn is defined and not in an open state.
References edge_connection_t::_base, socks_request_t::address, AP_CONN_STATE_CONNECT_WAIT, AP_CONN_STATE_OPEN, AP_CONN_STATE_RESOLVE_WAIT, edge_connection_t::chosen_exit_name, CIRCUIT_IS_ORIGIN, circuit_log_path(), client_dns_set_addressmap(), socks_request_t::command, relay_header_t::command, conn_state_to_string(), CONN_TYPE_AP, CONN_TYPE_DIR, connection_ap_handshake_socks_reply(), connection_ap_handshake_socks_resolved(), connection_ap_process_end_not_open(), connection_edge_end(), connection_edge_package_raw_inbuf(), consensus_is_waiting_for_certs(), control_event_bootstrap(), count_loading_descriptors_progress(), DIR_PURPOSE_FETCH_CERTIFICATE, DIR_PURPOSE_FETCH_CONSENSUS, DIR_PURPOSE_FETCH_SERVERDESC, edge_connection_t::edge_has_sent_end, edge_connection_t::end_reason, END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED, END_STREAM_REASON_FLAG_REMOTE, get_options(), get_uint32(), socks_request_t::has_finished, INET_NTOA_BUF_LEN, is_internal_IP(), LD_APP, LD_PROTOCOL, relay_header_t::length, cell_t::payload, connection_t::purpose, RELAY_HEADER_SIZE, remap_event_helper(), edge_connection_t::socks_request, connection_t::state, connection_t::timestamp_lastread, TO_CONN, TO_ORIGIN_CIRCUIT(), tor_assert, tor_inet_ntoa(), and connection_t::type.
Referenced by connection_edge_process_relay_cell().
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.
References edge_connection_t::_base, CONN_TYPE_AP, edge_connection_t::cpath_layer, edge_connection_t::edge_has_sent_end, edge_connection_t::end_reason, LD_APP, LD_BUG, connection_t::marked_for_close, connection_t::marked_for_close_file, edge_connection_t::on_circuit, relay_send_command_from_edge(), edge_connection_t::stream_id, TO_CONN, tor_assert, and connection_t::type.
Referenced by connection_ap_handshake_send_begin(), connection_ap_handshake_send_resolve(), connection_edge_consider_sending_sendme(), connection_edge_end(), connection_edge_finished_connecting(), connection_edge_package_raw_inbuf(), connection_exit_connect(), connection_exit_connect_dir(), send_resolved_cell(), and send_resolved_hostname_cell().
int connection_or_flush_from_first_active_circuit | ( | or_connection_t * | conn, | |
int | max, | |||
time_t | now | |||
) |
Pull as many cells as possible (but no more than max) from the queue of the first active circuit on conn, and write them to conn->outbuf. Return the number of cells written. Advance the active circuit pointer to the next active circuit in the ring.
References or_connection_t::active_circuit_pqueue, or_connection_t::active_circuit_pqueue_last_recalibrated, or_connection_t::active_circuits, add_cell_ewma_to_conn(), packed_cell_t::body, cell_ewma_tick_from_timeval(), cell_ewma_to_circuit(), CELL_NETWORK_SIZE, CELL_QUEUE_LOWWATER_SIZE, cell_queue_pop(), CIRCUIT_IS_ORIGIN, insertion_time_elem_t::counter, DIRREQ_CIRC_QUEUE_FLUSHED, ewma_scale_factor, insertion_time_queue_t::first, geoip_change_dirreq_state(), get_options(), cell_queue_t::head, insertion_time_elem_t::insertion_time, cell_queue_t::insertion_times, insertion_time_queue_t::last, LD_BUG, LD_GENERAL, make_circuit_inactive_on_conn(), cell_queue_t::n, circuit_t::n_conn, circuit_t::n_conn_cells, insertion_time_elem_t::next, next_circ_on_conn_p(), or_circuit_t::p_conn_cells, packed_cell_free_unchecked(), pop_first_cell_ewma_from_conn(), or_circuit_t::processed_cells, scale_active_circuits(), set_streams_blocked_on_circ(), circuit_t::streams_blocked_on_n_conn, circuit_t::streams_blocked_on_p_conn, or_connection_t::timestamp_last_added_nonpadding, TO_CONN, TO_OR_CIRCUIT(), tor_assert, and or_circuit_t::total_cell_waiting_time.
Referenced by append_cell_to_circuit_queue(), and connection_or_flushed_some().
void connection_or_unlink_all_active_circs | ( | or_connection_t * | orconn | ) |
Remove all circuits from the list of circuits with pending cells on conn.
References or_connection_t::active_circuit_pqueue, or_connection_t::active_circuits, next_circ_on_conn_p(), prev_circ_on_conn_p(), and smartlist_clear().
Referenced by circuit_unlink_all_from_or_conn().
const char* decode_address_from_payload | ( | tor_addr_t * | addr_out, | |
const char * | 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.
References get_uint32(), tor_addr_from_ipv4n(), tor_addr_from_ipv6_bytes(), and tor_addr_make_unspec().
Referenced by command_process_netinfo_cell().
void dump_cell_pool_usage | ( | int | severity | ) |
Log current statistics for cell pool allocation at log level severity.
References _circuit_get_global_list(), CIRCUIT_IS_ORIGIN, LD_MM, cell_queue_t::n, circuit_t::n_conn_cells, circuit_t::next, or_circuit_t::p_conn_cells, and TO_OR_CIRCUIT().
Referenced by dumpmemusage().
static int edge_reason_is_retriable | ( | int | reason | ) | [static] |
Return 1 if reason is something that you should retry if you get the end cell before you've connected; else return 0.
Referenced by connection_ap_process_end_not_open().
void free_cell_pool | ( | void | ) |
Free all storage used to hold cells (and insertion times if we measure cell statistics).
Referenced by tor_free_all().
static INLINE double get_scale_factor | ( | unsigned | from_tick, | |
unsigned | to_tick | |||
) | [static] |
Return the multiplier necessary to convert the value of a cell sent in 'from_tick' to one sent in 'to_tick'.
Referenced by scale_active_circuits(), and scale_single_cell_ewma().
void init_cell_pool | ( | void | ) |
void make_circuit_active_on_conn | ( | circuit_t * | circ, | |
or_connection_t * | conn | |||
) |
Add circ to the list of circuits with pending cells on conn. No effect if circ is already linked.
References or_connection_t::active_circuits, add_cell_ewma_to_conn(), circuit_t::n_cell_ewma, circuit_t::n_conn, next_circ_on_conn_p(), or_circuit_t::p_cell_ewma, or_circuit_t::p_conn, prev_circ_on_conn_p(), TO_OR_CIRCUIT(), and tor_assert.
Referenced by append_cell_to_circuit_queue(), and HT_HEAD().
void make_circuit_inactive_on_conn | ( | circuit_t * | circ, | |
or_connection_t * | conn | |||
) |
Remove circ from the list of circuits with pending cells on conn. No effect if circ is already unlinked.
References or_connection_t::active_circuits, circuit_t::n_cell_ewma, circuit_t::n_conn, next_circ_on_conn_p(), or_circuit_t::p_cell_ewma, or_circuit_t::p_conn, prev_circ_on_conn_p(), remove_cell_ewma_from_conn(), TO_OR_CIRCUIT(), and tor_assert.
Referenced by connection_or_flush_from_first_active_circuit(), and HT_HEAD().
static INLINE circuit_t** next_circ_on_conn_p | ( | circuit_t * | circ, | |
or_connection_t * | conn | |||
) | [static] |
Return a pointer to the "next_active_on_{n,p}_conn" pointer of circ, depending on whether conn matches n_conn or p_conn.
References circuit_t::n_conn, circuit_t::next_active_on_n_conn, or_circuit_t::next_active_on_p_conn, or_circuit_t::p_conn, TO_OR_CIRCUIT(), and tor_assert.
Referenced by assert_active_circuits_ok(), connection_or_flush_from_first_active_circuit(), connection_or_unlink_all_active_circs(), make_circuit_active_on_conn(), and make_circuit_inactive_on_conn().
static INLINE packed_cell_t* packed_cell_alloc | ( | void | ) | [static] |
Allocate and return a new packed_cell_t.
Referenced by packed_cell_copy().
static INLINE packed_cell_t* packed_cell_copy | ( | const cell_t * | cell | ) | [static] |
Allocate a new copy of packed cell.
References cell_pack(), packed_cell_t::next, and packed_cell_alloc().
Referenced by cell_queue_append_packed_copy().
static INLINE void packed_cell_free_unchecked | ( | packed_cell_t * | cell | ) | [static] |
Release storage held by cell.
Referenced by cell_queue_clear(), and connection_or_flush_from_first_active_circuit().
static cell_ewma_t* pop_first_cell_ewma_from_conn | ( | or_connection_t * | conn | ) | [static] |
Remove and return the first cell_ewma_t from conn's priority queue of active circuits. Requires that the priority queue is nonempty.
References or_connection_t::active_circuit_pqueue, compare_cell_ewma_counts(), smartlist_pqueue_pop(), and STRUCT_OFFSET.
Referenced by connection_or_flush_from_first_active_circuit().
static INLINE circuit_t** prev_circ_on_conn_p | ( | circuit_t * | circ, | |
or_connection_t * | conn | |||
) | [static] |
Return a pointer to the "prev_active_on_{n,p}_conn" pointer of circ, depending on whether conn matches n_conn or p_conn.
References circuit_t::n_conn, or_circuit_t::p_conn, circuit_t::prev_active_on_n_conn, or_circuit_t::prev_active_on_p_conn, TO_OR_CIRCUIT(), and tor_assert.
Referenced by assert_active_circuits_ok(), connection_or_unlink_all_active_circs(), make_circuit_active_on_conn(), and make_circuit_inactive_on_conn().
static const char* relay_command_to_string | ( | uint8_t | command | ) | [static] |
Convert the relay command into a human-readable string.
Referenced by relay_send_command_from_edge().
static int relay_crypt | ( | circuit_t * | circ, | |
cell_t * | cell, | |||
cell_direction_t | cell_direction, | |||
crypt_path_t ** | layer_hint, | |||
char * | recognized | |||
) | [static] |
Do the appropriate en/decryptions for cell arriving on circ in direction cell_direction.
If cell_direction == CELL_DIRECTION_IN:
If cell_direction == CELL_DIRECTION_OUT:
If cell is recognized, set *recognized to 1, and set *layer_hint to the hop that recognized it.
Return -1 to indicate that we should mark the circuit for close, else return 0.
References crypt_path_t::b_crypto, crypt_path_t::b_digest, CELL_DIRECTION_IN, CELL_DIRECTION_OUT, CIRCUIT_IS_ORIGIN, origin_circuit_t::cpath, LD_OR, LD_PROTOCOL, crypt_path_t::next, cell_t::payload, relay_header_t::recognized, relay_crypt_one_payload(), relay_digest_matches(), relay_header_unpack(), crypt_path_t::state, TO_OR_CIRCUIT(), TO_ORIGIN_CIRCUIT(), and tor_assert.
Referenced by circuit_receive_relay_cell().
static int relay_crypt_one_payload | ( | crypto_cipher_env_t * | cipher, | |
char * | in, | |||
int | encrypt_mode | |||
) | [static] |
Apply cipher to CELL_PAYLOAD_SIZE bytes of in (in place).
If encrypt_mode is 1 then encrypt, else decrypt.
Return -1 if the crypto fails, else return 0.
References CELL_PAYLOAD_SIZE, crypto_cipher_crypt_inplace(), and LD_BUG.
Referenced by circuit_package_relay_cell(), and relay_crypt().
static int relay_digest_matches | ( | crypto_digest_env_t * | digest, | |
cell_t * | cell | |||
) | [static] |
Does the digest for this circuit indicate that this cell is for us?
Update digest from the payload of cell (with the integrity part set to 0). If the integrity part is valid, return 1, else restore digest and cell to their original state and return 0.
References CELL_PAYLOAD_SIZE, crypto_digest_add_bytes(), crypto_digest_assign(), crypto_digest_dup(), crypto_digest_get_digest(), crypto_free_digest_env(), relay_header_t::integrity, cell_t::payload, relay_header_pack(), and relay_header_unpack().
Referenced by relay_crypt().
void relay_header_pack | ( | char * | 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.
References relay_header_t::command, relay_header_t::integrity, relay_header_t::length, relay_header_t::recognized, set_uint16(), and relay_header_t::stream_id.
Referenced by relay_digest_matches(), relay_send_command_from_edge(), and relay_set_digest().
void relay_header_unpack | ( | relay_header_t * | dest, | |
const char * | src | |||
) |
Unpack the network-order buffer src into a host-order relay_header_t structure dest.
References relay_header_t::command, get_uint16(), relay_header_t::integrity, relay_header_t::length, relay_header_t::recognized, and relay_header_t::stream_id.
Referenced by circuit_extend(), connection_edge_process_relay_cell(), connection_exit_begin_conn(), connection_exit_begin_resolve(), relay_crypt(), relay_digest_matches(), relay_lookup_conn(), and relay_set_digest().
static edge_connection_t * relay_lookup_conn | ( | circuit_t * | circ, | |
cell_t * | cell, | |||
cell_direction_t | cell_direction, | |||
crypt_path_t * | layer_hint | |||
) | [static] |
If cell's stream_id matches the stream_id of any conn that's attached to circ, return that conn, else return NULL.
References edge_connection_t::_base, CELL_DIRECTION_OUT, CIRCUIT_IS_ORIGIN, connection_edge_is_rendezvous_stream(), edge_connection_t::cpath_layer, LD_APP, connection_t::marked_for_close, edge_connection_t::next_stream, cell_t::payload, relay_header_unpack(), edge_connection_t::stream_id, relay_header_t::stream_id, TO_OR_CIRCUIT(), and TO_ORIGIN_CIRCUIT().
Referenced by circuit_receive_relay_cell().
int relay_send_command_from_edge | ( | uint16_t | stream_id, | |
circuit_t * | circ, | |||
uint8_t | relay_command, | |||
const char * | payload, | |||
size_t | payload_len, | |||
crypt_path_t * | cpath_layer | |||
) |
Make a relay cell out of relay_command and payload, and send it onto the open circuit circ. stream_id is the ID on circ for the stream that's sending the relay cell, or 0 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.
References approx_time(), CELL_DIRECTION_IN, CELL_DIRECTION_OUT, cell_t::circ_id, CIRCUIT_IS_ORIGIN, circuit_package_relay_cell(), CIRCUIT_PURPOSE_IS_ESTABLISHED_REND, or_connection_t::client_used, relay_header_t::command, cell_t::command, origin_circuit_t::cpath, DIRREQ_END_CELL_SENT, circuit_t::dirreq_id, geoip_change_dirreq_state(), LD_BUG, LD_OR, relay_header_t::length, circuit_t::n_circ_id, circuit_t::n_conn, or_circuit_t::p_circ_id, cell_t::payload, circuit_t::purpose, relay_command_to_string(), origin_circuit_t::relay_early_cells_sent, origin_circuit_t::relay_early_commands, relay_header_pack(), RELAY_HEADER_SIZE, RELAY_PAYLOAD_SIZE, origin_circuit_t::remaining_relay_early_cells, smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), relay_header_t::stream_id, TO_OR_CIRCUIT(), TO_ORIGIN_CIRCUIT(), tor_assert, and tor_free.
Referenced by circuit_consider_sending_sendme(), circuit_send_next_onion_skin(), command_process_created_cell(), command_process_destroy_cell(), connection_edge_process_relay_cell(), connection_edge_send_command(), relay_send_end_cell_from_edge(), rend_client_send_establish_rendezvous(), rend_mid_establish_intro(), rend_mid_establish_rendezvous(), rend_mid_introduce(), rend_mid_rendezvous(), rend_service_intro_has_opened(), rend_service_rendezvous_has_opened(), and router_perform_bandwidth_test().
static void relay_set_digest | ( | crypto_digest_env_t * | digest, | |
cell_t * | cell | |||
) | [static] |
Update digest from the payload of cell. Assign integrity part to cell.
References CELL_PAYLOAD_SIZE, crypto_digest_add_bytes(), crypto_digest_get_digest(), relay_header_t::integrity, cell_t::payload, relay_header_pack(), and relay_header_unpack().
Referenced by circuit_package_relay_cell().
static void remap_event_helper | ( | edge_connection_t * | conn, | |
uint32_t | new_addr | |||
) | [static] |
Helper: change the socks_request->address field on conn to the dotted-quad representation of new_addr (given in host order), and send an appropriate REMAP event.
References socks_request_t::address, control_event_stream_status(), REMAP_STREAM_SOURCE_EXIT, edge_connection_t::socks_request, and tor_inet_ntoa().
Referenced by connection_edge_process_relay_cell_not_open().
static void remove_cell_ewma_from_conn | ( | or_connection_t * | conn, | |
cell_ewma_t * | ewma | |||
) | [static] |
Remove ewma from conn's priority queue of active circuits
References or_connection_t::active_circuit_pqueue, compare_cell_ewma_counts(), cell_ewma_t::heap_index, smartlist_pqueue_remove(), STRUCT_OFFSET, and tor_assert.
Referenced by make_circuit_inactive_on_conn().
static void scale_active_circuits | ( | or_connection_t * | conn, | |
unsigned | cur_tick | |||
) | [static] |
Adjust the cell count of every active circuit on conn so that they are scaled with respect to cur_tick
Ordinarily it isn't okay to change the value of an element in a heap, but it's okay here, since we are preserving the order.
References or_connection_t::active_circuit_pqueue, or_connection_t::active_circuit_pqueue_last_recalibrated, get_scale_factor(), and tor_assert.
Referenced by connection_or_flush_from_first_active_circuit().
static void scale_single_cell_ewma | ( | cell_ewma_t * | ewma, | |
unsigned | cur_tick | |||
) | [static] |
Adjust the cell count of ewma so that it is scaled with respect to cur_tick
References cell_ewma_t::cell_count, get_scale_factor(), and cell_ewma_t::last_adjusted_tick.
Referenced by add_cell_ewma_to_conn().
static void set_streams_blocked_on_circ | ( | circuit_t * | circ, | |
or_connection_t * | orconn, | |||
int | block | |||
) | [static] |
Block (if block is true) or unblock (if block is false) every edge connection that is using circ to write to orconn, and start or stop reading as appropriate.
References CIRCUIT_IS_ORIGIN, connection_is_reading(), connection_start_reading(), connection_stop_reading(), edge_connection_t::edge_blocked_on_circ, circuit_t::n_conn, or_circuit_t::n_streams, edge_connection_t::next_stream, origin_circuit_t::p_streams, connection_t::read_event, circuit_t::streams_blocked_on_n_conn, circuit_t::streams_blocked_on_p_conn, TO_CONN, TO_OR_CIRCUIT(), TO_ORIGIN_CIRCUIT(), and tor_assert.
Referenced by append_cell_to_circuit_queue(), and connection_or_flush_from_first_active_circuit().
struct timeval cached_time_hires = {0, 0} [static] |
Cache the current hi-res time; the cache gets reset when libevent calls us.
A memory pool to allocate packed_cell_t objects.
double ewma_scale_factor = 0.1 [static] |
The per-tick scale factor to be used when computing cell-count EWMA values. (A cell sent N ticks before the start of the current tick has value ewma_scale_factor ** N.)
Referenced by connection_or_flush_from_first_active_circuit().
Memory pool to allocate insertion_time_elem_t objects used for cell statistics.
uint64_t stats_n_data_bytes_packaged = 0 |
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.
Referenced by dumpstats().
uint64_t stats_n_data_bytes_received = 0 |
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.
Referenced by connection_edge_process_relay_cell(), and dumpstats().
uint64_t stats_n_data_cells_packaged = 0 |
How many relay_data cells have we built, ever?
Referenced by dumpstats().
uint64_t stats_n_data_cells_received = 0 |
How many relay_data cells have we received, ever?
Referenced by connection_edge_process_relay_cell(), and dumpstats().
uint64_t stats_n_relay_cells_delivered = 0 |
Stats: how many relay cells have been delivered to streams at this hop?
Referenced by dumpstats().
uint64_t stats_n_relay_cells_relayed = 0 |
Stats: how many relay cells have originated at this hop, or have been relayed onward (not recognized at this hop)?
Referenced by dumpstats().
int total_cells_allocated = 0 [static] |
The total number of cells we have allocated from the memory pool.