circuitbuild.c File Reference

The actual details of building circuits. More...

#include "or.h"
#include "crypto.h"
#include <math.h>

Data Structures

struct  entry_guard_t
struct  bridge_info_t

Defines

#define CIRCUIT_PRIVATE
#define ENTRY_GUARD_REMOVE_AFTER   (30*24*60*60)

Functions

static int circuit_deliver_create_cell (circuit_t *circ, uint8_t cell_type, const char *payload)
static int onion_pick_cpath_exit (origin_circuit_t *circ, extend_info_t *exit)
static crypt_path_tonion_next_hop_in_cpath (crypt_path_t *cpath)
static int onion_extend_cpath (origin_circuit_t *circ)
static int count_acceptable_routers (smartlist_t *routers)
static int onion_append_hop (crypt_path_t **head_ptr, extend_info_t *choice)
static void entry_guards_changed (void)
static int32_t circuit_build_times_max_timeouts (void)
static int32_t circuit_build_times_min_circs_to_observe (void)
double circuit_build_times_quantile_cutoff (void)
static int32_t circuit_build_times_test_frequency (void)
static int32_t circuit_build_times_min_timeout (void)
int32_t circuit_build_times_initial_timeout (void)
static int32_t circuit_build_times_recent_circuit_count (void)
void circuit_build_times_new_consensus_params (circuit_build_times_t *cbt, networkstatus_t *ns)
void circuitbuild_running_unit_tests (void)
static double circuit_build_times_get_initial_timeout (void)
void circuit_build_times_reset (circuit_build_times_t *cbt)
void circuit_build_times_init (circuit_build_times_t *cbt)
static void circuit_build_times_rewind_history (circuit_build_times_t *cbt, int n)
int circuit_build_times_add_time (circuit_build_times_t *cbt, build_time_t time)
static build_time_t circuit_build_times_max (circuit_build_times_t *cbt)
static uint32_t * circuit_build_times_create_histogram (circuit_build_times_t *cbt, build_time_t *nbins)
static build_time_t circuit_build_times_mode (circuit_build_times_t *cbt)
void circuit_build_times_update_state (circuit_build_times_t *cbt, or_state_t *state)
static void circuit_build_times_shuffle_and_store_array (circuit_build_times_t *cbt, build_time_t *raw_times, int num_times)
int circuit_build_times_parse_state (circuit_build_times_t *cbt, or_state_t *state, char **msg)
void circuit_build_times_update_alpha (circuit_build_times_t *cbt)
double circuit_build_times_calculate_timeout (circuit_build_times_t *cbt, double quantile)
double circuit_build_times_cdf (circuit_build_times_t *cbt, double x)
build_time_t circuit_build_times_generate_sample (circuit_build_times_t *cbt, double q_lo, double q_hi)
void circuit_build_times_add_timeout_worker (circuit_build_times_t *cbt, double quantile_cutoff)
void circuit_build_times_initial_alpha (circuit_build_times_t *cbt, double quantile, double timeout_ms)
static void circuit_build_times_count_pretimeouts (circuit_build_times_t *cbt)
int circuit_build_times_needs_circuits (circuit_build_times_t *cbt)
int circuit_build_times_needs_circuits_now (circuit_build_times_t *cbt)
void circuit_build_times_network_is_live (circuit_build_times_t *cbt)
void circuit_build_times_network_circ_success (circuit_build_times_t *cbt)
static void circuit_build_times_network_timeout (circuit_build_times_t *cbt, int did_onehop, time_t start_time)
int circuit_build_times_network_check_live (circuit_build_times_t *cbt)
int circuit_build_times_network_check_changed (circuit_build_times_t *cbt)
int circuit_build_times_add_timeout (circuit_build_times_t *cbt, int did_onehop, time_t start_time)
void circuit_build_times_set_timeout (circuit_build_times_t *cbt)
static circid_t get_unique_circ_id_by_conn (or_connection_t *conn)
static char * circuit_list_path_impl (origin_circuit_t *circ, int verbose, int verbose_names)
char * circuit_list_path (origin_circuit_t *circ, int verbose)
char * circuit_list_path_for_controller (origin_circuit_t *circ)
void circuit_log_path (int severity, unsigned int domain, origin_circuit_t *circ)
void circuit_rep_hist_note_result (origin_circuit_t *circ)
static int onion_populate_cpath (origin_circuit_t *circ)
origin_circuit_torigin_circuit_init (uint8_t purpose, int flags)
origin_circuit_tcircuit_establish_circuit (uint8_t purpose, extend_info_t *exit, int flags)
int circuit_handle_first_hop (origin_circuit_t *circ)
void circuit_n_conn_done (or_connection_t *or_conn, int status)
int inform_testing_reachability (void)
static INLINE int should_use_create_fast_for_circuit (origin_circuit_t *circ)
int circuit_send_next_onion_skin (origin_circuit_t *circ)
void circuit_note_clock_jumped (int seconds_elapsed)
int circuit_extend (cell_t *cell, circuit_t *circ)
int circuit_init_cpath_crypto (crypt_path_t *cpath, const char *key_data, int reverse)
int circuit_finish_handshake (origin_circuit_t *circ, uint8_t reply_type, const char *reply)
int circuit_truncated (origin_circuit_t *circ, crypt_path_t *layer)
int onionskin_answer (or_circuit_t *circ, uint8_t cell_type, const char *payload, const char *keys)
static int new_route_len (uint8_t purpose, extend_info_t *exit, smartlist_t *routers)
static smartlist_tcircuit_get_unhandled_ports (time_t now)
int circuit_all_predicted_ports_handled (time_t now, int *need_uptime, int *need_capacity)
static int router_handles_some_port (routerinfo_t *router, smartlist_t *needed_ports)
static int ap_stream_wants_exit_attention (connection_t *conn)
static routerinfo_tchoose_good_exit_server_general (routerlist_t *dir, int need_uptime, int need_capacity)
static routerinfo_tchoose_good_exit_server (uint8_t purpose, routerlist_t *dir, int need_uptime, int need_capacity, int is_internal)
static void warn_if_last_router_excluded (origin_circuit_t *circ, const extend_info_t *exit)
int circuit_append_new_exit (origin_circuit_t *circ, extend_info_t *exit)
int circuit_extend_to_new_exit (origin_circuit_t *circ, extend_info_t *exit)
void onion_append_to_cpath (crypt_path_t **head_ptr, crypt_path_t *new_hop)
static routerinfo_tchoose_good_middle_server (uint8_t purpose, cpath_build_state_t *state, crypt_path_t *head, int cur_len)
static routerinfo_tchoose_good_entry_server (uint8_t purpose, cpath_build_state_t *state)
extend_info_textend_info_alloc (const char *nickname, const char *digest, crypto_pk_env_t *onion_key, const tor_addr_t *addr, uint16_t port)
extend_info_textend_info_from_router (routerinfo_t *r)
void extend_info_free (extend_info_t *info)
extend_info_textend_info_dup (extend_info_t *info)
routerinfo_tbuild_state_get_exit_router (cpath_build_state_t *state)
const char * build_state_get_exit_nickname (cpath_build_state_t *state)
static int entry_guard_set_status (entry_guard_t *e, routerinfo_t *ri, time_t now, or_options_t *options, const char **reason)
static int entry_is_time_to_retry (entry_guard_t *e, time_t now)
static INLINE routerinfo_tentry_is_live (entry_guard_t *e, int need_uptime, int need_capacity, int assume_reachable, const char **msg)
static int num_live_entry_guards (void)
static INLINE entry_guard_tis_an_entry_guard (const char *digest)
static void log_entry_guards (int severity)
static void control_event_guard_deferred (void)
static routerinfo_tadd_an_entry_guard (routerinfo_t *chosen, int reset_status)
static void pick_entry_guards (void)
static void entry_guard_free (entry_guard_t *e)
static int remove_obsolete_entry_guards (void)
static int remove_dead_entry_guards (void)
void entry_guards_compute_status (void)
int entry_guard_register_connect_status (const char *digest, int succeeded, int mark_relay_status, time_t now)
void entry_nodes_should_be_added (void)
static void entry_guards_prepend_from_config (void)
int entry_list_is_constrained (or_options_t *options)
static int entry_list_is_totally_static (or_options_t *options)
routerinfo_tchoose_random_entry (cpath_build_state_t *state)
int entry_guards_parse_state (or_state_t *state, int set, char **msg)
void entry_guards_update_state (or_state_t *state)
int getinfo_helper_entry_guards (control_connection_t *conn, const char *question, char **answer)
void clear_bridge_list (void)
static bridge_info_trouterinfo_get_configured_bridge (routerinfo_t *ri)
int routerinfo_is_a_configured_bridge (routerinfo_t *ri)
void bridge_add_from_config (const tor_addr_t *addr, uint16_t port, char *digest)
static bridge_info_tfind_bridge_by_digest (const char *digest)
static void launch_direct_bridge_descriptor_fetch (bridge_info_t *bridge)
void retry_bridge_descriptor_fetch_directly (const char *digest)
void fetch_bridge_descriptors (time_t now)
void learned_bridge_descriptor (routerinfo_t *ri, int from_cache)
int any_bridge_descriptors_known (void)
int any_pending_bridge_descriptor_fetches (void)
static int bridges_retry_helper (int act)
int bridges_known_but_down (void)
void bridges_retry_all (void)
void entry_guards_free_all (void)

