27#define CIRCUITBUILD_PRIVATE
28#define OCIRC_EVENT_PRIVATE
54#include "core/or/trace_probes_circuit.h"
57#include "feature/client/circpathbias.h"
83#include "core/or/or_circuit_st.h"
86#include "trunnel/extension.h"
87#include "trunnel/congestion_control.h"
135#define MAX_CIRCID_ATTEMPTS 64
137 unsigned n_with_circ = 0, n_pending_destroy = 0, n_weird_pending_destroy = 0;
141 int64_t pending_destroy_time_total = 0;
142 int64_t pending_destroy_time_max = 0;
148 "Trying to pick a circuit ID for a connection from "
149 "a client with no identity.");
152 max_range = (chan->wide_circ_ids) ? (1u<<31) : (1u<<15);
153 mask = max_range - 1;
156 if (++attempts > MAX_CIRCID_ATTEMPTS) {
173 int64_t queued_destroys;
178 if (n_pending_destroy)
179 pending_destroy_time_total /= n_pending_destroy;
180 log_warn(
LD_CIRC,
"No unused circIDs found on channel %s wide "
181 "circID support, with %u inbound and %u outbound circuits. "
182 "Found %u circuit IDs in use by circuits, and %u with "
183 "pending destroy cells. (%u of those were marked bogusly.) "
184 "The ones with pending destroy cells "
185 "have been marked unusable for an average of %ld seconds "
186 "and a maximum of %ld seconds. This channel is %ld seconds "
187 "old. Failing a circuit.%s",
188 chan->wide_circ_ids ?
"with" :
"without",
190 n_with_circ, n_pending_destroy, n_weird_pending_destroy,
191 (
long)pending_destroy_time_total,
192 (
long)pending_destroy_time_max,
199 log_warn(
LD_BUG,
" This channel somehow has no cmux on it!");
207 queued_destroys = circuitmux_count_queued_destroy_cells(chan,
210 log_warn(
LD_CIRC,
" Circuitmux on this channel has %u circuits, "
211 "of which %u are active. It says it has %"PRId64
212 " destroy cells queued.",
222 circuitmux_assert_okay(chan->
cmux);
230 crypto_rand((
char*) &test_circ_id,
sizeof(test_circ_id));
231 test_circ_id &= mask;
232 }
while (test_circ_id == 0);
234 test_circ_id |= high_bit;
239 else if (in_use == 2) {
246 pending_destroy_time_total += waiting;
247 if (waiting > pending_destroy_time_max)
248 pending_destroy_time_max = waiting;
250 ++n_weird_pending_destroy;
268 const char *states[] = {
"closed",
"waiting for keys",
"open"};
281 (nickname?nickname:
"*unnamed*"));
291 if (!verbose && hop->
state != CPATH_STATE_OPEN)
324 }
while (hop != circ->
cpath);
328 smartlist_free(elements);
360 tor_log(severity,domain,
"%s",s);
370 cpath = head = circ->
cpath;
378 if (!extend_info_supports_ntor(cpath->
extend_info)) {
382 }
while (cpath != head);
401 log_info(
LD_CIRC,
"Generating cpath hop failed.");
415 if (circuit_can_use_tap(circ)) {
439 if (BUG(!path_supports_ntor)) {
489 int is_hs_v3_rp_circuit = 0;
492 is_hs_v3_rp_circuit = 1;
506 circuit_mark_for_close(
TO_CIRCUIT(circ), -err_reason);
510 tor_trace(
TR_SUBSYS(circuit), TR_EV(establish), circ);
547 circuit_mark_for_close(
TO_CIRCUIT(circ), -err_reason);
551 tor_trace(
TR_SUBSYS(circuit), TR_EV(establish), circ);
556circuit_guard_state_t *
580 ocirc_chan_publish(msg);
593 const char *msg = NULL;
594 int should_launch = 0;
611 "Client asked me to connect directly to a private address");
612 return -END_CIRC_REASON_TORPROTOCOL;
623 orport4 ? &orport4->addr : NULL,
624 orport6 ? &orport6->addr : NULL,
631 log_info(
LD_CIRC,
"Next router is %s: %s",
639 log_info(
LD_CIRC,
"connect to firsthop failed. Closing.");
640 return -END_CIRC_REASON_CONNECTFAILED;
650 log_debug(
LD_CIRC,
"connecting in progress (or finished). Good.");
658 circ->base_.
n_chan = n_chan;
662 log_debug(
LD_CIRC,
"Conn open for %s. Delivering first onion skin.",
665 log_info(
LD_CIRC,
"circuit_send_next_onion_skin failed.");
666 circ->base_.
n_chan = NULL;
690 log_debug(
LD_CIRC,
"chan to %s, status=%d",
701 if (circ->marked_for_close || circ->n_chan || !circ->n_hop ||
705 const char *rsa_ident = NULL;
708 rsa_ident = circ->n_hop->identity_digest;
711 ed_ident = &circ->n_hop->ed_identity;
714 if (rsa_ident == NULL && ed_ident == NULL) {
731 log_info(
LD_CIRC,
"Channel failed; closing circ.");
732 circuit_mark_for_close(circ, END_CIRC_REASON_CHANNEL_CLOSED);
737 log_info(
LD_CIRC,
"Channel deprecated for origin circs; closing circ.");
738 circuit_mark_for_close(circ, END_CIRC_REASON_CHANNEL_CLOSED);
741 log_debug(
LD_CIRC,
"Found circ, sending create cell.");
746 extend_info_free(circ->n_hop);
753 "send_next_onion_skin failed; circuit marked for closing.");
754 circuit_mark_for_close(circ, -err_reason);
763 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
770 SMARTLIST_FOREACH_END(circ);
772 smartlist_free(pending_circs);
795 create_cell->
cell_type == CELL_CREATE_FAST ||
800 static ratelim_t circid_warning_limit = RATELIM_INIT(9600);
802 "failed to get unique circID.");
808 memset(&cell, 0,
sizeof(
cell_t));
809 r = relayed ? create_cell_format_relayed(&cell, create_cell)
810 : create_cell_format(&cell, create_cell);
812 log_warn(
LD_CIRC,
"Couldn't format create cell");
815 log_debug(
LD_CIRC,
"Chosen circID %u.", (
unsigned)
id);
825 if (!CHANNEL_IS_OPEN(circ->
n_chan)) {
827 "Got first hop for a circuit without an opened channel. "
853 return ! circuit_has_usable_onion_key(circ);
886 uint16_t *handshake_type_out,
891 if (extend_info_supports_ntor(ei)) {
892 *cell_type_out = CELL_CREATE2;
897 *handshake_type_out = ONION_HANDSHAKE_TYPE_NTOR_V3;
899 *handshake_type_out = ONION_HANDSHAKE_TYPE_NTOR;
902 *cell_type_out = CELL_CREATE;
903 *handshake_type_out = ONION_HANDSHAKE_TYPE_TAP;
918 uint8_t *create_cell_type_out,
919 uint16_t *handshake_type_out,
927 if (*handshake_type_out != ONION_HANDSHAKE_TYPE_TAP) {
928 *cell_type_out = RELAY_COMMAND_EXTEND2;
929 *create_cell_type_out = CELL_CREATE2;
932 *cell_type_out = RELAY_COMMAND_EXTEND;
933 *create_cell_type_out = CELL_CREATE;
984 if (circ->
cpath->
state == CPATH_STATE_CLOSED) {
1020 memset(&cc, 0,
sizeof(cc));
1022 log_debug(
LD_CIRC,
"First skin; sending create cell.");
1056 log_warn(
LD_CIRC,
"onion_skin_create (first hop) failed.");
1057 return - END_CIRC_REASON_INTERNAL;
1062 return - END_CIRC_REASON_RESOURCELIMIT;
1063 tor_trace(
TR_SUBSYS(circuit), TR_EV(first_onion_skin), circ, circ->
cpath);
1065 circ->
cpath->
state = CPATH_STATE_AWAITING_KEYS;
1067 log_info(
LD_CIRC,
"First hop: finished sending %s cell to '%s'",
1068 fast ?
"CREATE_FAST" :
"CREATE",
1087 log_warn(
LD_BUG,
"%d-hop circuit %p with purpose %d has no "
1091 r = GUARD_USABLE_NOW;
1095 const int is_usable_for_streams = (r == GUARD_USABLE_NOW);
1096 if (r == GUARD_USABLE_NOW) {
1098 }
else if (r == GUARD_MAYBE_USABLE_LATER) {
1103 tor_assert_nonfatal(r == GUARD_USABLE_NEVER);
1104 return - END_CIRC_REASON_INTERNAL;
1113 log_info(
LD_CIRC,
"circuit built!");
1121 if (is_usable_for_streams)
1129 "Tor has successfully opened a circuit. "
1130 "Looks like client functionality is working.");
1135 !router_all_orports_seem_reachable(options)) {
1142 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
1162 memset(&ec, 0,
sizeof(ec));
1166 log_debug(
LD_CIRC,
"starting to send subsequent skin.");
1177 int n_addrs_set = 0;
1183 if (orport6 && include_ipv6) {
1189 if (n_addrs_set == 0) {
1190 log_warn(
LD_BUG,
"No supported address family found in extend_info.");
1191 return - END_CIRC_REASON_INTERNAL;
1204 log_warn(
LD_CIRC,
"onion_skin_create failed.");
1205 return - END_CIRC_REASON_INTERNAL;
1209 log_info(
LD_CIRC,
"Sending extend relay cell.");
1212 uint16_t payload_len=0;
1215 log_warn(
LD_CIRC,
"Couldn't format extend cell");
1216 return -END_CIRC_REASON_INTERNAL;
1221 if (relay_send_command_from_edge(0,
TO_CIRCUIT(circ),
1223 (
char*)payload, payload_len,
1227 hop->
state = CPATH_STATE_AWAITING_KEYS;
1228 tor_trace(
TR_SUBSYS(circuit), TR_EV(intermediate_onion_skin), circ, hop);
1242 " seconds; assuming established circuits no longer work.",
1246 "Your system clock just jumped %"PRId64
" seconds %s; "
1247 "assuming established circuits no longer work.",
1249 seconds_elapsed >=0 ? seconds_elapsed : -seconds_elapsed),
1250 seconds_elapsed >=0 ?
"forward" :
"backward");
1254 (seconds_elapsed), was_idle?1:0);
1261 if (seconds_elapsed < 0) {
1280 char keys[CPATH_KEY_MATERIAL_LEN];
1285 log_warn(
LD_CIRC,
"pathbias_count_build_attempt failed: %d", rv);
1289 if (circ->
cpath->
state == CPATH_STATE_AWAITING_KEYS) {
1294 log_warn(
LD_PROTOCOL,
"got extended when circ already built? Closing.");
1295 return - END_CIRC_REASON_TORPROTOCOL;
1302 const char *msg = NULL;
1306 (uint8_t*)keys,
sizeof(keys),
1311 log_warn(
LD_CIRC,
"onion_skin_client_handshake failed: %s", msg);
1312 return -END_CIRC_REASON_TORPROTOCOL;
1319 return -END_CIRC_REASON_TORPROTOCOL;
1338 "Unexpected path length %d for exit circuit %d, purpose %d",
1347 "Unexpected path length %d for exit circuit %d, purpose %d",
1356 hop->
state = CPATH_STATE_OPEN;
1357 log_info(
LD_CIRC,
"Finished building circuit hop:");
1387 while (layer->next != circ->
cpath) {
1389 victim = layer->next;
1390 log_debug(
LD_CIRC,
"Killing a layer of the cpath.");
1393 if (stream->cpath_layer == victim) {
1394 log_info(
LD_APP,
"Marking stream %d for close because of truncate.",
1399 connection_mark_unattached_ap(stream, END_STREAM_REASON_DESTROY);
1403 layer->next = victim->next;
1407 log_info(
LD_CIRC,
"finished");
1453 int known_purpose = 0;
1522 if (BUG(exit_ei && !known_purpose)) {
1523 log_warn(
LD_BUG,
"Unhandled purpose %d with a chosen exit; "
1524 "assuming routelen %d.", purpose, routelen);
1548 log_debug(
LD_CIRC,
"Chosen route length %d (%d direct and %d indirect "
1549 "routers suitable).", routelen, num_acceptable_direct,
1550 num_acceptable_indirect);
1552 if (num_acceptable_direct < 1 || num_acceptable_indirect < routelen - 1) {
1554 "Not enough acceptable routers (%d/%d direct and %d/%d "
1555 "indirect routers suitable). Discarding this circuit.",
1556 num_acceptable_direct, routelen,
1557 num_acceptable_indirect, routelen);
1582 int *need_capacity))
1592 enough = (smartlist_len(sl) == 0);
1593 for (i = 0; i < smartlist_len(sl); ++i) {
1594 port = smartlist_get(sl, i);
1612 for (i = 0; i < smartlist_len(needed_ports); ++i) {
1616 port = *(uint16_t *)smartlist_get(needed_ports, i);
1662 int n_pending_connections = 0;
1664 int best_support = -1;
1665 int n_best_support=0;
1668 const node_t *selected_node=NULL;
1669 const int need_uptime = (flags & CRN_NEED_UPTIME) != 0;
1670 const int need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
1697 ++n_pending_connections;
1709 n_supported = tor_calloc(smartlist_len(the_nodes),
sizeof(
int));
1711 const int i = node_sl_idx;
1713 n_supported[i] = -1;
1720 if (!router_can_choose_node(node, flags)) {
1721 n_supported[i] = -1;
1724 if (node->is_bad_exit) {
1725 n_supported[i] = -1;
1729 n_supported[i] = -1;
1734 n_supported[i] = -1;
1738 n_supported[i] = -1;
1756 } SMARTLIST_FOREACH_END(conn);
1757 if (n_pending_connections > 0 && n_supported[i] == 0) {
1762 if (n_supported[i] > best_support) {
1765 best_support = n_supported[i]; n_best_support=1;
1768 }
else if (n_supported[i] == best_support) {
1773 } SMARTLIST_FOREACH_END(node);
1775 "Found %d servers that might support %d/%d pending connections.",
1776 n_best_support, best_support >= 0 ? best_support : 0,
1777 n_pending_connections);
1781 if (best_support > 0) {
1785 if (n_supported[node_sl_idx] == best_support)
1790 smartlist_free(supporting);
1799 if (best_support == -1) {
1800 if (need_uptime || need_capacity) {
1802 "We couldn't find any live%s%s routers; falling back "
1803 "to list of all routers.",
1804 need_capacity?
", fast":
"",
1805 need_uptime?
", stable":
"");
1807 flags &= ~(CRN_NEED_UPTIME|CRN_NEED_CAPACITY);
1810 log_notice(
LD_CIRC,
"All routers are down or won't exit%s -- "
1811 "choosing a doomed exit at random.",
1816 for (attempt = 0; attempt < 2; attempt++) {
1820 if (n_supported[node_sl_idx] != -1 &&
1826 } SMARTLIST_FOREACH_END(node);
1834 if (smartlist_len(needed_ports))
1838 smartlist_free(needed_ports);
1839 smartlist_free(supporting);
1843 if (selected_node) {
1845 return selected_node;
1849 "No exits in ExitNodes%s seem to be running: "
1850 "can't choose an exit.",
1852 ", except possibly those excluded by your configuration, " :
"");
1880 const routerset_t *pick_from,
1881 const routerset_t *exclude_set,
1885 const node_t *middle_node = NULL;
1901 } SMARTLIST_FOREACH_END(live_node);
1918#define MAX_SANE_RESTRICTED_NODES 20
1925 if (smartlist_len(allowlisted_live_middles) <=
1926 MAX_SANE_RESTRICTED_NODES) {
1929 static ratelim_t pinned_notice_limit = RATELIM_INIT(24*3600);
1931 "Your _HSLayer%dNodes setting has resulted "
1932 "in %d total nodes. This is a lot of nodes. "
1933 "You may want to consider using a Tor controller "
1934 "to select and update a smaller set of nodes instead.",
1935 position_hint, smartlist_len(allowlisted_live_middles));
1945 smartlist_free(allowlisted_live_middles);
1946 smartlist_free(all_live_nodes);
1966 flags |= CRN_NEED_DESC;
1974 tor_assert_nonfatal(is_internal);
1985 const node_t *rendezvous_node = pick_rendezvous_node(flags);
1986 log_info(
LD_REND,
"Picked new RP: %s",
1988 return rendezvous_node;
2004 const char *description;
2005 uint8_t purpose = circ->base_.
purpose;
2017 log_warn(
LD_BUG,
"Called on non-origin circuit (purpose %d, %s)",
2025 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
2028 description =
"requested exit node";
2043 description =
"chosen rendezvous point";
2047 description =
"controller-selected circuit target";
2054 log_warn(
LD_BUG,
"Using %s '%s' which is listed in ExcludeNodes%s, "
2055 "even though StrictNodes is set. Please report. "
2056 "(Circuit purpose: %s)",
2061 log_warn(
LD_CIRC,
"Using %s '%s' which is listed in "
2062 "ExcludeNodes%s, because no better options were available. To "
2063 "prevent this (and possibly break your Tor functionality), "
2064 "set the StrictNodes configuration option. "
2065 "(Circuit purpose: %s)",
2087 flags |= CRN_NEED_UPTIME;
2089 flags |= CRN_NEED_CAPACITY;
2107 if (state->is_ipv6_selftest && cur_len == state->desired_path_len - 2)
2108 return CRN_INITIATE_IPV6_EXTEND;
2123 int is_hs_v3_rp_circuit)
2128 log_debug(
LD_CIRC,
"Launching a one-hop circuit for dir tunnel%s.",
2129 (hs_service_allow_non_anonymous_connection(
get_options()) ?
2130 ", or intro or rendezvous connection" :
""));
2141 log_info(
LD_CIRC,
"Using requested exit node '%s'",
2146 flags |= cpath_build_state_to_crn_flags(state);
2150 flags |= CRN_DIRECT_CONN;
2151 if (is_hs_v3_rp_circuit)
2152 flags |= CRN_RENDEZVOUS_V3;
2154 flags |= CRN_CONFLUX;
2158 log_warn(
LD_CIRC,
"Failed to choose an exit server");
2168 if (BUG(exit_ei == NULL))
2211 log_warn(
LD_CIRC,
"Couldn't extend circuit to new point %s.",
2213 circuit_mark_for_close(
TO_CIRCUIT(circ), -err_reason);
2231 int flags = CRN_NEED_DESC;
2234 flags |= CRN_DIRECT_CONN;
2240 if (!router_can_choose_node(node, flags))
2243 } SMARTLIST_FOREACH_END(node);
2304 for (i = 0, cpath = head; cpath && i < cur_len; ++i, cpath=cpath->
next) {
2347 for (i = 0, cpath = head; cpath && i < cur_len; ++i, cpath=cpath->
next) {
2359 uint8_t purpose,
int cur_len)
2392 const routerset_t *vanguard_routerset = NULL;
2393 const node_t *node = NULL;
2399 }
else if (cur_len == 2) {
2407 if (BUG(!vanguard_routerset)) {
2416 static ratelim_t pinned_warning_limit = RATELIM_INIT(300);
2418 "Could not find a node that matches the configured "
2419 "_HSLayer%dNodes set", cur_len+1);
2442 tor_assert(CIRCUIT_PURPOSE_MIN_ <= purpose &&
2443 purpose <= CIRCUIT_PURPOSE_MAX_);
2445 log_debug(
LD_CIRC,
"Contemplating intermediate hop #%d: random choice.",
2450 flags |= cpath_build_state_to_crn_flags(state);
2451 flags |= cpath_build_state_to_crn_ipv6_extend_flag(state, cur_len);
2455 log_debug(
LD_GENERAL,
"Picking a sticky node (cur_len = %d)", cur_len);
2457 smartlist_free(excluded);
2479 smartlist_free(excluded);
2495 circuit_guard_state_t **guard_state_out)
2509 tor_assert_nonfatal(state);
2528 flags |= cpath_build_state_to_crn_flags(state);
2532 smartlist_free(excluded);
2545 uint8_t purpose = circ->base_.
purpose;
2551 log_debug(
LD_CIRC,
"Path is complete: %d steps long",
2556 log_debug(
LD_CIRC,
"Path is %d long; we want %d", cur_len,
2561 }
else if (cur_len == 0) {
2571 tor_assert_nonfatal(info || client);
2588 "Failed to find node for hop #%d of our path. Discarding "
2589 "this circuit.", cur_len+1);
2592 "Failed to find node for hop #%d of our path. Discarding "
2593 "this circuit.", cur_len+1);
2598 log_debug(
LD_CIRC,
"Chose router %s for hop #%d (exit is %s)",
2603 extend_info_free(info);
2646circuit_purpose_can_use_tap_impl(uint8_t purpose)
2661 return (circuit_purpose_can_use_tap_impl(circ->base_.
purpose) &&
2673 circuit_can_use_tap(circ));
2685 if (to_upgrade == NULL)
2688 log_info(
LD_GUARD,
"Upgrading %d circuits from 'waiting for better guard' "
2689 "to 'open'.", smartlist_len(to_upgrade));
2694 } SMARTLIST_FOREACH_END(circ);
2696 smartlist_free(to_upgrade);
2710 size_t *msg_len_out)
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
void tor_addr_make_unspec(tor_addr_t *a)
const char * hex_str(const char *from, size_t fromlen)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
int extend_info_is_a_configured_bridge(const extend_info_t *ei)
Header file for circuitbuild.c.
Fixed-size cell structure.
void channel_timestamp_client(channel_t *chan)
channel_t * channel_get_for_extend(const char *rsa_id_digest, const ed25519_public_key_t *ed_id, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr, bool for_origin_circ, const char **msg_out, int *launch_out)
const char * channel_state_to_string(channel_state_t state)
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
int channel_remote_identity_matches(const channel_t *chan, const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
channel_t * channel_connect(const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id)
const char * channel_describe_peer(channel_t *chan)
void channel_dump_statistics(channel_t *chan, int severity)
Header file for channel.c.
void channel_mark_as_used_for_origin_circuit(channel_t *chan)
int pathbias_count_build_attempt(origin_circuit_t *circ)
void pathbias_count_build_success(origin_circuit_t *circ)
static int circuit_send_first_onion_skin(origin_circuit_t *circ)
static void circuit_pick_extend_handshake(uint8_t *cell_type_out, uint8_t *create_cell_type_out, uint16_t *handshake_type_out, const extend_info_t *ei)
static int circuit_build_no_more_hops(origin_circuit_t *circ)
int circuit_extend_to_new_exit(origin_circuit_t *circ, extend_info_t *exit_ei)
STATIC int count_acceptable_nodes(const smartlist_t *nodes, int direct)
STATIC int onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit_ei, int is_hs_v3_rp_circuit)
const char * build_state_get_exit_nickname(cpath_build_state_t *state)
int circuit_handle_first_hop(origin_circuit_t *circ)
static int middle_node_must_be_vanguard(const or_options_t *options, uint8_t purpose, int cur_len)
void circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
static const node_t * pick_restricted_middle_node(router_crn_flags_t flags, const routerset_t *pick_from, const routerset_t *exclude_set, const smartlist_t *exclude_list, int position_hint)
STATIC circid_t get_unique_circ_id_by_chan(channel_t *chan)
static smartlist_t * build_middle_exclude_list(const origin_circuit_t *circ, uint8_t purpose, cpath_build_state_t *state, crypt_path_t *head, int cur_len)
int route_len_for_purpose(uint8_t purpose, extend_info_t *exit_ei)
STATIC int onion_extend_cpath(origin_circuit_t *circ)
int client_circ_negotiation_message(const extend_info_t *ei, uint8_t **msg_out, size_t *msg_len_out)
static void circuit_pick_create_handshake(uint8_t *cell_type_out, uint16_t *handshake_type_out, const extend_info_t *ei)
char * circuit_list_path_for_controller(origin_circuit_t *circ)
STATIC int new_route_len(uint8_t purpose, extend_info_t *exit_ei, const smartlist_t *nodes)
static const node_t * choose_good_middle_server(const origin_circuit_t *, uint8_t purpose, cpath_build_state_t *state, crypt_path_t *head, int cur_len)
circuit_guard_state_t * origin_circuit_get_guard_state(origin_circuit_t *circ)
static int onion_populate_cpath(origin_circuit_t *circ)
int circuit_deliver_create_cell(circuit_t *circ, const struct create_cell_t *create_cell, int relayed)
static int circuit_may_omit_guard(const origin_circuit_t *circ)
static int ap_stream_wants_exit_attention(connection_t *conn)
const uint8_t * build_state_get_exit_rsa_id(cpath_build_state_t *state)
void circuit_n_chan_done(channel_t *chan, int status, int close_origin_circuits)
static smartlist_t * build_vanguard_middle_exclude_list(uint8_t purpose, cpath_build_state_t *state, crypt_path_t *head, int cur_len)
static int circuit_cpath_supports_ntor(const origin_circuit_t *circ)
int circuit_timeout_want_to_count_circ(const origin_circuit_t *circ)
static smartlist_t * circuit_get_unhandled_ports(time_t now)
static const node_t * pick_vanguard_middle_node(const or_options_t *options, router_crn_flags_t flags, int cur_len, const smartlist_t *excluded)
static const node_t * choose_good_exit_server(origin_circuit_t *circ, router_crn_flags_t flags, int is_internal)
static void warn_if_last_router_excluded(origin_circuit_t *circ, const extend_info_t *exit_ei)
origin_circuit_t * circuit_establish_circuit_conflux(const uint8_t *conflux_nonce, uint8_t purpose, extend_info_t *exit_ei, int flags)
channel_t * channel_connect_for_circuit(const extend_info_t *ei)
char * circuit_list_path(origin_circuit_t *circ, int verbose)
int circuit_all_predicted_ports_handled(time_t now, int *need_uptime, int *need_capacity)
void circuit_note_clock_jumped(int64_t seconds_elapsed, bool was_idle)
int circuit_send_next_onion_skin(origin_circuit_t *circ)
int circuit_finish_handshake(origin_circuit_t *circ, const created_cell_t *reply)
static const node_t * choose_good_exit_server_general(router_crn_flags_t flags)
int circuit_append_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)
int circuit_truncated(origin_circuit_t *circ, int reason)
const node_t * choose_good_entry_server(const origin_circuit_t *circ, uint8_t purpose, cpath_build_state_t *state, circuit_guard_state_t **guard_state_out)
static void circuit_chan_publish(const origin_circuit_t *circ, const channel_t *chan)
static bool should_use_create_fast_for_circuit(origin_circuit_t *circ)
static int circuit_send_intermediate_onion_skin(origin_circuit_t *circ, crypt_path_t *hop)
const node_t * build_state_get_exit_node(cpath_build_state_t *state)
static int node_handles_some_port(const node_t *node, smartlist_t *needed_ports)
static char * circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
void circuit_upgrade_circuits_from_guard_wait(void)
origin_circuit_t * origin_circuit_init(uint8_t purpose, int flags)
Header file for circuitbuild.c.
int circuit_id_in_use_on_channel(circid_t circ_id, channel_t *chan)
void circuit_set_n_circid_chan(circuit_t *circ, circid_t id, channel_t *chan)
void circuit_mark_all_dirty_circs_as_unusable(void)
void circuit_set_state(circuit_t *circ, uint8_t state)
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
origin_circuit_t * origin_circuit_new(void)
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
int circuit_get_cpath_len(origin_circuit_t *circ)
int circuit_get_cpath_opened_len(const origin_circuit_t *circ)
void circuit_get_all_pending_on_channel(smartlist_t *out, channel_t *chan)
int circuit_event_status(origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
time_t circuit_id_when_marked_unusable_on_channel(circid_t circ_id, channel_t *chan)
crypt_path_t * circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum)
const char * circuit_purpose_to_string(uint8_t purpose)
void circuit_mark_all_unused_circs(void)
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_S_CONNECT_REND
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT
#define CIRCUIT_PURPOSE_REND_POINT_WAITING
#define CIRCUIT_STATE_OPEN
#define CIRCUIT_STATE_BUILDING
#define CIRCUIT_PURPOSE_C_REND_JOINED
#define CIRCUIT_PURPOSE_INTRO_POINT
#define CIRCUIT_PURPOSE_CONTROLLER
#define CIRCUIT_IS_ORIGIN(c)
#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
unsigned int circuitmux_num_active_circuits(circuitmux_t *cmux)
unsigned int circuitmux_num_circuits(circuitmux_t *cmux)
void circpad_machine_event_circ_added_hop(origin_circuit_t *on_circ)
void circpad_machine_event_circ_built(origin_circuit_t *circ)
Header file for circuitpadding.c.
void circuit_build_times_handle_completed_hop(origin_circuit_t *circ)
Header file for circuitstats.c.
int circuit_should_use_vanguards(uint8_t purpose)
void circuit_has_opened(origin_circuit_t *circ)
void circuit_reset_failure_count(int timeout)
int circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min)
void circuit_remove_handled_ports(smartlist_t *needed_ports)
int circuit_purpose_is_hidden_service(uint8_t purpose)
Header file for circuituse.c.
#define CIRCLAUNCH_NEED_CAPACITY
#define CIRCLAUNCH_IS_IPV6_SELFTEST
#define CIRCLAUNCH_ONEHOP_TUNNEL
#define CIRCLAUNCH_IS_V3_RP
#define CIRCLAUNCH_IS_INTERNAL
#define CIRCLAUNCH_NEED_UPTIME
#define CIRCLAUNCH_NEED_CONFLUX
void command_setup_channel(channel_t *chan)
Header file for command.c.
const or_options_t * get_options(void)
tor_cmdline_mode_t command
Header file for config.c.
void conflux_add_middles_to_exclude_list(const origin_circuit_t *orig_circ, smartlist_t *excluded)
Header file for conflux_pool.c.
congestion_control_t * congestion_control_new(const circuit_params_t *params, cc_path_t path)
int congestion_control_build_ext_request(uint8_t **msg_out, size_t *msg_len_out)
bool congestion_control_enabled(void)
Public APIs for congestion control.
Header file for connection.c.
int connection_ap_can_use_exit(const entry_connection_t *conn, const node_t *exit_node)
int connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
entry_connection_t * TO_ENTRY_CONN(connection_t *c)
edge_connection_t * TO_EDGE_CONN(connection_t *c)
Header file for connection_edge.c.
#define AP_CONN_STATE_CIRCUIT_WAIT
void clear_broken_connection_map(int stop_recording)
Header file for connection_or.c.
void control_event_bootstrap(bootstrap_status_t status, int progress)
int control_event_general_status(int severity, const char *format,...)
int control_event_client_status(int severity, const char *format,...)
Header file for control_events.c.
Circuit-build-stse structure.
crypt_path_t * cpath_get_next_non_open_hop(crypt_path_t *cpath)
int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
int cpath_init_circuit_crypto(crypt_path_t *cpath, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3)
void cpath_free(crypt_path_t *victim)
Header file for crypt_path.c.
void ed25519_pubkey_copy(ed25519_public_key_t *dest, const ed25519_public_key_t *src)
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
void * smartlist_choose(const smartlist_t *sl)
void crypto_rand(char *to, size_t n)
Common functions for using (pseudo-)random number generators.
const char * extend_info_describe(const extend_info_t *ei)
const char * node_describe(const node_t *node)
Header file for describe.c.
Header file for directory.c.
Entry connection structure.
const routerset_t * get_layer2_guards(void)
guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p)
bool vanguards_lite_is_enabled(void)
const node_t * guards_choose_guard(const origin_circuit_t *circ, cpath_build_state_t *state, uint8_t purpose, circuit_guard_state_t **guard_state_out)
Header file for circuitbuild.c.
Header file for Tor tracing instrumentation definition.
extend_info_t * extend_info_dup(extend_info_t *info)
extend_info_t * extend_info_from_node(const node_t *node, int for_direct_connect, bool for_exit)
const tor_addr_port_t * extend_info_pick_orport(const extend_info_t *ei)
const tor_addr_port_t * extend_info_get_orport(const extend_info_t *ei, int family)
bool extend_info_any_orport_addr_is_internal(const extend_info_t *ei)
Header for core/or/extendinfo.c.
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
#define log_fn_ratelim(ratelim, severity, domain, args,...)
void note_that_we_maybe_cant_complete_circuits(void)
int have_completed_a_circuit(void)
void note_that_we_completed_a_circuit(void)
smartlist_t * get_connection_array(void)
void reset_all_main_loop_timers(void)
Header file for mainloop.c.
Header file for microdesc.c.
Header file for networkstatus.c.
int is_legal_nickname(const char *s)
Header file for nickname.c.
const node_t * router_choose_random_node(smartlist_t *excludedsmartlist, routerset_t *excludedset, router_crn_flags_t flags)
const node_t * node_sl_choose_by_bandwidth(const smartlist_t *sl, bandwidth_weight_rule_t rule)
Header file for node_select.c.
Node information structure.
const node_t * node_get_by_id(const char *identity_digest)
void nodelist_add_node_and_family(smartlist_t *sl, const node_t *node)
const smartlist_t * nodelist_get_list(void)
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
int router_have_minimum_dir_info(void)
int node_exit_policy_rejects_all(const node_t *node)
Header file for nodelist.c.
Header file for ocirc_event.c.
int extend_cell_format(uint8_t *command_out, uint16_t *len_out, uint8_t *payload_out, const extend_cell_t *cell_in)
int onion_skin_client_handshake(int type, const onion_handshake_state_t *handshake_state, const uint8_t *reply, size_t reply_len, uint8_t *keys_out, size_t keys_out_len, uint8_t *rend_authenticator_out, circuit_params_t *params_out, const char **msg_out)
int onion_skin_create(int type, const extend_info_t *node, onion_handshake_state_t *state_out, uint8_t *onion_skin_out, size_t onion_skin_out_maxlen)
void onion_handshake_state_release(onion_handshake_state_t *state)
Header file for onion_crypto.c.
Header file for onion_fast.c.
Header file for onion_tap.c.
Master header file for Tor-specific functionality.
#define MIN_CIRCUITS_HANDLING_STREAM
#define DEFAULT_ROUTE_LEN
#define END_CIRC_REASON_NOPATH
#define MAX_VERBOSE_NICKNAME_LEN
#define RELAY_PAYLOAD_SIZE
#define END_CIRC_REASON_FLAG_REMOTE
Origin circuit structure.
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_remove_predicted_ports(const smartlist_t *rmv_ports)
smartlist_t * rep_hist_get_predicted_ports(time_t now)
Header file for predict_ports.c.
char * rate_limit_log(ratelim_t *lim, time_t now)
void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan, cell_t *cell, cell_direction_t direction, streamid_t fromstream)
int router_digest_is_me(const char *digest)
Header file for router.c.
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
Header file for routerlist.c.
int server_mode(const or_options_t *options)
Header file for routermode.c.
int routerset_contains_node(const routerset_t *set, const node_t *node)
void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset, const routerset_t *excludeset, int running_only)
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
void routerset_subtract_nodes(smartlist_t *lst, const routerset_t *routerset)
Header file for routerset.c.
void router_do_reachability_checks(void)
Header file for selftest.c.
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
int smartlist_contains_int_as_string(const smartlist_t *sl, int num)
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_clear(smartlist_t *sl)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
int(* is_canonical)(channel_t *)
unsigned int num_n_circuits
circ_id_type_bitfield_t circ_id_type
char identity_digest[DIGEST_LEN]
uint64_t global_identifier
channel_usage_info_t channel_usage
ratelim_t last_warned_circ_ids_exhausted
struct timeval timestamp_began
uint16_t marked_for_close
extend_info_t * chosen_exit
unsigned int is_ipv6_selftest
unsigned int onehop_tunnel
unsigned int need_capacity
unsigned int need_conflux
uint8_t onionskin[CELL_PAYLOAD_SIZE - 4]
uint8_t reply[CELL_PAYLOAD_SIZE - 2]
struct crypt_path_t * prev
struct crypt_path_t * next
extend_info_t * extend_info
char rend_circ_nonce[DIGEST_LEN]
onion_handshake_state_t handshake_state
struct congestion_control_t * ccontrol
struct edge_connection_t * next_stream
unsigned int use_begindir
tor_addr_port_t orport_ipv4
create_cell_t create_cell
struct ed25519_public_key_t ed_pubkey
uint8_t node_id[DIGEST_LEN]
tor_addr_port_t orport_ipv6
ed25519_public_key_t ed_identity
char identity_digest[DIGEST_LEN]
char nickname[MAX_HEX_NICKNAME_LEN+1]
bool exit_supports_congestion_control
char identity[DIGEST_LEN]
struct routerset_t * ExcludeExitNodesUnion_
struct routerset_t * ExcludeNodes
struct routerset_t * ExitNodes
struct routerset_t * HSLayer2Nodes
struct smartlist_t * LongLivedPorts
int ExtendAllowPrivateAddresses
struct routerset_t * MiddleNodes
struct routerset_t * HSLayer3Nodes
uint32_t global_identifier
edge_connection_t * p_streams
cpath_build_state_t * build_state
struct circuit_guard_state_t * guard_state
unsigned first_hop_from_controller
#define MOCK_IMPL(rv, funcname, arglist)
void tor_gettimeofday(struct timeval *timeval)
Headers for transports.c.
#define tor_assert_nonfatal_unreached()
#define tor_fragile_assert()
#define IF_BUG_ONCE(cond)
int tor_digest_is_zero(const char *digest)