tor  0.4.1.0-alpha-dev
Macros | Functions
circuitlist.h File Reference
#include "lib/testsupport/testsupport.h"
#include "feature/hs/hs_ident.h"
#include "core/or/ocirc_event.h"

Go to the source code of this file.

Macros

#define CIRCUIT_STATE_BUILDING   0
 
#define CIRCUIT_STATE_ONIONSKIN_PENDING   1
 
#define CIRCUIT_STATE_CHAN_WAIT   2
 
#define CIRCUIT_STATE_GUARD_WAIT   3
 
#define CIRCUIT_STATE_OPEN   4
 
#define CIRCUIT_PURPOSE_MIN_   1
 
#define CIRCUIT_PURPOSE_OR_MIN_   1
 
#define CIRCUIT_PURPOSE_OR   1
 
#define CIRCUIT_PURPOSE_INTRO_POINT   2
 
#define CIRCUIT_PURPOSE_REND_POINT_WAITING   3
 
#define CIRCUIT_PURPOSE_REND_ESTABLISHED   4
 
#define CIRCUIT_PURPOSE_OR_MAX_   4
 
#define CIRCUIT_PURPOSE_C_GENERAL   5
 
#define CIRCUIT_PURPOSE_C_HS_MIN_   6
 
#define CIRCUIT_PURPOSE_C_INTRODUCING   6
 
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT   7
 
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED   8
 
#define CIRCUIT_PURPOSE_C_ESTABLISH_REND   9
 
#define CIRCUIT_PURPOSE_C_REND_READY   10
 
#define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED   11
 
#define CIRCUIT_PURPOSE_C_REND_JOINED   12
 
#define CIRCUIT_PURPOSE_C_HSDIR_GET   13
 
#define CIRCUIT_PURPOSE_C_HS_MAX_   13
 
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT   14
 
#define CIRCUIT_PURPOSE_C_MAX_   14
 
#define CIRCUIT_PURPOSE_S_HS_MIN_   15
 
#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO   15
 
#define CIRCUIT_PURPOSE_S_INTRO   16
 
#define CIRCUIT_PURPOSE_S_CONNECT_REND   17
 
#define CIRCUIT_PURPOSE_S_REND_JOINED   18
 
#define CIRCUIT_PURPOSE_S_HSDIR_POST   19
 
#define CIRCUIT_PURPOSE_S_HS_MAX_   19
 
#define CIRCUIT_PURPOSE_TESTING   20
 
#define CIRCUIT_PURPOSE_CONTROLLER   21
 
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING   22
 
#define CIRCUIT_PURPOSE_HS_VANGUARDS   23
 
#define CIRCUIT_PURPOSE_MAX_   23
 
#define CIRCUIT_PURPOSE_UNKNOWN   255
 
#define CIRCUIT_PURPOSE_IS_ORIGIN(p)   ((p)>CIRCUIT_PURPOSE_OR_MAX_)
 
#define CIRCUIT_PURPOSE_IS_CLIENT(p)
 
#define CIRCUIT_IS_ORIGIN(c)   (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))
 
#define CIRCUIT_PURPOSE_IS_ESTABLISHED_REND(p)
 
#define CIRCUIT_IS_ORCIRC(c)   (((circuit_t *)(c))->magic == OR_CIRCUIT_MAGIC)
 
#define CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING(p)
 
#define circuit_mark_for_close(c, reason)   circuit_mark_for_close_((c), (reason), __LINE__, SHORT_FILE__)
 

Functions

or_circuit_tTO_OR_CIRCUIT (circuit_t *)
 
const or_circuit_tCONST_TO_OR_CIRCUIT (const circuit_t *)
 
origin_circuit_tTO_ORIGIN_CIRCUIT (circuit_t *)
 
const origin_circuit_tCONST_TO_ORIGIN_CIRCUIT (const circuit_t *)
 
 MOCK_DECL (smartlist_t *, circuit_get_global_list,(void))
 
smartlist_tcircuit_get_global_origin_circuit_list (void)
 
int circuit_any_opened_circuits (void)
 
int circuit_any_opened_circuits_cached (void)
 
void circuit_cache_opened_circuit_state (int circuits_are_opened)
 
const char * circuit_state_to_string (int state)
 
const char * circuit_purpose_to_controller_string (uint8_t purpose)
 
const char * circuit_purpose_to_controller_hs_state_string (uint8_t purpose)
 
const char * circuit_purpose_to_string (uint8_t purpose)
 
void circuit_dump_by_conn (connection_t *conn, int severity)
 
void circuit_set_p_circid_chan (or_circuit_t *circ, circid_t id, channel_t *chan)
 
void circuit_set_n_circid_chan (circuit_t *circ, circid_t id, channel_t *chan)
 
void channel_mark_circid_unusable (channel_t *chan, circid_t id)
 
void channel_mark_circid_usable (channel_t *chan, circid_t id)
 
time_t circuit_id_when_marked_unusable_on_channel (circid_t circ_id, channel_t *chan)
 
