tor  0.4.2.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_CIRCUIT_PADDING   15
 
#define CIRCUIT_PURPOSE_C_MAX_   15
 
#define CIRCUIT_PURPOSE_S_HS_MIN_   16
 
#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO   16
 
#define CIRCUIT_PURPOSE_S_INTRO   17
 
#define CIRCUIT_PURPOSE_S_CONNECT_REND   18
 
#define CIRCUIT_PURPOSE_S_REND_JOINED   19
 
#define CIRCUIT_PURPOSE_S_HSDIR_POST   20
 
#define CIRCUIT_PURPOSE_S_HS_MAX_   20
 
#define CIRCUIT_PURPOSE_TESTING   21
 
#define CIRCUIT_PURPOSE_CONTROLLER   22
 
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING   23
 
#define CIRCUIT_PURPOSE_HS_VANGUARDS   24
 
#define CIRCUIT_PURPOSE_MAX_   24
 
#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 *cfile))
 
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)
 
 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 152 of file circuitlist.h.

◆ 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 145 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_CIRCUIT_PADDING

#define CIRCUIT_PURPOSE_C_CIRCUIT_PADDING   15

This circuit is being held open by circuit padding

Definition at line 96 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_ESTABLISH_REND

#define CIRCUIT_PURPOSE_C_ESTABLISH_REND   9

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

Definition at line 82 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_GENERAL

#define CIRCUIT_PURPOSE_C_GENERAL   5

Client-side circuit purpose: Normal circuit, with cpath.

Definition at line 71 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_HSDIR_GET

#define CIRCUIT_PURPOSE_C_HSDIR_GET   13

This circuit is used for getting hsdirs

Definition at line 91 of file circuitlist.h.

◆ 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.

◆ 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.

◆ CIRCUIT_PURPOSE_C_INTRODUCING

#define CIRCUIT_PURPOSE_C_INTRODUCING   6

Client-side circuit purpose: at the client, connecting to intro point.

Definition at line 74 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT

#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT   14

This circuit is used for build time measurement only

Definition at line 94 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_REND_JOINED

#define CIRCUIT_PURPOSE_C_REND_JOINED   12

Client-side circuit purpose: at the client, rendezvous established.

Definition at line 89 of file circuitlist.h.

◆ 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.

◆ 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.

◆ CIRCUIT_PURPOSE_CONTROLLER

#define CIRCUIT_PURPOSE_CONTROLLER   22

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

Definition at line 119 of file circuitlist.h.

◆ 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 158 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_HS_VANGUARDS

#define CIRCUIT_PURPOSE_HS_VANGUARDS   24

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 129 of file circuitlist.h.

◆ 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.

◆ 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 141 of file circuitlist.h.

◆ 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:111

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

Definition at line 148 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 138 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_OR

#define CIRCUIT_PURPOSE_OR   1

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

Definition at line 38 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_PATH_BIAS_TESTING

#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING   23

This circuit is used for path bias probing only

Definition at line 121 of file circuitlist.h.

◆ 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.

◆ 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.

◆ CIRCUIT_PURPOSE_S_CONNECT_REND

#define CIRCUIT_PURPOSE_S_CONNECT_REND   18

Hidden-service-side circuit purpose: at the service, connecting to rend point.

Definition at line 108 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_S_ESTABLISH_INTRO

#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO   16

Hidden-service-side circuit purpose: at the service, waiting for introductions.

Definition at line 102 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_S_HSDIR_POST

#define CIRCUIT_PURPOSE_S_HSDIR_POST   20

This circuit is used for uploading hsdirs

Definition at line 113 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_S_INTRO

#define CIRCUIT_PURPOSE_S_INTRO   17

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

Definition at line 105 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_S_REND_JOINED

#define CIRCUIT_PURPOSE_S_REND_JOINED   19

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

Definition at line 111 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_TESTING

#define CIRCUIT_PURPOSE_TESTING   21

A testing circuit; not meant to be used for actual traffic.

Definition at line 117 of file circuitlist.h.

◆ 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 134 of file circuitlist.h.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ CIRCUIT_STATE_OPEN

#define CIRCUIT_STATE_OPEN   4

Circuit state: onionskin(s) processed, ready to send/receive cells.

Definition at line 31 of file circuitlist.h.

Function Documentation

◆ 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 713 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 750 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 739 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 1267 of file circuitlist.c.

References origin_circuit_t::cpath, cpath_free(), 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 1106 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 657 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 604 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.

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 2007 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 1897 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 1511 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 1526 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 1572 of file circuitlist.c.

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

Referenced by 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 1419 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 2071 of file circuitlist.c.

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

Referenced by circpad_padding_is_from_expected_hop().

◆ 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 2035 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 2051 of file circuitlist.c.

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

Referenced by 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 698 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 1804 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 1718 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 1770 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 1681 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 1540 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 1553 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 970 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 2106 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 2087 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 540 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 757 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 2134 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 1589 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 2664 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 1085 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 1013 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 )