42 #include "core/or/trace_probes_circuit.h"
45 #include "feature/client/circpathbias.h"
71 #include "core/or/or_circuit_st.h"
86 if ((edge_conn->hs_ident && !origin_circ->
hs_ident) ||
87 (!edge_conn->hs_ident && origin_circ->
hs_ident) ||
88 (edge_conn->hs_ident && origin_circ->
hs_ident &&
104 int must_be_open, uint8_t purpose,
105 int need_uptime,
int need_internal,
147 if (origin_circ->unusable_for_new_conns)
169 log_debug(
LD_CIRC,
"Not considering circuit with unknown router.");
175 log_debug(
LD_CIRC,
"Skipping one-hop circuit.");
296 }
else if (b_bits < 0) {
299 a_bits &= ~ oa->isolation_flags_mixed;
300 a_bits &= ~ ob->isolation_flags_mixed;
328 int must_be_open, uint8_t purpose,
329 int need_uptime,
int need_internal)
352 need_uptime,need_internal, (time_t)now.tv_sec))
361 SMARTLIST_FOREACH_END(circ);
373 if (circ->marked_for_close ||
381 SMARTLIST_FOREACH_END(circ);
399 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
400 cpath_next = cpath->
next;
433 struct timeval general_cutoff, begindir_cutoff, fourhop_cutoff,
434 close_cutoff, extremely_old_cutoff,
435 cannibalized_cutoff, c_intro_cutoff, s_intro_cutoff, stream_cutoff,
440 int any_opened_circs = 0;
450 #define SET_CUTOFF(target, msec) do { \
451 long ms = tor_lround(msec); \
452 struct timeval diff; \
453 diff.tv_sec = ms / 1000; \
454 diff.tv_usec = (int)((ms % 1000) * 1000); \
455 timersub(&now, &diff, &target); \
502 SET_CUTOFF(stream_cutoff,
MAX(options->CircuitStreamTimeout,15)*1000 + 1000);
506 SET_CUTOFF(cannibalized_cutoff,
508 options->CircuitStreamTimeout * 1000) + 1000);
535 victim->marked_for_close)
551 if (build_state && build_state->onehop_tunnel)
552 cutoff = begindir_cutoff;
554 cutoff = close_cutoff;
556 cutoff = c_intro_cutoff;
558 cutoff = s_intro_cutoff;
562 cutoff = fourhop_cutoff;
564 cutoff = c_rend_ready_cutoff;
566 cutoff = close_cutoff;
569 cutoff = cannibalized_cutoff;
570 else if (build_state && build_state->desired_path_len >= 4)
571 cutoff = fourhop_cutoff;
573 cutoff = general_cutoff;
575 if (
timercmp(&victim->timestamp_began, &cutoff, OP_GT))
585 if (
timercmp(&victim->timestamp_began, &close_cutoff, OP_GT)) {
591 "No circuits are opened. Relaxing timeout for circuit %d "
592 "(a %s %d-hop circuit in state %s with channel state %s).",
608 first_hop_succeeded);
613 static ratelim_t relax_timeout_limit = RATELIM_INIT(3600);
617 "No circuits are opened. Relaxed timeout for circuit %d "
618 "(a %s %d-hop circuit in state %s with channel state %s) to "
619 "%ldms. However, it appears the circuit has timed out "
629 (
long)build_close_ms);
638 if (!victim->timestamp_dirty)
642 victim->purpose, victim->build_state->chosen_exit_name,
646 "%d secs since dirty.",
648 victim->purpose, victim->build_state->chosen_exit_name,
650 (
int)(now - victim->timestamp_dirty));
657 switch (victim->purpose) {
669 victim->timestamp_dirty > cutoff.tv_sec)
692 if (victim->timestamp_dirty > cutoff.tv_sec)
701 log_warn(
LD_BUG,
"Circuit %d (purpose %d, %s) has timed out, "
702 "yet has attached streams!",
714 "Deciding to count the timeout for circuit %"PRIu32,
730 if (
timercmp(&victim->timestamp_began, &extremely_old_cutoff, OP_LT)) {
732 "Extremely large value for circuit build timeout: %lds. "
733 "Assuming clock jump. Purpose %d (%s)",
734 (
long)(now.tv_sec - victim->timestamp_began.tv_sec),
740 (time_t)victim->timestamp_created.tv_sec)) {
747 switch (victim->purpose) {
758 log_info(
LD_CIRC,
"Rendezvous circ %u (state %d:%s, purpose %d) "
759 "as timed-out, closing it. Relaunching rendezvous attempt.",
760 (
unsigned)victim->n_circ_id,
773 "Abandoning circ %u %s:%u (state %d,%d:%s, purpose %d, "
776 (
unsigned)victim->n_circ_id,
785 "Abandoning circ %u %u (state %d,%d:%s, purpose %d, len %d)",
787 (
unsigned)victim->n_circ_id,
800 circuit_mark_for_close(victim, END_CIRC_REASON_TIMEOUT);
803 } SMARTLIST_FOREACH_END(victim);
821 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_NONE);
822 } SMARTLIST_FOREACH_END(circ);
838 #define MAX_ANCIENT_ONEHOP_CIRCUITS_TO_LOG 10
839 time_t now = time(NULL);
840 time_t cutoff = now - age;
849 if (circ->timestamp_created.tv_sec >= cutoff)
853 if (hs_service_allow_non_anonymous_connection(options) &&
857 ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
862 if (smartlist_len(log_these) < MAX_ANCIENT_ONEHOP_CIRCUITS_TO_LOG)
866 SMARTLIST_FOREACH_END(circ);
872 "Diagnostic for issue 8387: Found %d one-hop circuits more "
873 "than %d seconds old! Logging %d...",
874 n_found, age, smartlist_len(log_these));
877 char created[ISO_TIME_LEN+1];
887 char dirty_since[ISO_TIME_LEN+1];
890 tor_asprintf(&dirty,
"Dirty since %s (%ld seconds vs %ld-second cutoff)",
894 dirty = tor_strdup(
"Not marked dirty");
897 log_notice(
LD_HEARTBEAT,
" #%d created at %s. %s, %s. %s for close. "
898 "Package window: %d. "
899 "%s for new conns. %s.",
906 ocirc->unusable_for_new_conns ?
"Not usable" :
"usable",
911 for (conn = ocirc->p_streams; conn; conn = conn->
next_stream) {
913 char stream_created[ISO_TIME_LEN+1];
914 if (++stream_num >= 5)
920 "%s conn in state %s. "
921 "It is %slinked and %sreading from a linked connection %p. "
922 "Package window %d. "
923 "%s for close (%s:%d). Hold-open is %sset. "
924 "Has %ssent RELAY_END. %s on circuit.",
944 log_notice(
LD_HEARTBEAT,
" Linked to %s connection in state %s "
945 "(Purpose %d). %s for close (%s:%d). Hold-open is %sset. ",
954 } SMARTLIST_FOREACH_END(ocirc);
956 log_notice(
LD_HEARTBEAT,
"It has been %ld seconds since I last called "
957 "circuit_expire_old_circuits_clientside().",
961 smartlist_free(log_these);
973 for (i = 0; i < smartlist_len(needed_ports); ++i) {
974 port = smartlist_get(needed_ports, i);
978 log_debug(
LD_CIRC,
"Port %d is already being handled; removing.", *port);
982 log_debug(
LD_CIRC,
"Port %d is not handled.", *port);
994 uint16_t port,
int min)
998 time_t now = time(NULL);
1005 !circ->marked_for_close &&
1007 (!circ->timestamp_dirty ||
1008 circ->timestamp_dirty +
get_options()->MaxCircuitDirtiness > now)) {
1013 if (origin_circ->unusable_for_new_conns)
1021 if (exitnode && (!need_uptime || build_state->
need_uptime)) {
1037 SMARTLIST_FOREACH_END(circ);
1042 #define MAX_UNUSED_OPEN_CIRCUITS 14
1050 circuit_is_available_for_use(
const circuit_t *circ)
1067 origin_circ = CONST_TO_ORIGIN_CIRCUIT(circ);
1068 if (origin_circ->unusable_for_new_conns)
1083 needs_exit_circuits(time_t now,
int *needs_uptime,
int *needs_capacity)
1091 #define SUFFICIENT_UPTIME_INTERNAL_HS_SERVERS 3
1096 needs_hs_server_circuits(time_t now,
int num_uptime_internal)
1103 if (num_uptime_internal >= SUFFICIENT_UPTIME_INTERNAL_HS_SERVERS) {
1125 #define SUFFICIENT_INTERNAL_HS_CLIENTS 3
1129 #define SUFFICIENT_UPTIME_INTERNAL_HS_CLIENTS 2
1134 needs_hs_client_circuits(time_t now,
int *needs_uptime,
int *needs_capacity,
1135 int num_internal,
int num_uptime_internal)
1140 int requires_uptime = num_uptime_internal <
1141 SUFFICIENT_UPTIME_INTERNAL_HS_CLIENTS &&
1144 return (used_internal_recently &&
1145 (requires_uptime || num_internal < SUFFICIENT_INTERNAL_HS_CLIENTS) &&
1151 #define DFLT_CBT_UNUSED_OPEN_CIRCS (10)
1152 #define MIN_CBT_UNUSED_OPEN_CIRCS 0
1153 #define MAX_CBT_UNUSED_OPEN_CIRCS MAX_UNUSED_OPEN_CIRCUITS
1159 needs_circuits_for_build(
int num)
1163 DFLT_CBT_UNUSED_OPEN_CIRCS,
1164 MIN_CBT_UNUSED_OPEN_CIRCS,
1165 MAX_CBT_UNUSED_OPEN_CIRCS) &&
1181 int num=0, num_internal=0, num_uptime_internal=0;
1182 int hidserv_needs_uptime=0, hidserv_needs_capacity=1;
1183 int port_needs_uptime=0, port_needs_capacity=1;
1184 time_t now = time(NULL);
1189 if (!circuit_is_available_for_use(circ))
1198 num_uptime_internal++;
1200 SMARTLIST_FOREACH_END(circ);
1206 if (needs_exit_circuits(now, &port_needs_uptime, &port_needs_capacity)) {
1207 if (port_needs_uptime)
1209 if (port_needs_capacity)
1213 "Have %d clean circs (%d internal), need another exit circ.",
1219 if (needs_hs_server_circuits(now, num_uptime_internal)) {
1224 "Have %d clean circs (%d internal), need another internal "
1225 "circ for my hidden service.",
1231 if (needs_hs_client_circuits(now, &hidserv_needs_uptime,
1232 &hidserv_needs_capacity,
1233 num_internal, num_uptime_internal))
1235 if (hidserv_needs_uptime)
1237 if (hidserv_needs_capacity)
1242 "Have %d clean circs (%d uptime-internal, %d internal), need"
1243 " another hidden service circ.",
1244 num, num_uptime_internal, num_internal);
1253 if (needs_circuits_for_build(num)) {
1261 "Have %d clean circs need another buildtime test circ.", num);
1268 #define TESTING_CIRCUIT_INTERVAL 300
1301 static time_t time_to_expire_and_reset = 0;
1303 if (time_to_expire_and_reset < now) {
1361 log_debug(
LD_APP,
"Removing stream %d from circ %u",
1407 log_warn(
LD_BUG,
"Edge connection not in circuit's list.");
1433 if (circ->timestamp_dirty &&
1434 circ->timestamp_dirty +
get_options()->MaxCircuitDirtiness <
1437 log_debug(
LD_CIRC,
"Closing n_circ_id %u (dirty %ld sec ago, "
1439 (
unsigned)circ->n_circ_id,
1440 (
long)(now.tv_sec - circ->timestamp_dirty),
1445 tor_trace(
TR_SUBSYS(circuit), TR_EV(idle_timeout),
1447 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
1450 if (
timercmp(&circ->timestamp_began, &cutoff, OP_LT)) {
1463 "Closing circuit %"PRIu32
1464 " that has been unused for %ld msec.",
1466 tv_mdiff(&circ->timestamp_began, &now));
1467 tor_trace(
TR_SUBSYS(circuit), TR_EV(idle_timeout),
1469 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
1479 "Ancient non-dirty circuit %d is still around after "
1480 "%ld milliseconds. Purpose: %d (%s)",
1482 tv_mdiff(&circ->timestamp_began, &now),
1490 } SMARTLIST_FOREACH_END(circ);
1508 #define IDLE_ONE_HOP_CIRC_TIMEOUT 60
1535 log_info(
LD_CIRC,
"Closing circ_id %u (empty %d secs ago)",
1538 circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
1541 SMARTLIST_FOREACH_END(circ);
1545 #define NUM_PARALLEL_TESTING_CIRCS 4
1577 SMARTLIST_FOREACH_END(circ);
1612 router_all_orports_seem_reachable(options))
1616 "Our testing circuit (to see if your ORPort is reachable) "
1617 "has failed. I'll try again later.");
1633 tor_trace(
TR_SUBSYS(circuit), TR_EV(opened), circ);
1729 int failed_at_last_hop = 0;
1746 static ratelim_t pathfail_limit = RATELIM_INIT(3600);
1748 "Our circuit %u (id: %" PRIu32
") died due to an invalid "
1749 "selected path, purpose %s. This may be a torrc "
1750 "configuration issue, or a bug.",
1757 HS_METRICS_ERR_RDV_PATH);
1771 failed_at_last_hop = 1;
1783 int already_marked = 0;
1784 if (circ->base_.
n_chan) {
1785 n_chan = circ->base_.
n_chan;
1798 "Our circuit %u (id: %" PRIu32
") failed to get a response "
1799 "from the first hop (%s). I'm going to try to rotate to a "
1800 "better connection.",
1806 "Our circuit %u (id: %" PRIu32
") died before the first hop "
1807 "with no connection",
1810 if (!already_marked) {
1824 switch (circ->base_.
purpose) {
1830 if (failed_at_last_hop) {
1865 "Couldn't connect to the client's chosen rend point %s "
1868 failed_at_last_hop?
"last":
"non-last");
1871 HS_METRICS_ERR_RDV_RP_CONN_FAILURE);
1890 #define MAX_CIRCUIT_FAILURES 5
1906 have_enough_path_info(
int need_exit)
1942 return (purpose >= CIRCUIT_PURPOSE_C_HS_MIN_ &&
1943 purpose <= CIRCUIT_PURPOSE_C_HS_MAX_);
1950 return (purpose >= CIRCUIT_PURPOSE_S_HS_MIN_ &&
1951 purpose <= CIRCUIT_PURPOSE_S_HS_MAX_);
1966 (CONST_TO_ORIGIN_CIRCUIT(circ)->hs_ident != NULL));
1999 int has_extend_info,
2004 if (onehop_tunnel) {
2065 log_debug(
LD_CIRC,
"Haven't %s yet; canceling "
2068 "fetched enough directory info" :
2069 "received a consensus with exits");
2076 extend_info != NULL,
2083 uint8_t old_purpose = circ->base_.
purpose;
2086 log_info(
LD_CIRC,
"Cannibalizing circ %u (id: %" PRIu32
") for "
2123 &old_timestamp_began);
2142 "unexpected purpose %d when cannibalizing a circ.",
2148 tor_trace(
TR_SUBSYS(circuit), TR_EV(cannibalized), circ);
2197 uint8_t desired_circuit_purpose,
2201 int check_exit_policy;
2202 int need_uptime, need_internal;
2210 log_err(
LD_BUG,
"Connection state mismatch: wanted "
2211 "AP_CONN_STATE_CIRCUIT_WAIT, but got %d (%s)",
2241 desired_circuit_purpose,
2242 need_uptime, need_internal);
2254 int have_path = have_enough_path_info(!need_internal);
2268 tor_assert_nonfatal_once(rv);
2270 "Application request when we haven't %s. "
2271 "Optimistically trying known %s again.",
2273 "used client functionality lately" :
2274 "received a consensus with exits",
2275 options->
UseBridges ?
"bridges" :
"entrynodes");
2283 "Application request when we haven't %s. "
2284 "Optimistically trying directory fetches again.",
2286 "used client functionality lately" :
2287 "received a consensus with exits");
2301 if (check_exit_policy) {
2313 "No Tor server allows exit to %s:%d. Rejecting.",
2325 "Requested exit point '%s' is excluded or "
2326 "would refuse request. %s.",
2333 desired_circuit_purpose,
2345 desired_circuit_purpose,
2346 need_uptime, need_internal);
2348 log_debug(
LD_CIRC,
"one on the way!");
2361 static ratelim_t delay_limit = RATELIM_INIT(10*60);
2364 log_notice(
LD_APP,
"We'd like to launch a circuit to handle a "
2365 "connection, but we already have %d general-purpose client "
2366 "circuits pending. Waiting until some finish.%s",
2380 log_info(
LD_REND,
"No intro points: re-fetching service descriptor.");
2385 log_info(
LD_REND,
"Chose %s as intro point for service",
2406 log_warn(
LD_CIRC,
"Could not make a one-hop connection to %s. "
2411 log_debug(
LD_DIR,
"considering %d, %s",
2426 log_info(
LD_DIR,
"Broken exit digest on tunnel conn. Closing.");
2430 log_info(
LD_DIR,
"Broken address %s on tunnel conn. Closing.",
2446 "Requested exit point '%s' is not known. %s.",
2453 desired_circuit_purpose,
2463 uint8_t new_circ_purpose;
2469 new_circ_purpose = desired_circuit_purpose;
2484 log_info(
LD_GENERAL,
"Getting rendezvous circuit to v3 service!");
2491 extend_info_free(extend_info);
2503 log_info(
LD_CIRC,
"The application request to %s:%d has launched "
2504 "%d circuits without finding one it likes.",
2513 if (edge_conn->hs_ident) {
2536 "No safe circuit (purpose %d) ready for edge "
2537 "connection; delaying.",
2538 desired_circuit_purpose);
2550 for (cpath = circ->
cpath; cpath_next != circ->
cpath; cpath = cpath_next) {
2551 cpath_next = cpath->
next;
2552 if (crypt_path == cpath)
2566 const node_t *exitnode = NULL;
2569 log_debug(
LD_APP|
LD_CIRC,
"attaching new conn to circ. n_circ_id %u.",
2578 ENTRY_TO_CONN(apconn)->timestamp_last_read_allowed = time(NULL);
2617 log_info(
LD_APP,
"Looks like completed circuit to %s %s allow "
2618 "optimistic data for connection to %s",
2637 if (cp[1] ==
'\0' ||
2639 !strcasecmp(address, &cp[1]))
2641 }
else if (strcasecmp(cp, address) == 0) {
2644 } SMARTLIST_FOREACH_END(cp);
2657 char *new_address = NULL;
2659 uint64_t stream_id = 0;
2799 "Tried for %d seconds to get a connection to %s:%d. Giving up.",
2818 if (networkstatus_consensus_is_already_downloading(
2824 log_info(
LD_DIR,
"Closing extra consensus fetch (to %s) since one "
2836 if (!node && !want_onehop) {
2843 "Requested exit point '%s' is not known. %s.",
2855 "Requested exit point '%s' is excluded or "
2856 "would refuse request. %s.",
2882 "Attaching apconn to circ %u (stream %d sec old).",
2883 (
unsigned)circ->base_.
n_circ_id, conn_age);
2901 if (retval < 0)
return -1;
2907 "rend joined circ %u (id: %" PRIu32
") already here. "
2908 "Attaching. (stream %d sec old)",
2934 log_info(
LD_REND,
"This connection is no longer ready to attach; its "
2936 "(We probably have to re-fetch its descriptor.)");
2940 if (rendcirc && (rendcirc->base_.
purpose ==
2943 "pending-join circ %u (id: %" PRIu32
") already here, with "
2944 "intro ack. Stalling. (stream %d sec old)",
2953 if (retval < 0)
return -1;
2958 log_info(
LD_REND,
"Intro circ %u (id: %" PRIu32
") present and "
2959 "awaiting ACK. Rend circuit %u (id: %" PRIu32
"). "
2960 "Stalling. (stream %d sec old)",
2962 introcirc->global_identifier,
2963 rendcirc ? (
unsigned)
TO_CIRCUIT(rendcirc)->n_circ_id : 0,
2971 if (rendcirc && introcirc &&
2974 "ready rend circ %u (id: %" PRIu32
") already here. No"
2975 "intro-ack yet on intro %u (id: %" PRIu32
"). "
2976 "(stream %d sec old)",
2980 introcirc->global_identifier, conn_age);
2985 log_info(
LD_REND,
"Found open intro circ %u (id: %" PRIu32
"). "
2986 "Rend circuit %u (id: %" PRIu32
"); Sending "
2987 "introduction. (stream %d sec old)",
2989 introcirc->global_identifier,
2996 introcirc->base_.timestamp_dirty = time(NULL);
3015 log_info(
LD_REND,
"Intro %u (id: %" PRIu32
") and rend circuit %u "
3016 "(id: %" PRIu32
") circuits are not both ready. "
3017 "Stalling conn. (%d sec old)",
3018 introcirc ? (
unsigned)
TO_CIRCUIT(introcirc)->n_circ_id : 0,
3019 introcirc ? introcirc->global_identifier : 0,
3020 rendcirc ? (
unsigned)
TO_CIRCUIT(rendcirc)->n_circ_id : 0,
3030 uint8_t old_purpose;
3035 if (circ->
purpose == new_purpose)
return;
3038 char old_purpose_desc[80] =
"";
3041 old_purpose_desc[80-1] =
'\0';
3044 "changing purpose of origin circ %d "
3045 "from \"%s\" (%d) to \"%s\" (%d)",
3061 tor_trace(
TR_SUBSYS(circuit), TR_EV(change_purpose), circ, old_purpose,
3089 circ->unusable_for_new_conns = 1;
3103 "Wrong relay_body_len: %d (should be at most %d)",
int tor_addr_parse(tor_addr_t *addr, const char *src)
int tor_addr_is_null(const tor_addr_t *addr)
#define tor_addr_from_in(dest, in)
int addressmap_have_mapping(const char *address, int update_expiry)
void addressmap_clean(time_t now)
void addressmap_register(const char *address, char *new_address, time_t expires, addressmap_entry_source_t source, const int wildcard_addr, const int wildcard_new_addr, uint64_t stream_id)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
int n_bits_set_u8(uint8_t v)
Header file for circuitbuild.c.
time_t channel_when_last_xmit(channel_t *chan)
int channel_is_client(const channel_t *chan)
const char * channel_state_to_string(channel_state_t state)
const char * channel_describe_peer(channel_t *chan)
Header file for channel.c.
void pathbias_count_use_attempt(origin_circuit_t *circ)
int pathbias_check_close(origin_circuit_t *ocirc, int reason)
void pathbias_count_timeout(origin_circuit_t *circ)
const char * build_state_get_exit_nickname(cpath_build_state_t *state)
int circuit_extend_to_new_exit(origin_circuit_t *circ, extend_info_t *exit_ei)
origin_circuit_t * circuit_establish_circuit(uint8_t purpose, extend_info_t *exit_ei, int flags)
void circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
const node_t * build_state_get_exit_node(cpath_build_state_t *state)
int circuit_timeout_want_to_count_circ(const origin_circuit_t *circ)
int circuit_all_predicted_ports_handled(time_t now, int *need_uptime, int *need_capacity)
Header file for circuitbuild.c.
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)
int circuit_any_opened_circuits(void)
int circuit_get_cpath_len(origin_circuit_t *circ)
void assert_circuit_ok(const circuit_t *c)
smartlist_t * circuit_get_global_list(void)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
smartlist_t * circuit_get_global_origin_circuit_list(void)
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)
const char * circuit_state_to_string(int state)
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_S_CONNECT_REND
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING
#define CIRCUIT_STATE_OPEN
#define CIRCUIT_PURPOSE_IS_ORIGIN(p)
#define CIRCUIT_PURPOSE_C_REND_JOINED
#define CIRCUIT_PURPOSE_S_INTRO
#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_PURPOSE_TESTING
#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_C_INTRODUCING
#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO
#define CIRCUIT_PURPOSE_C_ESTABLISH_REND
#define CIRCUIT_PURPOSE_C_GENERAL
#define CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING(p)
#define CIRCUIT_PURPOSE_HS_VANGUARDS
void circpad_machine_event_circ_purpose_changed(origin_circuit_t *circ)
void circpad_machine_event_circ_has_no_streams(origin_circuit_t *circ)
void circpad_machine_event_circ_has_streams(origin_circuit_t *circ)
Header file for circuitpadding.c.
int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt)
void circuit_build_times_set_timeout(circuit_build_times_t *cbt)
double get_circuit_build_timeout_ms(void)
void circuit_build_times_count_timeout(circuit_build_times_t *cbt, int did_onehop)
const circuit_build_times_t * get_circuit_build_times(void)
double get_circuit_build_close_time_ms(void)
void circuit_build_times_mark_circ_as_measurement_only(origin_circuit_t *circ)
int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt)
int circuit_build_times_count_close(circuit_build_times_t *cbt, int did_onehop, time_t start_time)
int circuit_build_times_disabled(const or_options_t *options)
circuit_build_times_t * get_circuit_build_times_mutable(void)
Header file for circuitstats.c.
void circuit_build_failed(origin_circuit_t *circ)
void circuit_sent_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
void circuit_expire_old_circuits_serverside(time_t now)
bool circuit_is_hs_v3(const circuit_t *circ)
void circuit_detach_stream(circuit_t *circ, edge_connection_t *conn)
static int count_pending_general_client_circuits(void)
static void circuit_testing_failed(origin_circuit_t *circ, int at_last_hop)
static void circuit_testing_opened(origin_circuit_t *circ)
static int circuit_matches_with_rend_stream(const edge_connection_t *edge_conn, const origin_circuit_t *origin_circ)
static int circuit_try_clearing_isolation_state(origin_circuit_t *circ)
bool circuit_purpose_is_hs_service(const uint8_t purpose)
origin_circuit_t * circuit_launch(uint8_t purpose, int flags)
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
void circuit_log_ancient_one_hop_circuits(int age)
void circuit_change_purpose(circuit_t *circ, uint8_t new_purpose)
static int have_performed_bandwidth_test
void circuit_expire_waiting_for_better_guard(void)
static int circuit_is_acceptable(const origin_circuit_t *origin_circ, const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal, time_t now)
void circuit_expire_old_circs_as_needed(time_t now)
static void circuit_predict_and_launch_new(void)
int circuit_should_use_vanguards(uint8_t purpose)
static origin_circuit_t * circuit_get_best(const entry_connection_t *conn, int must_be_open, uint8_t purpose, int need_uptime, int need_internal)
void reset_bandwidth_test(void)
int hostname_in_track_host_exits(const or_options_t *options, const char *address)
static void consider_recording_trackhost(const entry_connection_t *conn, const origin_circuit_t *circ)
static int n_circuit_failures
#define MAX_CIRCUIT_FAILURES
void circuit_has_opened(origin_circuit_t *circ)
void circuit_expire_building(void)
static int circuit_should_cannibalize_to_build(uint8_t purpose_to_build, int has_extend_info, int onehop_tunnel)
void circuit_build_needed_circs(time_t now)
static int did_circs_fail_last_period
bool circuit_purpose_is_hs_vanguards(const uint8_t purpose)
int connection_ap_handshake_attach_circuit(entry_connection_t *conn)
void circuit_reset_failure_count(int timeout)
#define IDLE_ONE_HOP_CIRC_TIMEOUT
STATIC void circuit_expire_old_circuits_clientside(void)
static int circuit_is_better(const origin_circuit_t *oa, const origin_circuit_t *ob, const entry_connection_t *conn)
bool circuit_purpose_is_hs_client(const uint8_t purpose)
int connection_ap_handshake_attach_chosen_circuit(entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath)
int circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min)
static void circuit_increment_failure_count(void)
static int circuit_get_open_circ_or_launch(entry_connection_t *conn, uint8_t desired_circuit_purpose, origin_circuit_t **circp)
#define MAX_UNUSED_OPEN_CIRCUITS
void circuit_remove_handled_ports(smartlist_t *needed_ports)
int circuit_enough_testing_circs(void)
origin_circuit_t * circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *extend_info, int flags)
static int connection_ap_get_nonrend_circ_purpose(const entry_connection_t *conn)
void mark_circuit_unusable_for_new_conns(origin_circuit_t *circ)
#define NUM_PARALLEL_TESTING_CIRCS
#define TESTING_CIRCUIT_INTERVAL
static time_t last_expired_clientside_circuits
void circuit_try_attaching_streams(origin_circuit_t *circ)
static void link_apconn_to_circ(entry_connection_t *apconn, origin_circuit_t *circ, crypt_path_t *cpath)
static int cpath_is_on_circuit(origin_circuit_t *circ, crypt_path_t *crypt_path)
int circuit_purpose_is_hidden_service(uint8_t purpose)
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
const or_options_t * get_options(void)
const char * escaped_safe_str_client(const char *address)
Header file for config.c.
const char * conn_state_to_string(int type, int state)
connection_t * connection_get_by_type(int type)
const char * conn_type_to_string(int type)
Header file for connection.c.
int connection_edge_compatible_with_circuit(const entry_connection_t *conn, const origin_circuit_t *circ)
void connection_ap_mark_as_waiting_for_renddesc(entry_connection_t *entry_conn)
void connection_ap_fail_onehop(const char *failed_digest, cpath_build_state_t *build_state)
void connection_ap_rescan_and_attach_pending(void)
int connection_ap_handshake_send_begin(entry_connection_t *ap_conn)
void circuit_clear_isolation(origin_circuit_t *circ)
entry_connection_t * EDGE_TO_ENTRY_CONN(edge_connection_t *c)
int connection_ap_handshake_send_resolve(entry_connection_t *ap_conn)
int connection_edge_update_circuit_isolation(const entry_connection_t *conn, origin_circuit_t *circ, int dry_run)
int connection_ap_can_use_exit(const entry_connection_t *conn, const node_t *exit_node)
void connection_ap_attach_pending(int retry)
int connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
void circuit_discard_optional_exit_enclaves(extend_info_t *info)
Header file for connection_edge.c.
#define AP_CONN_STATE_CONTROLLER_WAIT
#define AP_CONN_STATE_CIRCUIT_WAIT
int control_event_circuit_purpose_changed(origin_circuit_t *circ, int old_purpose)
int control_event_circuit_cannibalized(origin_circuit_t *circ, int old_purpose, const struct timeval *old_tv_created)
Header file for control_events.c.
Circuit-build-stse structure.
int ed25519_pubkey_eq(const ed25519_public_key_t *key1, const ed25519_public_key_t *key2)
const char * extend_info_describe(const extend_info_t *ei)
const char * node_describe(const node_t *node)
Header file for describe.c.
#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.
#define DIR_PURPOSE_UPLOAD_HSDESC
#define DIR_PURPOSE_FETCH_CONSENSUS
#define DIR_PURPOSE_FETCH_HSDESC
Entry connection structure.
#define ENTRY_TO_EDGE_CONN(c)
void entry_guard_failed(circuit_guard_state_t **guard_state_p)
int entry_list_is_constrained(const or_options_t *options)
int entry_guard_state_should_expire(circuit_guard_state_t *guard_state)
int guards_retry_optimistic(const or_options_t *options)
Header file for circuitbuild.c.
const char * escaped(const char *s)
Header file for Tor tracing instrumentation definition.
extend_info_t * extend_info_from_node(const node_t *node, int for_direct_connect, bool for_exit)
bool extend_info_has_orport(const extend_info_t *ei, const tor_addr_t *addr, uint16_t port)
extend_info_t * extend_info_new(const char *nickname, const char *rsa_id_digest, const ed25519_public_key_t *ed_id, crypto_pk_t *onion_key, const curve25519_public_key_t *ntor_key, const tor_addr_t *addr, uint16_t port, const protover_summary_flags_t *pv, bool for_exit_use)
Header for core/or/extendinfo.c.
void hs_circ_cleanup_on_repurpose(circuit_t *circ)
bool hs_circ_is_rend_sent_in_intro1(const origin_circuit_t *circ)
void hs_circ_retry_service_rendezvous_point(const origin_circuit_t *circ)
Header file containing circuit data for the whole HS subsystem.
void hs_client_note_connection_attempt_succeeded(const edge_connection_t *conn)
int hs_client_refetch_hsdesc(const ed25519_public_key_t *identity_pk)
int hs_client_send_introduce1(origin_circuit_t *intro_circ, origin_circuit_t *rend_circ)
void hs_client_circuit_has_opened(origin_circuit_t *circ)
extend_info_t * hs_client_get_random_intro_from_edge(const edge_connection_t *edge_conn)
Header file containing client data for the HS subsystem.
void hs_dec_rdv_stream_counter(origin_circuit_t *circ)
Header file containing common data for the whole HS subsystem.
hs_ident_circuit_t * hs_ident_circuit_new(const ed25519_public_key_t *identity_pk)
Header file containing circuit and connection identifier data for the whole HS subsystem.
Header for feature/hs/hs_metrics.c.
#define hs_metrics_failed_rdv(i, reason)
void hs_service_circuit_has_opened(origin_circuit_t *circ)
unsigned int hs_service_get_num_services(void)
void hs_stats_note_service_rendezvous_launch(void)
Header file for hs_stats.c.
int tor_inet_aton(const char *str, struct in_addr *addr)
#define log_fn(severity, domain, args,...)
#define log_fn_ratelim(ratelim, severity, domain, args,...)
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.
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port, int need_uptime)
const node_t * node_get_by_nickname(const char *nickname, unsigned flags)
consensus_path_type_t router_have_consensus_path(void)
const node_t * node_get_by_id(const char *identity_digest)
int router_have_minimum_dir_info(void)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define MIN_CIRCUITS_HANDLING_STREAM
#define RELAY_PAYLOAD_SIZE
#define END_CIRC_REASON_MEASUREMENT_EXPIRED
#define END_CIRC_AT_ORIGIN
Origin circuit structure.
@ PATH_STATE_BUILD_SUCCEEDED
addr_policy_result_t compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)
addr_policy_result_t compare_tor_addr_to_node_policy(const tor_addr_t *addr, uint16_t port, const node_t *node)
Header file for policies.c.
@ ADDR_POLICY_PROBABLY_REJECTED
void rep_hist_note_used_internal(time_t now, int need_uptime, int need_capacity)
int rep_hist_get_predicted_internal(time_t now, int *need_uptime, int *need_capacity)
Header file for predict_ports.c.
int tor_asprintf(char **strp, const char *fmt,...)
int proxy_mode(const or_options_t *options)
Header file for proxymode.c.
char * rate_limit_log(ratelim_t *lim, time_t now)
void routerlist_retry_directory_downloads(time_t now)
int hexdigest_to_digest(const char *hexdigest, char *digest)
Header file for routerlist.c.
int server_mode(const or_options_t *options)
Header file for routermode.c.
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
int router_orport_seems_reachable(const or_options_t *options, int family)
void router_do_reachability_checks(void)
void router_perform_bandwidth_test(int num_circs, time_t now)
Header file for selftest.c.
int smartlist_contains_int_as_string(const smartlist_t *sl, int num)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_del(smartlist_t *sl, int idx)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
Client request structure.
#define SOCKS_COMMAND_CONNECT
unsigned int is_bad_for_new_circs
unsigned int received_destroy
uint16_t marked_for_close
struct timeval timestamp_began
struct timeval timestamp_created
struct connection_t * linked_conn
unsigned int hold_open_until_flushed
unsigned int reading_from_linked_conn
uint16_t marked_for_close
const char * marked_for_close_file
extend_info_t * chosen_exit
unsigned int onehop_tunnel
struct crypt_path_t * prev
struct crypt_path_t * next
extend_info_t * extend_info
char * requested_resource
struct crypt_path_t * cpath_layer
struct edge_connection_t * next_stream
unsigned int edge_has_sent_end
unsigned int edge_blocked_on_circ
struct circuit_t * on_circuit
socks_request_t * socks_request
unsigned int num_circuits_launched
unsigned int chosen_exit_optional
unsigned int may_use_optimistic_data
unsigned int use_begindir
unsigned int socks_iso_keep_alive
char identity_digest[DIGEST_LEN]
ed25519_public_key_t identity_pk
ed25519_public_key_t identity_pk
edge_connection_t * resolving_streams
struct or_circuit_t * rend_splice
edge_connection_t * n_streams
struct routerset_t * ExcludeExitNodes
struct smartlist_t * TrackHostExits
struct routerset_t * EntryNodes
struct routerset_t * ExcludeNodes
int MaxClientCircuitsPending
int DisablePredictedCircuits
struct smartlist_t * LongLivedPorts
uint32_t global_identifier
unsigned int relaxed_timeout
struct hs_ident_circuit_t * hs_ident
edge_connection_t * p_streams
unsigned int isolation_values_set
uint32_t n_overhead_written_circ_bw
path_state_bitfield_t path_state
uint32_t n_delivered_read_circ_bw
uint32_t n_delivered_written_circ_bw
uint32_t n_overhead_read_circ_bw
smartlist_t * prepend_policy
cpath_build_state_t * build_state
unsigned int isolation_any_streams_attached
struct circuit_guard_state_t * guard_state
char address[MAX_SOCKS_ADDR_LEN]
void format_local_iso_time(char *buf, time_t t)
#define timercmp(tv1, tv2, op)
void tor_gettimeofday(struct timeval *timeval)
long tv_mdiff(const struct timeval *start, const struct timeval *end)
#define tor_fragile_assert()
int strcasecmpend(const char *s1, const char *s2)
int tor_digest_is_zero(const char *digest)