int circuit_event_status (origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
 
void circuit_set_state (circuit_t *circ, uint8_t state)
 
void circuit_close_all_marked (void)
 
int32_t circuit_initial_package_window (void)
 
origin_circuit_torigin_circuit_new (void)
 
or_circuit_tor_circuit_new (circid_t p_circ_id, channel_t *p_chan)
 
circuit_tcircuit_get_by_circid_channel (circid_t circ_id, channel_t *chan)
 
circuit_tcircuit_get_by_circid_channel_even_if_marked (circid_t circ_id, channel_t *chan)
 
int circuit_id_in_use_on_channel (circid_t circ_id, channel_t *chan)
 
circuit_tcircuit_get_by_edge_conn (edge_connection_t *conn)
 
void circuit_unlink_all_from_channel (channel_t *chan, int reason)
 
origin_circuit_tcircuit_get_by_global_id (uint32_t id)
 
origin_circuit_tcircuit_get_ready_rend_circ_by_rend_data (const rend_data_t *rend_data)
 
origin_circuit_tcircuit_get_next_by_pk_and_purpose (origin_circuit_t *start, const uint8_t *digest, uint8_t purpose)
 
origin_circuit_tcircuit_get_next_intro_circ (const origin_circuit_t *start, bool want_client_circ)
 
origin_circuit_tcircuit_get_next_service_rp_circ (origin_circuit_t *start)
 
origin_circuit_tcircuit_get_next_service_hsdir_circ (origin_circuit_t *start)
 
origin_circuit_tcircuit_find_to_cannibalize (uint8_t purpose, extend_info_t *info, int flags)
 
void circuit_mark_all_unused_circs (void)
 
void circuit_mark_all_dirty_circs_as_unusable (void)
 
void circuit_synchronize_written_or_bandwidth (const circuit_t *c, circuit_channel_direction_t dir)
 
 MOCK_DECL (void, circuit_mark_for_close_,(circuit_t *circ, int reason, int line, const char *file))
 
int circuit_get_cpath_len (origin_circuit_t *circ)
 
int circuit_get_cpath_opened_len (const origin_circuit_t *)
 
void circuit_clear_cpath (origin_circuit_t *circ)
 
crypt_path_tcircuit_get_cpath_hop (origin_circuit_t *circ, int hopnum)
 
void circuit_get_all_pending_on_channel (smartlist_t *out, channel_t *chan)
 
int circuit_count_pending_on_channel (channel_t *chan)
 
void assert_cpath_layer_ok (const crypt_path_t *cp)
 
 MOCK_DECL (void, assert_circuit_ok,(const circuit_t *c))
 
void circuit_free_all (void)
 
void circuits_handle_oom (size_t current_allocation)
 
void circuit_clear_testing_cell_stats (circuit_t *circ)
 
void channel_note_destroy_pending (channel_t *chan, circid_t id)
 
 MOCK_DECL (void, channel_note_destroy_not_pending,(channel_t *chan, circid_t id))
 
smartlist_tcircuit_find_circuits_to_upgrade_from_guard_wait (void)
 

Detailed Description

Header file for circuitlist.c.

Definition in file circuitlist.h.

Macro Definition Documentation

◆ CIRCUIT_IS_ORCIRC

#define CIRCUIT_IS_ORCIRC (   c)    (((circuit_t *)(c))->magic == OR_CIRCUIT_MAGIC)

True iff the circuit_t c is actually an or_circuit_t

Definition at line 150 of file circuitlist.h.

Referenced by circuit_synchronize_written_or_bandwidth().

◆ CIRCUIT_IS_ORIGIN

#define CIRCUIT_IS_ORIGIN (   c)    (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))

True iff the circuit_t c is actually an origin_circuit_t.

Definition at line 143 of file circuitlist.h.

Referenced by circpad_deliver_unrecognized_cell_events(), circpad_estimate_circ_rtt_on_received(), circpad_estimate_circ_rtt_on_send(), circpad_handle_padding_negotiate(), circpad_handle_padding_negotiated(), circpad_padding_is_from_expected_hop(), circuit_about_to_free(), circuit_about_to_free_atexit(), circuit_alloc_in_half_streams(), circuit_change_purpose(), circuit_dump_by_conn(), circuit_enough_testing_circs(), circuit_expire_old_circuits_clientside(), circuit_expire_old_circuits_serverside(), circuit_free_all(), circuit_get_best(), circuit_get_by_edge_conn(), circuit_get_by_global_id(), circuit_log_ancient_one_hop_circuits(), circuit_mark_all_dirty_circs_as_unusable(), circuit_mark_all_unused_circs(), circuit_max_queued_cell_age(), circuit_max_queued_data_age(), circuit_queue_streams_are_blocked(), circuit_resume_edge_reading_helper(), circuit_state_publish(), circuit_stream_is_being_handled(), circuit_unlink_all_from_channel(), circuit_update_channel_usage(), clear_circ_bw_fields(), connection_exit_begin_conn(), control_event_circ_bandwidth_used(), count_pending_general_client_circuits(), dump_cell_pool_usage(), entry_guard_chan_failed(), format_cell_stats(), marked_circuit_free_stream_bytes(), n_cells_in_circ_queues(), pathbias_count_circs_in_states(), relay_lookup_conn(), rend_client_close_other_intros(), rend_process_relay_cell(), rep_hist_buffer_stats_add_circ(), and set_streams_blocked_on_circ().

◆ CIRCUIT_PURPOSE_C_ESTABLISH_REND

#define CIRCUIT_PURPOSE_C_ESTABLISH_REND   9

◆ CIRCUIT_PURPOSE_C_GENERAL

#define CIRCUIT_PURPOSE_C_GENERAL   5

◆ CIRCUIT_PURPOSE_C_HSDIR_GET

#define CIRCUIT_PURPOSE_C_HSDIR_GET   13

◆ CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT

#define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT   7

Client-side circuit purpose: at the client, sent INTRODUCE1 to intro point, waiting for ACK/NAK.

Definition at line 77 of file circuitlist.h.

Referenced by circuit_get_best(), circuit_is_acceptable(), circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), and rend_client_close_other_intros().

