Tor 0.4.9.0-alpha-dev
Macros | Functions
circuituse.h File Reference

Header file for circuituse.c. More...

Go to the source code of this file.

Macros

#define CIRCLAUNCH_ONEHOP_TUNNEL   (1<<0)
 
#define CIRCLAUNCH_NEED_UPTIME   (1<<1)
 
#define CIRCLAUNCH_NEED_CAPACITY   (1<<2)
 
#define CIRCLAUNCH_IS_INTERNAL   (1<<3)
 
#define CIRCLAUNCH_IS_V3_RP   (1<<4)
 
#define CIRCLAUNCH_IS_IPV6_SELFTEST   (1<<5)
 
#define CIRCLAUNCH_NEED_CONFLUX   (1<<6)
 

Functions

void circuit_expire_building (void)
 
void circuit_expire_waiting_for_better_guard (void)
 
void circuit_remove_handled_ports (smartlist_t *needed_ports)
 
int circuit_stream_is_being_handled (entry_connection_t *conn, uint16_t port, int min)
 
void circuit_log_ancient_one_hop_circuits (int age)
 
void circuit_build_needed_circs (time_t now)
 
void circuit_expire_old_circs_as_needed (time_t now)
 
void circuit_detach_stream (circuit_t *circ, edge_connection_t *conn)
 
void circuit_expire_old_circuits_serverside (time_t now)
 
void reset_bandwidth_test (void)
 
int circuit_enough_testing_circs (void)
 
void circuit_has_opened (origin_circuit_t *circ)
 
void circuit_try_attaching_streams (origin_circuit_t *circ)
 
void circuit_build_failed (origin_circuit_t *circ)
 
origin_circuit_tcircuit_launch_by_extend_info (uint8_t purpose, extend_info_t *info, int flags)
 
origin_circuit_tcircuit_launch (uint8_t purpose, int flags)
 
void circuit_reset_failure_count (int timeout)
 
int connection_ap_handshake_attach_chosen_circuit (entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath)
 
int connection_ap_handshake_attach_circuit (entry_connection_t *conn)
 
void circuit_change_purpose (circuit_t *circ, uint8_t new_purpose)
 
int hostname_in_track_host_exits (const or_options_t *options, const char *address)
 
void mark_circuit_unusable_for_new_conns (origin_circuit_t *circ)
 
int circuit_purpose_is_hidden_service (uint8_t)
 
bool circuit_purpose_is_hs_client (const uint8_t purpose)
 
bool circuit_purpose_is_hs_service (const uint8_t purpose)
 
bool circuit_purpose_is_hs_vanguards (const uint8_t purpose)
 
bool circuit_is_hs_v3 (const circuit_t *circ)
 
int circuit_is_acceptable (const origin_circuit_t *origin_circ, const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal, time_t now)
 
int circuit_should_use_vanguards (uint8_t)
 
void circuit_sent_valid_data (origin_circuit_t *circ, uint16_t relay_body_len)
 
void circuit_read_valid_data (origin_circuit_t *circ, uint16_t relay_body_len)
 

Detailed Description

Header file for circuituse.c.

Definition in file circuituse.h.

Macro Definition Documentation

◆ CIRCLAUNCH_IS_INTERNAL

#define CIRCLAUNCH_IS_INTERNAL   (1<<3)

Flag to set when the last hop of a circuit doesn't need to be an exit node.

Definition at line 46 of file circuituse.h.

◆ CIRCLAUNCH_IS_IPV6_SELFTEST

#define CIRCLAUNCH_IS_IPV6_SELFTEST   (1<<5)

Flag to set when we are trying to launch a self-testing circuit to our IPv6 ORPort. We need to apply some additional filters on the second-last node in the circuit. (We are both the client and the last node in the circuit.)

Definition at line 54 of file circuituse.h.

◆ CIRCLAUNCH_IS_V3_RP

#define CIRCLAUNCH_IS_V3_RP   (1<<4)

Flag to set when we are trying to launch a v3 rendezvous circuit. We need to apply some additional filters on the node picked.

Definition at line 49 of file circuituse.h.

◆ CIRCLAUNCH_NEED_CAPACITY

#define CIRCLAUNCH_NEED_CAPACITY   (1<<2)

Flag to set when a circuit needs to be built of high-capacity nodes

Definition at line 43 of file circuituse.h.

