52 #define CIRCUITLIST_PRIVATE
53 #define OCIRC_EVENT_PRIVATE
59 #include "feature/client/circpathbias.h"
68 #include "core/or/trace_probes_circuit.h"
98 #include "core/or/channelpadding.h"
118 #include "core/or/or_circuit_st.h"
157 uint64_t cc_stats_circs_closed = 0;
183 CONST_TO_ORIGIN_CIRCUIT(
const circuit_t *x)
197 time_t made_placeholder_at;
207 return a->chan == b->chan && a->circ_id == b->circ_id;
212 static inline unsigned int
217 uintptr_t chan = (uintptr_t) (
void*) a->chan;
219 array[0] = a->circ_id;
222 array[1] = (uint32_t) (chan >> 6);
223 return (
unsigned) siphash24g(array,
sizeof(array));
228 chan_circid_map = HT_INITIALIZER();
246 circuit_set_circid_chan_helper(
circuit_t *circ,
int direction,
254 int make_active, attached = 0;
266 old_chan = *chan_ptr;
267 old_id = *circid_ptr;
269 if (
id == old_id && chan == old_chan)
272 if (_last_circid_chan_ent &&
273 ((old_id == _last_circid_chan_ent->circ_id &&
274 old_chan == _last_circid_chan_ent->chan) ||
275 (
id == _last_circid_chan_ent->circ_id &&
276 chan == _last_circid_chan_ent->chan))) {
277 _last_circid_chan_ent = NULL;
287 if (old_id != 0 && (old_chan != chan || old_id !=
id) &&
294 search.circ_id = old_id;
295 search.chan = old_chan;
296 found = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
304 --(old_chan->num_p_circuits);
320 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
322 found->circuit = circ;
323 found->made_placeholder_at = 0;
328 found->circuit = circ;
329 HT_INSERT(chan_circid_map, &chan_circid_map, found);
337 if (chan &&
id != 0 && (old_chan != chan || old_id !=
id) &&
348 if (make_active && attached)
349 update_circuit_on_cmux(circ, direction);
355 ++chan->num_p_circuits;
370 memset(&search, 0,
sizeof(search));
373 ent = HT_FIND(chan_circid_map, &chan_circid_map, &search);
375 if (ent && ent->circuit) {
377 log_warn(
LD_BUG,
"Tried to mark %u unusable on %p, but there was already "
378 "a circuit there.", (
unsigned)
id, chan);
381 if (!ent->made_placeholder_at)
389 HT_INSERT(chan_circid_map, &chan_circid_map, ent);
403 memset(&search, 0,
sizeof(search));
406 ent = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
407 if (ent && ent->circuit) {
408 log_warn(
LD_BUG,
"Tried to mark %u usable on %p, but there was already "
409 "a circuit there.", (
unsigned)
id, chan);
412 if (_last_circid_chan_ent == ent)
413 _last_circid_chan_ent = NULL;
519 msg->
reason = reason_code;
522 ocirc_cevent_publish(msg);
540 ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
548 ocirc_state_publish(msg);
557 if (state == circ->
state)
580 tor_trace(
TR_SUBSYS(circuit), TR_EV(change_state), circ, circ->
state, state);
614 } SMARTLIST_FOREACH_END(circ);
628 cnt = smartlist_len(sl);
630 log_debug(
LD_CIRC,
"or_conn to %s, %d pending circs",
685 if (idx < smartlist_len(lst)) {
686 circuit_t *replacement = smartlist_get(lst, idx);
698 } SMARTLIST_FOREACH_END(circ);
733 if (!
TO_CIRCUIT(next_circ)->marked_for_close &&
734 next_circ->has_opened &&
737 next_circ->build_state &&
742 } SMARTLIST_FOREACH_END(next_circ);
784 log_warn(
LD_BUG,
"Unknown circuit state %d", state);
785 tor_snprintf(buf,
sizeof(buf),
"unknown state [%d]", state);
807 return "HS_CLIENT_HSDIR";
812 return "HS_CLIENT_INTRO";
818 return "HS_CLIENT_REND";
821 return "HS_SERVICE_HSDIR";
825 return "HS_SERVICE_INTRO";
829 return "HS_SERVICE_REND";
834 return "MEASURE_TIMEOUT";
838 return "PATH_BIAS_TESTING";
840 return "HS_VANGUARDS";
842 return "CIRCUIT_PADDING";
845 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
860 "Unrecognized circuit purpose: %d",
876 return "OR_HSSI_ESTABLISHED";
878 return "OR_HSCR_ESTABLISHED";
880 return "OR_HS_R_JOINED";
884 return "HSCI_CONNECTING";
886 return "HSCI_INTRO_SENT";
891 return "HSCR_CONNECTING";
893 return "HSCR_ESTABLISHED_IDLE";
895 return "HSCR_ESTABLISHED_WAITING";
897 return "HSCR_JOINED";
901 return "HSSI_CONNECTING";
903 return "HSSI_ESTABLISHED";
906 return "HSSR_CONNECTING";
908 return "HSSR_JOINED";
921 return "Circuit at relay";
923 return "Acting as intro point";
925 return "Acting as rendezvous (pending)";
927 return "Acting as rendezvous (established)";
929 return "General-purpose client";
931 return "Hidden service client: Connecting to intro point";
933 return "Hidden service client: Waiting for ack from intro point";
935 return "Hidden service client: Received ack from intro point";
937 return "Hidden service client: Establishing rendezvous point";
939 return "Hidden service client: Pending rendezvous point";
941 return "Hidden service client: Pending rendezvous point (ack received)";
943 return "Hidden service client: Active rendezvous point";
945 return "Hidden service client: Fetching HS descriptor";
948 return "Measuring circuit timeout";
951 return "Hidden service: Establishing introduction point";
953 return "Hidden service: Introduction point";
955 return "Hidden service: Connecting to rendezvous point";
957 return "Hidden service: Active rendezvous point";
959 return "Hidden service: Uploading HS descriptor";
962 return "Testing circuit";
965 return "Circuit made by controller";
968 return "Path-bias testing circuit";
971 return "Hidden service: Pre-built vanguard circuit";
974 return "Circuit kept open for padding";
977 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
989 CIRCWINDOW_START_MIN,
990 CIRCWINDOW_START_MAX);
1021 #define DFLT_IDLE_TIMEOUT_WHILE_LEARNING (3*60)
1022 #define MIN_IDLE_TIMEOUT_WHILE_LEARNING (10)
1023 #define MAX_IDLE_TIMEOUT_WHILE_LEARNING (1000*60)
1034 static uint32_t n_circuits_allocated = 1;
1059 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1060 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1069 int prediction_time_remaining =
1076 "Circuit chose a negative idle timeout of %d based on "
1077 "%d seconds of predictive building remaining.",
1079 prediction_time_remaining);
1083 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1084 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1088 "Circuit %"PRIu32
" chose an idle timeout of %d based on "
1089 "%d seconds of predictive building remaining.",
1092 prediction_time_remaining);
1095 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_origin), circ);
1118 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_or), circ);
1142 int should_free = 1;
1170 half_edge_free(half_conn);
1171 } SMARTLIST_FOREACH_END(half_conn);
1188 crypto_pk_free(ocirc->intro_key);
1192 hs_ident_circuit_free(ocirc->
hs_ident);
1196 if (ocirc->socks_username) {
1197 memwipe(ocirc->socks_username, 0x12, ocirc->socks_username_len);
1200 if (ocirc->socks_password) {
1201 memwipe(ocirc->socks_password, 0x06, ocirc->socks_password_len);
1232 extend_info_free(circ->
n_hop);
1259 log_info(
LD_CIRC,
"Circuit %u (id: %" PRIu32
") has been freed.",
1268 circuit_handles_clear(circ);
1272 tor_trace(
TR_SUBSYS(circuit), TR_EV(free), circ);
1295 head = cpath = circ->
cpath;
1302 while (cpath->
next && cpath->
next != head) {
1304 cpath = victim->
next;
1329 tmp->global_circuitlist_idx = -1;
1333 } SMARTLIST_FOREACH_END(tmp);
1335 smartlist_free(lst);
1352 for (elt = HT_START(chan_circid_map, &chan_circid_map);
1356 next = HT_NEXT_RMV(chan_circid_map, &chan_circid_map, elt);
1362 HT_CLEAR(chan_circid_map, &chan_circid_map);
1371 int conn_array_index,
1377 "(other side %u), state %d (%s), born %ld:",
1378 conn_array_index, type, (
unsigned)this_circid, (
unsigned)other_circid,
1408 if (
TO_CONN(tmpconn) == conn) {
1410 "App-ward", p_circ_id, n_circ_id);
1418 if (
TO_CONN(tmpconn) == conn) {
1420 "Exit-ward", n_circ_id, p_circ_id);
1425 SMARTLIST_FOREACH_END(circ);
1442 SMARTLIST_FOREACH_END(circ);
1456 int *found_entry_out)
1461 if (_last_circid_chan_ent &&
1462 circ_id == _last_circid_chan_ent->circ_id &&
1463 chan == _last_circid_chan_ent->chan) {
1464 found = _last_circid_chan_ent;
1466 search.circ_id = circ_id;
1468 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1469 _last_circid_chan_ent = found;
1471 if (found && found->circuit) {
1473 "circuit_get_by_circid_channel_impl() returning circuit %p for"
1474 " circ_id %u, channel ID %"PRIu64
" (%p)",
1475 found->circuit, (
unsigned)circ_id,
1477 if (found_entry_out)
1478 *found_entry_out = 1;
1479 return found->circuit;
1483 "circuit_get_by_circid_channel_impl() found %s for"
1484 " circ_id %u, channel ID %"PRIu64
" (%p)",
1485 found ?
"placeholder" :
"nothing",
1489 if (found_entry_out)
1490 *found_entry_out = found ? 1 : 0;
1570 memset(&search, 0,
sizeof(search));
1571 search.circ_id = circ_id;
1574 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1576 if (! found || found->circuit)
1579 return found->made_placeholder_at;
1609 #ifdef DEBUG_CIRCUIT_UNLINK_ALL
1612 int mismatch = 0, badlen = 0;
1615 if (circ->
n_chan == chan ||
1621 SMARTLIST_FOREACH_END(circ);
1623 if (smartlist_len(detached) != smartlist_len(detached_2)) {
1624 log_warn(
LD_BUG,
"List of detached circuits had the wrong length! "
1625 "(got %d, should have gotten %d)",
1626 (
int)smartlist_len(detached),
1627 (
int)smartlist_len(detached_2));
1634 if (c != smartlist_get(detached_2, c_sl_idx))
1639 log_warn(
LD_BUG,
"Mismatch in list of detached circuits.");
1641 if (badlen || mismatch) {
1642 smartlist_free(detached);
1643 detached = detached_2;
1645 log_notice(
LD_CIRC,
"List of %d circuits was as expected.",
1646 (
int)smartlist_len(detached));
1647 smartlist_free(detached_2);
1654 if (circ->
n_chan == chan) {
1666 if (or_circ->
p_chan == chan) {
1672 log_warn(
LD_BUG,
"Circuit on detached list which I had no reason "
1677 circuit_mark_for_close(circ, reason);
1678 } SMARTLIST_FOREACH_END(circ);
1680 smartlist_free(detached);
1700 bool want_client_circ)
1706 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1709 for ( ; idx < smartlist_len(lst); ++idx) {
1710 circuit_t *circ = smartlist_get(lst, idx);
1719 if (want_client_circ) {
1757 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1760 for ( ; idx < smartlist_len(lst); ++idx) {
1761 circuit_t *circ = smartlist_get(lst, idx);
1790 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1792 for ( ; idx < smartlist_len(lst); ++idx) {
1793 circuit_t *circ = smartlist_get(lst, idx);
1819 if (BUG(!chosen_exit)) {
1877 int purpose_to_search_for;
1884 purpose_to_produce);
1890 "Hunting for a circ to cannibalize: purpose %d, uptime %d, "
1891 "capacity %d, internal %d",
1892 purpose_to_produce, need_uptime, need_capacity,
internal);
1897 !circ_->marked_for_close &&
1898 circ_->purpose == purpose_to_search_for &&
1899 !circ_->timestamp_dirty) {
1921 !circ->unusable_for_new_conns &&
1939 }
while (hop!=circ->
cpath);
1952 }
while (hop != circ->
cpath);
1957 log_debug(
LD_GENERAL,
"Skipping uncannibalizable circuit for v3 "
1958 "rendezvous point.");
1968 SMARTLIST_FOREACH_END(circ_);
1995 if (circuits_upgraded && smartlist_len(result)) {
1998 smartlist_free(result);
2009 if (circ && circ->
cpath) {
2011 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2012 cpath_next = cpath->
next;
2025 if (circ && circ->
cpath) {
2027 for (cpath = circ->
cpath;
2028 cpath->
state == CPATH_STATE_OPEN
2029 && cpath_next != circ->
cpath;
2030 cpath = cpath_next) {
2031 cpath_next = cpath->
next;
2044 if (circ && circ->
cpath && hopnum > 0) {
2046 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2047 cpath_next = cpath->
next;
2064 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
2066 SMARTLIST_FOREACH_END(circ);
2086 SMARTLIST_FOREACH_END(circ);
2110 uint64_t written_sync;
2117 or_circ = CONST_TO_OR_CIRCUIT(c);
2119 if (dir == CIRCUIT_N_CHAN) {
2130 cell_size = get_cell_network_size(chan->wide_circ_ids);
2136 bool is_ipv6 = chan &&
2142 written_sync = cells*(cell_size+TLS_PER_CELL_OVERHEAD);
2170 int orig_reason = reason;
2182 "Duplicate call to circuit_mark_for_close at %s:%d"
2183 " (first at %s:%d)", file, line,
2189 log_warn(
LD_BUG,
"Specified 'at-origin' non-reason for ending circuit, "
2190 "but circuit was not at origin. (called %s:%d, purpose=%d)",
2193 reason = END_CIRC_REASON_NONE;
2203 reason = END_CIRC_REASON_NONE;
2212 if (reason < END_CIRC_REASON_MIN_ || reason > END_CIRC_REASON_MAX_) {
2214 log_warn(
LD_BUG,
"Reason %d out of range at %s:%d", reason, file, line);
2215 reason = END_CIRC_REASON_NONE;
2254 cc_stats_circs_closed++;
2263 log_info(
LD_GENERAL,
"Circuit %u (id: %" PRIu32
") marked for close at "
2264 "%s:%d (orig reason: %d, new reason: %d)",
2268 file, line, orig_reason, reason);
2269 tor_trace(
TR_SUBSYS(circuit), TR_EV(mark_for_close), circ);
2334 CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED,
2341 if (!CHANNEL_CONDEMNED(circ->
n_chan)) {
2363 conn->
end_reason = END_STREAM_REASON_DESTROY;
2365 connection_mark_for_close(
TO_CONN(conn));
2373 if (!CHANNEL_CONDEMNED(or_circ->
p_chan)) {
2400 log_warn(
LD_BUG,
"Called on non-marked circuit");
2441 result += single_conn_free_bytes(conn);
2443 result += single_conn_free_bytes(conn->
linked_conn);
2501 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&c->
n_chan_cells.head)))
2506 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->
p_chan_cells.head))) {
2522 uint32_t age = 0, age2;
2542 uint32_t age = 0, age2;
2565 CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
2568 CONST_TO_OR_CIRCUIT(c)->n_streams, now);
2580 if (cell_age > data_age)
2598 else if (age_a == age_b)
2604 static uint32_t now_ts_for_buf_cmp;
2618 else if (age_a == age_b)
2624 #define FRACTION_OF_DATA_TO_RETAIN_ON_OOM 0.90
2637 size_t mem_to_recover;
2638 size_t mem_recovered=0;
2639 int n_circuits_killed=0;
2640 int n_dirconns_killed=0;
2641 int n_edgeconns_killed = 0;
2643 log_notice(
LD_GENERAL,
"We're low on memory (cell queues total alloc:"
2644 " %"TOR_PRIuSZ
" buffer total alloc: %" TOR_PRIuSZ
","
2645 " tor compress total alloc: %" TOR_PRIuSZ
2646 " (zlib: %" TOR_PRIuSZ
", zstd: %" TOR_PRIuSZ
","
2647 " lzma: %" TOR_PRIuSZ
"),"
2648 " rendezvous cache total alloc: %" TOR_PRIuSZ
"). Killing"
2649 " circuits withover-long queues. (This behavior is controlled by"
2650 " MaxMemInQueues.)",
2651 cell_queues_get_total_allocation(),
2652 buf_get_total_allocation(),
2657 hs_cache_get_total_allocation());
2660 FRACTION_OF_DATA_TO_RETAIN_ON_OOM);
2661 if (current_allocation <= mem_target)
2663 mem_to_recover = current_allocation - mem_target;
2671 } SMARTLIST_FOREACH_END(circ);
2680 } SMARTLIST_FOREACH_END(circ);
2683 now_ts_for_buf_cmp = now_ts;
2685 now_ts_for_buf_cmp = 0;
2690 } SMARTLIST_FOREACH_END(conn);
2705 if (conn_age < circ->age_tmp) {
2713 connection_mark_for_close(conn);
2714 mem_recovered += single_conn_free_bytes(conn);
2717 ++n_dirconns_killed;
2719 ++n_edgeconns_killed;
2722 if (mem_recovered >= mem_to_recover)
2723 goto done_recovering_mem;
2732 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
2737 ++n_circuits_killed;
2740 mem_recovered += half_stream_alloc;
2741 mem_recovered += freed;
2743 if (mem_recovered >= mem_to_recover)
2744 goto done_recovering_mem;
2745 } SMARTLIST_FOREACH_END(circ);
2747 done_recovering_mem:
2748 log_notice(
LD_GENERAL,
"Removed %"TOR_PRIuSZ
" bytes by killing %d circuits; "
2749 "%d circuits remain alive. Also killed %d non-linked directory "
2750 "connections. Killed %d edge connections",
2753 smartlist_len(circlist) - n_circuits_killed,
2755 n_edgeconns_killed);
2757 return mem_recovered;
2773 c->
purpose <= CIRCUIT_PURPOSE_MAX_);
2776 origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
2778 or_circ = CONST_TO_OR_CIRCUIT(c);
2791 if (or_circ && or_circ->
p_chan) {
2820 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)
double cc_stats_circ_close_ss_cwnd_ma
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)
double cc_stats_circ_close_cwnd_ma
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)
bool circuit_is_queue_full(const circuit_t *circ, cell_direction_t direction)
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.
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_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)
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)