◆ CIRCUIT_PURPOSE_C_INTRODUCE_ACKED

#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED   8

Client-side circuit purpose: at the client, introduced and acked, closing.

Definition at line 80 of file circuitlist.h.

Referenced by circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), and circuit_purpose_to_string().

◆ CIRCUIT_PURPOSE_C_INTRODUCING

#define CIRCUIT_PURPOSE_C_INTRODUCING   6

◆ CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT

#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT   14

◆ CIRCUIT_PURPOSE_C_REND_JOINED

#define CIRCUIT_PURPOSE_C_REND_JOINED   12

◆ CIRCUIT_PURPOSE_C_REND_READY

#define CIRCUIT_PURPOSE_C_REND_READY   10

Client-side circuit purpose: at the client, waiting for the service.

Definition at line 84 of file circuitlist.h.

Referenced by circuit_get_ready_rend_circ_by_rend_data(), circuit_is_acceptable(), circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), and circuit_purpose_to_string().

◆ CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED

#define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED   11

Client-side circuit purpose: at the client, waiting for the service, INTRODUCE has been acknowledged.

Definition at line 87 of file circuitlist.h.

Referenced by circuit_is_acceptable(), circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), and circuit_purpose_to_string().

◆ CIRCUIT_PURPOSE_CONTROLLER

#define CIRCUIT_PURPOSE_CONTROLLER   21

A controller made this circuit and Tor should not use it.

Definition at line 117 of file circuitlist.h.

Referenced by circuit_purpose_from_string(), circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), and circuit_purpose_to_string().

◆ CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING

#define CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING (   p)
Value:
#define CIRCUIT_PURPOSE_C_HSDIR_GET
Definition: circuitlist.h:91
#define CIRCUIT_PURPOSE_C_GENERAL
Definition: circuitlist.h:71

True iff this circuit purpose should count towards the global pending rate limit (set by MaxClientCircuitsPending). We count all general purpose circuits, as well as the first step of client onion service connections (HSDir gets).

Definition at line 156 of file circuitlist.h.

Referenced by count_pending_general_client_circuits().

◆ CIRCUIT_PURPOSE_HS_VANGUARDS

#define CIRCUIT_PURPOSE_HS_VANGUARDS   23

This circuit is used for vanguards/restricted paths.

This type of circuit is only created preemptively and never on-demand. When an HS operation needs to take place (e.g. connect to an intro point), these circuits are then cannibalized and repurposed to the actual needed HS purpose.

Definition at line 127 of file circuitlist.h.

Referenced by circuit_get_best(), circuit_is_acceptable(), circuit_launch_predicted_hs_circ(), circuit_purpose_is_hidden_service(), circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), circuit_should_cannibalize_to_build(), get_circuit_purpose_needed_to_cannibalize(), and route_len_for_purpose().

◆ CIRCUIT_PURPOSE_INTRO_POINT

#define CIRCUIT_PURPOSE_INTRO_POINT   2

OR-side circuit purpose: At OR, from the service, waiting for intro from clients.

Definition at line 41 of file circuitlist.h.

Referenced by circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), and warn_if_last_router_excluded().

◆ CIRCUIT_PURPOSE_IS_CLIENT

#define CIRCUIT_PURPOSE_IS_CLIENT (   p)
Value:
((p)> CIRCUIT_PURPOSE_OR_MAX_ && \
(p)<=CIRCUIT_PURPOSE_C_MAX_)

True iff the circuit purpose p is for a circuit that originated here to serve as a client. (Hidden services don't count here.)

Definition at line 139 of file circuitlist.h.

Referenced by relay_send_end_cell_from_edge().

◆ CIRCUIT_PURPOSE_IS_ESTABLISHED_REND

#define CIRCUIT_PURPOSE_IS_ESTABLISHED_REND (   p)
Value:
#define CIRCUIT_PURPOSE_C_REND_JOINED
Definition: circuitlist.h:89
#define CIRCUIT_PURPOSE_S_REND_JOINED
Definition: circuitlist.h:109

True iff the circuit purpose p is for an established rendezvous circuit.

Definition at line 146 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_IS_ORIGIN

#define CIRCUIT_PURPOSE_IS_ORIGIN (   p)    ((p)>CIRCUIT_PURPOSE_OR_MAX_)

True iff the circuit purpose p is for a circuit that originated at this node.

Definition at line 136 of file circuitlist.h.

Referenced by circuit_change_purpose(), and circuit_get_next_by_pk_and_purpose().

◆ CIRCUIT_PURPOSE_OR

#define CIRCUIT_PURPOSE_OR   1

OR-side circuit purpose: normal circuit, at OR.

Definition at line 38 of file circuitlist.h.

Referenced by circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), and warn_if_last_router_excluded().