◆ CIRCLAUNCH_NEED_CONFLUX

#define CIRCLAUNCH_NEED_CONFLUX   (1<<6)

Flag to set when a circuit needs the exit to support conflux.

Definition at line 56 of file circuituse.h.

◆ CIRCLAUNCH_NEED_UPTIME

#define CIRCLAUNCH_NEED_UPTIME   (1<<1)

Flag to set when a circuit needs to be built of high-uptime nodes

Definition at line 41 of file circuituse.h.

◆ CIRCLAUNCH_ONEHOP_TUNNEL

#define CIRCLAUNCH_ONEHOP_TUNNEL   (1<<0)

Flag to set when a circuit should have only a single hop.

Definition at line 39 of file circuituse.h.

Function Documentation

◆ circuit_build_failed()

void circuit_build_failed ( origin_circuit_t circ)

Called whenever a circuit could not be successfully built.

Definition at line 1756 of file circuituse.c.

Referenced by circuit_about_to_free().

◆ circuit_build_needed_circs()

void circuit_build_needed_circs ( time_t  now)

This function is called once a second, if router_have_minimum_dir_info() is true. Its job is to make sure all services we offer have enough circuits available. Some services just want enough circuits for current tasks, whereas others want a minimum set of idle circuits hanging around.

Definition at line 1298 of file circuituse.c.

Referenced by second_elapsed_callback().

◆ circuit_change_purpose()

void circuit_change_purpose ( circuit_t circ,
uint8_t  new_purpose 
)

Change circ's purpose to new_purpose.

Definition at line 3095 of file circuituse.c.

Referenced by close_or_reextend_intro_circ(), and finalize_rend_circuit().

◆ circuit_detach_stream()

void circuit_detach_stream ( circuit_t circ,
edge_connection_t conn 
)

If the stream conn is a member of any of the linked lists of circ, then remove it from the list.

Definition at line 1352 of file circuituse.c.

Referenced by connection_exit_about_to_close().

◆ circuit_enough_testing_circs()

int circuit_enough_testing_circs ( void  )

Return 1 if we've already exercised our bandwidth, or if we have fewer than NUM_PARALLEL_TESTING_CIRCS testing circuits established or on the way. Else return 0.

Definition at line 1592 of file circuituse.c.

Referenced by router_do_reachability_checks().

◆ circuit_expire_building()

void circuit_expire_building ( void  )

Close all circuits that start at us, aren't open, and were born at least CircuitBuildTimeout seconds ago.

TODO: This function is now partially redundant to circuit_build_times_handle_completed_hop(), but that function only covers circuits up to and including 3 hops that are still actually completing hops. However, circuit_expire_building() also handles longer circuits, as well as circuits that are completely stalled. In the future (after prop247/other path selection revamping), we probably want to eliminate this rats nest in favor of a simpler approach.

Because circuit build timeout is calculated only based on 3 hop general purpose circuit construction, we need to scale the timeout to make it properly apply to longer circuits, and circuits of certain usage types. The following diagram illustrates how we derive the scaling below. In short, we calculate the number of times our telescoping-based circuit construction causes cells to traverse each link for the circuit purpose types in question, and then assume each link is equivalent.

OP –a--> A –b--> B –c--> C OP –a--> A –b--> B –c--> C –d--> D

Let h = a = b = c = d

Three hops (general_cutoff) RTTs = 3a + 2b + c RTTs = 6h Cannibalized: RTTs = a+b+c+d RTTs = 4h Four hops: RTTs = 4a + 3b + 2c + d RTTs = 10h Client INTRODUCE1+ACK: // XXX: correct? RTTs = 5a + 4b + 3c + 2d RTTs = 14h Server intro: RTTs = 4a + 3b + 2c RTTs = 9h

Definition at line 445 of file circuituse.c.

Referenced by second_elapsed_callback().

◆ circuit_expire_old_circs_as_needed()

void circuit_expire_old_circs_as_needed ( time_t  now)

Called once a second either directly or from circuit_build_needed_circs(). As appropriate (once per NewCircuitPeriod) resets failure counts and expires old circuits.

Definition at line 1321 of file circuituse.c.

Referenced by second_elapsed_callback().

◆ circuit_expire_old_circuits_serverside()

void circuit_expire_old_circuits_serverside ( time_t  now)

Find each non-origin circuit that has been unused for too long, has no streams on it, came from a client, and ends here: mark it for close.