Variables

circuit_build_times_t circ_times
circuit_tglobal_circuitlist
static smartlist_tentry_guards = NULL
static int entry_guards_dirty = 0
static int unit_tests = 0
static int should_add_entry_nodes = 0
static smartlist_tbridge_list = NULL


Detailed Description

The actual details of building circuits.


Define Documentation

#define ENTRY_GUARD_REMOVE_AFTER   (30*24*60*60)

How long (in seconds) do we allow an entry guard to be nonfunctional, unlisted, excluded, or otherwise nonusable before we give up on it?

Referenced by remove_dead_entry_guards().


Function Documentation

static routerinfo_t* add_an_entry_guard ( routerinfo_t chosen,
int  reset_status 
) [static]

Add a new (preferably stable and fast) router to our entry_guards list. Return a pointer to the router if we succeed, or NULL if we can't find any more suitable entries.

If chosen is defined, use that one, and if it's not already in our entry_guards list, put it at the *beginning*. Else, put the one we pick at the end of the list.

References entry_guard_t::bad_since, routerinfo_t::cache_info, entry_guard_t::can_retry, choose_good_entry_server(), entry_guard_t::chosen_by_version, entry_guard_t::chosen_on_date, CIRCUIT_PURPOSE_C_GENERAL, control_event_guard(), control_event_guard_deferred(), crypto_rand_int(), DIGEST_LEN, entry_guard_t::identity, signed_descriptor_t::identity_digest, is_an_entry_guard(), LD_CIRC, log_entry_guards(), entry_guard_t::nickname, routerinfo_t::nickname, smartlist_add(), and smartlist_insert().

Referenced by choose_random_entry(), learned_bridge_descriptor(), and pick_entry_guards().

int any_bridge_descriptors_known ( void   ) 

Return 1 if any of our entry guards have descriptors that are marked with purpose 'bridge' and are running. Else return 0.

We use this function to decide if we're ready to start building circuits through our bridges, or if we need to wait until the directory "server/authority" requests finish.

References choose_random_entry(), get_options(), and tor_assert.

Referenced by circuit_get_open_circ_or_launch(), control_event_bootstrap_problem(), learned_bridge_descriptor(), and should_delay_dir_fetches().

int any_pending_bridge_descriptor_fetches ( void   ) 

Return 1 if there are any directory conns fetching bridge descriptors that aren't marked for close. We use this to guess if we should tell the controller that we have a problem.

References CONN_TYPE_DIR, DIR_PURPOSE_FETCH_SERVERDESC, get_connection_array(), LD_DIR, ROUTER_PURPOSE_BRIDGE, and TO_DIR_CONN().

Referenced by control_event_bootstrap_problem().

static int ap_stream_wants_exit_attention ( connection_t conn  )  [static]

void bridge_add_from_config ( const tor_addr_t addr,
uint16_t  port,
char *  digest 
)

Remember a new bridge at addr:port. If digest is set, it tells us the identity key too.

References bridge_info_t::addr, DIGEST_LEN, bridge_info_t::fetch_status, bridge_info_t::identity, bridge_info_t::port, download_status_t::schedule, smartlist_add(), smartlist_create(), and tor_addr_copy().

Referenced by parse_bridge_line().

int bridges_known_but_down ( void   ) 

Do we know any descriptors for our bridges, and are they all down?

References bridges_retry_helper().

Referenced by circuit_get_open_circ_or_launch().

void bridges_retry_all ( void   ) 

Mark all down known bridges up.

References bridges_retry_helper().

Referenced by circuit_get_open_circ_or_launch().

static int bridges_retry_helper ( int  act  )  [static]

Return 1 if we have at least one descriptor for a bridge and all descriptors we know are down. Else return 0. If act is 1, then mark the down bridges up; else just observe and report.

References routerinfo_t::is_running, LD_DIR, routerinfo_t::purpose, router_get_by_digest(), ROUTER_PURPOSE_BRIDGE, and smartlist_create().

Referenced by bridges_known_but_down(), and bridges_retry_all().

const char* build_state_get_exit_nickname ( cpath_build_state_t state  ) 

Return the nickname for the chosen exit router in state. If there is no chosen exit, or if we don't know the routerinfo_t for the chosen exit, return NULL.

References cpath_build_state_t::chosen_exit, and extend_info_t::nickname.

Referenced by _circuit_mark_for_close(), circuit_build_failed(), circuit_launch_by_extend_info(), circuit_list_path_impl(), and onion_extend_cpath().

routerinfo_t* build_state_get_exit_router ( cpath_build_state_t state  ) 