◆ CIRCUIT_PURPOSE_PATH_BIAS_TESTING

#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING   22

◆ CIRCUIT_PURPOSE_REND_ESTABLISHED

#define CIRCUIT_PURPOSE_REND_ESTABLISHED   4

OR-side circuit purpose: At OR, both circuits have this purpose.

Definition at line 46 of file circuitlist.h.

Referenced by circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), and warn_if_last_router_excluded().

◆ CIRCUIT_PURPOSE_REND_POINT_WAITING

#define CIRCUIT_PURPOSE_REND_POINT_WAITING   3

OR-side circuit purpose: At OR, from the client, waiting for the service.

Definition at line 44 of file circuitlist.h.

Referenced by circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), and warn_if_last_router_excluded().

◆ CIRCUIT_PURPOSE_S_CONNECT_REND

#define CIRCUIT_PURPOSE_S_CONNECT_REND   17

◆ CIRCUIT_PURPOSE_S_ESTABLISH_INTRO

#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO   15

◆ CIRCUIT_PURPOSE_S_HSDIR_POST

#define CIRCUIT_PURPOSE_S_HSDIR_POST   19

◆ CIRCUIT_PURPOSE_S_INTRO

#define CIRCUIT_PURPOSE_S_INTRO   16

Hidden-service-side circuit purpose: at the service, successfully established intro.

Definition at line 103 of file circuitlist.h.

Referenced by circuit_purpose_to_controller_hs_state_string(), circuit_purpose_to_controller_string(), circuit_purpose_to_string(), count_intro_point_circuits(), find_expiring_intro_point(), find_intro_circuit(), and find_intro_point().

◆ CIRCUIT_PURPOSE_S_REND_JOINED

#define CIRCUIT_PURPOSE_S_REND_JOINED   18

◆ CIRCUIT_PURPOSE_TESTING

#define CIRCUIT_PURPOSE_TESTING   20

◆ CIRCUIT_PURPOSE_UNKNOWN

#define CIRCUIT_PURPOSE_UNKNOWN   255

A catch-all for unrecognized purposes. Currently we don't expect to make or see any circuits with this purpose.

Definition at line 132 of file circuitlist.h.

Referenced by circuit_purpose_from_string().

◆ CIRCUIT_STATE_BUILDING

#define CIRCUIT_STATE_BUILDING   0

Circuit state: I'm the origin, still haven't done all my handshakes.

Definition at line 20 of file circuitlist.h.

Referenced by circuit_extend_to_new_exit(), circuit_send_next_onion_skin(), and circuit_state_to_string().

◆ CIRCUIT_STATE_CHAN_WAIT

#define CIRCUIT_STATE_CHAN_WAIT   2

Circuit state: I'd like to deliver a create, but my n_chan is still connecting.

Definition at line 25 of file circuitlist.h.

Referenced by circuit_about_to_free(), circuit_get_all_pending_on_channel(), circuit_state_to_string(), and origin_circuit_init().

◆ CIRCUIT_STATE_GUARD_WAIT

#define CIRCUIT_STATE_GUARD_WAIT   3

Circuit state: the circuit is open but we don't want to actually use it until we find out if a better guard will be available.

Definition at line 29 of file circuitlist.h.

Referenced by circuit_about_to_free(), and circuit_state_to_string().

◆ CIRCUIT_STATE_ONIONSKIN_PENDING

#define CIRCUIT_STATE_ONIONSKIN_PENDING   1

Circuit state: Waiting to process the onionskin.

Definition at line 22 of file circuitlist.h.

Referenced by circuit_about_to_free(), and circuit_state_to_string().

◆ CIRCUIT_STATE_OPEN

#define CIRCUIT_STATE_OPEN   4

Function Documentation

◆ assert_cpath_layer_ok()

void assert_cpath_layer_ok ( const crypt_path_t cp)

Verify that cpath layer cp has all of its invariants correct. Trigger an assert if anything is invalid.

Definition at line 2786 of file circuitlist.c.

References crypt_path_t::crypto, crypt_path_t::deliver_window, LD_BUG, LOG_ERR, log_fn, crypt_path_t::package_window, crypt_path_t::rend_dh_handshake_state, crypt_path_t::state, and tor_assert().

Referenced by assert_cpath_ok().

◆ channel_mark_circid_unusable()

void channel_mark_circid_unusable ( channel_t chan,
circid_t  id 
)

Mark that circuit id id shouldn't be used on channel chan, even if there is no circuit on the channel. We use this to keep the circuit id from getting re-used while we have queued but not yet sent a destroy cell.

Definition at line 350 of file circuitlist.c.