Definition at line 1543 of file circuituse.c.

Referenced by expire_old_circuits_serverside_callback().

◆ circuit_expire_waiting_for_better_guard()

void circuit_expire_waiting_for_better_guard ( void  )

Mark for close all circuits that start here, that were built through a guard we weren't sure if we wanted to use, and that have been waiting around for way too long.

Definition at line 828 of file circuituse.c.

Referenced by second_elapsed_callback().

◆ circuit_has_opened()

void circuit_has_opened ( origin_circuit_t circ)

The circuit circ has just become open. Take the next step: for rendezvous circuits, we pass circ to the appropriate function in rendclient or rendservice. For general circuits, we call connection_ap_attach_pending, which looks for pending streams that could use circ.

Definition at line 1659 of file circuituse.c.

◆ circuit_is_acceptable()

int circuit_is_acceptable ( const origin_circuit_t origin_circ,
const entry_connection_t conn,
int  must_be_open,
uint8_t  purpose,
int  need_uptime,
int  need_internal,
time_t  now 
)

Return 1 if circ could be returned by circuit_get_best(). Else return 0.

Definition at line 107 of file circuituse.c.

Referenced by circuit_get_best().

◆ circuit_is_hs_v3()

bool circuit_is_hs_v3 ( const circuit_t circ)

Return true iff the given circuit is an HS v3 circuit.

Definition at line 1996 of file circuituse.c.

Referenced by cleanup_on_close_client_circ(), cleanup_on_free_client_circ(), and hs_circ_cleanup_on_close().

◆ circuit_launch()

origin_circuit_t * circuit_launch ( uint8_t  purpose,
int  flags 
)

Launch a new circuit; see circuit_launch_by_extend_info() for details on arguments.

Definition at line 1928 of file circuituse.c.

Referenced by circuit_expire_old_circs_as_needed().

◆ circuit_launch_by_extend_info()

origin_circuit_t * circuit_launch_by_extend_info ( uint8_t  purpose,
extend_info_t extend_info,
int  flags 
)

Launch a new circuit with purpose purpose and exit node extend_info (or NULL to select a random exit node).

If flags contains:

  • CIRCLAUNCH_ONEHOP_TUNNEL: the circuit will have only one hop;
  • CIRCLAUNCH_NEED_UPTIME: choose routers with high uptime;
  • CIRCLAUNCH_NEED_CAPACITY: choose routers with high bandwidth;
  • CIRCLAUNCH_IS_IPV6_SELFTEST: the second-last hop must support IPv6 extends;
  • CIRCLAUNCH_IS_INTERNAL: the last hop need not be an exit node;
  • CIRCLAUNCH_IS_V3_RP: the last hop must support v3 onion service rendezvous.

Return the newly allocated circuit on success, or NULL on failure.

Definition at line 2089 of file circuituse.c.

Referenced by circuit_launch().

◆ circuit_log_ancient_one_hop_circuits()

void circuit_log_ancient_one_hop_circuits ( int  age)

As a diagnostic for bug 8387, log information about how many one-hop circuits we have around that have been there for at least age seconds. Log a few of them. Ignores Single Onion Service intro, it is expected to be long-term one-hop circuits.

Definition at line 852 of file circuituse.c.

◆ circuit_purpose_is_hidden_service()

int circuit_purpose_is_hidden_service ( uint8_t  purpose)

Tell us if a circuit is a hidden service circuit.

Definition at line 1951 of file circuituse.c.

Referenced by circuit_should_use_vanguards(), middle_node_must_be_vanguard(), and route_len_for_purpose().

◆ circuit_purpose_is_hs_client()

bool circuit_purpose_is_hs_client ( const uint8_t  purpose)

Return true iff the given circuit is an HS client circuit.

Definition at line 1973 of file circuituse.c.

Referenced by circuit_purpose_is_hidden_service(), hs_circ_cleanup_on_close(), and hs_circ_cleanup_on_free().

◆ circuit_purpose_is_hs_service()

bool circuit_purpose_is_hs_service ( const uint8_t  purpose)

Return true iff the given circuit is an HS service circuit.

Definition at line 1981 of file circuituse.c.

Referenced by circuit_purpose_is_hidden_service(), and hs_circ_cleanup_on_close().

◆ circuit_purpose_is_hs_vanguards()

bool circuit_purpose_is_hs_vanguards ( const uint8_t  purpose)