Return the routerinfo_t for the chosen exit router in state. If there is no chosen exit, or if we don't know the routerinfo_t for the chosen exit, return NULL.

References cpath_build_state_t::chosen_exit, extend_info_t::identity_digest, and router_get_by_digest().

Referenced by choose_good_entry_server(), choose_good_middle_server(), choose_random_entry(), circuit_is_acceptable(), and circuit_stream_is_being_handled().

static routerinfo_t* choose_good_entry_server ( uint8_t  purpose,
cpath_build_state_t state 
) [static]

Pick a good entry server for the circuit to be built according to state. Don't reuse a chosen exit (if any), don't use this router (if we're an OR), and respect firewall settings; if we're configured to use entry guards, return one.

If state is NULL, we're choosing a router to serve as an entry guard, not for any particular circuit.

References or_options_t::BridgeRelay, build_state_get_exit_router(), choose_random_entry(), CIRCUIT_PURPOSE_TESTING, fascist_firewall_allows_or(), firewall_is_fascist_or(), get_options(), router_get_by_digest(), router_get_routerlist(), routerlist_add_family(), routerlist_t::routers, smartlist_add(), smartlist_create(), and or_options_t::UseEntryGuards.

Referenced by add_an_entry_guard(), and onion_extend_cpath().

static routerinfo_t* choose_good_exit_server ( uint8_t  purpose,
routerlist_t dir,
int  need_uptime,
int  need_capacity,
int  is_internal 
) [static]

Return a pointer to a suitable router to be the exit node for the circuit of purpose purpose that we're about to build (or NULL if no router is suitable).

For general-purpose circuits, pass it off to choose_good_exit_server_general()

For client-side rendezvous circuits, choose a random node, weighted toward the preferences in 'options'.

References or_options_t::_AllowInvalid, choose_good_exit_server_general(), CIRCUIT_PURPOSE_C_ESTABLISH_REND, CIRCUIT_PURPOSE_C_GENERAL, or_options_t::ExcludeNodes, get_options(), LD_BUG, router_choose_random_node(), and tor_fragile_assert.

Referenced by onion_pick_cpath_exit().

static routerinfo_t* choose_good_exit_server_general ( routerlist_t dir,
int  need_uptime,
int  need_capacity 
) [static]

static routerinfo_t* choose_good_middle_server ( uint8_t  purpose,
cpath_build_state_t state,
crypt_path_t head,
int  cur_len 
) [static]

A helper function used by onion_extend_cpath(). Use purpose and state and the cpath head (currently populated only to length cur_len to decide a suitable middle hop for a circuit. In particular, make sure we don't pick the exit node or its family, and make sure we don't duplicate any previous nodes or their families.

References or_options_t::_AllowInvalid, build_state_get_exit_router(), or_options_t::ExcludeNodes, get_options(), LD_CIRC, cpath_build_state_t::need_capacity, cpath_build_state_t::need_uptime, crypt_path_t::next, router_choose_random_node(), router_get_by_digest(), routerlist_add_family(), smartlist_add(), smartlist_create(), smartlist_free(), and tor_assert.

Referenced by onion_extend_cpath().

routerinfo_t* choose_random_entry ( cpath_build_state_t state  ) 

int circuit_all_predicted_ports_handled ( time_t  now,
int *  need_uptime,
int *  need_capacity 
)

Return 1 if we already have circuits present or on the way for all anticipated ports. Return 0 if we should make more.

If we're returning 0, set need_uptime and need_capacity to indicate any requirements that the unhandled ports have.

References circuit_get_unhandled_ports(), get_options(), or_options_t::LongLivedPorts, smartlist_free(), smartlist_string_num_isin(), tor_assert, and tor_free.

Referenced by circuit_predict_and_launch_new().

int circuit_append_new_exit ( origin_circuit_t circ,
extend_info_t exit 
)

Give circ a new exit destination to exit, and add a hop to the cpath reflecting this. Don't send the next extend cell -- the caller will do this if it wants to.

References origin_circuit_t::build_state, cpath_build_state_t::chosen_exit, origin_circuit_t::cpath, cpath_build_state_t::desired_path_len, extend_info_dup(), extend_info_free(), onion_append_hop(), and tor_assert.

Referenced by circuit_extend_to_new_exit(), and handle_control_extendcircuit().

int circuit_build_times_add_time ( circuit_build_times_t cbt,
build_time_t  time 
)

int circuit_build_times_add_timeout ( circuit_build_times_t cbt,
int  did_onehop,
time_t  start_time 
)

void circuit_build_times_add_timeout_worker ( circuit_build_times_t cbt,
double  quantile_cutoff 
)

double circuit_build_times_calculate_timeout ( circuit_build_times_t cbt,
double  quantile 
)

This is the Pareto Quantile Function. It calculates the point x in the distribution such that F(x) = quantile (ie quantile*100% of the mass of the density function is below x on the curve).

We use it to calculate the timeout and also to generate synthetic values of time for circuits that timeout before completion.

See http://en.wikipedia.org/wiki/Quantile_function, http://en.wikipedia.org/wiki/Inverse_transform_sampling and http://en.wikipedia.org/wiki/Pareto_distribution#Generating_a_ random_sample_from_Pareto_distribution That's right. I'll cite wikipedia all day long.

Return value is in milliseconds.

References circuit_build_times_t::alpha, tor_assert, and circuit_build_times_t::Xm.

Referenced by circuit_build_times_generate_sample(), and circuit_build_times_set_timeout().

double circuit_build_times_cdf ( circuit_build_times_t cbt,
double  x 
)

static void circuit_build_times_count_pretimeouts ( circuit_build_times_t cbt  )  [static]

static uint32_t* circuit_build_times_create_histogram ( circuit_build_times_t cbt,
build_time_t nbins 
) [static]

Calculate and return a histogram for the set of build times.

Returns an allocated array of histrogram bins representing the frequency of index*CBT_BIN_WIDTH millisecond build times. Also outputs the number of bins in nbins.

The return value must be freed by the caller.

References CBT_BIN_WIDTH, circuit_build_times_t::circuit_build_times, and circuit_build_times_max().

Referenced by circuit_build_times_mode(), and circuit_build_times_update_state().

build_time_t circuit_build_times_generate_sample ( circuit_build_times_t cbt,
double  q_lo,
double  q_hi 
)

Generate a synthetic time using our distribution parameters.

The return value will be within the [q_lo, q_hi) quantile points on the CDF.

References circuit_build_times_calculate_timeout(), crypto_rand_uint64(), tor_assert, and tor_lround().

Referenced by circuit_build_times_add_timeout_worker().

static double circuit_build_times_get_initial_timeout ( void   )  [static]

void circuit_build_times_init ( circuit_build_times_t cbt  ) 

Initialize the buildtimes structure for first use.

Sets the initial timeout value based to either the config setting or BUILD_TIMEOUT_INITIAL_VALUE.

References circuit_build_times_get_initial_timeout(), control_event_buildtimeout_set(), circuit_build_times_t::liveness, network_liveness_t::num_recent_circs, circuit_build_times_t::timeout_ms, and network_liveness_t::timeouts_after_firsthop.

Referenced by circuit_build_times_parse_state().

void circuit_build_times_initial_alpha ( circuit_build_times_t cbt,
double  quantile,
double  timeout_ms 
)

Estimate an initial alpha parameter by solving the quantile function with a quantile point and a specific timeout value.

References circuit_build_times_t::alpha, tor_assert, tor_mathlog(), and circuit_build_times_t::Xm.

Referenced by circuit_build_times_count_pretimeouts().

static build_time_t circuit_build_times_max ( circuit_build_times_t cbt  )  [static]

Return maximum circuit build time

References CBT_NCIRCUITS_TO_OBSERVE, and circuit_build_times_t::circuit_build_times.

Referenced by circuit_build_times_create_histogram().

static build_time_t circuit_build_times_mode ( circuit_build_times_t cbt  )  [static]

Return the most frequent build time (rounded to CBT_BIN_WIDTH ms).

Ties go in favor of the slower time.

References CBT_BIN_WIDTH, circuit_build_times_create_histogram(), and tor_free.

Referenced by circuit_build_times_count_pretimeouts(), and circuit_build_times_update_alpha().

int circuit_build_times_needs_circuits ( circuit_build_times_t cbt  ) 

Returns true if we need circuits to be built

References circuit_build_times_t::total_build_times.

Referenced by circuit_build_times_needs_circuits_now(), and circuit_expire_old_circuits_clientside().

int circuit_build_times_needs_circuits_now ( circuit_build_times_t cbt  ) 

Returns true if we should build a timeout test circuit right now.

References approx_time(), circuit_build_times_needs_circuits(), and circuit_build_times_t::last_circ_at.

Referenced by circuit_predict_and_launch_new().

int circuit_build_times_network_check_changed ( circuit_build_times_t cbt  ) 

Returns true if we have seen more than MAX_RECENT_TIMEOUT_COUNT of the past RECENT_CIRCUITS time out after the first hop. Used to detect if the network connection has changed significantly.

Also resets the entire timeout history in this case and causes us to restart the process of building test circuits and estimating a new timeout.

References network_liveness_t::after_firsthop_idx, circuit_build_times_get_initial_timeout(), circuit_build_times_reset(), control_event_buildtimeout_set(), LD_CIRC, circuit_build_times_t::liveness, network_liveness_t::num_recent_circs, circuit_build_times_t::timeout_ms, network_liveness_t::timeouts_after_firsthop, tor_lround(), and circuit_build_times_t::total_build_times.

Referenced by circuit_build_times_add_timeout().

int circuit_build_times_network_check_live ( circuit_build_times_t cbt  ) 

void circuit_build_times_network_circ_success ( circuit_build_times_t cbt  ) 

Called to indicate that we completed a circuit. Because this circuit succeeded, it doesn't count as a timeout-after-the-first-hop.

References network_liveness_t::after_firsthop_idx, circuit_build_times_t::liveness, network_liveness_t::num_recent_circs, and network_liveness_t::timeouts_after_firsthop.

Referenced by circuit_send_next_onion_skin().

void circuit_build_times_network_is_live ( circuit_build_times_t cbt  ) 

Called to indicate that the network showed some signs of liveness.

This function is called every time we receive a cell. Avoid syscalls, events, and other high-intensity work.

References approx_time(), circuit_build_times_t::liveness, network_liveness_t::network_last_live, network_liveness_t::nonlive_discarded, and network_liveness_t::nonlive_timeouts.

Referenced by connection_or_process_cells_from_inbuf(), connection_or_set_state_open(), and connection_tls_finish_handshake().

static void circuit_build_times_network_timeout ( circuit_build_times_t cbt,
int  did_onehop,
time_t  start_time 
) [static]

A circuit just timed out. If there has been no recent network activity at all, but this circuit was launched back when we thought the network was live, increment the number of "nonlive" circuit timeouts.

Also distinguish between whether it failed before the first hop and record that in our history for later deciding if the network has changed.

References network_liveness_t::after_firsthop_idx, circuit_build_times_t::liveness, network_liveness_t::network_last_live, network_liveness_t::nonlive_timeouts, network_liveness_t::num_recent_circs, circuit_build_times_t::timeout_ms, and network_liveness_t::timeouts_after_firsthop.

Referenced by circuit_build_times_add_timeout().

void circuit_build_times_new_consensus_params ( circuit_build_times_t cbt,
networkstatus_t ns 
)

This function is called when we get a consensus update.

It checks to see if we have changed any consensus parameters that require reallocation or discard of previous stats.

References network_liveness_t::after_firsthop_idx, CBT_DEFAULT_RECENT_CIRCUITS, LD_CIRC, circuit_build_times_t::liveness, networkstatus_get_param(), network_liveness_t::num_recent_circs, network_liveness_t::timeouts_after_firsthop, tor_assert, and tor_free.

Referenced by networkstatus_set_current_consensus().

int circuit_build_times_parse_state ( circuit_build_times_t cbt,
or_state_t state,
char **  msg 
)

Load histogram from state, shuffling the resulting array after we do so. Use this result to estimate parameters and calculate the timeout.

Returns -1 and sets msg on error. Msg must be freed by the caller.

References or_state_t::BuildtimeHistogram, circuit_build_times_t::circuit_build_times, circuit_build_times_init(), circuit_build_times_set_timeout(), circuit_build_times_shuffle_and_store_array(), LD_CIRC, config_line_t::next, smartlist_create(), smartlist_free(), smartlist_split_string(), tor_assert, tor_free, tor_parse_ulong(), circuit_build_times_t::total_build_times, or_state_t::TotalBuildTimes, and config_line_t::value.

Referenced by or_state_set().

void circuit_build_times_reset ( circuit_build_times_t cbt  ) 

static void circuit_build_times_rewind_history ( circuit_build_times_t cbt,
int  n 
) [static]

void circuit_build_times_set_timeout ( circuit_build_times_t cbt  ) 

static void circuit_build_times_shuffle_and_store_array ( circuit_build_times_t cbt,
build_time_t raw_times,
int  num_times 
) [static]

Shuffle the build times array.

Stolen from http://en.wikipedia.org/wiki/Fisher

References circuit_build_times_add_time(), crypto_rand_int(), and LD_CIRC.

Referenced by circuit_build_times_parse_state().

void circuit_build_times_update_alpha ( circuit_build_times_t cbt  ) 

Estimates the Xm and Alpha parameters using http://en.wikipedia.org/wiki/Pareto_distribution#Parameter_estimation

The notable difference is that we use mode instead of min to estimate Xm. This is because our distribution is frechet-like. We claim this is an acceptable approximation because we are only concerned with the accuracy of the CDF of the tail.

References circuit_build_times_t::alpha, circuit_build_times_t::circuit_build_times, circuit_build_times_mode(), LD_CIRC, tor_assert, tor_mathlog(), circuit_build_times_t::total_build_times, and circuit_build_times_t::Xm.

Referenced by circuit_build_times_set_timeout().

void circuit_build_times_update_state ( circuit_build_times_t cbt,
or_state_t state 
)

static int circuit_deliver_create_cell ( circuit_t circ,
uint8_t  cell_type,
const char *  payload 
) [static]

Find a new circid that isn't currently in use on the circ->n_conn for the outgoing circuit circ, and deliver a cell of type cell_type (either CELL_CREATE or CELL_CREATE_FAST) with payload payload to this circuit. Return -1 if we failed to find a suitable circid, else return 0.

References append_cell_to_circuit_queue(), CELL_DIRECTION_OUT, cell_t::circ_id, CIRCUIT_IS_ORIGIN, circuit_set_n_circid_orconn(), or_connection_t::client_used, cell_t::command, get_unique_circ_id_by_conn(), LD_CIRC, circuit_t::n_circ_id, circuit_t::n_conn, cell_t::payload, and tor_assert.

Referenced by circuit_extend(), circuit_n_conn_done(), and circuit_send_next_onion_skin().

origin_circuit_t* circuit_establish_circuit ( uint8_t  purpose,
extend_info_t exit,
int  flags 
)

Build a new circuit for purpose. If exit is defined, then use that as your exit router, else choose a suitable exit node.

Also launch a connection to the first OR in the chosen path, if it's not open already.

References circuit_handle_first_hop(), control_event_circuit_status(), END_CIRC_REASON_NOPATH, onion_pick_cpath_exit(), onion_populate_cpath(), origin_circuit_init(), and TO_CIRCUIT.

Referenced by circuit_launch_by_extend_info().

int circuit_extend ( cell_t cell,
circuit_t circ 
)

Take the 'extend' cell, pull out addr/port plus the onion skin and identity digest for the next hop. If we're already connected, pass the onion skin to the next hop using a create cell; otherwise launch a new OR connection, and circ will notice when the connection succeeds or fails.

Return -1 if we want to warn and tear down the circuit, else return 0.

References or_connection_t::_base, connection_t::address, circuit_deliver_create_cell(), circuit_set_state(), CIRCUIT_STATE_OR_WAIT, connection_or_connect(), connection_or_get_for_extend(), DIGEST_LEN, extend_info_alloc(), fmt_addr(), get_options(), get_uint16(), get_uint32(), LD_CIRC, LD_OR, LD_PROTOCOL, relay_header_t::length, circuit_t::n_conn, circuit_t::n_conn_onionskin, circuit_t::n_hop, cell_t::payload, connection_t::port, RELAY_HEADER_SIZE, relay_header_unpack(), server_mode(), TO_OR_CIRCUIT(), tor_addr_from_ipv4h, tor_assert, and tor_digest_is_zero().

Referenced by connection_edge_process_relay_cell().

int circuit_extend_to_new_exit ( origin_circuit_t circ,
extend_info_t exit 
)

Take an open circ, and add a new hop at the end, based on info. Set its state back to CIRCUIT_STATE_BUILDING, and then send the next extend cell to begin connecting to that hop.

References circuit_append_new_exit(), circuit_send_next_onion_skin(), circuit_set_state(), CIRCUIT_STATE_BUILDING, LD_CIRC, extend_info_t::nickname, TO_CIRCUIT, and warn_if_last_router_excluded().

Referenced by circuit_launch_by_extend_info(), and rend_client_introduction_acked().

int circuit_finish_handshake ( origin_circuit_t circ,
uint8_t  reply_type,
const char *  reply 
)

A created or extended cell came back to us on the circuit, and it included reply as its body. (If reply_type is CELL_CREATED, the body contains (the second DH key, plus KH). If reply_type is CELL_CREATED_FAST, the body contains a secret y and a hash H(x|y).)

Calculate the appropriate keys and digests, make sure KH is correct, and initialize this hop of the cpath.

Return - reason if we want to mark circ for close, else return 0.

References CIPHER_KEY_LEN, circuit_init_cpath_crypto(), circuit_log_path(), control_event_circuit_status(), origin_circuit_t::cpath, crypto_dh_free(), crypt_path_t::dh_handshake_state, DIGEST_LEN, fast_client_handshake(), crypt_path_t::fast_handshake_state, crypt_path_t::handshake_digest, LD_CIRC, LD_PROTOCOL, onion_next_hop_in_cpath(), onion_skin_client_handshake(), crypt_path_t::state, and tor_assert.

Referenced by command_process_created_cell(), and connection_edge_process_relay_cell().

static smartlist_t* circuit_get_unhandled_ports ( time_t  now  )  [static]

Fetch the list of predicted ports, dup it into a smartlist of uint16_t's, remove the ones that are already handled by an existing circuit, and return it.

References circuit_remove_handled_ports(), rep_hist_get_predicted_ports(), smartlist_add(), and smartlist_create().

Referenced by choose_good_exit_server_general(), and circuit_all_predicted_ports_handled().

int circuit_handle_first_hop ( origin_circuit_t circ  ) 

int circuit_init_cpath_crypto ( crypt_path_t cpath,
const char *  key_data,
int  reverse 
)

Initialize cpath->{f|b}_{crypto|digest} from the key material in key_data. key_data must contain CPATH_KEY_MATERIAL bytes, which are used as follows:

  • 20 to initialize f_digest
  • 20 to initialize b_digest
  • 16 to key f_crypto
  • 16 to key b_crypto

(If 'reverse' is true, then f_XX and b_XX are swapped.)

References crypt_path_t::b_crypto, crypt_path_t::b_digest, CIPHER_KEY_LEN, crypto_create_init_cipher(), crypto_digest_add_bytes(), crypto_new_digest_env(), DIGEST_LEN, crypt_path_t::f_crypto, crypt_path_t::f_digest, LD_BUG, and tor_assert.

Referenced by circuit_finish_handshake(), onionskin_answer(), rend_client_receive_rendezvous(), and rend_service_introduce().

char* circuit_list_path ( origin_circuit_t circ,
int  verbose 
)

If verbose is false, allocate and return a comma-separated list of the currently built elements of circuit_t. If verbose is true, also list information about link status in a more verbose format using spaces.

References circuit_list_path_impl().

Referenced by circuit_log_path().

char* circuit_list_path_for_controller ( origin_circuit_t circ  ) 

Allocate and return a comma-separated list of the currently built elements of circuit_t, giving each as a verbose nickname.

References circuit_list_path_impl().

Referenced by control_event_circuit_status(), and getinfo_helper_events().

static char* circuit_list_path_impl ( origin_circuit_t circ,
int  verbose,
int  verbose_names 
) [static]

void circuit_log_path ( int  severity,
unsigned int  domain,
origin_circuit_t circ 
)

Log, at severity severity, the nicknames of each router in circ's cpath. Also log the length of the cpath, and the intended exit point.

References circuit_list_path(), tor_free, and tor_log().

Referenced by circuit_dump_details(), circuit_expire_building(), circuit_finish_handshake(), connection_ap_handshake_attach_circuit(), connection_ap_process_end_not_open(), connection_edge_process_relay_cell_not_open(), and warn_if_last_router_excluded().

void circuit_n_conn_done ( or_connection_t or_conn,
int  status 
)

void circuit_note_clock_jumped ( int  seconds_elapsed  ) 

Our clock just jumped by seconds_elapsed. Assume something has also gone wrong with our network: notify the user, and abandon all not-yet-used circuits.

References circuit_expire_all_dirty_circs(), circuit_mark_all_unused_circs(), control_event_client_status(), control_event_general_status(), get_options(), has_completed_circuit, LD_GENERAL, server_mode(), and tor_log().

Referenced by second_elapsed_callback().

void circuit_rep_hist_note_result ( origin_circuit_t circ  ) 

Tell the rep(utation)hist(ory) module about the status of the links in circ. Hops that have become OPEN are marked as successfully extended; the _first_ hop that isn't open (if any) is marked as unable to extend.

References routerinfo_t::cache_info, origin_circuit_t::cpath, crypt_path_t::extend_info, get_options(), extend_info_t::identity_digest, signed_descriptor_t::identity_digest, crypt_path_t::next, rep_hist_note_extend_failed(), rep_hist_note_extend_succeeded(), router_get_by_digest(), router_get_my_routerinfo(), server_mode(), and crypt_path_t::state.

Referenced by _circuit_mark_for_close(), and circuit_send_next_onion_skin().

int circuit_send_next_onion_skin ( origin_circuit_t circ  ) 

This is the backbone function for building circuits.

If circ's first hop is closed, then we need to build a create cell and send it forward.

Otherwise, we need to build a relay extend cell and send it forward.

Return -reason if we want to tear down circ, else return 0.

References origin_circuit_t::_base, extend_info_t::addr, origin_circuit_t::build_state, check_whether_orport_reachable(), circuit_build_times_add_time(), circuit_build_times_network_circ_success(), circuit_build_times_set_timeout(), circuit_deliver_create_cell(), circuit_has_opened(), circuit_rep_hist_note_result(), circuit_reset_failure_count(), circuit_set_state(), CIRCUIT_STATE_BUILDING, CIRCUIT_STATE_OPEN, consider_testing_reachability(), control_event_bootstrap(), control_event_client_status(), origin_circuit_t::cpath, crypto_rand(), crypt_path_t::dh_handshake_state, DIGEST_LEN, crypt_path_t::extend_info, crypt_path_t::fast_handshake_state, get_options(), has_completed_circuit, circuit_t::highres_created, extend_info_t::identity_digest, or_connection_t::identity_digest, inform_testing_reachability(), LD_BUG, LD_CIRC, LD_GENERAL, circuit_t::n_conn, routerinfo_t::nickname, cpath_build_state_t::onehop_tunnel, extend_info_t::onion_key, onion_next_hop_in_cpath(), onion_skin_create(), extend_info_t::port, crypt_path_t::prev, relay_send_command_from_edge(), router_get_by_digest(), server_mode(), set_uint16(), set_uint32(), should_use_create_fast_for_circuit(), circuit_t::state, crypt_path_t::state, TO_CIRCUIT, tor_addr_family(), tor_addr_to_ipv4n(), tor_assert, tor_gettimeofday(), and tv_mdiff().

Referenced by circuit_extend_to_new_exit(), circuit_handle_first_hop(), circuit_n_conn_done(), command_process_created_cell(), connection_edge_process_relay_cell(), and handle_control_extendcircuit().

int circuit_truncated ( origin_circuit_t circ,
crypt_path_t layer 
)

We received a relay truncated cell on circ.

Since we don't ask for truncates currently, getting a truncated means that a connection broke or an extend failed. For now, just give up: for circ to close, and return 0.

References circuit_free_cpath_node(), origin_circuit_t::cpath, END_CIRC_REASON_FLAG_REMOTE, LD_APP, LD_CIRC, crypt_path_t::next, edge_connection_t::next_stream, origin_circuit_t::p_streams, TO_CIRCUIT, and tor_assert.

Referenced by connection_edge_process_relay_cell().

void circuitbuild_running_unit_tests ( void   ) 

Make a note that we're running unit tests (rather than running Tor itself), so we avoid clobbering our state file.

References unit_tests.

void clear_bridge_list ( void   ) 

Initialize the bridge list to empty, creating it if needed.

References smartlist_clear(), smartlist_create(), and tor_free.

Referenced by entry_guards_free_all(), and options_act().

static void control_event_guard_deferred ( void   )  [static]

Called when one or more guards that we would previously have used for some purpose are no longer in use because a higher-priority guard has become usable again.

References control_event_guard(), entry_is_live(), get_options(), and or_options_t::NumEntryGuards.

Referenced by add_an_entry_guard().

static int count_acceptable_routers ( smartlist_t routers  )  [static]

Return the number of routers in routers that are currently up and available for building circuits through.

References routerinfo_t::is_running, and routerinfo_t::is_valid.

Referenced by new_route_len().

static void entry_guard_free ( entry_guard_t e  )  [static]

int entry_guard_register_connect_status ( const char *  digest,
int  succeeded,
int  mark_relay_status,
time_t  now 
)

Called when a connection to an OR with the identity digest digest is established (succeeded==1) or has failed (succeeded==0). If the OR is an entry, change that entry's up/down status. Return 0 normally, or -1 if we want to tear down the new connection.

If mark_relay_status, also call router_set_status() on this relay.

XXX022 change succeeded and mark_relay_status into 'int flags'.

References DIGEST_LEN, and HEX_DIGEST_LEN.

Referenced by circuit_build_failed(), connection_about_to_close_connection(), connection_or_check_valid_tls_handshake(), connection_or_connect(), and connection_or_set_state_open().

static int entry_guard_set_status ( entry_guard_t e,
routerinfo_t ri,
time_t  now,
or_options_t options,
const char **  reason 
) [static]

Check whether the entry guard e is usable, given the directory authorities' opinion about the router (stored in ri) and the user's configuration (in options). Set e->bad_since accordingly. Return true iff the entry guard's status changes.

If it's not usable, set *reason to a static string explaining why.

References entry_guard_t::bad_since, base16_encode(), control_event_guard(), DIGEST_LEN, or_options_t::EntryNodes, or_options_t::ExcludeNodes, HEX_DIGEST_LEN, entry_guard_t::identity, routerinfo_t::is_possible_guard, routerinfo_t::is_running, LD_CIRC, entry_guard_t::nickname, routerinfo_t::purpose, ROUTER_PURPOSE_BRIDGE, routerset_contains_router(), tor_assert, and or_options_t::UseBridges.

Referenced by entry_guards_compute_status().

static void entry_guards_changed ( void   )  [static]

Our list of entry guards has changed, or some element of one of our entry guards has changed. Write the changes to disk within the next few minutes.

References or_options_t::AvoidDiskWrites, entry_guards_dirty, get_options(), get_or_state(), and or_state_mark_dirty().

Referenced by choose_random_entry(), entry_guards_compute_status(), and pick_entry_guards().

void entry_guards_compute_status ( void   ) 

A new directory or router-status has arrived; update the down/listed status of the entry guards.

An entry is 'down' if the directory lists it as nonrunning. An entry is 'unlisted' if the directory doesn't include it.

Don't call this on startup; only on a fresh download. Otherwise we'll think that things are unlisted.

References digestmap_free(), digestmap_get(), digestmap_new(), digestmap_set(), entry_guard_set_status(), entry_guards_changed(), entry_is_live(), entry_nodes_should_be_added(), or_options_t::EntryNodes, get_options(), LD_CIRC, log_entry_guards(), num_live_entry_guards(), remove_dead_entry_guards(), router_get_by_digest(), and tor_assert.

Referenced by directory_info_has_arrived().

void entry_guards_free_all ( void   ) 

Release all storage held by the list of entry guards and related memory structs.

References bridge_list, clear_bridge_list(), entry_guard_free(), and smartlist_free().

Referenced by tor_free_all().

int entry_guards_parse_state ( or_state_t state,
int  set,
char **  msg 
)

static void entry_guards_prepend_from_config ( void   )  [static]

Add all nodes in EntryNodes that aren't currently guard nodes to the list of guard nodes, at the front.

References or_options_t::EntryNodes, get_options(), is_an_entry_guard(), LD_CIRC, routerset_get_all_routers(), routerset_to_string(), smartlist_add(), smartlist_create(), smartlist_digest_isin(), tor_assert, and tor_free.

Referenced by choose_random_entry().

void entry_guards_update_state ( or_state_t state  ) 

If the entry guard info has not changed, do nothing and return. Otherwise, free the EntryGuards piece of state and create a new one out of the global entry_guards list, and then mark state dirty so it will get saved to disk.

References or_options_t::AvoidDiskWrites, base16_encode(), config_free_lines(), DIGEST_LEN, entry_guards_dirty, or_state_t::EntryGuards, format_iso_time(), get_options(), get_or_state(), HEX_DIGEST_LEN, config_line_t::key, MAX_NICKNAME_LEN, config_line_t::next, or_state_mark_dirty(), smartlist_create(), tor_snprintf(), and config_line_t::value.

Referenced by or_state_save().

static INLINE routerinfo_t* entry_is_live ( entry_guard_t e,
int  need_uptime,
int  need_capacity,
int  assume_reachable,
const char **  msg 
) [static]

Return the router corresponding to e, if e is working well enough that we are willing to use it as an entry right now. (Else return NULL.) In particular, it must be

  • Listed as either up or never yet contacted;
  • Present in the routerlist;
  • Listed as 'stable' or 'fast' by the current dirserver consensus, if demanded by need_uptime or need_capacity (unless it's a configured EntryNode);
  • Allowed by our current ReachableORAddresses config option; and
  • Currently thought to be reachable by us (unless assume_reachable is true).

If the answer is no, set *msg to an explanation of why.

References entry_guard_t::bad_since, entry_guard_t::can_retry, entry_is_time_to_retry(), or_options_t::EntryNodes, fascist_firewall_allows_or(), get_options(), entry_guard_t::identity, routerinfo_t::purpose, router_get_by_digest(), router_is_unreliable(), ROUTER_PURPOSE_BRIDGE, ROUTER_PURPOSE_GENERAL, routerset_contains_router(), tor_assert, and entry_guard_t::unreachable_since.

Referenced by choose_random_entry(), control_event_guard_deferred(), entry_guards_compute_status(), log_entry_guards(), and num_live_entry_guards().

static int entry_is_time_to_retry ( entry_guard_t e,
time_t  now 
) [static]

Return true iff enough time has passed since we last tried to connect to the unreachable guard e that we're willing to try again.

References entry_guard_t::last_attempted, and entry_guard_t::unreachable_since.

Referenced by entry_is_live().

int entry_list_is_constrained ( or_options_t options  ) 

Return 0 if we're fine adding arbitrary routers out of the directory to our entry guard list, or return 1 if we have a list already and we'd prefer to stick to it.

References or_options_t::EntryNodes, and or_options_t::UseBridges.

Referenced by choose_random_entry(), and connection_dir_request_failed().

void entry_nodes_should_be_added ( void   ) 

Called when the value of EntryNodes changes in our configuration.

References LD_CIRC.

Referenced by entry_guards_compute_status(), and options_act().

extend_info_t* extend_info_alloc ( const char *  nickname,
const char *  digest,
crypto_pk_env_t onion_key,
const tor_addr_t addr,
uint16_t  port 
)

extend_info_t* extend_info_dup ( extend_info_t info  ) 

void extend_info_free ( extend_info_t info  ) 

extend_info_t* extend_info_from_router ( routerinfo_t r  ) 

void fetch_bridge_descriptors ( time_t  now  ) 

static bridge_info_t* find_bridge_by_digest ( const char *  digest  )  [static]

If digest is one of our known bridges, return it.

References DIGEST_LEN.

Referenced by retry_bridge_descriptor_fetch_directly().

static circid_t get_unique_circ_id_by_conn ( or_connection_t conn  )  [static]

Iterate over values of circ_id, starting from conn->next_circ_id, and with the high bit specified by conn->circ_id_type, until we get a circ_id that is not in use by any other circuit on that conn.

Return it, or 0 if can't get a unique circ_id.

References or_connection_t::circ_id_type, CIRC_ID_TYPE_HIGHER, CIRC_ID_TYPE_NEITHER, circuit_id_in_use_on_orconn(), LD_BUG, LD_CIRC, or_connection_t::next_circ_id, and tor_assert.

Referenced by circuit_deliver_create_cell().

int getinfo_helper_entry_guards ( control_connection_t conn,
const char *  question,
char **  answer 
)

If question is the string "entry-guards", then dump to *answer a newly allocated string describing all of the nodes in the global entry_guards list. See control-spec.txt for details. For backward compatibility, we also handle the string "helper-nodes".

References base16_encode(), DIGEST_LEN, format_iso_time(), MAX_VERBOSE_NICKNAME_LEN, router_get_by_digest(), router_get_verbose_nickname(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_free, and tor_snprintf().

int inform_testing_reachability ( void   ) 

We've decided to start our reachability testing. If all is set, log this to the user. Return 1 if we did, or 0 if we chose not to log anything.

References routerinfo_t::address, control_event_server_status(), routerinfo_t::dir_port, LD_OR, routerinfo_t::or_port, router_get_my_routerinfo(), TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT, and tor_snprintf().

Referenced by circuit_send_next_onion_skin(), and options_act().

static INLINE entry_guard_t* is_an_entry_guard ( const char *  digest  )  [static]

If digest matches the identity of any node in the entry_guards list, return that node. Else return NULL.

References DIGEST_LEN.

Referenced by add_an_entry_guard(), and entry_guards_prepend_from_config().

static void launch_direct_bridge_descriptor_fetch ( bridge_info_t bridge  )  [static]

void learned_bridge_descriptor ( routerinfo_t ri,
int  from_cache 
)

static void log_entry_guards ( int  severity  )  [static]

static int new_route_len ( uint8_t  purpose,
extend_info_t exit,
smartlist_t routers 
) [static]

Choose a length for a circuit of purpose purpose. Default length is 3 + the number of endpoints that would give something away. If the routerlist routers doesn't have enough routers to handle the desired path length, return as large a path length as is feasible, except if it's less than 2, in which case return -1.

References CIRCUIT_PURPOSE_S_ESTABLISH_INTRO, CIRCUIT_PURPOSE_TESTING, count_acceptable_routers(), LD_CIRC, and tor_assert.

Referenced by onion_pick_cpath_exit().

static int num_live_entry_guards ( void   )  [static]

Return the number of entry guards that we think are usable.

References entry_is_live().

Referenced by entry_guards_compute_status(), and pick_entry_guards().

static int onion_append_hop ( crypt_path_t **  head_ptr,
extend_info_t choice 
) [static]

Create a new hop, annotate it with information about its corresponding router choice, and append it to the end of the cpath head_ptr.

References circuit_initial_package_window(), CIRCWINDOW_START, crypt_path_t::deliver_window, crypt_path_t::extend_info, extend_info_dup(), crypt_path_t::magic, onion_append_to_cpath(), crypt_path_t::package_window, and crypt_path_t::state.

Referenced by circuit_append_new_exit(), and onion_extend_cpath().

void onion_append_to_cpath ( crypt_path_t **  head_ptr,
crypt_path_t new_hop 
)

Add new_hop to the end of the doubly-linked-list head_ptr. This function is used to extend cpath by another hop.

References crypt_path_t::next, and crypt_path_t::prev.

Referenced by onion_append_hop(), rend_client_receive_rendezvous(), and rend_service_rendezvous_has_opened().

static int onion_extend_cpath ( origin_circuit_t circ  )  [static]

static crypt_path_t * onion_next_hop_in_cpath ( crypt_path_t cpath  )  [static]

Return the first non-open hop in cpath, or return NULL if all hops are open.

References crypt_path_t::next, and crypt_path_t::state.

Referenced by circuit_finish_handshake(), circuit_handle_first_hop(), and circuit_send_next_onion_skin().

static int onion_pick_cpath_exit ( origin_circuit_t circ,
extend_info_t exit 
) [static]

static int onion_populate_cpath ( origin_circuit_t circ  )  [static]

Pick all the entries in our cpath. Stop and return 0 when we're happy, or return -1 if an error occurs.

References LD_CIRC, and onion_extend_cpath().

Referenced by circuit_establish_circuit().

int onionskin_answer ( or_circuit_t circ,
uint8_t  cell_type,
const char *  payload,
const char *  keys 
)

origin_circuit_t* origin_circuit_init ( uint8_t  purpose,
int  flags 
)

static void pick_entry_guards ( void   )  [static]

If the use of entry guards is configured, choose more entry guards until we have enough in the list.

References add_an_entry_guard(), entry_guards_changed(), get_options(), num_live_entry_guards(), or_options_t::NumEntryGuards, and tor_assert.

Referenced by choose_random_entry().

static int remove_dead_entry_guards ( void   )  [static]

Remove all entry guards that have been down or unlisted for so long that we don't think they'll come up again. Return 1 if we removed any, or 0 if we did nothing.

References entry_guard_t::bad_since, base16_encode(), control_event_guard(), DIGEST_LEN, entry_guard_free(), ENTRY_GUARD_REMOVE_AFTER, format_local_iso_time(), HEX_DIGEST_LEN, entry_guard_t::identity, LD_CIRC, log_entry_guards(), entry_guard_t::nickname, and smartlist_del_keeporder().

Referenced by entry_guards_compute_status().

static int remove_obsolete_entry_guards ( void   )  [static]

void retry_bridge_descriptor_fetch_directly ( const char *  digest  ) 

Fetching the bridge descriptor from the bridge authority returned a "not found". Fall back to trying a direct fetch.

References find_bridge_by_digest(), and launch_direct_bridge_descriptor_fetch().

Referenced by dir_routerdesc_download_failed().

static int router_handles_some_port ( routerinfo_t router,
smartlist_t needed_ports 
) [static]

Return 1 if router can handle one or more of the ports in needed_ports, else return 0.

References ADDR_POLICY_PROBABLY_REJECTED, ADDR_POLICY_REJECTED, compare_addr_to_addr_policy(), routerinfo_t::exit_policy, and tor_assert.

Referenced by choose_good_exit_server_general().

static bridge_info_t* routerinfo_get_configured_bridge ( routerinfo_t ri  )  [static]

Return a bridge pointer if ri is one of our known bridges (either by comparing keys if possible, else by comparing addr/port). Else return NULL.

References routerinfo_t::addr, routerinfo_t::cache_info, DIGEST_LEN, signed_descriptor_t::identity_digest, routerinfo_t::or_port, tor_addr_eq_ipv4h(), and tor_digest_is_zero().

Referenced by learned_bridge_descriptor(), and routerinfo_is_a_configured_bridge().

int routerinfo_is_a_configured_bridge ( routerinfo_t ri  ) 

Return 1 if ri is one of our known bridges, else 0.

References routerinfo_get_configured_bridge().

Referenced by router_add_to_routerlist().

static INLINE int should_use_create_fast_for_circuit ( origin_circuit_t circ  )  [static]

Return true iff we should send a create_fast cell to start building a given circuit

References origin_circuit_t::cpath, crypt_path_t::extend_info, or_options_t::FastFirstHopPK, get_options(), extend_info_t::onion_key, server_mode(), and tor_assert.

Referenced by circuit_send_next_onion_skin().

static void warn_if_last_router_excluded ( origin_circuit_t circ,
const extend_info_t exit 
) [static]


Variable Documentation

smartlist_t* bridge_list = NULL [static]

A list of configured bridges. Whenever we actually get a descriptor for one, we add it as an entry guard.

Referenced by entry_guards_free_all().

smartlist_t* entry_guards = NULL [static]

A list of our chosen entry guards.

int entry_guards_dirty = 0 [static]

A value of 1 means that the entry_guards list has changed and those changes need to be flushed to disk.

Referenced by entry_guards_changed(), entry_guards_parse_state(), and entry_guards_update_state().

A global list of all circuits at this hop.

int should_add_entry_nodes = 0 [static]

When we try to choose an entry guard, should we parse and add config's EntryNodes first?

int unit_tests = 0 [static]

If set, we're running the unit tests: we should avoid clobbering our state file or accessing get_options() or get_or_state()

Referenced by circuit_build_times_add_time(), circuit_build_times_get_initial_timeout(), circuit_build_times_update_state(), and circuitbuild_running_unit_tests().


Generated on Tue May 25 00:30:40 2010 for tor by  doxygen 1.5.6