Referenced by channel_note_destroy_pending(), circuit_set_n_circid_chan(), and circuit_set_p_circid_chan().

◆ channel_mark_circid_usable()

void channel_mark_circid_usable ( channel_t chan,
circid_t  id 
)

Mark that a circuit id id can be used again on chan. We use this to re-enable the circuit ID after we've sent a destroy cell.

Definition at line 383 of file circuitlist.c.

Referenced by circuitmux_mark_destroyed_circids_usable(), and MOCK_IMPL().

◆ channel_note_destroy_pending()

void channel_note_destroy_pending ( channel_t chan,
circid_t  id 
)

Called to indicate that a DESTROY is pending on chan with circuit ID id, but hasn't been sent yet.

Definition at line 406 of file circuitlist.c.

References channel_mark_circid_unusable(), circuit_get_by_circid_channel_even_if_marked(), circuit_t::n_chan, circuit_t::n_circ_id, circuit_t::n_delete_pending, or_circuit_t::p_chan, or_circuit_t::p_circ_id, circuit_t::p_delete_pending, and TO_OR_CIRCUIT().

◆ circuit_any_opened_circuits()

int circuit_any_opened_circuits ( void  )

Return true if we have any opened general-purpose 3 hop origin circuits.

The result from this function is cached for use by circuit_any_opened_circuits_cached().

Definition at line 714 of file circuitlist.c.

References circuit_cache_opened_circuit_state(), circuit_get_global_origin_circuit_list(), CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT, CIRCUIT_STATE_OPEN, DEFAULT_ROUTE_LEN, SMARTLIST_FOREACH_BEGIN, and TO_CIRCUIT.

Referenced by circuit_expire_building().

◆ circuit_any_opened_circuits_cached()

int circuit_any_opened_circuits_cached ( void  )

Return true if there were any opened circuits since the last call to circuit_any_opened_circuits(), or since circuit_expire_building() last ran (it runs roughly once per second).

Definition at line 751 of file circuitlist.c.

References any_opened_circs_cached_val.

Referenced by circuit_build_times_handle_completed_hop().

◆ circuit_cache_opened_circuit_state()

void circuit_cache_opened_circuit_state ( int  circuits_are_opened)

Cache the "any circuits opened" state, as specified in param circuits_are_opened. This is a helper function to update the circuit opened status whenever we happen to look at the circuit list.

Definition at line 740 of file circuitlist.c.

References any_opened_circs_cached_val.

Referenced by circuit_any_opened_circuits().

◆ circuit_clear_cpath()

void circuit_clear_cpath ( origin_circuit_t circ)

Deallocate the linked list circ->cpath, and remove the cpath from circ.

Definition at line 1255 of file circuitlist.c.

References circuit_free_cpath_node(), origin_circuit_t::cpath, and crypt_path_t::next.

◆ circuit_clear_testing_cell_stats()

void circuit_clear_testing_cell_stats ( circuit_t circ)

Free all storage held in circ->testing_cell_stats

Definition at line 1100 of file circuitlist.c.

References SMARTLIST_FOREACH, circuit_t::testing_cell_stats, and tor_free.

Referenced by circuit_free_().

◆ circuit_close_all_marked()

void circuit_close_all_marked ( void  )

Detach from the global circuit list, and deallocate, all circuits that have been marked for close.

Definition at line 658 of file circuitlist.c.

References circuits_pending_close, circuit_t::global_circuitlist_idx, circuit_t::marked_for_close, smartlist_del(), SMARTLIST_FOREACH_BEGIN, and tor_assert().

Referenced by postloop_cleanup_cb().

◆ circuit_count_pending_on_channel()

int circuit_count_pending_on_channel ( channel_t chan)

Return the number of circuits in state CHAN_WAIT, waiting for the given channel.

Definition at line 605 of file circuitlist.c.

References circuit_get_all_pending_on_channel(), and tor_assert().

◆ circuit_dump_by_conn()

void circuit_dump_by_conn ( connection_t conn,
int  severity 
)

◆ circuit_event_status()

int circuit_event_status ( origin_circuit_t circ,
circuit_status_event_t  tp,
int  reason_code 
)

Helper function to publish a message about events on an origin circuit

Publishes a message to subscribers of origin circuit events, and sends the control event.

Definition at line 496 of file circuitlist.c.

References tor_assert().

Referenced by circuit_about_to_free(), circuit_build_times_mark_circ_as_measurement_only(), and circuit_has_opened().

◆ circuit_find_circuits_to_upgrade_from_guard_wait()

smartlist_t* circuit_find_circuits_to_upgrade_from_guard_wait ( void  )

Check whether any of the origin circuits that are waiting to see if their guard is good enough to use can be upgraded to "ready". If so, return a new smartlist containing them. Otherwise return NULL.

Definition at line 2011 of file circuitlist.c.

References circuits_pending_other_guards.

Referenced by circuit_upgrade_circuits_from_guard_wait().

◆ circuit_find_to_cannibalize()

origin_circuit_t* circuit_find_to_cannibalize ( uint8_t  purpose_to_produce,
extend_info_t info,
int  flags 
)

