52#define CIRCUITLIST_PRIVATE
53#define OCIRC_EVENT_PRIVATE
59#include "feature/client/circpathbias.h"
68#include "core/or/dos.h"
71#include "core/or/trace_probes_circuit.h"
101#include "core/or/channelpadding.h"
121#include "core/or/or_circuit_st.h"
161uint64_t cc_stats_circs_closed = 0;
191CONST_TO_ORIGIN_CIRCUIT(
const circuit_t *x)
205 time_t made_placeholder_at;
215 return a->chan == b->chan && a->circ_id == b->circ_id;
220static inline unsigned int
225 uintptr_t chan = (uintptr_t) (
void*) a->chan;
227 array[0] = a->circ_id;
230 array[1] = (uint32_t) (chan >> 6);
231 return (
unsigned) siphash24g(array,
sizeof(array));
236 chan_circid_map = HT_INITIALIZER();
254circuit_set_circid_chan_helper(
circuit_t *circ,
int direction,
262 int make_active, attached = 0;
274 old_chan = *chan_ptr;
275 old_id = *circid_ptr;
277 if (
id == old_id && chan == old_chan)
280 if (_last_circid_chan_ent &&
281 ((old_id == _last_circid_chan_ent->circ_id &&
282 old_chan == _last_circid_chan_ent->chan) ||
283 (
id == _last_circid_chan_ent->circ_id &&
284 chan == _last_circid_chan_ent->chan))) {
285 _last_circid_chan_ent = NULL;
295 if (old_id != 0 && (old_chan != chan || old_id !=
id) &&
302 search.circ_id = old_id;
303 search.chan = old_chan;
304 found = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
312 --(old_chan->num_p_circuits);
328 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
330 found->circuit = circ;
331 found->made_placeholder_at = 0;
336 found->circuit = circ;
337 HT_INSERT(chan_circid_map, &chan_circid_map, found);
345 if (chan &&
id != 0 && (old_chan != chan || old_id !=
id) &&
356 if (make_active && attached)
357 update_circuit_on_cmux(circ, direction);
363 ++chan->num_p_circuits;
378 memset(&search, 0,
sizeof(search));
381 ent = HT_FIND(chan_circid_map, &chan_circid_map, &search);
383 if (ent && ent->circuit) {
385 log_warn(
LD_BUG,
"Tried to mark %u unusable on %p, but there was already "
386 "a circuit there.", (
unsigned)
id, chan);
389 if (!ent->made_placeholder_at)
397 HT_INSERT(chan_circid_map, &chan_circid_map, ent);
411 memset(&search, 0,
sizeof(search));
414 ent = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
415 if (ent && ent->circuit) {
416 log_warn(
LD_BUG,
"Tried to mark %u usable on %p, but there was already "
417 "a circuit there.", (
unsigned)
id, chan);
420 if (_last_circid_chan_ent == ent)
421 _last_circid_chan_ent = NULL;
527 msg->
reason = reason_code;
530 ocirc_cevent_publish(msg);
548 ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
556 ocirc_state_publish(msg);
565 if (state == circ->
state)
588 tor_trace(
TR_SUBSYS(circuit), TR_EV(change_state), circ, circ->
state, state);
622 } SMARTLIST_FOREACH_END(circ);
636 cnt = smartlist_len(sl);
638 log_debug(
LD_CIRC,
"or_conn to %s, %d pending circs",
693 if (idx < smartlist_len(lst)) {
694 circuit_t *replacement = smartlist_get(lst, idx);
706 } SMARTLIST_FOREACH_END(circ);
741 if (!
TO_CIRCUIT(next_circ)->marked_for_close &&
742 next_circ->has_opened &&
745 next_circ->build_state &&
750 } SMARTLIST_FOREACH_END(next_circ);
792 log_warn(
LD_BUG,
"Unknown circuit state %d", state);
793 tor_snprintf(buf,
sizeof(buf),
"unknown state [%d]", state);
815 return "HS_CLIENT_HSDIR";
820 return "HS_CLIENT_INTRO";
826 return "HS_CLIENT_REND";
829 return "HS_SERVICE_HSDIR";
833 return "HS_SERVICE_INTRO";
837 return "HS_SERVICE_REND";
842 return "MEASURE_TIMEOUT";
846 return "PATH_BIAS_TESTING";
848 return "HS_VANGUARDS";
850 return "CIRCUIT_PADDING";
853 return "CONFLUX_UNLINKED";
854 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
855 return "CONFLUX_LINKED";
858 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
873 "Unrecognized circuit purpose: %d",
887 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
891 return "OR_HSSI_ESTABLISHED";
893 return "OR_HSCR_ESTABLISHED";
895 return "OR_HS_R_JOINED";
899 return "HSCI_CONNECTING";
901 return "HSCI_INTRO_SENT";
906 return "HSCR_CONNECTING";
908 return "HSCR_ESTABLISHED_IDLE";
910 return "HSCR_ESTABLISHED_WAITING";
912 return "HSCR_JOINED";
916 return "HSSI_CONNECTING";
918 return "HSSI_ESTABLISHED";
921 return "HSSR_CONNECTING";
923 return "HSSR_JOINED";
936 return "Circuit at relay";
938 return "Acting as intro point";
940 return "Acting as rendezvous (pending)";
942 return "Acting as rendezvous (established)";
944 return "General-purpose client";
946 return "Hidden service client: Connecting to intro point";
948 return "Hidden service client: Waiting for ack from intro point";
950 return "Hidden service client: Received ack from intro point";
952 return "Hidden service client: Establishing rendezvous point";
954 return "Hidden service client: Pending rendezvous point";
956 return "Hidden service client: Pending rendezvous point (ack received)";
958 return "Hidden service client: Active rendezvous point";
960 return "Hidden service client: Fetching HS descriptor";
963 return "Measuring circuit timeout";
966 return "Hidden service: Establishing introduction point";
968 return "Hidden service: Introduction point";
970 return "Hidden service: Connecting to rendezvous point";
972 return "Hidden service: Active rendezvous point";
974 return "Hidden service: Uploading HS descriptor";
977 return "Testing circuit";
980 return "Circuit made by controller";
983 return "Path-bias testing circuit";
986 return "Hidden service: Pre-built vanguard circuit";
989 return "Circuit kept open for padding";
992 return "Unlinked conflux circuit";
994 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
995 return "Linked conflux circuit";
998 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
1010 CIRCWINDOW_START_MIN,
1011 CIRCWINDOW_START_MAX);
1042#define DFLT_IDLE_TIMEOUT_WHILE_LEARNING (3*60)
1043#define MIN_IDLE_TIMEOUT_WHILE_LEARNING (10)
1044#define MAX_IDLE_TIMEOUT_WHILE_LEARNING (1000*60)
1055 static uint32_t n_circuits_allocated = 1;
1080 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1081 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1090 int prediction_time_remaining =
1097 "Circuit chose a negative idle timeout of %d based on "
1098 "%d seconds of predictive building remaining.",
1100 prediction_time_remaining);
1104 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1105 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1109 "Circuit %"PRIu32
" chose an idle timeout of %d based on "
1110 "%d seconds of predictive building remaining.",
1113 prediction_time_remaining);
1116 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_origin), circ);
1138 dos_stream_init_circ_tbf(circ);
1140 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_or), circ);
1164 int should_free = 1;
1192 half_edge_free(half_conn);
1193 } SMARTLIST_FOREACH_END(half_conn);
1210 crypto_pk_free(ocirc->intro_key);
1214 hs_ident_circuit_free(ocirc->
hs_ident);
1218 if (ocirc->socks_username) {
1219 memwipe(ocirc->socks_username, 0x12, ocirc->socks_username_len);
1222 if (ocirc->socks_password) {
1223 memwipe(ocirc->socks_password, 0x06, ocirc->socks_password_len);
1254 extend_info_free(circ->
n_hop);
1281 log_info(
LD_CIRC,
"Circuit %u (id: %" PRIu32
") has been freed.",
1290 circuit_handles_clear(circ);
1294 tor_trace(
TR_SUBSYS(circuit), TR_EV(free), circ);
1317 head = cpath = circ->
cpath;
1324 while (cpath->
next && cpath->
next != head) {
1326 cpath = victim->
next;
1351 tmp->global_circuitlist_idx = -1;
1355 } SMARTLIST_FOREACH_END(tmp);
1357 smartlist_free(lst);
1374 for (elt = HT_START(chan_circid_map, &chan_circid_map);
1378 next = HT_NEXT_RMV(chan_circid_map, &chan_circid_map, elt);
1384 HT_CLEAR(chan_circid_map, &chan_circid_map);
1393 int conn_array_index,
1399 "(other side %u), state %d (%s), born %ld:",
1400 conn_array_index, type, (
unsigned)this_circid, (
unsigned)other_circid,
1430 if (
TO_CONN(tmpconn) == conn) {
1432 "App-ward", p_circ_id, n_circ_id);
1440 if (
TO_CONN(tmpconn) == conn) {
1442 "Exit-ward", n_circ_id, p_circ_id);
1447 SMARTLIST_FOREACH_END(circ);
1464 SMARTLIST_FOREACH_END(circ);
1478 int *found_entry_out)
1483 if (_last_circid_chan_ent &&
1484 circ_id == _last_circid_chan_ent->circ_id &&
1485 chan == _last_circid_chan_ent->chan) {
1486 found = _last_circid_chan_ent;
1488 search.circ_id = circ_id;
1490 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1491 _last_circid_chan_ent = found;
1493 if (found && found->circuit) {
1495 "circuit_get_by_circid_channel_impl() returning circuit %p for"
1496 " circ_id %u, channel ID %"PRIu64
" (%p)",
1497 found->circuit, (
unsigned)circ_id,
1499 if (found_entry_out)
1500 *found_entry_out = 1;
1501 return found->circuit;
1505 "circuit_get_by_circid_channel_impl() found %s for"
1506 " circ_id %u, channel ID %"PRIu64
" (%p)",
1507 found ?
"placeholder" :
"nothing",
1511 if (found_entry_out)
1512 *found_entry_out = found ? 1 : 0;
1592 memset(&search, 0,
sizeof(search));
1593 search.circ_id = circ_id;
1596 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1598 if (! found || found->circuit)
1601 return found->made_placeholder_at;
1631#ifdef DEBUG_CIRCUIT_UNLINK_ALL
1634 int mismatch = 0, badlen = 0;
1637 if (circ->
n_chan == chan ||
1643 SMARTLIST_FOREACH_END(circ);
1645 if (smartlist_len(detached) != smartlist_len(detached_2)) {
1646 log_warn(
LD_BUG,
"List of detached circuits had the wrong length! "
1647 "(got %d, should have gotten %d)",
1648 (
int)smartlist_len(detached),
1649 (
int)smartlist_len(detached_2));
1656 if (c != smartlist_get(detached_2, c_sl_idx))
1661 log_warn(
LD_BUG,
"Mismatch in list of detached circuits.");
1663 if (badlen || mismatch) {
1664 smartlist_free(detached);
1665 detached = detached_2;
1667 log_notice(
LD_CIRC,
"List of %d circuits was as expected.",
1668 (
int)smartlist_len(detached));
1669 smartlist_free(detached_2);
1676 if (circ->
n_chan == chan) {
1688 if (or_circ->
p_chan == chan) {
1694 log_warn(
LD_BUG,
"Circuit on detached list which I had no reason "
1699 circuit_mark_for_close(circ, reason);
1700 } SMARTLIST_FOREACH_END(circ);
1702 smartlist_free(detached);
1722 bool want_client_circ)
1728 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1731 for ( ; idx < smartlist_len(lst); ++idx) {
1732 circuit_t *circ = smartlist_get(lst, idx);
1741 if (want_client_circ) {
1779 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1782 for ( ; idx < smartlist_len(lst); ++idx) {
1783 circuit_t *circ = smartlist_get(lst, idx);
1812 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1814 for ( ; idx < smartlist_len(lst); ++idx) {
1815 circuit_t *circ = smartlist_get(lst, idx);
1841 if (BUG(!chosen_exit)) {
1868 purpose != CIRCUIT_PURPOSE_CONFLUX_LINKED);
1902 int purpose_to_search_for;
1909 purpose_to_produce);
1914 tor_assert_nonfatal(purpose_to_search_for !=
1919 "Hunting for a circ to cannibalize: purpose %d, uptime %d, "
1920 "capacity %d, internal %d",
1921 purpose_to_produce, need_uptime, need_capacity, internal);
1926 !circ_->marked_for_close &&
1927 circ_->purpose == purpose_to_search_for &&
1928 !circ_->timestamp_dirty) {
1950 !circ->unusable_for_new_conns &&
1968 }
while (hop!=circ->
cpath);
1981 }
while (hop != circ->
cpath);
1986 log_debug(
LD_GENERAL,
"Skipping uncannibalizable circuit for v3 "
1987 "rendezvous point.");
1997 SMARTLIST_FOREACH_END(circ_);
2024 if (circuits_upgraded && smartlist_len(result)) {
2027 smartlist_free(result);
2038 if (circ && circ->
cpath) {
2040 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2041 cpath_next = cpath->
next;
2054 if (circ && circ->
cpath) {
2056 for (cpath = circ->
cpath;
2057 cpath->
state == CPATH_STATE_OPEN
2058 && cpath_next != circ->
cpath;
2059 cpath = cpath_next) {
2060 cpath_next = cpath->
next;
2073 if (circ && circ->
cpath && hopnum > 0) {
2075 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2076 cpath_next = cpath->
next;
2093 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
2095 SMARTLIST_FOREACH_END(circ);
2115 SMARTLIST_FOREACH_END(circ);
2139 uint64_t written_sync;
2146 or_circ = CONST_TO_OR_CIRCUIT(c);
2148 if (dir == CIRCUIT_N_CHAN) {
2159 cell_size = get_cell_network_size(chan->wide_circ_ids);
2165 bool is_ipv6 = chan &&
2171 written_sync = cells*(cell_size+TLS_PER_CELL_OVERHEAD);
2199 int orig_reason = reason;
2204 if (reason == END_CIRC_REASON_TORPROTOCOL) {
2215 "Duplicate call to circuit_mark_for_close at %s:%d"
2216 " (first at %s:%d)", file, line,
2222 log_warn(
LD_BUG,
"Specified 'at-origin' non-reason for ending circuit, "
2223 "but circuit was not at origin. (called %s:%d, purpose=%d)",
2226 reason = END_CIRC_REASON_NONE;
2236 reason = END_CIRC_REASON_NONE;
2243 reason &= ~END_CIRC_REASON_FLAG_REMOTE;
2245 if (reason < END_CIRC_REASON_MIN_ || reason > END_CIRC_REASON_MAX_) {
2247 log_warn(
LD_BUG,
"Reason %d out of range at %s:%d", reason, file, line);
2248 reason = END_CIRC_REASON_NONE;
2271 if (CIRCUIT_IS_CONFLUX(circ)) {
2292 cc_stats_circs_closed++;
2301 log_info(
LD_GENERAL,
"Circuit %u (id: %" PRIu32
") marked for close at "
2302 "%s:%d (orig reason: %d, new reason: %d)",
2306 file, line, orig_reason, reason);
2307 tor_trace(
TR_SUBSYS(circuit), TR_EV(mark_for_close), circ);
2377 CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED,
2384 if (!CHANNEL_CONDEMNED(circ->
n_chan)) {
2407 conn->
end_reason = END_STREAM_REASON_DESTROY;
2409 connection_mark_for_close(
TO_CONN(conn));
2417 if (!CHANNEL_CONDEMNED(or_circ->
p_chan)) {
2444 log_warn(
LD_BUG,
"Called on non-marked circuit");
2485 result += single_conn_free_bytes(conn);
2487 result += single_conn_free_bytes(conn->
linked_conn);
2545 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&c->
n_chan_cells.head)))
2550 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->
p_chan_cells.head))) {
2566 uint32_t age = 0, age2;
2586 uint32_t age = 0, age2;
2609 CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
2612 CONST_TO_OR_CIRCUIT(c)->n_streams, now);
2624 if (cell_age > data_age)
2642 else if (age_a == age_b)
2648static uint32_t now_ts_for_buf_cmp;
2662 else if (age_a == age_b)
2668#define FRACTION_OF_DATA_TO_RETAIN_ON_OOM 0.90
2681 size_t mem_to_recover;
2682 size_t mem_recovered=0;
2683 int n_circuits_killed=0;
2684 int n_dirconns_killed=0;
2685 int n_edgeconns_killed = 0;
2687 log_notice(
LD_GENERAL,
"We're low on memory (cell queues total alloc:"
2688 " %"TOR_PRIuSZ
" buffer total alloc: %" TOR_PRIuSZ
","
2689 " tor compress total alloc: %" TOR_PRIuSZ
2690 " (zlib: %" TOR_PRIuSZ
", zstd: %" TOR_PRIuSZ
","
2691 " lzma: %" TOR_PRIuSZ
"),"
2692 " rendezvous cache total alloc: %" TOR_PRIuSZ
"). Killing"
2693 " circuits withover-long queues. (This behavior is controlled by"
2694 " MaxMemInQueues.)",
2695 cell_queues_get_total_allocation(),
2696 buf_get_total_allocation(),
2701 hs_cache_get_total_allocation());
2704 FRACTION_OF_DATA_TO_RETAIN_ON_OOM);
2705 if (current_allocation <= mem_target)
2707 mem_to_recover = current_allocation - mem_target;
2715 } SMARTLIST_FOREACH_END(circ);
2724 } SMARTLIST_FOREACH_END(circ);
2727 now_ts_for_buf_cmp = now_ts;
2729 now_ts_for_buf_cmp = 0;
2734 } SMARTLIST_FOREACH_END(conn);
2749 if (conn_age < circ->age_tmp) {
2757 connection_mark_for_close(conn);
2758 mem_recovered += single_conn_free_bytes(conn);
2761 ++n_dirconns_killed;
2763 ++n_edgeconns_killed;
2766 if (mem_recovered >= mem_to_recover)
2767 goto done_recovering_mem;
2776 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
2781 ++n_circuits_killed;
2784 mem_recovered += half_stream_alloc;
2785 mem_recovered += freed;
2788 if (mem_recovered >= mem_to_recover)
2789 goto done_recovering_mem;
2790 } SMARTLIST_FOREACH_END(circ);
2792 done_recovering_mem:
2793 log_notice(
LD_GENERAL,
"Removed %"TOR_PRIuSZ
" bytes by killing %d circuits; "
2794 "%d circuits remain alive. Also killed %d non-linked directory "
2795 "connections. Killed %d edge connections",
2798 smartlist_len(circlist) - n_circuits_killed,
2800 n_edgeconns_killed);
2802 return mem_recovered;
2818 c->
purpose <= CIRCUIT_PURPOSE_MAX_);
2821 origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
2823 or_circ = CONST_TO_OR_CIRCUIT(c);
2836 if (or_circ && or_circ->
p_chan) {
2865 if (origin_circ && origin_circ->
cpath) {
static sa_family_t tor_addr_family(const tor_addr_t *a)
void buf_clear(buf_t *buf)
size_t buf_allocation(const buf_t *buf)
uint32_t buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now)
Header file for buffers.c.
void bwhist_note_bytes_written(uint64_t num_bytes, time_t when, bool ipv6)
Header for feature/stats/bwhist.c.
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
int channel_send_destroy(circid_t circ_id, channel_t *chan, int reason)
int channel_get_addr_if_possible(const channel_t *chan, tor_addr_t *addr_out)
const char * channel_describe_peer(channel_t *chan)
Header file for channel.c.
Header file for channeltls.c.
int pathbias_check_close(origin_circuit_t *ocirc, int reason)
#define DEAD_CIRCUIT_MAGIC
#define ORIGIN_CIRCUIT_MAGIC
void circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
int route_len_for_purpose(uint8_t purpose, extend_info_t *exit_ei)
Header file for circuitbuild.c.
static circuit_t * circuit_get_by_circid_channel_impl(circid_t circ_id, channel_t *chan, int *found_entry_out)
STATIC uint32_t circuit_max_queued_item_age(const circuit_t *c, uint32_t now)
static int chan_circid_entries_eq_(chan_circid_circuit_map_t *a, chan_circid_circuit_map_t *b)
static uint32_t circuit_get_streams_max_data_age(const edge_connection_t *stream, uint32_t now)
STATIC void circuit_free_(circuit_t *circ)
void circuit_close_all_marked(void)
const char * circuit_purpose_to_controller_hs_state_string(uint8_t purpose)
void circuit_mark_for_close_(circuit_t *circ, int reason, int line, const char *file)
static smartlist_t * global_circuitlist
int circuit_any_opened_circuits_cached(void)
void channel_note_destroy_pending(channel_t *chan, circid_t id)
static int any_opened_circs_cached_val
uint64_t circ_n_proto_violation
circuit_t * circuit_get_by_circid_channel_even_if_marked(circid_t circ_id, channel_t *chan)
void circuit_set_p_circid_chan(or_circuit_t *or_circ, circid_t id, channel_t *chan)
origin_circuit_t * circuit_get_next_by_purpose(origin_circuit_t *start, uint8_t purpose)
int circuit_id_in_use_on_channel(circid_t circ_id, channel_t *chan)
STATIC size_t n_cells_in_circ_queues(const circuit_t *c)
static void circuit_dump_conn_details(int severity, circuit_t *circ, int conn_array_index, const char *type, circid_t this_circid, circid_t other_circid)
or_circuit_t * or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
void circuit_synchronize_written_or_bandwidth(const circuit_t *c, circuit_channel_direction_t dir)
void circuit_set_n_circid_chan(circuit_t *circ, circid_t id, channel_t *chan)
double cc_stats_circ_close_ss_cwnd_ma
static void init_circuit_base(circuit_t *circ)
static uint32_t conn_get_buffer_age(const connection_t *conn, uint32_t now_ts)
void circuit_mark_all_dirty_circs_as_unusable(void)
static int circuits_compare_by_oldest_queued_item_(const void **a_, const void **b_)
void circuit_clear_cpath(origin_circuit_t *circ)
void circuit_set_state(circuit_t *circ, uint8_t state)
void circuit_free_all(void)
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
origin_circuit_t * circuit_get_next_intro_circ(const origin_circuit_t *start, bool want_client_circ)
origin_circuit_t * circuit_get_by_global_id(uint32_t id)
origin_circuit_t * origin_circuit_new(void)
static unsigned int chan_circid_entry_hash_(chan_circid_circuit_map_t *a)
void channel_mark_circid_unusable(channel_t *chan, circid_t id)
void circuit_dump_by_conn(connection_t *conn, int severity)
int circuit_any_opened_circuits(void)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now)
int circuit_get_cpath_len(origin_circuit_t *circ)
void channel_mark_circid_usable(channel_t *chan, circid_t id)
static smartlist_t * circuits_pending_close
int circuit_get_cpath_opened_len(const origin_circuit_t *circ)
const char * circuit_purpose_to_controller_string(uint8_t purpose)
void assert_circuit_ok(const circuit_t *c)
static void circuit_remove_from_origin_circuit_list(origin_circuit_t *origin_circ)
static smartlist_t * circuits_pending_other_guards
const char * circuit_state_to_string(int state)
static size_t marked_circuit_free_stream_bytes(circuit_t *c)
int circuit_count_pending_on_channel(channel_t *chan)
static HT_HEAD(HT_PROTOTYPE(chan_circid_map, HT_PROTOTYPE(chan_circid_circuit_map_t)
STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now)
static int conns_compare_by_buffer_age_(const void **a_, const void **b_)
size_t circuits_handle_oom(size_t current_allocation)
void circuit_get_all_pending_on_channel(smartlist_t *out, channel_t *chan)
static void circuit_about_to_free(circuit_t *circ)
int circuit_event_status(origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
static void circuit_about_to_free_atexit(circuit_t *circ)
static size_t marked_circuit_streams_free_bytes(edge_connection_t *stream)
time_t circuit_id_when_marked_unusable_on_channel(circid_t circ_id, channel_t *chan)
void circuit_cache_opened_circuit_state(int circuits_are_opened)
#define DFLT_IDLE_TIMEOUT_WHILE_LEARNING
origin_circuit_t * circuit_get_next_service_rp_circ(origin_circuit_t *start)
circuit_t * circuit_get_by_circid_channel(circid_t circ_id, channel_t *chan)
static void circuit_add_to_origin_circuit_list(origin_circuit_t *origin_circ)
double cc_stats_circ_close_cwnd_ma
static smartlist_t * circuits_pending_chans
crypt_path_t * circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum)
origin_circuit_t * circuit_find_to_cannibalize(uint8_t purpose_to_produce, extend_info_t *info, int flags)
const char * circuit_purpose_to_string(uint8_t purpose)
static uint8_t get_circuit_purpose_needed_to_cannibalize(uint8_t purpose)
void channel_note_destroy_not_pending(channel_t *chan, circid_t id)
static void circuit_state_publish(const circuit_t *circ)
void circuit_clear_testing_cell_stats(circuit_t *circ)
static size_t circuit_alloc_in_half_streams(const circuit_t *c)
smartlist_t * circuit_get_global_origin_circuit_list(void)
bool circuit_is_queue_full(const circuit_t *circ, cell_direction_t direction)
smartlist_t * circuit_get_global_list(void)
void circuit_unlink_all_from_channel(channel_t *chan, int reason)
static void marked_circuit_free_cells(circuit_t *circ)
static int circuit_can_be_cannibalized_for_v3_rp(const origin_circuit_t *circ)
static smartlist_t * global_origin_circuit_list
void circuit_mark_all_unused_circs(void)
int32_t circuit_initial_package_window(void)
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_S_CONNECT_REND
#define CIRCUIT_STATE_ONIONSKIN_PENDING
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT
#define CIRCUIT_PURPOSE_REND_POINT_WAITING
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING
#define CIRCUIT_STATE_OPEN
#define CIRCUIT_IS_ORCIRC(c)
#define CIRCUIT_PURPOSE_IS_ORIGIN(p)
#define CIRCUIT_STATE_BUILDING
#define CIRCUIT_PURPOSE_C_REND_JOINED
#define CIRCUIT_PURPOSE_S_INTRO
#define CIRCUIT_PURPOSE_INTRO_POINT
#define CIRCUIT_PURPOSE_CONTROLLER
#define CIRCUIT_IS_ORIGIN(c)
#define CIRCUIT_PURPOSE_C_CIRCUIT_PADDING
#define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
#define CIRCUIT_STATE_GUARD_WAIT
#define CIRCUIT_PURPOSE_TESTING
#define CIRCUIT_PURPOSE_OR
#define CIRCUIT_STATE_CHAN_WAIT
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
#define CIRCUIT_PURPOSE_S_REND_JOINED
#define CIRCUIT_PURPOSE_C_REND_READY
#define CIRCUIT_PURPOSE_S_HSDIR_POST
#define CIRCUIT_PURPOSE_C_HSDIR_GET
#define CIRCUIT_PURPOSE_REND_ESTABLISHED
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED
#define CIRCUIT_PURPOSE_C_INTRODUCING
#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO
#define CIRCUIT_PURPOSE_C_ESTABLISH_REND
#define CIRCUIT_PURPOSE_C_GENERAL
#define CIRCUIT_PURPOSE_CONFLUX_UNLINKED
#define CIRCUIT_PURPOSE_HS_VANGUARDS
void circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ, cell_direction_t direction)
void circuitmux_detach_circuit(circuitmux_t *cmux, circuit_t *circ)
void circpad_circuit_free_all_machineinfos(circuit_t *circ)
int circpad_marked_circuit_for_padding(circuit_t *circ, int reason)
Header file for circuitpadding.c.
circuit_build_times_t * get_circuit_build_times_mutable(void)
const circuit_build_times_t * get_circuit_build_times(void)
int circuit_build_times_disabled(const or_options_t *options)
int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt)
Header file for circuitstats.c.
void circuit_build_failed(origin_circuit_t *circ)
int circuit_should_use_vanguards(uint8_t purpose)
void mark_circuit_unusable_for_new_conns(origin_circuit_t *circ)
Header file for circuituse.c.
#define CIRCLAUNCH_NEED_CAPACITY
#define CIRCLAUNCH_ONEHOP_TUNNEL
#define CIRCLAUNCH_IS_V3_RP
#define CIRCLAUNCH_IS_INTERNAL
#define CIRCLAUNCH_NEED_UPTIME
uint32_t monotime_coarse_get_stamp(void)
size_t tor_compress_state_size(const tor_compress_state_t *state)
size_t tor_compress_get_total_allocation(void)
size_t tor_lzma_get_total_allocation(void)
Header for compress_lzma.c.
size_t tor_zlib_get_total_allocation(void)
Header for compress_zlib.c.
size_t tor_zstd_get_total_allocation(void)
Header for compress_zstd.c.
const or_options_t * get_options(void)
Header file for config.c.
uint64_t conflux_get_circ_bytes_allocation(const circuit_t *circ)
Public APIs for conflux multipath support.
void conflux_circuit_has_closed(circuit_t *circ)
void conflux_circuit_about_to_free(circuit_t *circ)
Header file for conflux_pool.c.
Header file for conflux_util.c.
Public APIs for congestion control.
#define congestion_control_free(cc)
static int32_t cell_queue_highwatermark(void)
Structure definitions for congestion control.
void connection_free_(connection_t *conn)
Header file for connection.c.
int connection_edge_destroy(circid_t circ_id, edge_connection_t *conn)
Header file for connection_edge.c.
Header file for connection_or.c.
int control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
Header file for control_events.c.
Circuit-build-stse structure.
void cpath_assert_ok(const crypt_path_t *cp)
void cpath_free(crypt_path_t *victim)
Header file for crypt_path.c.
reference-counting structure for crypt_path_t
Common functions for using (pseudo-)random number generators.
int crypto_rand_int(unsigned int max)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
int tor_memeq(const void *a, const void *b, size_t sz)
#define tor_memneq(a, b, sz)
Client/server directory connection structure.
dir_connection_t * TO_DIR_CONN(connection_t *c)
Header file for directory.c.
Edge-connection structure.
void entry_guard_cancel(circuit_guard_state_t **guard_state_p)
int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs, const smartlist_t *all_circuits_in, smartlist_t *newly_complete_out)
int entry_guard_could_succeed(const circuit_guard_state_t *guard_state)
guard_selection_t * get_guard_selection_info(void)
Header file for circuitbuild.c.
Header for core/or/extendinfo.c.
Half-open connection structure.
Header file for hs_cache.c.
void hs_circ_cleanup_on_close(circuit_t *circ)
void hs_circ_cleanup_on_free(circuit_t *circ)
Header file containing circuit data for the whole HS subsystem.
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
Header file for hs_circuitmap.c.
Header file containing circuit and connection identifier data for the whole HS subsystem.
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
smartlist_t * get_connection_array(void)
STATIC smartlist_t * connection_array
void mainloop_schedule_postloop_cleanup(void)
Header file for mainloop.c.
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
void tor_free_(void *mem)
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Header file for networkstatus.c.
const node_t * node_get_by_id(const char *identity_digest)
bool node_supports_v3_rendezvous_point(const node_t *node)
int nodes_in_same_family(const node_t *node1, const node_t *node2)
Header file for nodelist.c.
Header file for ocirc_event.c.
Header file for onion_crypto.c.
Header file for onion_fast.c.
void onion_pending_remove(or_circuit_t *circ)
Header file for onion_queue.c.
Master header file for Tor-specific functionality.
#define DEFAULT_ROUTE_LEN
#define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT
#define CELL_MAX_NETWORK_SIZE
#define END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED
#define END_CIRC_REASON_FLAG_REMOTE
#define DOWNCAST(to, ptr)
#define END_CIRC_AT_ORIGIN
circuit_channel_direction_t
Origin circuit structure.
Header file for policies.c.
int predicted_ports_prediction_time_remaining(time_t now)
Header file for predict_ports.c.
int tor_snprintf(char *str, size_t size, const char *format,...)
void channel_unlink_all_circuits(channel_t *chan, smartlist_t *circuits_out)
void circuit_reset_sendme_randomness(circuit_t *circ)
void cell_queue_clear(cell_queue_t *queue)
void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan)
void cell_queue_init(cell_queue_t *queue)
size_t packed_cell_mem_cost(void)
Header for relay_crypto.c.
void relay_crypto_assert_ok(const relay_crypto_t *crypto)
void relay_crypto_clear(relay_crypto_t *crypto)
Header file for rendcommon.c.
void rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval)
Header file for rephist.c.
Header file for routerlist.c.
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
Header file for routerset.c.
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
void smartlist_sort_pointers(smartlist_t *sl)
int smartlist_contains(const smartlist_t *sl, const void *element)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_clear(smartlist_t *sl)
void smartlist_remove(smartlist_t *sl, const void *element)
void smartlist_del(smartlist_t *sl, int idx)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
#define SMARTLIST_DEL_CURRENT(sl, var)
void note_circ_closed_for_unrecognized_cells(time_t n_seconds, uint32_t n_cells)
time_t timestamp_last_had_circuits
unsigned int num_n_circuits
char identity_digest[DIGEST_LEN]
uint64_t global_identifier
enum channel_t::@8 reason_for_closing
unsigned int p_delete_pending
int marked_for_close_reason
int global_circuitlist_idx
int marked_for_close_orig_reason
struct create_cell_t * n_chan_create_cell
cell_queue_t n_chan_cells
smartlist_t * sendme_last_digests
uint16_t marked_for_close
const char * marked_for_close_file
unsigned int n_delete_pending
struct timeval timestamp_began
smartlist_t * testing_cell_stats
struct timeval timestamp_created
struct congestion_control_t * ccontrol
struct connection_t * linked_conn
uint16_t marked_for_close
extend_info_t * chosen_exit
unsigned int onehop_tunnel
unsigned int need_capacity
struct crypt_path_t * next
extend_info_t * extend_info
struct tor_compress_state_t * compress_state
struct edge_connection_t * next_stream
unsigned int edge_has_sent_end
struct circuit_t * on_circuit
char identity_digest[DIGEST_LEN]
edge_connection_t * resolving_streams
unsigned int remaining_relay_early_cells
struct workqueue_entry_t * workqueue_entry
uint32_t n_cells_discarded_at_end
cell_queue_t p_chan_cells
struct or_circuit_t * rend_splice
edge_connection_t * n_streams
struct routerset_t * ExcludeNodes
uint32_t global_identifier
struct hs_ident_circuit_t * hs_ident
edge_connection_t * p_streams
unsigned int isolation_values_set
unsigned int remaining_relay_early_cells
int global_origin_circuit_list_idx
smartlist_t * prepend_policy
cpath_build_state_t * build_state
struct circuit_guard_state_t * guard_state
streamid_t next_stream_id
smartlist_t * half_streams
uint32_t inserted_timestamp
#define MOCK_IMPL(rv, funcname, arglist)
void tor_gettimeofday(struct timeval *timeval)
Integer definitions used throughout Tor.
#define FALLTHROUGH_UNLESS_ALL_BUGS_ARE_FATAL
#define tor_fragile_assert()
int tor_digest_is_zero(const char *digest)