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

Header file for circuitlist.c. More...

#include "lib/container/handles.h"
#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_CONFLUX_UNLINKED   25
 
#define CIRCUIT_PURPOSE_CONFLUX_LINKED   26
 
#define CIRCUIT_PURPOSE_MAX_   26
 
#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__)
 
#define circuit_handle_free(h)    FREE_AND_NULL(circuit_handle_t, circuit_handle_free_, (h))
 

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 *)
 
smartlist_tcircuit_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_next_by_purpose (origin_circuit_t *start, 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)
 
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)
 
void assert_circuit_ok (const circuit_t *c)
 
void circuit_free_all (void)
 
size_t 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)
 
void channel_note_destroy_not_pending (channel_t *chan, circid_t id)
 
smartlist_tcircuit_find_circuits_to_upgrade_from_guard_wait (void)
 
bool circuit_is_queue_full (const circuit_t *circ, cell_direction_t direction)
 

Variables

double cc_stats_circ_close_cwnd_ma
 
double cc_stats_circ_close_ss_cwnd_ma
 
uint64_t cc_stats_circs_closed
 
uint64_t circ_n_proto_violation
 

Detailed Description

Header file for circuitlist.c.

Definition in file circuitlist.h.

Macro Definition Documentation

◆ circuit_handle_free

#define circuit_handle_free (   h)     FREE_AND_NULL(circuit_handle_t, circuit_handle_free_, (h))

Definition at line 262 of file circuitlist.h.

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

◆ circuit_mark_for_close

#define circuit_mark_for_close (   c,
  reason 
)     circuit_mark_for_close_((c), (reason), __LINE__, SHORT_FILE__)

Definition at line 243 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 95 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 81 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 70 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_HS_MAX_

#define CIRCUIT_PURPOSE_C_HS_MAX_   13

Definition at line 91 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_HS_MIN_

#define CIRCUIT_PURPOSE_C_HS_MIN_   6

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 90 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 76 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 79 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 73 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_C_MAX_

#define CIRCUIT_PURPOSE_C_MAX_   15

Definition at line 96 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 93 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 88 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 83 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 86 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_CONFLUX_LINKED

#define CIRCUIT_PURPOSE_CONFLUX_LINKED   26

Definition at line 138 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_CONFLUX_UNLINKED

#define CIRCUIT_PURPOSE_CONFLUX_UNLINKED   25

These two purposes are for conflux. The first is for circuits that are being built, but not yet linked. The second is for circuits that are linked and ready to use for streams.

Definition at line 137 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_CONTROLLER

#define CIRCUIT_PURPOSE_CONTROLLER   22

A controller made this circuit and Tor should not cannibalize it or attach streams to it without explicitly being told.

Definition at line 121 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:90
#define CIRCUIT_PURPOSE_C_GENERAL
Definition: circuitlist.h:70

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 167 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 131 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 42 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 150 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:88
#define CIRCUIT_PURPOSE_S_REND_JOINED
Definition: circuitlist.h:110

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

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

◆ CIRCUIT_PURPOSE_MAX_

#define CIRCUIT_PURPOSE_MAX_   26

Definition at line 140 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_MIN_

#define CIRCUIT_PURPOSE_MIN_   1

Definition at line 34 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_OR

#define CIRCUIT_PURPOSE_OR   1

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

Definition at line 39 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_OR_MAX_

#define CIRCUIT_PURPOSE_OR_MAX_   4

Definition at line 48 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_OR_MIN_

#define CIRCUIT_PURPOSE_OR_MIN_   1

Definition at line 37 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 123 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 47 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 45 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 107 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 101 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_S_HS_MAX_

#define CIRCUIT_PURPOSE_S_HS_MAX_   20

Definition at line 113 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_S_HS_MIN_

#define CIRCUIT_PURPOSE_S_HS_MIN_   16

Definition at line 98 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 112 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 104 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 110 of file circuitlist.h.

◆ CIRCUIT_PURPOSE_TESTING

#define CIRCUIT_PURPOSE_TESTING   21

A testing circuit; not meant to be used for actual traffic. It is used for bandwidth measurement, reachability test and address discovery from an authority using the NETINFO cell.

Definition at line 118 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 143 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 21 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 26 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 30 of file circuitlist.h.

◆ CIRCUIT_STATE_ONIONSKIN_PENDING

#define CIRCUIT_STATE_ONIONSKIN_PENDING   1

Circuit state: Waiting to process the onionskin.

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

Function Documentation

◆ assert_circuit_ok()

void assert_circuit_ok ( const circuit_t c)

Verify that circuit c has all of its invariants correct. Trigger an assert if anything is invalid.

Definition at line 2809 of file circuitlist.c.

Referenced by circuit_mark_for_close_(), connection_exit_begin_conn(), connection_exit_begin_resolve(), and handle_hs_exit_conn().

◆ 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 372 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 405 of file circuitlist.c.

Referenced by channel_note_destroy_not_pending(), and circuitmux_mark_destroyed_circids_usable().

◆ channel_note_destroy_not_pending()

void channel_note_destroy_not_pending ( channel_t chan,
circid_t  id 
)

Called to indicate that a DESTROY is no longer pending on chan with circuit ID id – typically, because it has been sent.

Definition at line 448 of file circuitlist.c.

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

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

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 774 of file circuitlist.c.

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 763 of file circuitlist.c.

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 1313 of file circuitlist.c.

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

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 681 of file circuitlist.c.

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 628 of file circuitlist.c.

◆ circuit_dump_by_conn()

void circuit_dump_by_conn ( connection_t conn,
int  severity 
)

Log, at severity severity, information about each circuit that is connected to conn.

Definition at line 1412 of file circuitlist.c.

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