Return a circuit that is open, is CIRCUIT_PURPOSE_C_GENERAL, has a timestamp_dirty value of 0, has flags matching the CIRCLAUNCH_* flags in flags, and if info is defined, does not already use info as any of its hops; or NULL if no circuit fits this description.

The purpose argument refers to the purpose of the circuit we want to create, not the purpose of the circuit we want to cannibalize.

If !CIRCLAUNCH_NEED_UPTIME, prefer returning non-uptime circuits.

To "cannibalize" a circuit means to extend it an extra hop, and use it for some other purpose than we had originally intended. We do this when we want to perform some low-bandwidth task at a specific relay, and we would like the circuit to complete as soon as possible. (If we were going to use a lot of bandwidth, we wouldn't want a circuit with an extra hop. If we didn't care about circuit completion latency, we would just build a new circuit.)

Definition at line 1901 of file circuitlist.c.

References CIRCLAUNCH_IS_INTERNAL, CIRCLAUNCH_NEED_CAPACITY, CIRCLAUNCH_NEED_UPTIME, CIRCLAUNCH_ONEHOP_TUNNEL, get_circuit_purpose_needed_to_cannibalize(), and tor_assert().

◆ circuit_free_all()

void circuit_free_all ( void  )

◆ circuit_get_all_pending_on_channel()

void circuit_get_all_pending_on_channel ( smartlist_t out,
channel_t chan 
)

◆ circuit_get_by_circid_channel()

circuit_t* circuit_get_by_circid_channel ( circid_t  circ_id,
channel_t chan 
)

Return a circ such that:

  • circ->n_circ_id or circ->p_circ_id is equal to circ_id, and
  • circ is attached to chan, either as p_chan or n_chan.
  • circ is not marked for close. Return NULL if no such circuit exists.

Definition at line 1515 of file circuitlist.c.

References circuit_get_by_circid_channel_impl(), and circuit_t::marked_for_close.

Referenced by command_process_created_cell(), command_process_destroy_cell(), and command_process_relay_cell().

◆ circuit_get_by_circid_channel_even_if_marked()

circuit_t* circuit_get_by_circid_channel_even_if_marked ( circid_t  circ_id,
channel_t chan 
)

Return a circ such that:

  • circ->n_circ_id or circ->p_circ_id is equal to circ_id, and
  • circ is attached to chan, either as p_chan or n_chan. Return NULL if no such circuit exists.

Definition at line 1530 of file circuitlist.c.

References circuit_get_by_circid_channel_impl().

Referenced by channel_note_destroy_pending(), circuitmux_set_policy(), and MOCK_IMPL().

◆ circuit_get_by_edge_conn()

circuit_t* circuit_get_by_edge_conn ( edge_connection_t conn)

Return the circuit that a given edge connection is using.

Definition at line 1576 of file circuitlist.c.

References CIRCUIT_IS_ORIGIN, circuit_t::magic, edge_connection_t::on_circuit, and tor_assert().

Referenced by connection_edge_consider_sending_sendme(), and connection_exit_about_to_close().

◆ circuit_get_by_global_id()

origin_circuit_t* circuit_get_by_global_id ( uint32_t  id)

Return the circuit whose global ID is id, or NULL if no such circuit exists.

Definition at line 1423 of file circuitlist.c.

References CIRCUIT_IS_ORIGIN, circuit_t::marked_for_close, SMARTLIST_FOREACH_BEGIN, and TO_ORIGIN_CIRCUIT().

Referenced by get_circ().

◆ circuit_get_cpath_hop()

crypt_path_t* circuit_get_cpath_hop ( origin_circuit_t circ,
int  hopnum 
)

Return the hopnumth hop in circ->cpath, or NULL if there aren't that many hops in the list. hopnum starts at 1. Returns NULL if hopnum is 0 or negative.

Definition at line 2075 of file circuitlist.c.

References origin_circuit_t::cpath, and crypt_path_t::next.

Referenced by circpad_padding_is_from_expected_hop(), and circuit_get_nth_node().

◆ circuit_get_cpath_len()

int circuit_get_cpath_len ( origin_circuit_t circ)

Return the number of hops in circuit's path. If circ has no entries, or is NULL, returns 0.

Definition at line 2039 of file circuitlist.c.

References origin_circuit_t::cpath, and crypt_path_t::next.

Referenced by circuit_build_failed(), circuit_build_no_more_hops(), and onion_extend_cpath().

◆ circuit_get_cpath_opened_len()

int circuit_get_cpath_opened_len ( const origin_circuit_t circ)

Return the number of opened hops in circuit's path. If circ has no entries, or is NULL, returns 0.

Definition at line 2055 of file circuitlist.c.

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

Referenced by circpad_machine_conditions_met(), and circuit_timeout_want_to_count_circ().

◆ circuit_get_global_origin_circuit_list()

smartlist_t* circuit_get_global_origin_circuit_list ( void  )

Return a pointer to the global list of origin circuits.

Definition at line 699 of file circuitlist.c.

References global_origin_circuit_list.

Referenced by circuit_add_to_origin_circuit_list(), circuit_any_opened_circuits(), and circuit_expire_waiting_for_better_guard().

◆ circuit_get_next_by_pk_and_purpose()

