52 #define CIRCUITLIST_PRIVATE
53 #define OCIRC_EVENT_PRIVATE
59 #include "feature/client/circpathbias.h"
67 #include "core/or/trace_probes_circuit.h"
97 #include "core/or/channelpadding.h"
114 #include "core/or/or_circuit_st.h"
172 CONST_TO_ORIGIN_CIRCUIT(
const circuit_t *x)
186 time_t made_placeholder_at;
196 return a->chan == b->chan && a->circ_id == b->circ_id;
201 static inline unsigned int
206 uintptr_t chan = (uintptr_t) (
void*) a->chan;
208 array[0] = a->circ_id;
211 array[1] = (uint32_t) (chan >> 6);
212 return (
unsigned) siphash24g(array,
sizeof(array));
217 chan_circid_map = HT_INITIALIZER();
235 circuit_set_circid_chan_helper(
circuit_t *circ,
int direction,
243 int make_active, attached = 0;
255 old_chan = *chan_ptr;
256 old_id = *circid_ptr;
258 if (
id == old_id && chan == old_chan)
261 if (_last_circid_chan_ent &&
262 ((old_id == _last_circid_chan_ent->circ_id &&
263 old_chan == _last_circid_chan_ent->chan) ||
264 (
id == _last_circid_chan_ent->circ_id &&
265 chan == _last_circid_chan_ent->chan))) {
266 _last_circid_chan_ent = NULL;
276 if (old_id != 0 && (old_chan != chan || old_id !=
id) &&
283 search.circ_id = old_id;
284 search.chan = old_chan;
285 found = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
293 --(old_chan->num_p_circuits);
309 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
311 found->circuit = circ;
312 found->made_placeholder_at = 0;
317 found->circuit = circ;
318 HT_INSERT(chan_circid_map, &chan_circid_map, found);
326 if (chan &&
id != 0 && (old_chan != chan || old_id !=
id) &&
337 if (make_active && attached)
338 update_circuit_on_cmux(circ, direction);
344 ++chan->num_p_circuits;
359 memset(&search, 0,
sizeof(search));
362 ent = HT_FIND(chan_circid_map, &chan_circid_map, &search);
364 if (ent && ent->circuit) {
366 log_warn(
LD_BUG,
"Tried to mark %u unusable on %p, but there was already "
367 "a circuit there.", (
unsigned)
id, chan);
370 if (!ent->made_placeholder_at)
378 HT_INSERT(chan_circid_map, &chan_circid_map, ent);
392 memset(&search, 0,
sizeof(search));
395 ent = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
396 if (ent && ent->circuit) {
397 log_warn(
LD_BUG,
"Tried to mark %u usable on %p, but there was already "
398 "a circuit there.", (
unsigned)
id, chan);
401 if (_last_circid_chan_ent == ent)
402 _last_circid_chan_ent = NULL;
508 msg->
reason = reason_code;
511 ocirc_cevent_publish(msg);
529 ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
537 ocirc_state_publish(msg);
546 if (state == circ->
state)
569 tor_trace(
TR_SUBSYS(circuit), TR_EV(change_state), circ, circ->
state, state);
603 } SMARTLIST_FOREACH_END(circ);
617 cnt = smartlist_len(sl);
619 log_debug(
LD_CIRC,
"or_conn to %s, %d pending circs",
674 if (idx < smartlist_len(lst)) {
675 circuit_t *replacement = smartlist_get(lst, idx);
687 } SMARTLIST_FOREACH_END(circ);
722 if (!
TO_CIRCUIT(next_circ)->marked_for_close &&
723 next_circ->has_opened &&
726 next_circ->build_state &&
731 } SMARTLIST_FOREACH_END(next_circ);
773 log_warn(
LD_BUG,
"Unknown circuit state %d", state);
774 tor_snprintf(buf,
sizeof(buf),
"unknown state [%d]", state);
796 return "HS_CLIENT_HSDIR";
801 return "HS_CLIENT_INTRO";
807 return "HS_CLIENT_REND";
810 return "HS_SERVICE_HSDIR";
814 return "HS_SERVICE_INTRO";
818 return "HS_SERVICE_REND";
823 return "MEASURE_TIMEOUT";
827 return "PATH_BIAS_TESTING";
829 return "HS_VANGUARDS";
831 return "CIRCUIT_PADDING";
834 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
849 "Unrecognized circuit purpose: %d",
865 return "OR_HSSI_ESTABLISHED";
867 return "OR_HSCR_ESTABLISHED";
869 return "OR_HS_R_JOINED";
873 return "HSCI_CONNECTING";
875 return "HSCI_INTRO_SENT";
880 return "HSCR_CONNECTING";
882 return "HSCR_ESTABLISHED_IDLE";
884 return "HSCR_ESTABLISHED_WAITING";
886 return "HSCR_JOINED";
890 return "HSSI_CONNECTING";
892 return "HSSI_ESTABLISHED";
895 return "HSSR_CONNECTING";
897 return "HSSR_JOINED";
910 return "Circuit at relay";
912 return "Acting as intro point";
914 return "Acting as rendezvous (pending)";
916 return "Acting as rendezvous (established)";
918 return "General-purpose client";
920 return "Hidden service client: Connecting to intro point";
922 return "Hidden service client: Waiting for ack from intro point";
924 return "Hidden service client: Received ack from intro point";
926 return "Hidden service client: Establishing rendezvous point";
928 return "Hidden service client: Pending rendezvous point";
930 return "Hidden service client: Pending rendezvous point (ack received)";
932 return "Hidden service client: Active rendezvous point";
934 return "Hidden service client: Fetching HS descriptor";
937 return "Measuring circuit timeout";
940 return "Hidden service: Establishing introduction point";
942 return "Hidden service: Introduction point";
944 return "Hidden service: Connecting to rendezvous point";
946 return "Hidden service: Active rendezvous point";
948 return "Hidden service: Uploading HS descriptor";
951 return "Testing circuit";
954 return "Circuit made by controller";
957 return "Path-bias testing circuit";
960 return "Hidden service: Pre-built vanguard circuit";
963 return "Circuit kept open for padding";
966 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
978 CIRCWINDOW_START_MIN,
979 CIRCWINDOW_START_MAX);
1010 #define DFLT_IDLE_TIMEOUT_WHILE_LEARNING (3*60)
1011 #define MIN_IDLE_TIMEOUT_WHILE_LEARNING (10)
1012 #define MAX_IDLE_TIMEOUT_WHILE_LEARNING (1000*60)
1023 static uint32_t n_circuits_allocated = 1;
1048 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1049 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1058 int prediction_time_remaining =
1065 "Circuit chose a negative idle timeout of %d based on "
1066 "%d seconds of predictive building remaining.",
1068 prediction_time_remaining);
1072 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1073 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1077 "Circuit %"PRIu32
" chose an idle timeout of %d based on "
1078 "%d seconds of predictive building remaining.",
1081 prediction_time_remaining);
1084 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_origin), circ);
1107 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_or), circ);
1131 int should_free = 1;
1157 half_edge_free(half_conn);
1158 } SMARTLIST_FOREACH_END(half_conn);
1175 crypto_pk_free(ocirc->intro_key);
1179 hs_ident_circuit_free(ocirc->
hs_ident);
1183 if (ocirc->socks_username) {
1184 memwipe(ocirc->socks_username, 0x12, ocirc->socks_username_len);
1187 if (ocirc->socks_password) {
1188 memwipe(ocirc->socks_password, 0x06, ocirc->socks_password_len);
1219 extend_info_free(circ->
n_hop);
1246 log_info(
LD_CIRC,
"Circuit %u (id: %" PRIu32
") has been freed.",
1255 circuit_handles_clear(circ);
1259 tor_trace(
TR_SUBSYS(circuit), TR_EV(free), circ);
1282 head = cpath = circ->
cpath;
1289 while (cpath->
next && cpath->
next != head) {
1291 cpath = victim->
next;
1316 tmp->global_circuitlist_idx = -1;
1320 } SMARTLIST_FOREACH_END(tmp);
1322 smartlist_free(lst);
1339 for (elt = HT_START(chan_circid_map, &chan_circid_map);
1343 next = HT_NEXT_RMV(chan_circid_map, &chan_circid_map, elt);
1349 HT_CLEAR(chan_circid_map, &chan_circid_map);
1358 int conn_array_index,
1364 "(other side %u), state %d (%s), born %ld:",
1365 conn_array_index, type, (
unsigned)this_circid, (
unsigned)other_circid,
1395 if (
TO_CONN(tmpconn) == conn) {
1397 "App-ward", p_circ_id, n_circ_id);
1405 if (
TO_CONN(tmpconn) == conn) {
1407 "Exit-ward", n_circ_id, p_circ_id);
1412 SMARTLIST_FOREACH_END(circ);
1429 SMARTLIST_FOREACH_END(circ);
1443 int *found_entry_out)
1448 if (_last_circid_chan_ent &&
1449 circ_id == _last_circid_chan_ent->circ_id &&
1450 chan == _last_circid_chan_ent->chan) {
1451 found = _last_circid_chan_ent;
1453 search.circ_id = circ_id;
1455 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1456 _last_circid_chan_ent = found;
1458 if (found && found->circuit) {
1460 "circuit_get_by_circid_channel_impl() returning circuit %p for"
1461 " circ_id %u, channel ID %"PRIu64
" (%p)",
1462 found->circuit, (
unsigned)circ_id,
1464 if (found_entry_out)
1465 *found_entry_out = 1;
1466 return found->circuit;
1470 "circuit_get_by_circid_channel_impl() found %s for"
1471 " circ_id %u, channel ID %"PRIu64
" (%p)",
1472 found ?
"placeholder" :
"nothing",
1476 if (found_entry_out)
1477 *found_entry_out = found ? 1 : 0;
1557 memset(&search, 0,
sizeof(search));
1558 search.circ_id = circ_id;
1561 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1563 if (! found || found->circuit)
1566 return found->made_placeholder_at;
1596 #ifdef DEBUG_CIRCUIT_UNLINK_ALL
1599 int mismatch = 0, badlen = 0;
1602 if (circ->
n_chan == chan ||
1608 SMARTLIST_FOREACH_END(circ);
1610 if (smartlist_len(detached) != smartlist_len(detached_2)) {
1611 log_warn(
LD_BUG,
"List of detached circuits had the wrong length! "
1612 "(got %d, should have gotten %d)",
1613 (
int)smartlist_len(detached),
1614 (
int)smartlist_len(detached_2));
1621 if (c != smartlist_get(detached_2, c_sl_idx))
1626 log_warn(
LD_BUG,
"Mismatch in list of detached circuits.");
1628 if (badlen || mismatch) {
1629 smartlist_free(detached);
1630 detached = detached_2;
1632 log_notice(
LD_CIRC,
"List of %d circuits was as expected.",
1633 (
int)smartlist_len(detached));
1634 smartlist_free(detached_2);
1641 if (circ->
n_chan == chan) {
1653 if (or_circ->
p_chan == chan) {
1659 log_warn(
LD_BUG,
"Circuit on detached list which I had no reason "
1664 circuit_mark_for_close(circ, reason);
1665 } SMARTLIST_FOREACH_END(circ);
1667 smartlist_free(detached);
1687 bool want_client_circ)
1693 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1696 for ( ; idx < smartlist_len(lst); ++idx) {
1697 circuit_t *circ = smartlist_get(lst, idx);
1706 if (want_client_circ) {
1744 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1747 for ( ; idx < smartlist_len(lst); ++idx) {
1748 circuit_t *circ = smartlist_get(lst, idx);
1777 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1779 for ( ; idx < smartlist_len(lst); ++idx) {
1780 circuit_t *circ = smartlist_get(lst, idx);
1806 if (BUG(!chosen_exit)) {
1864 int purpose_to_search_for;
1871 purpose_to_produce);
1877 "Hunting for a circ to cannibalize: purpose %d, uptime %d, "
1878 "capacity %d, internal %d",
1879 purpose_to_produce, need_uptime, need_capacity,
internal);
1884 !circ_->marked_for_close &&
1885 circ_->purpose == purpose_to_search_for &&
1886 !circ_->timestamp_dirty) {
1908 !circ->unusable_for_new_conns &&
1926 }
while (hop!=circ->
cpath);
1939 }
while (hop != circ->
cpath);
1944 log_debug(
LD_GENERAL,
"Skipping uncannibalizable circuit for v3 "
1945 "rendezvous point.");
1955 SMARTLIST_FOREACH_END(circ_);
1982 if (circuits_upgraded && smartlist_len(result)) {
1985 smartlist_free(result);
1996 if (circ && circ->
cpath) {
1998 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
1999 cpath_next = cpath->
next;
2012 if (circ && circ->
cpath) {
2014 for (cpath = circ->
cpath;
2015 cpath->
state == CPATH_STATE_OPEN
2016 && cpath_next != circ->
cpath;
2017 cpath = cpath_next) {
2018 cpath_next = cpath->
next;
2031 if (circ && circ->
cpath && hopnum > 0) {
2033 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2034 cpath_next = cpath->
next;
2051 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
2053 SMARTLIST_FOREACH_END(circ);
2073 SMARTLIST_FOREACH_END(circ);
2097 uint64_t written_sync;
2104 or_circ = CONST_TO_OR_CIRCUIT(c);
2106 if (dir == CIRCUIT_N_CHAN) {
2117 cell_size = get_cell_network_size(chan->wide_circ_ids);
2123 bool is_ipv6 = chan &&
2129 written_sync = cells*(cell_size+TLS_PER_CELL_OVERHEAD);
2157 int orig_reason = reason;
2169 "Duplicate call to circuit_mark_for_close at %s:%d"
2170 " (first at %s:%d)", file, line,
2176 log_warn(
LD_BUG,
"Specified 'at-origin' non-reason for ending circuit, "
2177 "but circuit was not at origin. (called %s:%d, purpose=%d)",
2180 reason = END_CIRC_REASON_NONE;
2190 reason = END_CIRC_REASON_NONE;
2199 if (reason < END_CIRC_REASON_MIN_ || reason > END_CIRC_REASON_MAX_) {
2201 log_warn(
LD_BUG,
"Reason %d out of range at %s:%d", reason, file, line);
2202 reason = END_CIRC_REASON_NONE;
2230 log_info(
LD_GENERAL,
"Circuit %u (id: %" PRIu32
") marked for close at "
2231 "%s:%d (orig reason: %d, new reason: %d)",
2235 file, line, orig_reason, reason);
2236 tor_trace(
TR_SUBSYS(circuit), TR_EV(mark_for_close), circ);
2301 CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED,
2308 if (!CHANNEL_CONDEMNED(circ->
n_chan)) {
2330 conn->
end_reason = END_STREAM_REASON_DESTROY;
2332 connection_mark_for_close(
TO_CONN(conn));
2340 if (!CHANNEL_CONDEMNED(or_circ->
p_chan)) {
2361 log_warn(
LD_BUG,
"Called on non-marked circuit");
2402 result += single_conn_free_bytes(conn);
2404 result += single_conn_free_bytes(conn->
linked_conn);
2462 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&c->
n_chan_cells.head)))
2467 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->
p_chan_cells.head))) {
2483 uint32_t age = 0, age2;
2503 uint32_t age = 0, age2;
2526 CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
2529 CONST_TO_OR_CIRCUIT(c)->n_streams, now);
2541 if (cell_age > data_age)
2559 else if (age_a == age_b)
2565 static uint32_t now_ts_for_buf_cmp;
2579 else if (age_a == age_b)
2585 #define FRACTION_OF_DATA_TO_RETAIN_ON_OOM 0.90
2598 size_t mem_to_recover;
2599 size_t mem_recovered=0;
2600 int n_circuits_killed=0;
2601 int n_dirconns_killed=0;
2603 log_notice(
LD_GENERAL,
"We're low on memory (cell queues total alloc:"
2604 " %"TOR_PRIuSZ
" buffer total alloc: %" TOR_PRIuSZ
","
2605 " tor compress total alloc: %" TOR_PRIuSZ
2606 " (zlib: %" TOR_PRIuSZ
", zstd: %" TOR_PRIuSZ
","
2607 " lzma: %" TOR_PRIuSZ
"),"
2608 " rendezvous cache total alloc: %" TOR_PRIuSZ
"). Killing"
2609 " circuits withover-long queues. (This behavior is controlled by"
2610 " MaxMemInQueues.)",
2611 cell_queues_get_total_allocation(),
2612 buf_get_total_allocation(),
2617 hs_cache_get_total_allocation());
2620 FRACTION_OF_DATA_TO_RETAIN_ON_OOM);
2621 if (current_allocation <= mem_target)
2623 mem_to_recover = current_allocation - mem_target;
2631 } SMARTLIST_FOREACH_END(circ);
2640 } SMARTLIST_FOREACH_END(circ);
2643 now_ts_for_buf_cmp = now_ts;
2645 now_ts_for_buf_cmp = 0;
2650 } SMARTLIST_FOREACH_END(conn);
2665 if (conn_age < circ->age_tmp) {
2670 connection_mark_for_close(conn);
2671 mem_recovered += single_conn_free_bytes(conn);
2673 ++n_dirconns_killed;
2675 if (mem_recovered >= mem_to_recover)
2676 goto done_recovering_mem;
2685 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
2690 ++n_circuits_killed;
2693 mem_recovered += half_stream_alloc;
2694 mem_recovered += freed;
2696 if (mem_recovered >= mem_to_recover)
2697 goto done_recovering_mem;
2698 } SMARTLIST_FOREACH_END(circ);
2700 done_recovering_mem:
2701 log_notice(
LD_GENERAL,
"Removed %"TOR_PRIuSZ
" bytes by killing %d circuits; "
2702 "%d circuits remain alive. Also killed %d non-linked directory "
2706 smartlist_len(circlist) - n_circuits_killed,
2709 return mem_recovered;
2725 c->
purpose <= CIRCUIT_PURPOSE_MAX_);
2728 origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
2730 or_circ = CONST_TO_OR_CIRCUIT(c);
2743 if (or_circ && or_circ->
p_chan) {
2772 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 uint32_t circuit_max_queued_item_age(const circuit_t *c, uint32_t now)
const char * circuit_purpose_to_controller_hs_state_string(uint8_t purpose)
static int chan_circid_entries_eq_(chan_circid_circuit_map_t *a, chan_circid_circuit_map_t *b)
circuit_t * circuit_get_by_circid_channel_even_if_marked(circid_t circ_id, channel_t *chan)
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)
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
origin_circuit_t * circuit_get_next_intro_circ(const origin_circuit_t *start, bool want_client_circ)
void circuit_set_p_circid_chan(or_circuit_t *or_circ, circid_t id, channel_t *chan)
origin_circuit_t * circuit_find_to_cannibalize(uint8_t purpose_to_produce, extend_info_t *info, int flags)
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)
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)
static void init_circuit_base(circuit_t *circ)
circuit_t * circuit_get_by_circid_channel(circid_t circ_id, channel_t *chan)
static uint32_t conn_get_buffer_age(const connection_t *conn, uint32_t now_ts)
void circuit_mark_all_dirty_circs_as_unusable(void)
origin_circuit_t * origin_circuit_new(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)
origin_circuit_t * circuit_get_next_by_purpose(origin_circuit_t *start, uint8_t purpose)
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
const char * circuit_purpose_to_string(uint8_t purpose)
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)
const char * circuit_purpose_to_controller_string(uint8_t purpose)
STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now)
int circuit_get_cpath_len(origin_circuit_t *circ)
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
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)
void assert_circuit_ok(const circuit_t *c)
smartlist_t * circuit_get_global_list(void)
static void circuit_remove_from_origin_circuit_list(origin_circuit_t *origin_circ)
static smartlist_t * circuits_pending_other_guards
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)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
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)
smartlist_t * circuit_get_global_origin_circuit_list(void)
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)
crypt_path_t * circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum)
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)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
void circuit_cache_opened_circuit_state(int circuits_are_opened)
origin_circuit_t * circuit_get_next_service_rp_circ(origin_circuit_t *start)
#define DFLT_IDLE_TIMEOUT_WHILE_LEARNING
static void circuit_add_to_origin_circuit_list(origin_circuit_t *origin_circ)
static smartlist_t * circuits_pending_chans
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)
const char * circuit_state_to_string(int state)
void circuit_clear_testing_cell_stats(circuit_t *circ)
static size_t circuit_alloc_in_half_streams(const circuit_t *c)
static circuit_t * circuit_get_by_circid_channel_impl(circid_t circ_id, channel_t *chan, int *found_entry_out)
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)
or_circuit_t * or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
static smartlist_t * global_origin_circuit_list
origin_circuit_t * circuit_get_by_global_id(uint32_t id)
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_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.
const circuit_build_times_t * get_circuit_build_times(void)
int circuit_build_times_disabled(const or_options_t *options)
circuit_build_times_t * get_circuit_build_times_mutable(void)
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.
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_free_(void *mem)
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
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.
bool node_supports_v3_rendezvous_point(const node_t *node)
const node_t * node_get_by_id(const char *identity_digest)
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)
smartlist_t * smartlist_new(void)
int smartlist_contains(const smartlist_t *sl, const void *element)
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)
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 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
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)