Referenced by circuit_about_to_free(), and circuit_build_times_mark_circ_as_measurement_only().

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

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 1893 of file circuitlist.c.

◆ circuit_free_all()

void circuit_free_all ( void  )

Release all storage held by circuits.

Definition at line 1337 of file circuitlist.c.

◆ circuit_get_all_pending_on_channel()

void circuit_get_all_pending_on_channel ( smartlist_t out,
channel_t chan 
)

Append to out all circuits in state CHAN_WAIT waiting for the given connection.

Definition at line 597 of file circuitlist.c.

Referenced by circuit_count_pending_on_channel(), and entry_guard_chan_failed().

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

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 1560 of file circuitlist.c.

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

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

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 1453 of file circuitlist.c.

Referenced by get_circ(), and pow_worker_replyfn().

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

Referenced by circpad_padding_is_from_expected_hop(), circpad_send_command_to_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 2035 of file circuitlist.c.

Referenced by circpad_send_command_to_hop(), 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.

Referenced by circuit_timeout_want_to_count_circ().

◆ circuit_get_global_list()

smartlist_t * circuit_get_global_list ( void  )

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

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

◆ circuit_get_next_by_purpose()

origin_circuit_t * circuit_get_next_by_purpose ( origin_circuit_t start,
uint8_t  purpose 
)

Return the first circuit originating here in global_circuitlist after start whose purpose is purpose. 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.

Referenced by count_service_rp_circuits_pending().

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

Referenced by hs_client_close_intro_circuits_from_desc().

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

Referenced by close_service_rp_circuits().

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

◆ 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 1587 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 1007 of file circuitlist.c.

Referenced by init_circuit_base().

◆ circuit_is_queue_full()

bool circuit_is_queue_full ( const circuit_t circ,
cell_direction_t  direction 
)

Return true iff the circuit queue for the given direction is full that is above the high watermark.

Definition at line 2883 of file circuitlist.c.

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

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.

Referenced by circuit_note_clock_jumped(), and directory_info_has_arrived().

◆ circuit_mark_for_close_()

void circuit_mark_for_close_ ( circuit_t circ,
int  reason,
int  line,
const char *  file 
)

Mark circ to be closed next time we call circuit_close_all_marked(). Do any cleanup needed:

  • If state is onionskin_pending, remove circ from the onion_pending list.
  • If circ isn't open yet: call circuit_build_failed() if we're the origin.
  • If purpose is C_INTRODUCE_ACK_WAIT, report the intro point failure we just had to the hidden service client module.
  • If purpose is C_INTRODUCING and reason isn't TIMEOUT, report to the hidden service client module that the intro point we just tried may be unreachable.
  • Send appropriate destroys and edge_destroys for conns and streams attached to circ.
  • If circ->rend_splice is set (we are the midpoint of a joined rendezvous stream), then mark the other circuit to close as well.

Definition at line 2197 of file circuitlist.c.

◆ circuit_purpose_to_controller_hs_state_string()

const char * circuit_purpose_to_controller_hs_state_string ( uint8_t  purpose)

Return a string specifying the state of the hidden-service circuit purpose purpose, or NULL if purpose is not a hidden-service-related circuit purpose.

Definition at line 867 of file circuitlist.c.

◆ circuit_purpose_to_controller_string()

const char * circuit_purpose_to_controller_string ( uint8_t  purpose)

Map a circuit purpose to a string suitable to be displayed to a controller.

Definition at line 801 of file circuitlist.c.

◆ circuit_purpose_to_string()

const char * circuit_purpose_to_string ( uint8_t  purpose)

Return a human-readable string for the circuit purpose purpose.

Definition at line 929 of file circuitlist.c.

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

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 470 of file circuitlist.c.

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 562 of file circuitlist.c.

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 781 of file circuitlist.c.

◆ 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://bugs.torproject.org/tpo/core/tor/23512

Definition at line 2134 of file circuitlist.c.

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

◆ circuits_handle_oom()

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

Return the number of bytes removed.

Definition at line 2676 of file circuitlist.c.

◆ CONST_TO_OR_CIRCUIT()

const or_circuit_t * CONST_TO_OR_CIRCUIT ( const circuit_t x)

Definition at line 179 of file circuitlist.c.

◆ CONST_TO_ORIGIN_CIRCUIT()

const origin_circuit_t * CONST_TO_ORIGIN_CIRCUIT ( const circuit_t x)

Definition at line 191 of file circuitlist.c.

◆ 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 1123 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 1050 of file circuitlist.c.

Referenced by origin_circuit_init().

◆ TO_OR_CIRCUIT()

or_circuit_t * TO_OR_CIRCUIT ( circuit_t x)

◆ TO_ORIGIN_CIRCUIT()

origin_circuit_t * TO_ORIGIN_CIRCUIT ( circuit_t x)

Variable Documentation

◆ cc_stats_circ_close_cwnd_ma

double cc_stats_circ_close_cwnd_ma
extern

Stats.

Moving average of the cc->cwnd from each closed circuit.

Definition at line 157 of file circuitlist.c.

◆ cc_stats_circ_close_ss_cwnd_ma

double cc_stats_circ_close_ss_cwnd_ma
extern

Moving average of the cc->cwnd from each closed slow-start circuit.

Definition at line 159 of file circuitlist.c.

◆ cc_stats_circs_closed

uint64_t cc_stats_circs_closed
extern

Definition at line 161 of file circuitlist.c.

◆ circ_n_proto_violation

uint64_t circ_n_proto_violation
extern

Total number of circuit protocol violation. This is incremented when the END_CIRC_REASON_TORPROTOCOL is used to close a circuit.

Definition at line 165 of file circuitlist.c.

Referenced by fill_relay_circ_proto_violation().