origin_circuit_t* circuit_get_next_by_pk_and_purpose ( origin_circuit_t start,
const uint8_t *  digest,
uint8_t  purpose 
)

Return the first circuit originating here in global_circuitlist after start whose purpose is purpose, and where digest (if set) matches the private key digest of the rend data associated with the circuit. Return NULL if no circuit is found. If start is NULL, begin at the start of the list.

Definition at line 1808 of file circuitlist.c.

References CIRCUIT_PURPOSE_IS_ORIGIN, TO_CIRCUIT, and tor_assert().

Referenced by find_intro_circuit().

◆ circuit_get_next_intro_circ()

origin_circuit_t* circuit_get_next_intro_circ ( const origin_circuit_t start,
bool  want_client_circ 
)

Return the first introduction circuit originating from the global circuit list after start or at the start of the list if start is NULL. Return NULL if no circuit is found.

If want_client_circ is true, then we are looking for client-side introduction circuits: A client introduction point circuit has a purpose of either CIRCUIT_PURPOSE_C_INTRODUCING, CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT or CIRCUIT_PURPOSE_C_INTRODUCE_ACKED. This does not return a circuit marked for close, but it returns circuits regardless of their circuit state.

If want_client_circ is false, then we are looking for service-side introduction circuits: A service introduction point circuit has a purpose of either CIRCUIT_PURPOSE_S_ESTABLISH_INTRO or CIRCUIT_PURPOSE_S_INTRO. This does not return circuits marked for close, or in any state other than open.

Definition at line 1722 of file circuitlist.c.

References TO_CIRCUIT.

◆ circuit_get_next_service_rp_circ()

origin_circuit_t* circuit_get_next_service_rp_circ ( origin_circuit_t start)

Return the first service rendezvous circuit originating from the global circuit list after start or at the start of the list if start is NULL. Return NULL if no circuit is found.

A service rendezvous point circuit has a purpose of either CIRCUIT_PURPOSE_S_CONNECT_REND or CIRCUIT_PURPOSE_S_REND_JOINED. This does not return a circuit marked for close and its state must be open.

Definition at line 1774 of file circuitlist.c.

References TO_CIRCUIT.

◆ circuit_get_ready_rend_circ_by_rend_data()

origin_circuit_t* circuit_get_ready_rend_circ_by_rend_data ( const rend_data_t rend_data)

Return a circ such that

  • circ->rend_data->onion_address is equal to rend_data->onion_address,
  • circ->rend_data->rend_cookie is equal to rend_data->rend_cookie, and
  • circ->purpose is equal to CIRCUIT_PURPOSE_C_REND_READY.

Return NULL if no such circuit exists.

Definition at line 1685 of file circuitlist.c.

References CIRCUIT_PURPOSE_C_REND_READY, circuit_t::marked_for_close, circuit_t::purpose, rend_cmp_service_ids(), origin_circuit_t::rend_data, SMARTLIST_FOREACH_BEGIN, and TO_ORIGIN_CIRCUIT().

◆ circuit_id_in_use_on_channel()

int circuit_id_in_use_on_channel ( circid_t  circ_id,
channel_t chan 
)

Return true iff the circuit ID circ_id is currently used by a circuit, marked or not, on chan, or if the circ ID is reserved until a queued destroy cell can be sent.

(Return 1 if the circuit is present, marked or not; Return 2 if the circuit ID is pending a destroy.)

Definition at line 1544 of file circuitlist.c.

References circuit_get_by_circid_channel_impl().

◆ circuit_id_when_marked_unusable_on_channel()

time_t circuit_id_when_marked_unusable_on_channel ( circid_t  circ_id,
channel_t chan 
)

Helper for debugging 12184. Returns the time since which 'circ_id' has been marked unusable on 'chan'.

Definition at line 1557 of file circuitlist.c.

◆ circuit_initial_package_window()

int32_t circuit_initial_package_window ( void  )

Pick a reasonable package_window to start out for our circuits. Originally this was hard-coded at 1000, but now the consensus votes on the answer. See proposal 168.

Definition at line 965 of file circuitlist.c.

References CIRCWINDOW_START.

Referenced by init_circuit_base().

◆ circuit_mark_all_dirty_circs_as_unusable()

void circuit_mark_all_dirty_circs_as_unusable ( void  )

Go through the circuitlist; for each circuit that starts at us and is dirty, frob its timestamp_dirty so we won't use it for any new streams.

This is useful for letting the user change pseudonyms, so new streams will not be linkable to old streams.

Definition at line 2110 of file circuitlist.c.

References CIRCUIT_IS_ORIGIN, mark_circuit_unusable_for_new_conns(), circuit_t::marked_for_close, SMARTLIST_FOREACH_BEGIN, circuit_t::timestamp_dirty, and TO_ORIGIN_CIRCUIT().

Referenced by circuit_note_clock_jumped(), and directory_info_has_arrived().

◆ circuit_mark_all_unused_circs()

void circuit_mark_all_unused_circs ( void  )

Go through the circuitlist; mark-for-close each circuit that starts at us but has not yet been used.

Definition at line 2091 of file circuitlist.c.