Return true iff the given circuit is an HS Vanguards circuit.

Definition at line 1989 of file circuituse.c.

Referenced by circuit_purpose_is_hidden_service().

◆ circuit_read_valid_data()

void circuit_read_valid_data ( origin_circuit_t circ,
uint16_t  relay_body_len 
)

Add relay_body_len and RELAY_PAYLOAD_SIZE-relay_body_len to the valid delivered read field and the overhead field, respectively.

Definition at line 3197 of file circuituse.c.

◆ circuit_remove_handled_ports()

void circuit_remove_handled_ports ( smartlist_t needed_ports)

Remove any elements in needed_ports that are handled by an open or in-progress circuit.

Definition at line 984 of file circuituse.c.

Referenced by circuit_get_unhandled_ports().

◆ circuit_reset_failure_count()

void circuit_reset_failure_count ( int  timeout)

Reset the failure count for opening general circuits. This means we will try MAX_CIRCUIT_FAILURES times more (if necessary) before stopping again.

Definition at line 2218 of file circuituse.c.

Referenced by circuit_expire_old_circs_as_needed().

◆ circuit_sent_valid_data()

void circuit_sent_valid_data ( origin_circuit_t circ,
uint16_t  relay_body_len 
)

Add relay_body_len and RELAY_PAYLOAD_SIZE-relay_body_len to the valid delivered written fields and the overhead field, respectively.

Definition at line 3176 of file circuituse.c.

◆ circuit_should_use_vanguards()

int circuit_should_use_vanguards ( uint8_t  purpose)

Return true if this circuit purpose should use vanguards or pinned Layer2 or Layer3 guards.

This function takes both the circuit purpose and the torrc options for pinned middles/vanguards into account (ie: the circuit must be a hidden service circuit and vanguards/pinned middles must be enabled for it to return true).

Definition at line 2013 of file circuituse.c.

Referenced by build_middle_exclude_list(), and get_circuit_purpose_needed_to_cannibalize().

◆ circuit_stream_is_being_handled()

int circuit_stream_is_being_handled ( entry_connection_t conn,
uint16_t  port,
int  min 
)

Return 1 if at least min general-purpose non-internal circuits will have an acceptable exit node for exit stream conn if it is defined, else for "*:port". Else return 0.

Definition at line 1009 of file circuituse.c.

Referenced by ap_stream_wants_exit_attention().

◆ circuit_try_attaching_streams()

void circuit_try_attaching_streams ( origin_circuit_t circ)

Called when a circuit becomes ready for streams to be attached to it.

Definition at line 1739 of file circuituse.c.

◆ connection_ap_handshake_attach_chosen_circuit()

int connection_ap_handshake_attach_chosen_circuit ( entry_connection_t conn,
origin_circuit_t circ,
crypt_path_t cpath 
)

Attempt to attach the connection conn to circ, and send a begin or resolve cell as appropriate. Return values are as for connection_ap_handshake_attach_circuit. The stream will exit from the hop indicated by cpath, or from the last hop in circ's cpath if cpath is NULL.

Definition at line 2750 of file circuituse.c.

◆ connection_ap_handshake_attach_circuit()

int connection_ap_handshake_attach_circuit ( entry_connection_t conn)

Try to find a safe live circuit for stream conn. If we find one, attach the stream, send appropriate cells, and return 1. Otherwise, try to launch new circuit(s) for the stream. If we can launch circuits, return 0. Otherwise, if we simply can't proceed with this stream, return -1. (conn needs to die, and is maybe already marked).

Definition at line 2835 of file circuituse.c.

◆ hostname_in_track_host_exits()

int hostname_in_track_host_exits ( const or_options_t options,
const char *  address 
)

Return true iff address is matched by one of the entries in TrackHostExits.

Definition at line 2683 of file circuituse.c.

◆ mark_circuit_unusable_for_new_conns()

void mark_circuit_unusable_for_new_conns ( origin_circuit_t circ)

Mark circ so that no more connections can be attached to it.

Definition at line 3148 of file circuituse.c.

Referenced by circuit_mark_all_dirty_circs_as_unusable().

◆ reset_bandwidth_test()

void reset_bandwidth_test ( void  )

Reset have_performed_bandwidth_test, so we'll start building testing circuits again so we can exercise our bandwidth.

Definition at line 1582 of file circuituse.c.