52#define CIRCUITLIST_PRIVATE
53#define OCIRC_EVENT_PRIVATE
59#include "feature/client/circpathbias.h"
68#include "core/or/dos.h"
71#include "core/or/trace_probes_circuit.h"
101#include "core/or/channelpadding.h"
121#include "core/or/or_circuit_st.h"
161uint64_t cc_stats_circs_closed = 0;
191CONST_TO_ORIGIN_CIRCUIT(
const circuit_t *x)
205 time_t made_placeholder_at;
215 return a->chan == b->chan && a->circ_id == b->circ_id;
220static inline unsigned int
225 uintptr_t chan = (uintptr_t) (
void*) a->chan;
227 array[0] = a->circ_id;
230 array[1] = (uint32_t) (chan >> 6);
231 return (
unsigned) siphash24g(array,
sizeof(array));
236 chan_circid_map = HT_INITIALIZER();
254circuit_set_circid_chan_helper(
circuit_t *circ,
int direction,
262 int make_active, attached = 0;
274 old_chan = *chan_ptr;
275 old_id = *circid_ptr;
277 if (
id == old_id && chan == old_chan)
280 if (_last_circid_chan_ent &&
281 ((old_id == _last_circid_chan_ent->circ_id &&
282 old_chan == _last_circid_chan_ent->chan) ||
283 (
id == _last_circid_chan_ent->circ_id &&
284 chan == _last_circid_chan_ent->chan))) {
285 _last_circid_chan_ent = NULL;
295 if (old_id != 0 && (old_chan != chan || old_id !=
id) &&
302 search.circ_id = old_id;
303 search.chan = old_chan;
304 found = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
312 --(old_chan->num_p_circuits);
328 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
330 found->circuit = circ;
331 found->made_placeholder_at = 0;
336 found->circuit = circ;
337 HT_INSERT(chan_circid_map, &chan_circid_map, found);
345 if (chan &&
id != 0 && (old_chan != chan || old_id !=
id) &&
356 if (make_active && attached)
357 update_circuit_on_cmux(circ, direction);
363 ++chan->num_p_circuits;
378 memset(&search, 0,
sizeof(search));
381 ent = HT_FIND(chan_circid_map, &chan_circid_map, &search);
383 if (ent && ent->circuit) {
385 log_warn(
LD_BUG,
"Tried to mark %u unusable on %p, but there was already "
386 "a circuit there.", (
unsigned)
id, chan);
389 if (!ent->made_placeholder_at)
397 HT_INSERT(chan_circid_map, &chan_circid_map, ent);
411 memset(&search, 0,
sizeof(search));
414 ent = HT_REMOVE(chan_circid_map, &chan_circid_map, &search);
415 if (ent && ent->circuit) {
416 log_warn(
LD_BUG,
"Tried to mark %u usable on %p, but there was already "
417 "a circuit there.", (
unsigned)
id, chan);
420 if (_last_circid_chan_ent == ent)
421 _last_circid_chan_ent = NULL;
527 msg->
reason = reason_code;
530 ocirc_cevent_publish(msg);
548 ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
556 ocirc_state_publish(msg);
565 if (state == circ->
state)
588 tor_trace(
TR_SUBSYS(circuit), TR_EV(change_state), circ, circ->
state, state);
622 } SMARTLIST_FOREACH_END(circ);
636 cnt = smartlist_len(sl);
638 log_debug(
LD_CIRC,
"or_conn to %s, %d pending circs",
693 if (idx < smartlist_len(lst)) {
694 circuit_t *replacement = smartlist_get(lst, idx);
706 } SMARTLIST_FOREACH_END(circ);
715circuit_count_pending_close(
void)
753 if (!
TO_CIRCUIT(next_circ)->marked_for_close &&
754 next_circ->has_opened &&
757 next_circ->build_state &&
762 } SMARTLIST_FOREACH_END(next_circ);
804 log_warn(
LD_BUG,
"Unknown circuit state %d", state);
805 tor_snprintf(buf,
sizeof(buf),
"unknown state [%d]", state);
827 return "HS_CLIENT_HSDIR";
832 return "HS_CLIENT_INTRO";
838 return "HS_CLIENT_REND";
841 return "HS_SERVICE_HSDIR";
845 return "HS_SERVICE_INTRO";
849 return "HS_SERVICE_REND";
854 return "MEASURE_TIMEOUT";
858 return "PATH_BIAS_TESTING";
860 return "HS_VANGUARDS";
862 return "CIRCUIT_PADDING";
865 return "CONFLUX_UNLINKED";
866 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
867 return "CONFLUX_LINKED";
870 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
885 "Unrecognized circuit purpose: %d",
899 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
903 return "OR_HSSI_ESTABLISHED";
905 return "OR_HSCR_ESTABLISHED";
907 return "OR_HS_R_JOINED";
911 return "HSCI_CONNECTING";
913 return "HSCI_INTRO_SENT";
918 return "HSCR_CONNECTING";
920 return "HSCR_ESTABLISHED_IDLE";
922 return "HSCR_ESTABLISHED_WAITING";
924 return "HSCR_JOINED";
928 return "HSSI_CONNECTING";
930 return "HSSI_ESTABLISHED";
933 return "HSSR_CONNECTING";
935 return "HSSR_JOINED";
948 return "Circuit at relay";
950 return "Acting as intro point";
952 return "Acting as rendezvous (pending)";
954 return "Acting as rendezvous (established)";
956 return "General-purpose client";
958 return "Hidden service client: Connecting to intro point";
960 return "Hidden service client: Waiting for ack from intro point";
962 return "Hidden service client: Received ack from intro point";
964 return "Hidden service client: Establishing rendezvous point";
966 return "Hidden service client: Pending rendezvous point";
968 return "Hidden service client: Pending rendezvous point (ack received)";
970 return "Hidden service client: Active rendezvous point";
972 return "Hidden service client: Fetching HS descriptor";
975 return "Measuring circuit timeout";
978 return "Hidden service: Establishing introduction point";
980 return "Hidden service: Introduction point";
982 return "Hidden service: Connecting to rendezvous point";
984 return "Hidden service: Active rendezvous point";
986 return "Hidden service: Uploading HS descriptor";
989 return "Testing circuit";
992 return "Circuit made by controller";
995 return "Path-bias testing circuit";
998 return "Hidden service: Pre-built vanguard circuit";
1001 return "Circuit kept open for padding";
1004 return "Unlinked conflux circuit";
1006 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
1007 return "Linked conflux circuit";
1010 tor_snprintf(buf,
sizeof(buf),
"UNKNOWN_%d", (
int)purpose);
1022 CIRCWINDOW_START_MIN,
1023 CIRCWINDOW_START_MAX);
1054#define DFLT_IDLE_TIMEOUT_WHILE_LEARNING (3*60)
1055#define MIN_IDLE_TIMEOUT_WHILE_LEARNING (10)
1056#define MAX_IDLE_TIMEOUT_WHILE_LEARNING (1000*60)
1067 static uint32_t n_circuits_allocated = 1;
1092 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1093 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1102 int prediction_time_remaining =
1109 "Circuit chose a negative idle timeout of %d based on "
1110 "%d seconds of predictive building remaining.",
1112 prediction_time_remaining);
1116 MIN_IDLE_TIMEOUT_WHILE_LEARNING,
1117 MAX_IDLE_TIMEOUT_WHILE_LEARNING);
1121 "Circuit %"PRIu32
" chose an idle timeout of %d based on "
1122 "%d seconds of predictive building remaining.",
1125 prediction_time_remaining);
1128 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_origin), circ);
1150 dos_stream_init_circ_tbf(circ);
1152 tor_trace(
TR_SUBSYS(circuit), TR_EV(new_or), circ);
1176 int should_free = 1;
1204 half_edge_free(half_conn);
1205 } SMARTLIST_FOREACH_END(half_conn);
1222 crypto_pk_free(ocirc->intro_key);
1226 hs_ident_circuit_free(ocirc->
hs_ident);
1230 if (ocirc->socks_username) {
1231 memwipe(ocirc->socks_username, 0x12, ocirc->socks_username_len);
1234 if (ocirc->socks_password) {
1235 memwipe(ocirc->socks_password, 0x06, ocirc->socks_password_len);
1250 relay_crypto_clear(ô->
crypto);
1266 extend_info_free(circ->
n_hop);
1293 log_info(
LD_CIRC,
"Circuit %u (id: %" PRIu32
") has been freed.",
1302 circuit_handles_clear(circ);
1306 tor_trace(
TR_SUBSYS(circuit), TR_EV(free), circ);
1329 head = cpath = circ->
cpath;
1336 while (cpath->
next && cpath->
next != head) {
1338 cpath = victim->
next;
1354 tmp->global_circuitlist_idx = -1;
1371 } SMARTLIST_FOREACH_END(tmp);
1373 smartlist_free(lst);
1390 for (elt = HT_START(chan_circid_map, &chan_circid_map);
1394 next = HT_NEXT_RMV(chan_circid_map, &chan_circid_map, elt);
1400 HT_CLEAR(chan_circid_map, &chan_circid_map);
1409 int conn_array_index,
1415 "(other side %u), state %d (%s), born %ld:",
1416 conn_array_index, type, (
unsigned)this_circid, (
unsigned)other_circid,
1446 if (
TO_CONN(tmpconn) == conn) {
1448 "App-ward", p_circ_id, n_circ_id);
1456 if (
TO_CONN(tmpconn) == conn) {
1458 "Exit-ward", n_circ_id, p_circ_id);
1463 SMARTLIST_FOREACH_END(circ);
1480 SMARTLIST_FOREACH_END(circ);
1494 int *found_entry_out)
1499 if (_last_circid_chan_ent &&
1500 circ_id == _last_circid_chan_ent->circ_id &&
1501 chan == _last_circid_chan_ent->chan) {
1502 found = _last_circid_chan_ent;
1504 search.circ_id = circ_id;
1506 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1507 _last_circid_chan_ent = found;
1509 if (found && found->circuit) {
1511 "circuit_get_by_circid_channel_impl() returning circuit %p for"
1512 " circ_id %u, channel ID %"PRIu64
" (%p)",
1513 found->circuit, (
unsigned)circ_id,
1515 if (found_entry_out)
1516 *found_entry_out = 1;
1517 return found->circuit;
1521 "circuit_get_by_circid_channel_impl() found %s for"
1522 " circ_id %u, channel ID %"PRIu64
" (%p)",
1523 found ?
"placeholder" :
"nothing",
1527 if (found_entry_out)
1528 *found_entry_out = found ? 1 : 0;
1608 memset(&search, 0,
sizeof(search));
1609 search.circ_id = circ_id;
1612 found = HT_FIND(chan_circid_map, &chan_circid_map, &search);
1614 if (! found || found->circuit)
1617 return found->made_placeholder_at;
1647#ifdef DEBUG_CIRCUIT_UNLINK_ALL
1650 int mismatch = 0, badlen = 0;
1653 if (circ->
n_chan == chan ||
1659 SMARTLIST_FOREACH_END(circ);
1661 if (smartlist_len(detached) != smartlist_len(detached_2)) {
1662 log_warn(
LD_BUG,
"List of detached circuits had the wrong length! "
1663 "(got %d, should have gotten %d)",
1664 (
int)smartlist_len(detached),
1665 (
int)smartlist_len(detached_2));
1672 if (c != smartlist_get(detached_2, c_sl_idx))
1677 log_warn(
LD_BUG,
"Mismatch in list of detached circuits.");
1679 if (badlen || mismatch) {
1680 smartlist_free(detached);
1681 detached = detached_2;
1683 log_notice(
LD_CIRC,
"List of %d circuits was as expected.",
1684 (
int)smartlist_len(detached));
1685 smartlist_free(detached_2);
1692 if (circ->
n_chan == chan) {
1704 if (or_circ->
p_chan == chan) {
1710 log_warn(
LD_BUG,
"Circuit on detached list which I had no reason "
1715 circuit_mark_for_close(circ, reason);
1716 } SMARTLIST_FOREACH_END(circ);
1718 smartlist_free(detached);
1738 bool 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);
1757 if (want_client_circ) {
1795 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1798 for ( ; idx < smartlist_len(lst); ++idx) {
1799 circuit_t *circ = smartlist_get(lst, idx);
1828 idx =
TO_CIRCUIT(start)->global_circuitlist_idx + 1;
1830 for ( ; idx < smartlist_len(lst); ++idx) {
1831 circuit_t *circ = smartlist_get(lst, idx);
1860 purpose != CIRCUIT_PURPOSE_CONFLUX_LINKED);
1894 int purpose_to_search_for;
1901 purpose_to_produce);
1906 tor_assert_nonfatal(purpose_to_search_for !=
1911 "Hunting for a circ to cannibalize: purpose %d, uptime %d, "
1912 "capacity %d, internal %d",
1913 purpose_to_produce, need_uptime, need_capacity, internal);
1918 !circ_->marked_for_close &&
1919 circ_->purpose == purpose_to_search_for &&
1920 !circ_->timestamp_dirty) {
1942 !circ->unusable_for_new_conns &&
1960 }
while (hop!=circ->
cpath);
1973 }
while (hop != circ->
cpath);
1982 SMARTLIST_FOREACH_END(circ_);
2009 if (circuits_upgraded && smartlist_len(result)) {
2012 smartlist_free(result);
2023 if (circ && circ->
cpath) {
2025 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2026 cpath_next = cpath->
next;
2039 if (circ && circ->
cpath) {
2041 for (cpath = circ->
cpath;
2042 cpath->
state == CPATH_STATE_OPEN
2043 && cpath_next != circ->
cpath;
2044 cpath = cpath_next) {
2045 cpath_next = cpath->
next;
2058 if (circ && circ->
cpath && hopnum > 0) {
2060 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2061 cpath_next = cpath->
next;
2078 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
2080 SMARTLIST_FOREACH_END(circ);
2100 SMARTLIST_FOREACH_END(circ);
2124 uint64_t written_sync;
2131 or_circ = CONST_TO_OR_CIRCUIT(c);
2133 if (dir == CIRCUIT_N_CHAN) {
2144 cell_size = get_cell_network_size(chan->wide_circ_ids);
2150 bool is_ipv6 = chan &&
2156 written_sync = cells*(cell_size+TLS_PER_CELL_OVERHEAD);
2184 int orig_reason = reason;
2189 if (reason == END_CIRC_REASON_TORPROTOCOL) {
2200 "Duplicate call to circuit_mark_for_close at %s:%d"
2201 " (first at %s:%d)", file, line,
2207 log_warn(
LD_BUG,
"Specified 'at-origin' non-reason for ending circuit, "
2208 "but circuit was not at origin. (called %s:%d, purpose=%d)",
2211 reason = END_CIRC_REASON_NONE;
2221 reason = END_CIRC_REASON_NONE;
2236 reason &= ~END_CIRC_REASON_FLAG_REMOTE;
2238 if (reason < END_CIRC_REASON_MIN_ || reason > END_CIRC_REASON_MAX_) {
2240 log_warn(
LD_BUG,
"Reason %d out of range at %s:%d", reason, file, line);
2241 reason = END_CIRC_REASON_NONE;
2264 if (CIRCUIT_IS_CONFLUX(circ)) {
2285 cc_stats_circs_closed++;
2294 log_info(
LD_GENERAL,
"Circuit %u (id: %" PRIu32
") marked for close at "
2295 "%s:%d (orig reason: %d, new reason: %d)",
2299 file, line, orig_reason, reason);
2300 tor_trace(
TR_SUBSYS(circuit), TR_EV(mark_for_close), circ);
2370 CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED,
2377 if (!CHANNEL_CONDEMNED(circ->
n_chan)) {
2400 conn->
end_reason = END_STREAM_REASON_DESTROY;
2402 connection_mark_for_close(
TO_CONN(conn));
2410 if (!CHANNEL_CONDEMNED(or_circ->
p_chan)) {
2437 log_warn(
LD_BUG,
"Called on non-marked circuit");
2478 result += single_conn_free_bytes(conn);
2480 result += single_conn_free_bytes(conn->
linked_conn);
2538 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&c->
n_chan_cells.head)))
2543 if (NULL != (cell = TOR_SIMPLEQ_FIRST(&orcirc->
p_chan_cells.head))) {
2559 uint32_t age = 0, age2;
2579 uint32_t age = 0, age2;
2602 CONST_TO_ORIGIN_CIRCUIT(c)->p_streams, now);
2605 CONST_TO_OR_CIRCUIT(c)->n_streams, now);
2617 if (cell_age > data_age)
2635 else if (age_a == age_b)
2641static uint32_t now_ts_for_buf_cmp;
2655 else if (age_a == age_b)
2661#define FRACTION_OF_DATA_TO_RETAIN_ON_OOM 0.90
2674 size_t mem_to_recover;
2675 size_t mem_recovered=0;
2676 int n_circuits_killed=0;
2677 int n_dirconns_killed=0;
2678 int n_edgeconns_killed = 0;
2680 log_notice(
LD_GENERAL,
"We're low on memory (cell queues total alloc:"
2681 " %"TOR_PRIuSZ
" buffer total alloc: %" TOR_PRIuSZ
","
2682 " tor compress total alloc: %" TOR_PRIuSZ
2683 " (zlib: %" TOR_PRIuSZ
", zstd: %" TOR_PRIuSZ
","
2684 " lzma: %" TOR_PRIuSZ
"),"
2685 " rendezvous cache total alloc: %" TOR_PRIuSZ
"). Killing"
2686 " circuits withover-long queues. (This behavior is controlled by"
2687 " MaxMemInQueues.)",
2688 cell_queues_get_total_allocation(),
2689 buf_get_total_allocation(),
2694 hs_cache_get_total_allocation());
2696 size_t mem_target = (size_t)(
get_options()->MaxMemInQueues *
2697 FRACTION_OF_DATA_TO_RETAIN_ON_OOM);
2698 if (current_allocation <= mem_target)
2700 mem_to_recover = current_allocation - mem_target;
2708 } SMARTLIST_FOREACH_END(circ);
2717 } SMARTLIST_FOREACH_END(circ);
2720 now_ts_for_buf_cmp = now_ts;
2722 now_ts_for_buf_cmp = 0;
2727 } SMARTLIST_FOREACH_END(conn);
2742 if (conn_age < circ->age_tmp) {
2753 connection_mark_for_close(conn);
2755 mem_recovered += single_conn_free_bytes(conn);
2758 ++n_dirconns_killed;
2760 ++n_edgeconns_killed;
2763 if (mem_recovered >= mem_to_recover)
2764 goto done_recovering_mem;
2773 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
2778 ++n_circuits_killed;
2781 mem_recovered += half_stream_alloc;
2782 mem_recovered += freed;
2785 if (mem_recovered >= mem_to_recover)
2786 goto done_recovering_mem;
2787 } SMARTLIST_FOREACH_END(circ);
2789 done_recovering_mem:
2790 log_notice(
LD_GENERAL,
"Removed %"TOR_PRIuSZ
" bytes by killing %d circuits; "
2791 "%d circuits remain alive. Also killed %d non-linked directory "
2792 "connections. Killed %d edge connections",
2795 smartlist_len(circlist) - n_circuits_killed,
2797 n_edgeconns_killed);
2799 return mem_recovered;
2815 c->
purpose <= CIRCUIT_PURPOSE_MAX_);
2818 origin_circ = CONST_TO_ORIGIN_CIRCUIT(c);
2820 or_circ = CONST_TO_OR_CIRCUIT(c);
2833 if (or_circ && or_circ->
p_chan) {
2852 relay_crypto_assert_ok(&or_circ->
crypto);
2862 if (origin_circ && origin_circ->
cpath) {
static sa_family_t tor_addr_family(const tor_addr_t *a)
void buf_clear(buf_t *buf)
size_t buf_allocation(const buf_t *buf)
uint32_t buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now)
Header file for buffers.c.
void bwhist_note_bytes_written(uint64_t num_bytes, time_t when, bool ipv6)
Header for feature/stats/bwhist.c.
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
int channel_send_destroy(circid_t circ_id, channel_t *chan, int reason)
int channel_get_addr_if_possible(const channel_t *chan, tor_addr_t *addr_out)
const char * channel_describe_peer(channel_t *chan)
Header file for channel.c.
Header file for channeltls.c.
int pathbias_check_close(origin_circuit_t *ocirc, int reason)
#define DEAD_CIRCUIT_MAGIC
#define ORIGIN_CIRCUIT_MAGIC
void circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
int route_len_for_purpose(uint8_t purpose, extend_info_t *exit_ei)
Header file for circuitbuild.c.
static circuit_t * circuit_get_by_circid_channel_impl(circid_t circ_id, channel_t *chan, int *found_entry_out)
STATIC uint32_t circuit_max_queued_item_age(const circuit_t *c, uint32_t now)
static int chan_circid_entries_eq_(chan_circid_circuit_map_t *a, chan_circid_circuit_map_t *b)
static uint32_t circuit_get_streams_max_data_age(const edge_connection_t *stream, uint32_t now)
STATIC void circuit_free_(circuit_t *circ)
void circuit_close_all_marked(void)
const char * circuit_purpose_to_controller_hs_state_string(uint8_t purpose)
void circuit_mark_for_close_(circuit_t *circ, int reason, int line, const char *file)
static smartlist_t * global_circuitlist
int circuit_any_opened_circuits_cached(void)
void channel_note_destroy_pending(channel_t *chan, circid_t id)
static int any_opened_circs_cached_val
uint64_t circ_n_proto_violation
circuit_t * circuit_get_by_circid_channel_even_if_marked(circid_t circ_id, channel_t *chan)
void circuit_set_p_circid_chan(or_circuit_t *or_circ, circid_t id, channel_t *chan)
origin_circuit_t * circuit_get_next_by_purpose(origin_circuit_t *start, uint8_t purpose)
int circuit_id_in_use_on_channel(circid_t circ_id, channel_t *chan)
STATIC size_t n_cells_in_circ_queues(const circuit_t *c)
static void circuit_dump_conn_details(int severity, circuit_t *circ, int conn_array_index, const char *type, circid_t this_circid, circid_t other_circid)
or_circuit_t * or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
void circuit_synchronize_written_or_bandwidth(const circuit_t *c, circuit_channel_direction_t dir)
void circuit_set_n_circid_chan(circuit_t *circ, circid_t id, channel_t *chan)
double cc_stats_circ_close_ss_cwnd_ma
static void init_circuit_base(circuit_t *circ)
static uint32_t conn_get_buffer_age(const connection_t *conn, uint32_t now_ts)
void circuit_mark_all_dirty_circs_as_unusable(void)
static int circuits_compare_by_oldest_queued_item_(const void **a_, const void **b_)
void circuit_clear_cpath(origin_circuit_t *circ)
void circuit_set_state(circuit_t *circ, uint8_t state)
void circuit_free_all(void)
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
origin_circuit_t * circuit_get_next_intro_circ(const origin_circuit_t *start, bool want_client_circ)
origin_circuit_t * circuit_get_by_global_id(uint32_t id)
origin_circuit_t * origin_circuit_new(void)
static unsigned int chan_circid_entry_hash_(chan_circid_circuit_map_t *a)
void channel_mark_circid_unusable(channel_t *chan, circid_t id)
void circuit_dump_by_conn(connection_t *conn, int severity)
int circuit_any_opened_circuits(void)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now)
int circuit_get_cpath_len(origin_circuit_t *circ)
void channel_mark_circid_usable(channel_t *chan, circid_t id)
static smartlist_t * circuits_pending_close
int circuit_get_cpath_opened_len(const origin_circuit_t *circ)
const char * circuit_purpose_to_controller_string(uint8_t purpose)
void assert_circuit_ok(const circuit_t *c)
static void circuit_remove_from_origin_circuit_list(origin_circuit_t *origin_circ)
static smartlist_t * circuits_pending_other_guards
const char * circuit_state_to_string(int state)
static size_t marked_circuit_free_stream_bytes(circuit_t *c)
int circuit_count_pending_on_channel(channel_t *chan)
STATIC 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 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_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)
edge_connection_t * TO_EDGE_CONN(connection_t *c)
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.
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)
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.
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)
enum channel_t::@9 reason_for_closing
time_t timestamp_last_had_circuits
unsigned int num_n_circuits
char identity_digest[DIGEST_LEN]
uint64_t global_identifier
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)