References CIRCUIT_IS_ORIGIN, circuit_t::marked_for_close, SMARTLIST_FOREACH_BEGIN, and circuit_t::timestamp_dirty.

Referenced by circuit_note_clock_jumped(), and directory_info_has_arrived().

◆ circuit_purpose_to_controller_hs_state_string()

const char* circuit_purpose_to_controller_hs_state_string ( uint8_t  purpose)

◆ circuit_purpose_to_controller_string()

const char* circuit_purpose_to_controller_string ( uint8_t  purpose)

◆ circuit_purpose_to_string()

const char* circuit_purpose_to_string ( uint8_t  purpose)

◆ circuit_set_n_circid_chan()

void circuit_set_n_circid_chan ( circuit_t circ,
circid_t  id,
channel_t chan 
)

Set the n_conn field of a circuit circ, along with the corresponding circuit ID, and add the circuit as appropriate to the (chan,id)->circuit map.

Definition at line 471 of file circuitlist.c.

References approx_time(), CELL_DIRECTION_OUT, channel_mark_circid_unusable(), circuit_t::n_chan, circuit_t::n_circ_id, circuit_t::n_delete_pending, and channel_s::timestamp_last_had_circuits.

Referenced by circuit_about_to_free_atexit().

◆ circuit_set_p_circid_chan()

void circuit_set_p_circid_chan ( or_circuit_t or_circ,
circid_t  id,
channel_t chan 
)

Set the p_conn field of a circuit circ, along with the corresponding circuit ID, and add the circuit as appropriate to the (chan,id)->circuit map.

Definition at line 448 of file circuitlist.c.

References approx_time(), CELL_DIRECTION_IN, channel_mark_circid_unusable(), or_circuit_t::p_chan, or_circuit_t::p_circ_id, circuit_t::p_delete_pending, channel_s::timestamp_last_had_circuits, and TO_CIRCUIT.

Referenced by circuit_about_to_free_atexit().

◆ circuit_set_state()

void circuit_set_state ( circuit_t circ,
uint8_t  state 
)

Change the state of circ to state, adding it to or removing it from lists as appropriate.

Definition at line 542 of file circuitlist.c.

References circuit_t::state, and tor_assert().

Referenced by circuit_extend_to_new_exit(), and origin_circuit_init().

◆ circuit_state_to_string()

const char* circuit_state_to_string ( int  state)

Function to make circ->state human-readable

Definition at line 758 of file circuitlist.c.

References CIRCUIT_STATE_BUILDING, CIRCUIT_STATE_CHAN_WAIT, CIRCUIT_STATE_GUARD_WAIT, CIRCUIT_STATE_ONIONSKIN_PENDING, and CIRCUIT_STATE_OPEN.

◆ circuit_synchronize_written_or_bandwidth()

void circuit_synchronize_written_or_bandwidth ( const circuit_t c,
circuit_channel_direction_t  dir 
)

Report any queued cells on or_circuits as written in our bandwidth totals, for the specified channel direction.

When we close a circuit or clear its cell queues, we've read data and recorded those bytes in our read statistics, but we're not going to write it. This discrepancy can be used by an adversary to infer information from our public relay statistics and perform attacks such as guard discovery.

This function is in the critical path of circuit_mark_for_close(). It must be (and is) O(1)!

See https://trac.torproject.org/projects/tor/ticket/23512.

Definition at line 2138 of file circuitlist.c.

References CIRCUIT_IS_ORCIRC.

◆ circuit_unlink_all_from_channel()

void circuit_unlink_all_from_channel ( channel_t chan,
int  reason 
)

For each circuit that has chan as n_chan or p_chan, unlink the circuit from the chan,circid map, and mark it for close if it hasn't been marked already.

Definition at line 1593 of file circuitlist.c.

References channel_unlink_all_circuits(), CIRCUIT_IS_ORIGIN, circuit_t::n_chan, smartlist_add(), SMARTLIST_FOREACH_BEGIN, and TO_OR_CIRCUIT().

◆ circuits_handle_oom()

void circuits_handle_oom ( size_t  current_allocation)

We're out of memory for cells, having allocated current_allocation bytes' worth. Kill the 'worst' circuits until we're under FRACTION_OF_DATA_TO_RETAIN_ON_OOM of our maximum usage.

Definition at line 2663 of file circuitlist.c.

References connection_array.

◆ or_circuit_new()

or_circuit_t* or_circuit_new ( circid_t  p_circ_id,
channel_t p_chan 
)

Allocate a new or_circuit_t, connected to p_chan as p_circ_id. If p_chan is NULL, the circuit is unattached.

Definition at line 1079 of file circuitlist.c.

◆ origin_circuit_new()

origin_circuit_t* origin_circuit_new ( void  )

Allocate space for a new circuit, initializing with p_circ_id and p_conn. Add it to the global circuit list.

Definition at line 1007 of file circuitlist.c.

Referenced by origin_circuit_init().

◆ TO_OR_CIRCUIT()

or_circuit_t* TO_OR_CIRCUIT ( circuit_t )

◆ TO_ORIGIN_CIRCUIT()

origin_circuit_t* TO_ORIGIN_CIRCUIT ( circuit_t )