52#define CIRCUITLIST_PRIVATE
53#define OCIRC_EVENT_PRIVATE
59#include "feature/client/circpathbias.h"
70#include "core/or/trace_probes_circuit.h"
100#include "core/or/channelpadding.h"
120#include "core/or/or_circuit_st.h"
160uint64_t cc_stats_circs_closed = 0;
186CONST_TO_ORIGIN_CIRCUIT(
const circuit_t *x)
200 time_t made_placeholder_at;
210 return a->chan == b->chan && a->circ_id == b->circ_id;
215static inline unsigned int
220 uintptr_t chan = (uintptr_t) (
void*) a->chan;
222 array[0] = a->circ_id;
225 array[1] = (uint32_t) (chan >> 6);
226 return (
unsigned) siphash24g(array,
sizeof(array));
231 chan_circid_map = HT_INITIALIZER();
249circuit_set_circid_chan_helper(
circuit_t *circ,
int direction,
257 int make_active, attached = 0;
269 old_chan = *chan_ptr;
270 old_id = *circid_ptr;
272 if (
id == old_id && chan == old_chan)
275 if (_last_circid_chan_ent &&
276 ((old_id == _last_circid_chan_ent->circ_id &&
277 old_chan == _last_circid_chan_ent->chan) ||
278 (
id == _last_circid_chan_ent->circ_id &&
279 chan == _last_circid_chan_ent->chan))) {
280 _last_circid_chan_ent = NULL;
290 if (old_id != 0 && (old_chan != chan || old_id !=
id) &&
297 search.circ_id = old_id;
298 search.chan = old_chan;
299 found = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
307 --(old_chan->num_p_circuits);
323 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
325 found->circuit = circ;
326 found->made_placeholder_at = 0;
331 found->circuit = circ;
332 HT_INSERT(chan_circid_map, &chan_circid_map, found);
340 if (chan &&
id != 0 && (old_chan != chan || old_id !=
id) &&
351 if (make_active && attached)
352 update_circuit_on_cmux(circ, direction);
358 ++chan->num_p_circuits;
373 memset(&search, 0,
sizeof(search));
376 ent = HT_FIND(chan_circid_map, &chan_circid_map, &search);
378 if (ent && ent->circuit) {
380 log_warn(
LD_BUG,
"Tried to mark %u unusable on %p, but there was already "
381 "a circuit there.", (
unsigned)
id, chan);
384 if (!ent->made_placeholder_at)
392 HT_INSERT(chan_circid_map, &chan_circid_map, ent);
406 memset(&search, 0,
sizeof(search));
409 ent = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
410 if (ent && ent->circuit) {
411 log_warn(
LD_BUG,
"Tried to mark %u usable on %p, but there was already "
412 "a circuit there.", (
unsigned)
id, chan);
415 if (_last_circid_chan_ent == ent)
416 _last_circid_chan_ent = NULL;
522 msg->
reason = reason_code;
525 ocirc_cevent_publish(msg);
543 ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
551 ocirc_state_publish(msg);
560 if (state == circ->
state)
583 tor_trace(
TR_SUBSYS(circuit), TR_EV(change_state), circ, circ->
state, state);
617 } SMARTLIST_FOREACH_END(circ);
631 cnt = smartlist_len(sl);
633 log_debug(
LD_CIRC,
"or_conn to %s, %d pending circs",
688 if (idx < smartlist_len(lst)) {
689 circuit_t *replacement = smartlist_get(lst, idx);
701 } SMARTLIST_FOREACH_END(circ);
736 if (!
TO_CIRCUIT(next_circ)->marked_for_close &&
737 next_circ->has_opened &&
740 next_circ->build_state &&
745 } SMARTLIST_FOREACH_END(next_circ);
787 log_warn(
LD_BUG,
"Unknown circuit state %d", state);
788 tor_snprintf(buf,
sizeof(buf),
"unknown state [%d]", state);
810 return "HS_CLIENT_HSDIR";
815 return "HS_CLIENT_INTRO";
821 return "HS_CLIENT_REND";
824 return "HS_SERVICE_HSDIR";
828 return "HS_SERVICE_INTRO";
832 return "HS_SERVICE_REND";
837 return "MEASURE_TIMEOUT";
841 return "PATH_BIAS_TESTING";
843 return "HS_VANGUARDS";
845 return "CIRCUIT_PADDING";
848 return "CONFLUX_UNLINKED";
849 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
850 return "CONFLUX_LINKED";
853 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
868 "Unrecognized circuit purpose: %d",
882 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
886 return "OR_HSSI_ESTABLISHED";
888 return "OR_HSCR_ESTABLISHED";
890 return "OR_HS_R_JOINED";
894 return "HSCI_CONNECTING";
896 return "HSCI_INTRO_SENT";
901 return "HSCR_CONNECTING";
903 return "HSCR_ESTABLISHED_IDLE";
905 return "HSCR_ESTABLISHED_WAITING";
907 return "HSCR_JOINED";
911 return "HSSI_CONNECTING";
913 return "HSSI_ESTABLISHED";
916 return "HSSR_CONNECTING";
918 return "HSSR_JOINED";
931 return "Circuit at relay";
933 return "Acting as intro point";
935 return "Acting as rendezvous (pending)";
937 return "Acting as rendezvous (established)";
939 return "General-purpose client";
941 return "Hidden service client: Connecting to intro point";
943 return "Hidden service client: Waiting for ack from intro point";
945 return "Hidden service client: Received ack from intro point";
947 return "Hidden service client: Establishing rendezvous point";
949 return "Hidden service client: Pending rendezvous point";
951 return "Hidden service client: Pending rendezvous point (ack received)";
953 return "Hidden service client: Active rendezvous point";
955 return "Hidden service client: Fetching HS descriptor";
958 return "Measuring circuit timeout";
961 return "Hidden service: Establishing introduction point";
963 return "Hidden service: Introduction point";
965 return "Hidden service: Connecting to rendezvous point";
967 return "Hidden service: Active rendezvous point";
969 return "Hidden service: Uploading HS descriptor";
972 return "Testing circuit";
975 return "Circuit made by controller";
978 return "Path-bias testing circuit";
981 return "Hidden service: Pre-built vanguard circuit";
984 return "Circuit kept open for padding";
987 return "Unlinked conflux circuit";
989 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
990 return "Linked conflux circuit";
993 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
1005 CIRCWINDOW_START_MIN,
1006 CIRCWINDOW_START_MAX);
1037#define DFLT_IDLE_TIMEOUT_WHILE_LEARNING (3*60)
1038#define MIN_IDLE_TIMEOUT_WHILE_LEARNING (10)
1039#define MAX_IDLE_TIMEOUT_WHILE_LEARNING (1000*60)
1050 static uint32_t n_circuits_allocated = 1;
1075 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1076 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1085 int prediction_time_remaining =
1092 "Circuit chose a negative idle timeout of %d based on "
1093 "%d seconds of predictive building remaining.",
1095 prediction_time_remaining);
1099 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1100 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1104 "Circuit %"PRIu32
" chose an idle timeout of %d based on "
1105 "%d seconds of predictive building remaining.",
1108 prediction_time_remaining);
1111 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_origin), circ);
1134 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_or), circ);
1158 int should_free = 1;
1186 half_edge_free(half_conn);
1187 } SMARTLIST_FOREACH_END(half_conn);
1204 crypto_pk_free(ocirc->intro_key);
1208 hs_ident_circuit_free(ocirc->
hs_ident);
1212 if (ocirc->socks_username) {
1213 memwipe(ocirc->socks_username, 0x12, ocirc->socks_username_len);
1216 if (ocirc->socks_password) {
1217 memwipe(ocirc->socks_password, 0x06, ocirc->socks_password_len);
1248 extend_info_free(circ->
n_hop);
1275 log_info(
LD_CIRC,
"Circuit %u (id: %" PRIu32
") has been freed.",
1284 circuit_handles_clear(circ);
1288 tor_trace(
TR_SUBSYS(circuit), TR_EV(free), circ);
1311 head = cpath = circ->
cpath;
1318 while (cpath->
next && cpath->
next != head) {
1320 cpath = victim->
next;
1345 tmp->global_circuitlist_idx = -1;
1349 } SMARTLIST_FOREACH_END(tmp);
1351 smartlist_free(lst);
1368 for (elt = HT_START(chan_circid_map, &chan_circid_map);
1372 next = HT_NEXT_RMV(chan_circid_map, &chan_circid_map, elt);
1378 HT_CLEAR(chan_circid_map, &chan_circid_map);
1387 int conn_array_index,
1393 "(other side %u), state %d (%s), born %ld:",
1394 conn_array_index, type, (
unsigned)this_circid, (
unsigned)other_circid,
1424 if (
TO_CONN(tmpconn) == conn) {
1426 "App-ward", p_circ_id, n_circ_id);
1434 if (
TO_CONN(tmpconn) == conn) {
1436 "Exit-ward", n_circ_id, p_circ_id);
1441 SMARTLIST_FOREACH_END(circ);
1458 SMARTLIST_FOREACH_END(circ);
1472 int *found_entry_out)
1477 if (_last_circid_chan_ent &&
1478 circ_id == _last_circid_chan_ent->circ_id &&
1479 chan == _last_circid_chan_ent->chan) {
1480 found = _last_circid_chan_ent;
1482 search.circ_id = circ_id;
1484 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1485 _last_circid_chan_ent = found;
1487 if (found && found->circuit) {
1489 "circuit_get_by_circid_channel_impl() returning circuit %p for"
1490 " circ_id %u, channel ID %"PRIu64
" (%p)",
1491 found->circuit, (
unsigned)circ_id,
1493 if (found_entry_out)
1494 *found_entry_out = 1;
1495 return found->circuit;
1499 "circuit_get_by_circid_channel_impl() found %s for"
1500 " circ_id %u, channel ID %"PRIu64
" (%p)",
1501 found ?
"placeholder" :
"nothing",
1505 if (found_entry_out)
1506 *found_entry_out = found ? 1 : 0;
1586 memset(&search, 0,
sizeof(search));
1587 search.circ_id = circ_id;
1590 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1592 if (! found || found->circuit)
1595 return found->made_placeholder_at;
1625#ifdef DEBUG_CIRCUIT_UNLINK_ALL
1628 int mismatch = 0, badlen = 0;
1631 if (circ->
n_chan == chan ||
1637 SMARTLIST_FOREACH_END(circ);
1639 if (smartlist_len(detached) != smartlist_len(detached_2)) {
1640 log_warn(
LD_BUG,
"List of detached circuits had the wrong length! "
1641 "(got %d, should have gotten %d)",
1642 (
int)smartlist_len(detached),
1643 (
int)smartlist_len(detached_2));
1650 if (c != smartlist_get(detached_2, c_sl_idx))
1655 log_warn(
LD_BUG,
"Mismatch in list of detached circuits.");
1657 if (badlen || mismatch) {
1658 smartlist_free(detached);
1659 detached = detached_2;
1661 log_notice(
LD_CIRC,
"List of %d circuits was as expected.",
1662 (
int)smartlist_len(detached));
1663 smartlist_free(detached_2);
1670 if (circ->
n_chan == chan) {
1682 if (or_circ->
p_chan == chan) {
1688 log_warn(
LD_BUG,
"Circuit on detached list which I had no reason "
1693 circuit_mark_for_close(circ, reason);
1694 } SMARTLIST_FOREACH_END(circ);
1696 smartlist_free(detached);
1716 bool want_client_circ)
1722 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1725 for ( ; idx < smartlist_len(lst); ++idx) {
1726 circuit_t *circ = smartlist_get(lst, idx);
1735 if (want_client_circ) {
1773 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1776 for ( ; idx < smartlist_len(lst); ++idx) {
1777 circuit_t *circ = smartlist_get(lst, idx);
1806 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1808 for ( ; idx < smartlist_len(lst); ++idx) {
1809 circuit_t *circ = smartlist_get(lst, idx);
1835 if (BUG(!chosen_exit)) {
1862 purpose != CIRCUIT_PURPOSE_CONFLUX_LINKED);
1896 int purpose_to_search_for;
1903 purpose_to_produce);
1908 tor_assert_nonfatal(purpose_to_search_for !=
1913 "Hunting for a circ to cannibalize: purpose %d, uptime %d, "
1914 "capacity %d, internal %d",
1915 purpose_to_produce, need_uptime, need_capacity, internal);
1920 !circ_->marked_for_close &&
1921 circ_->purpose == purpose_to_search_for &&
1922 !circ_->timestamp_dirty) {
1944 !circ->unusable_for_new_conns &&
1962 }
while (hop!=circ->
cpath);
1975 }
while (hop != circ->
cpath);
1980 log_debug(
LD_GENERAL,
"Skipping uncannibalizable circuit for v3 "
1981 "rendezvous point.");
1991 SMARTLIST_FOREACH_END(circ_);
2018 if (circuits_upgraded && smartlist_len(result)) {
2021 smartlist_free(result);
2032 if (circ && circ->
cpath) {
2034 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2035 cpath_next = cpath->
next;
2048 if (circ && circ->
cpath) {
2050 for (cpath = circ->
cpath;
2051 cpath->
state == CPATH_STATE_OPEN
2052 && cpath_next != circ->
cpath;
2053 cpath = cpath_next) {
2054 cpath_next = cpath->
next;
2067 if (circ && circ->
cpath && hopnum > 0) {
2069 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2070 cpath_next = cpath->
next;
2087 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
2089 SMARTLIST_FOREACH_END(circ);
2109 SMARTLIST_FOREACH_END(circ);
2133 uint64_t written_sync;
2140 or_circ = CONST_TO_OR_CIRCUIT(c);
2142 if (dir == CIRCUIT_N_CHAN) {
2153 cell_size = get_cell_network_size(chan->wide_circ_ids);
2159 bool is_ipv6 = chan &&
2165 written_sync = cells*(cell_size+TLS_PER_CELL_OVERHEAD);
2193 int orig_reason = reason;
2205 "Duplicate call to circuit_mark_for_close at %s:%d"
2206 " (first at %s:%d)", file, line,
2212 log_warn(
LD_BUG,
"Specified 'at-origin' non-reason for ending circuit, "
2213 "but circuit was not at origin. (called %s:%d, purpose=%d)",
2216 reason = END_CIRC_REASON_NONE;
2226 reason = END_CIRC_REASON_NONE;
2233 reason &= ~END_CIRC_REASON_FLAG_REMOTE;
2235 if (reason < END_CIRC_REASON_MIN_ || reason > END_CIRC_REASON_MAX_) {
2237 log_warn(
LD_BUG,
"Reason %d out of range at %s:%d", reason, file, line);
2238 reason = END_CIRC_REASON_NONE;
2261 if (CIRCUIT_IS_CONFLUX(circ)) {
2282 cc_stats_circs_closed++;
2291 log_info(
LD_GENERAL,
"Circuit %u (id: %" PRIu32
") marked for close at "
2292 "%s:%d (orig reason: %d, new reason: %d)",
2296 file, line, orig_reason, reason);
2297 tor_trace(
TR_SUBSYS(circuit), TR_EV(mark_for_close), circ);
2367 CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED,
2374 if (!CHANNEL_CONDEMNED(circ->
n_chan)) {
2397 conn->
end_reason = END_STREAM_REASON_DESTROY;
2399 connection_mark_for_close(
TO_CONN(conn));
2407 if (!CHANNEL_CONDEMNED(or_circ->
p_chan)) {
2434 log_warn(
LD_BUG,
"Called on non-marked circuit");
2475 result += single_conn_free_bytes(conn);
2477 result += single_conn_free_bytes(conn->
linked_conn);
2535 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&c->
n_chan_cells.head)))
2540 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->
p_chan_cells.head))) {
2556 uint32_t age = 0, age2;
2576 uint32_t age = 0, age2;
2599 CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
2602 CONST_TO_OR_CIRCUIT(c)->n_streams, now);
2614 if (cell_age > data_age)
2632 else if (age_a == age_b)
2638static uint32_t now_ts_for_buf_cmp;
2652 else if (age_a == age_b)
2658#define FRACTION_OF_DATA_TO_RETAIN_ON_OOM 0.90
2671 size_t mem_to_recover;
2672 size_t mem_recovered=0;
2673 int n_circuits_killed=0;
2674 int n_dirconns_killed=0;
2675 int n_edgeconns_killed = 0;
2677 log_notice(
LD_GENERAL,
"We're low on memory (cell queues total alloc:"
2678 " %"TOR_PRIuSZ
" buffer total alloc: %" TOR_PRIuSZ
","
2679 " tor compress total alloc: %" TOR_PRIuSZ
2680 " (zlib: %" TOR_PRIuSZ
", zstd: %" TOR_PRIuSZ
","
2681 " lzma: %" TOR_PRIuSZ
"),"
2682 " rendezvous cache total alloc: %" TOR_PRIuSZ
"). Killing"
2683 " circuits withover-long queues. (This behavior is controlled by"
2684 " MaxMemInQueues.)",
2685 cell_queues_get_total_allocation(),
2686 buf_get_total_allocation(),
2691 hs_cache_get_total_allocation());
2694 FRACTION_OF_DATA_TO_RETAIN_ON_OOM);
2695 if (current_allocation <= mem_target)
2697 mem_to_recover = current_allocation - mem_target;
2705 } SMARTLIST_FOREACH_END(circ);
2714 } SMARTLIST_FOREACH_END(circ);
2717 now_ts_for_buf_cmp = now_ts;
2719 now_ts_for_buf_cmp = 0;
2724 } SMARTLIST_FOREACH_END(conn);
2739 if (conn_age < circ->age_tmp) {
2747 connection_mark_for_close(conn);
2748 mem_recovered += single_conn_free_bytes(conn);
2751 ++n_dirconns_killed;
2753 ++n_edgeconns_killed;
2756 if (mem_recovered >= mem_to_recover)
2757 goto done_recovering_mem;
2766 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
2771 ++n_circuits_killed;
2774 mem_recovered += half_stream_alloc;
2775 mem_recovered += freed;
2778 if (mem_recovered >= mem_to_recover)
2779 goto done_recovering_mem;
2780 } SMARTLIST_FOREACH_END(circ);
2782 done_recovering_mem:
2783 log_notice(
LD_GENERAL,
"Removed %"TOR_PRIuSZ
" bytes by killing %d circuits; "
2784 "%d circuits remain alive. Also killed %d non-linked directory "
2785 "connections. Killed %d edge connections",
2788 smartlist_len(circlist) - n_circuits_killed,
2790 n_edgeconns_killed);
2792 return mem_recovered;
2808 c->
purpose <= CIRCUIT_PURPOSE_MAX_);
2811 origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
2813 or_circ = CONST_TO_OR_CIRCUIT(c);
2826 if (or_circ && or_circ->
p_chan) {
2855 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
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)