Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
circuitbuild.c
Go to the documentation of this file.
1/* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
5/* See LICENSE for licensing information */
6
7/**
8 * \file circuitbuild.c
9 *
10 * \brief Implements the details of building circuits (by choosing paths,
11 * constructing/sending create/extend cells, and so on).
12 *
13 * On the client side, this module handles launching circuits. Circuit
14 * launches are started from circuit_establish_circuit(), called from
15 * circuit_launch_by_extend_info()). To choose the path the circuit will
16 * take, onion_extend_cpath() calls into a maze of node selection functions.
17 *
18 * Once the circuit is ready to be launched, the first hop is treated as a
19 * special case with circuit_handle_first_hop(), since it might need to open a
20 * channel. As the channel opens, and later as CREATED and RELAY_EXTENDED
21 * cells arrive, the client will invoke circuit_send_next_onion_skin() to send
22 * CREATE or RELAY_EXTEND cells.
23 *
24 * The server side is handled in feature/relay/circuitbuild_relay.c.
25 **/
26
27#define CIRCUITBUILD_PRIVATE
28#define OCIRC_EVENT_PRIVATE
29
30#include "core/or/or.h"
31#include "app/config/config.h"
32#include "lib/confmgt/confmgt.h"
33#include "core/crypto/hs_ntor.h"
38#include "core/or/channel.h"
40#include "core/or/circuitlist.h"
42#include "core/or/circuituse.h"
44#include "core/or/command.h"
48#include "core/or/extendinfo.h"
49#include "core/or/onion.h"
50#include "core/or/ocirc_event.h"
51#include "core/or/policies.h"
52#include "core/or/relay.h"
53#include "core/or/trace_probes_circuit.h"
54#include "core/or/crypt_path.h"
56#include "feature/client/circpathbias.h"
74#include "lib/trace/events.h"
76
77#include "core/or/cell_st.h"
82#include "core/or/or_circuit_st.h"
84
85#include "trunnel/extension.h"
86#include "trunnel/congestion_control.h"
87
91 crypt_path_t *hop);
93 uint8_t purpose,
95 crypt_path_t *head,
96 int cur_len);
97
98/** This function tries to get a channel to the specified endpoint,
99 * and then calls command_setup_channel() to give it the right
100 * callbacks.
101 */
104{
105 channel_t *chan;
106
107 const tor_addr_port_t *orport = extend_info_pick_orport(ei);
108 if (!orport)
109 return NULL;
110 const char *id_digest = ei->identity_digest;
111 const ed25519_public_key_t *ed_id = &ei->ed_identity;
112
113 chan = channel_connect(&orport->addr, orport->port, id_digest, ed_id);
114 if (chan) command_setup_channel(chan);
115
116 return chan;
117}
118
119/** Search for a value for circ_id that we can use on <b>chan</b> for an
120 * outbound circuit, until we get a circ_id that is not in use by any other
121 * circuit on that conn.
122 *
123 * Return it, or 0 if can't get a unique circ_id.
124 */
127{
128/* This number is chosen somewhat arbitrarily; see comment below for more
129 * info. When the space is 80% full, it gives a one-in-a-million failure
130 * chance; when the space is 90% full, it gives a one-in-850 chance; and when
131 * the space is 95% full, it gives a one-in-26 failure chance. That seems
132 * okay, though you could make a case IMO for anything between N=32 and
133 * N=256. */
134#define MAX_CIRCID_ATTEMPTS 64
135 int in_use;
136 unsigned n_with_circ = 0, n_pending_destroy = 0, n_weird_pending_destroy = 0;
137 circid_t test_circ_id;
138 circid_t attempts=0;
139 circid_t high_bit, max_range, mask;
140 int64_t pending_destroy_time_total = 0;
141 int64_t pending_destroy_time_max = 0;
142
143 tor_assert(chan);
144
145 if (chan->circ_id_type == CIRC_ID_TYPE_NEITHER) {
146 log_warn(LD_BUG,
147 "Trying to pick a circuit ID for a connection from "
148 "a client with no identity.");
149 return 0;
150 }
151 max_range = (chan->wide_circ_ids) ? (1u<<31) : (1u<<15);
152 mask = max_range - 1;
153 high_bit = (chan->circ_id_type == CIRC_ID_TYPE_HIGHER) ? max_range : 0;
154 do {
155 if (++attempts > MAX_CIRCID_ATTEMPTS) {
156 /* Make sure we don't loop forever because all circuit IDs are used.
157 *
158 * Once, we would try until we had tried every possible circuit ID. But
159 * that's quite expensive. Instead, we try MAX_CIRCID_ATTEMPTS random
160 * circuit IDs, and then give up.
161 *
162 * This potentially causes us to give up early if our circuit ID space
163 * is nearly full. If we have N circuit IDs in use, then we will reject
164 * a new circuit with probability (N / max_range) ^ MAX_CIRCID_ATTEMPTS.
165 * This means that in practice, a few percent of our circuit ID capacity
166 * will go unused.
167 *
168 * The alternative here, though, is to do a linear search over the
169 * whole circuit ID space every time we extend a circuit, which is
170 * not so great either.
171 */
172 int64_t queued_destroys;
174 approx_time());
175 if (m == NULL)
176 return 0; /* This message has been rate-limited away. */
177 if (n_pending_destroy)
178 pending_destroy_time_total /= n_pending_destroy;
179 log_warn(LD_CIRC,"No unused circIDs found on channel %s wide "
180 "circID support, with %u inbound and %u outbound circuits. "
181 "Found %u circuit IDs in use by circuits, and %u with "
182 "pending destroy cells. (%u of those were marked bogusly.) "
183 "The ones with pending destroy cells "
184 "have been marked unusable for an average of %ld seconds "
185 "and a maximum of %ld seconds. This channel is %ld seconds "
186 "old. Failing a circuit.%s",
187 chan->wide_circ_ids ? "with" : "without",
188 chan->num_p_circuits, chan->num_n_circuits,
189 n_with_circ, n_pending_destroy, n_weird_pending_destroy,
190 (long)pending_destroy_time_total,
191 (long)pending_destroy_time_max,
192 (long)(approx_time() - chan->timestamp_created),
193 m);
194 tor_free(m);
195
196 if (!chan->cmux) {
197 /* This warning should be impossible. */
198 log_warn(LD_BUG, " This channel somehow has no cmux on it!");
199 return 0;
200 }
201
202 /* analysis so far on 12184 suggests that we're running out of circuit
203 IDs because it looks like we have too many pending destroy
204 cells. Let's see how many we really have pending.
205 */
206 queued_destroys = circuitmux_count_queued_destroy_cells(chan,
207 chan->cmux);
208
209 log_warn(LD_CIRC, " Circuitmux on this channel has %u circuits, "
210 "of which %u are active. It says it has %"PRId64
211 " destroy cells queued.",
214 (queued_destroys));
215
216 /* Change this into "if (1)" in order to get more information about
217 * possible failure modes here. You'll need to know how to use gdb with
218 * Tor: this will make Tor exit with an assertion failure if the cmux is
219 * corrupt. */
220 if (0)
221 circuitmux_assert_okay(chan->cmux);
222
224
225 return 0;
226 }
227
228 do {
229 crypto_rand((char*) &test_circ_id, sizeof(test_circ_id));
230 test_circ_id &= mask;
231 } while (test_circ_id == 0);
232
233 test_circ_id |= high_bit;
234
235 in_use = circuit_id_in_use_on_channel(test_circ_id, chan);
236 if (in_use == 1)
237 ++n_with_circ;
238 else if (in_use == 2) {
239 time_t since_when;
240 ++n_pending_destroy;
241 since_when =
243 if (since_when) {
244 time_t waiting = approx_time() - since_when;
245 pending_destroy_time_total += waiting;
246 if (waiting > pending_destroy_time_max)
247 pending_destroy_time_max = waiting;
248 } else {
249 ++n_weird_pending_destroy;
250 }
251 }
252 } while (in_use);
253 return test_circ_id;
254}
255
256/** If <b>verbose</b> is false, allocate and return a comma-separated list of
257 * the currently built elements of <b>circ</b>. If <b>verbose</b> is true, also
258 * list information about link status in a more verbose format using spaces.
259 * If <b>verbose_names</b> is false, give hex digests; if <b>verbose_names</b>
260 * is true, use $DIGEST=Name style names.
261 */
262static char *
263circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
264{
265 crypt_path_t *hop;
266 smartlist_t *elements;
267 const char *states[] = {"closed", "waiting for keys", "open"};
268 char *s;
269
270 elements = smartlist_new();
271
272 if (verbose) {
273 const char *nickname = build_state_get_exit_nickname(circ->build_state);
274 smartlist_add_asprintf(elements, "%s%s circ (length %d%s%s):",
275 circ->build_state->is_internal ? "internal" : "exit",
276 circ->build_state->need_uptime ? " (high-uptime)" : "",
278 circ->base_.state == CIRCUIT_STATE_OPEN ? "" : ", last hop ",
279 circ->base_.state == CIRCUIT_STATE_OPEN ? "" :
280 (nickname?nickname:"*unnamed*"));
281 }
282
283 hop = circ->cpath;
284 do {
285 char *elt;
286 const char *id;
287 const node_t *node;
288 if (!hop)
289 break;
290 if (!verbose && hop->state != CPATH_STATE_OPEN)
291 break;
292 if (!hop->extend_info)
293 break;
294 id = hop->extend_info->identity_digest;
295 if (verbose_names) {
296 elt = tor_malloc(MAX_VERBOSE_NICKNAME_LEN+1);
297 if ((node = node_get_by_id(id))) {
298 node_get_verbose_nickname(node, elt);
299 } else if (is_legal_nickname(hop->extend_info->nickname)) {
300 elt[0] = '$';
302 elt[HEX_DIGEST_LEN+1]= '~';
303 strlcpy(elt+HEX_DIGEST_LEN+2,
305 } else {
306 elt[0] = '$';
308 }
309 } else { /* ! verbose_names */
310 elt = tor_malloc(HEX_DIGEST_LEN+2);
311 elt[0] = '$';
313 }
314 tor_assert(elt);
315 if (verbose) {
316 tor_assert(hop->state <= 2);
317 smartlist_add_asprintf(elements,"%s(%s)",elt,states[hop->state]);
318 tor_free(elt);
319 } else {
320 smartlist_add(elements, elt);
321 }
322 hop = hop->next;
323 } while (hop != circ->cpath);
324
325 s = smartlist_join_strings(elements, verbose?" ":",", 0, NULL);
326 SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
327 smartlist_free(elements);
328 return s;
329}
330
331/** If <b>verbose</b> is false, allocate and return a comma-separated
332 * list of the currently built elements of <b>circ</b>. If
333 * <b>verbose</b> is true, also list information about link status in
334 * a more verbose format using spaces.
335 */
336char *
338{
339 return circuit_list_path_impl(circ, verbose, 0);
340}
341
342/** Allocate and return a comma-separated list of the currently built elements
343 * of <b>circ</b>, giving each as a verbose nickname.
344 */
345char *
347{
348 return circuit_list_path_impl(circ, 0, 1);
349}
350
351/** Log, at severity <b>severity</b>, the nicknames of each router in
352 * <b>circ</b>'s cpath. Also log the length of the cpath, and the intended
353 * exit point.
354 */
355void
356circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
357{
358 char *s = circuit_list_path(circ,1);
359 tor_log(severity,domain,"%s",s);
360 tor_free(s);
361}
362
363/** Return 1 iff every node in circ's cpath definitely supports ntor. */
364static int
366{
367 crypt_path_t *head, *cpath;
368
369 cpath = head = circ->cpath;
370 do {
371 /* if the extend_info is missing, we can't tell if it supports ntor */
372 if (!cpath->extend_info) {
373 return 0;
374 }
375
376 /* if the key is blank, it definitely doesn't support ntor */
377 if (!extend_info_supports_ntor(cpath->extend_info)) {
378 return 0;
379 }
380 cpath = cpath->next;
381 } while (cpath != head);
382
383 return 1;
384}
385
386/** Pick all the entries in our cpath. Stop and return 0 when we're
387 * happy, or return -1 if an error occurs. */
388static int
390{
391 int r = 0;
392
393 /* onion_extend_cpath assumes these are non-NULL */
394 tor_assert(circ);
395 tor_assert(circ->build_state);
396
397 while (r == 0) {
398 r = onion_extend_cpath(circ);
399 if (r < 0) {
400 log_info(LD_CIRC,"Generating cpath hop failed.");
401 return -1;
402 }
403 }
404
405 /* The path is complete */
406 tor_assert(r == 1);
407
408 /* Does every node in this path support ntor? */
409 int path_supports_ntor = circuit_cpath_supports_ntor(circ);
410
411 /* We would like every path to support ntor, but we have to allow for some
412 * edge cases. */
414
415 if (circuit_get_cpath_len(circ) == 1) {
416 /* Allow for bootstrapping: when we're fetching directly from a fallback,
417 * authority, or bridge, we have no way of knowing its ntor onion key
418 * before we connect to it. So instead, we try connecting, and end up using
419 * CREATE_FAST. */
420 tor_assert(circ->cpath);
422 const node_t *node = node_get_by_id(
424 /* If we don't know the node and its descriptor, we must be bootstrapping.
425 */
426 if (!node || !node_has_preferred_descriptor(node, 1)) {
427 return 0;
428 }
429 }
430
431 if (BUG(!path_supports_ntor)) {
432 /* If we're building a multi-hop path, and it's not one of the HS or
433 * bootstrapping exceptions, and it doesn't support ntor, something has
434 * gone wrong. */
435 return -1;
436 }
437
438 return 0;
439}
440
441/** Create and return a new origin circuit. Initialize its purpose and
442 * build-state based on our arguments. The <b>flags</b> argument is a
443 * bitfield of CIRCLAUNCH_* flags, see circuit_launch_by_extend_info() for
444 * more details. */
446origin_circuit_init(uint8_t purpose, int flags)
447{
448 /* sets circ->p_circ_id and circ->p_chan */
451 circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
453 ((flags & CIRCLAUNCH_ONEHOP_TUNNEL) ? 1 : 0);
454 circ->build_state->need_uptime =
455 ((flags & CIRCLAUNCH_NEED_UPTIME) ? 1 : 0);
457 ((flags & CIRCLAUNCH_NEED_CAPACITY) ? 1 : 0);
458 circ->build_state->is_internal =
459 ((flags & CIRCLAUNCH_IS_INTERNAL) ? 1 : 0);
461 ((flags & CIRCLAUNCH_IS_IPV6_SELFTEST) ? 1 : 0);
463 ((flags & CIRCLAUNCH_NEED_CONFLUX) ? 1 : 0);
464 circ->base_.purpose = purpose;
465 return circ;
466}
467
468/** Build a new circuit for <b>purpose</b>. If <b>exit</b> is defined, then use
469 * that as your exit router, else choose a suitable exit node. The <b>flags</b>
470 * argument is a bitfield of CIRCLAUNCH_* flags, see
471 * circuit_launch_by_extend_info() for more details.
472 *
473 * Also launch a connection to the first OR in the chosen path, if
474 * it's not open already.
475 */
477circuit_establish_circuit(uint8_t purpose, extend_info_t *exit_ei, int flags)
478{
479 origin_circuit_t *circ;
480 int err_reason = 0;
481
482 circ = origin_circuit_init(purpose, flags);
483
484 if (onion_pick_cpath_exit(circ, exit_ei) < 0 ||
485 onion_populate_cpath(circ) < 0) {
486 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_NOPATH);
487 return NULL;
488 }
489
490 circuit_event_status(circ, CIRC_EVENT_LAUNCHED, 0);
491
492 if ((err_reason = circuit_handle_first_hop(circ)) < 0) {
493 circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
494 return NULL;
495 }
496
497 tor_trace(TR_SUBSYS(circuit), TR_EV(establish), circ);
498 return circ;
499}
500
501/**
502 * Build a new conflux circuit for <b>purpose</b>. If <b>exit</b> is defined,
503 * then use that as your exit router, else choose a suitable exit node.
504 * The <b>flags</b> argument is a bitfield of CIRCLAUNCH_* flags, see
505 * circuit_launch_by_extend_info() for more details.
506 *
507 * Also launch a connection to the first OR in the chosen path, if
508 * it's not open already.
509 */
511circuit_establish_circuit_conflux,(const uint8_t *conflux_nonce,
512 uint8_t purpose, extend_info_t *exit_ei,
513 int flags))
514{
515 origin_circuit_t *circ;
516 int err_reason = 0;
517
518 /* Right now, only conflux client circuits use this function */
520
521 circ = origin_circuit_init(purpose, flags);
522 TO_CIRCUIT(circ)->conflux_pending_nonce =
523 tor_memdup(conflux_nonce, DIGEST256_LEN);
524
525 if (onion_pick_cpath_exit(circ, exit_ei) < 0 ||
526 onion_populate_cpath(circ) < 0) {
527 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_NOPATH);
528 return NULL;
529 }
530
531 circuit_event_status(circ, CIRC_EVENT_LAUNCHED, 0);
532
533 if ((err_reason = circuit_handle_first_hop(circ)) < 0) {
534 circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
535 return NULL;
536 }
537
538 tor_trace(TR_SUBSYS(circuit), TR_EV(establish), circ);
539 return circ;
540}
541
542/** Return the guard state associated with <b>circ</b>, which may be NULL. */
543circuit_guard_state_t *
545{
546 return circ->guard_state;
547}
548
549/**
550 * Helper function to publish a channel association message
551 *
552 * circuit_handle_first_hop() calls this to notify subscribers about a
553 * channel launch event, which associates a circuit with a channel.
554 * This doesn't always correspond to an assignment of the circuit's
555 * n_chan field, because that seems to be only for fully-open
556 * channels.
557 **/
558static void
560{
561 ocirc_chan_msg_t *msg = tor_malloc(sizeof(*msg));
562
563 msg->gid = circ->global_identifier;
564 msg->chan = chan->global_identifier;
565 msg->onehop = circ->build_state->onehop_tunnel;
566
567 ocirc_chan_publish(msg);
568}
569
570/** Start establishing the first hop of our circuit. Figure out what
571 * OR we should connect to, and if necessary start the connection to
572 * it. If we're already connected, then send the 'create' cell.
573 * Return 0 for ok, -reason if circ should be marked-for-close. */
574int
576{
577 crypt_path_t *firsthop;
578 channel_t *n_chan;
579 int err_reason = 0;
580 const char *msg = NULL;
581 int should_launch = 0;
582 const or_options_t *options = get_options();
583
584 firsthop = cpath_get_next_non_open_hop(circ->cpath);
585 tor_assert(firsthop);
586 tor_assert(firsthop->extend_info);
587
588 /* Some bridges are on private addresses. Others pass a dummy private
589 * address to the pluggable transport, which ignores it.
590 * Deny the connection if:
591 * - the address is internal, and
592 * - we're not connecting to a configured bridge, and
593 * - we're not configured to allow extends to private addresses. */
596 !options->ExtendAllowPrivateAddresses) {
597 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
598 "Client asked me to connect directly to a private address");
599 return -END_CIRC_REASON_TORPROTOCOL;
600 }
601
602 /* now see if we're already connected to the first OR in 'route' */
603 const tor_addr_port_t *orport4 =
604 extend_info_get_orport(firsthop->extend_info, AF_INET);
605 const tor_addr_port_t *orport6 =
606 extend_info_get_orport(firsthop->extend_info, AF_INET6);
607 n_chan = channel_get_for_extend(
608 firsthop->extend_info->identity_digest,
609 &firsthop->extend_info->ed_identity,
610 orport4 ? &orport4->addr : NULL,
611 orport6 ? &orport6->addr : NULL,
612 true,
613 &msg,
614 &should_launch);
615
616 if (!n_chan) {
617 /* not currently connected in a useful way. */
618 log_info(LD_CIRC, "Next router is %s: %s",
619 safe_str_client(extend_info_describe(firsthop->extend_info)),
620 msg?msg:"???");
621 circ->base_.n_hop = extend_info_dup(firsthop->extend_info);
622
623 if (should_launch) {
624 n_chan = channel_connect_for_circuit(firsthop->extend_info);
625 if (!n_chan) { /* connect failed, forget the whole thing */
626 log_info(LD_CIRC,"connect to firsthop failed. Closing.");
627 return -END_CIRC_REASON_CONNECTFAILED;
628 }
629 /* We didn't find a channel, but we're launching one for an origin
630 * circuit. (If we decided not to launch a channel, then we found at
631 * least one once good in-progress channel use for this circuit, and
632 * marked it in channel_get_for_extend().) */
634 circuit_chan_publish(circ, n_chan);
635 }
636
637 log_debug(LD_CIRC,"connecting in progress (or finished). Good.");
638 /* return success. The onion/circuit/etc will be taken care of
639 * automatically (may already have been) whenever n_chan reaches
640 * OR_CONN_STATE_OPEN.
641 */
642 return 0;
643 } else { /* it's already open. use it. */
644 tor_assert(!circ->base_.n_hop);
645 circ->base_.n_chan = n_chan;
646 /* We found a channel, and we're using it for an origin circuit. */
648 circuit_chan_publish(circ, n_chan);
649 log_debug(LD_CIRC,"Conn open for %s. Delivering first onion skin.",
650 safe_str_client(extend_info_describe(firsthop->extend_info)));
651 if ((err_reason = circuit_send_next_onion_skin(circ)) < 0) {
652 log_info(LD_CIRC,"circuit_send_next_onion_skin failed.");
653 circ->base_.n_chan = NULL;
654 return err_reason;
655 }
656 }
657 return 0;
658}
659
660/** Find any circuits that are waiting on <b>or_conn</b> to become
661 * open and get them to send their create cells forward.
662 *
663 * Status is 1 if connect succeeded, or 0 if connect failed.
664 *
665 * Close_origin_circuits is 1 if we should close all the origin circuits
666 * through this channel, or 0 otherwise. (This happens when we want to retry
667 * an older guard.)
668 */
669void
670circuit_n_chan_done(channel_t *chan, int status, int close_origin_circuits)
671{
672 smartlist_t *pending_circs;
673 int err_reason = 0;
674
675 tor_assert(chan);
676
677 log_debug(LD_CIRC,"chan to %s, status=%d",
678 channel_describe_peer(chan), status);
679
680 pending_circs = smartlist_new();
681 circuit_get_all_pending_on_channel(pending_circs, chan);
682
683 SMARTLIST_FOREACH_BEGIN(pending_circs, circuit_t *, circ)
684 {
685 /* These checks are redundant wrt get_all_pending_on_or_conn, but I'm
686 * leaving them in in case it's possible for the status of a circuit to
687 * change as we're going down the list. */
688 if (circ->marked_for_close || circ->n_chan || !circ->n_hop ||
689 circ->state != CIRCUIT_STATE_CHAN_WAIT)
690 continue;
691
692 const char *rsa_ident = NULL;
693 const ed25519_public_key_t *ed_ident = NULL;
694 if (! tor_digest_is_zero(circ->n_hop->identity_digest)) {
695 rsa_ident = circ->n_hop->identity_digest;
696 }
697 if (! ed25519_public_key_is_zero(&circ->n_hop->ed_identity)) {
698 ed_ident = &circ->n_hop->ed_identity;
699 }
700
701 if (rsa_ident == NULL && ed_ident == NULL) {
702 /* Look at addr/port. This is an unkeyed connection. */
703 if (!channel_matches_extend_info(chan, circ->n_hop))
704 continue;
705 } else {
706 /* We expected a key or keys. See if they matched. */
707 if (!channel_remote_identity_matches(chan, rsa_ident, ed_ident))
708 continue;
709
710 /* If the channel is canonical, great. If not, it needs to match
711 * the requested address exactly. */
712 if (! chan->is_canonical &&
713 ! channel_matches_extend_info(chan, circ->n_hop)) {
714 continue;
715 }
716 }
717 if (!status) { /* chan failed; close circ */
718 log_info(LD_CIRC,"Channel failed; closing circ.");
719 circuit_mark_for_close(circ, END_CIRC_REASON_CHANNEL_CLOSED);
720 continue;
721 }
722
723 if (close_origin_circuits && CIRCUIT_IS_ORIGIN(circ)) {
724 log_info(LD_CIRC,"Channel deprecated for origin circs; closing circ.");
725 circuit_mark_for_close(circ, END_CIRC_REASON_CHANNEL_CLOSED);
726 continue;
727 }
728 log_debug(LD_CIRC, "Found circ, sending create cell.");
729 /* circuit_deliver_create_cell will set n_circ_id and add us to
730 * chan_circuid_circuit_map, so we don't need to call
731 * set_circid_chan here. */
732 circ->n_chan = chan;
733 extend_info_free(circ->n_hop);
734 circ->n_hop = NULL;
735
736 if (CIRCUIT_IS_ORIGIN(circ)) {
737 if ((err_reason =
739 log_info(LD_CIRC,
740 "send_next_onion_skin failed; circuit marked for closing.");
741 circuit_mark_for_close(circ, -err_reason);
742 continue;
743 /* XXX could this be bad, eg if next_onion_skin failed because conn
744 * died? */
745 }
746 } else {
747 /* pull the create cell out of circ->n_chan_create_cell, and send it */
748 tor_assert(circ->n_chan_create_cell);
749 if (circuit_deliver_create_cell(circ, circ->n_chan_create_cell, 1)<0) {
750 circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
751 continue;
752 }
753 tor_free(circ->n_chan_create_cell);
755 }
756 }
757 SMARTLIST_FOREACH_END(circ);
758
759 smartlist_free(pending_circs);
760}
761
762/** Find a new circid that isn't currently in use on the circ->n_chan
763 * for the outgoing
764 * circuit <b>circ</b>, and deliver the cell <b>create_cell</b> to this
765 * circuit. If <b>relayed</b> is true, this is a create cell somebody
766 * gave us via an EXTEND cell, so we shouldn't worry if we don't understand
767 * it. Return -1 if we failed to find a suitable circid, else return 0.
768 */
769MOCK_IMPL(int,
771 const struct create_cell_t *create_cell,
772 int relayed))
773{
774 cell_t cell;
775 circid_t id;
776 int r;
777
778 tor_assert(circ);
779 tor_assert(circ->n_chan);
780 tor_assert(create_cell);
781 tor_assert(create_cell->cell_type == CELL_CREATE ||
782 create_cell->cell_type == CELL_CREATE_FAST ||
783 create_cell->cell_type == CELL_CREATE2);
784
786 if (!id) {
787 static ratelim_t circid_warning_limit = RATELIM_INIT(9600);
788 log_fn_ratelim(&circid_warning_limit, LOG_WARN, LD_CIRC,
789 "failed to get unique circID.");
790 goto error;
791 }
792
793 tor_assert_nonfatal_once(circ->n_chan->is_canonical);
794
795 memset(&cell, 0, sizeof(cell_t));
796 r = relayed ? create_cell_format_relayed(&cell, create_cell)
797 : create_cell_format(&cell, create_cell);
798 if (r < 0) {
799 log_warn(LD_CIRC,"Couldn't format create cell");
800 goto error;
801 }
802 log_debug(LD_CIRC,"Chosen circID %u.", (unsigned)id);
803 circuit_set_n_circid_chan(circ, id, circ->n_chan);
804 cell.circ_id = circ->n_circ_id;
805
806 if (append_cell_to_circuit_queue(circ, circ->n_chan, &cell,
807 CELL_DIRECTION_OUT, 0) < 0) {
808 return -1;
809 }
810
811 if (CIRCUIT_IS_ORIGIN(circ)) {
812 /* Update began timestamp for circuits starting their first hop */
813 if (TO_ORIGIN_CIRCUIT(circ)->cpath->state == CPATH_STATE_CLOSED) {
814 if (!CHANNEL_IS_OPEN(circ->n_chan)) {
815 log_warn(LD_CIRC,
816 "Got first hop for a circuit without an opened channel. "
817 "State: %s.", channel_state_to_string(circ->n_chan->state));
819 }
820
822 }
823
824 /* mark it so it gets better rate limiting treatment. */
826 }
827
828 return 0;
829 error:
830 circ->n_chan = NULL;
831 return -1;
832}
833
834/** Return true iff we should send a create_fast cell to start building a
835 * given circuit */
836static inline bool
838{
839 tor_assert(circ->cpath);
841
842 return ! circuit_has_usable_onion_key(circ);
843}
844
845/**
846 * Return true if <b>circ</b> is the type of circuit we want to count
847 * timeouts from.
848 *
849 * In particular, we want to consider any circuit that plans to build
850 * at least 3 hops (but maybe more), but has 3 or fewer hops built
851 * so far.
852 *
853 * We still want to consider circuits before 3 hops, because we need
854 * to decide if we should convert them to a measurement circuit in
855 * circuit_build_times_handle_completed_hop(), rather than letting
856 * slow circuits get killed right away.
857 */
858int
860{
861 return !circ->has_opened
864}
865
866/** Decide whether to use a TAP or ntor handshake for connecting to <b>ei</b>
867 * directly, and set *<b>cell_type_out</b> and *<b>handshake_type_out</b>
868 * accordingly.
869 * Note that TAP handshakes in CREATE cells are only used for direct
870 * connections:
871 * - from Single Onions to rend points not in the service's consensus.
872 * This is checked in onion_populate_cpath. */
873static void
874circuit_pick_create_handshake(uint8_t *cell_type_out,
875 uint16_t *handshake_type_out,
876 const extend_info_t *ei)
877{
878 /* torspec says: In general, clients SHOULD use CREATE whenever they are
879 * using the TAP handshake, and CREATE2 otherwise. */
880 *cell_type_out = CELL_CREATE2;
881 /* Only use ntor v3 with exits that support congestion control,
882 * and only when it is enabled. */
885 *handshake_type_out = ONION_HANDSHAKE_TYPE_NTOR_V3;
886 else
887 *handshake_type_out = ONION_HANDSHAKE_TYPE_NTOR;
888}
889
890/** Decide whether to use a TAP or ntor handshake for extending to <b>ei</b>
891 * and set *<b>handshake_type_out</b> accordingly. Decide whether we should
892 * use an EXTEND2 or an EXTEND cell to do so, and set *<b>cell_type_out</b>
893 * and *<b>create_cell_type_out</b> accordingly.
894 * Note that TAP handshakes in EXTEND cells are only used:
895 * - from clients to intro points, and
896 * - from hidden services to rend points.
897 * This is checked in onion_populate_cpath.
898 */
899static void
900circuit_pick_extend_handshake(uint8_t *cell_type_out,
901 uint8_t *create_cell_type_out,
902 uint16_t *handshake_type_out,
903 const extend_info_t *ei)
904{
905 uint8_t t;
906 circuit_pick_create_handshake(&t, handshake_type_out, ei);
907
908 *cell_type_out = RELAY_COMMAND_EXTEND2;
909 *create_cell_type_out = CELL_CREATE2;
910}
911
912/**
913 * Return true iff <b>circ</b> is allowed
914 * to have no guard configured, even if the circuit is multihop
915 * and guards are enabled.
916 */
917static int
919{
920 if (BUG(!circ))
921 return 0;
922
923 if (circ->first_hop_from_controller) {
924 /* The controller picked the first hop: that bypasses the guard system. */
925 return 1;
926 }
927
928 switch (circ->base_.purpose) {
931 /* Testing circuits may omit guards because they're measuring
932 * liveness or performance, and don't want guards to interfere. */
933 return 1;
934 default:
935 /* All other multihop circuits should use guards if guards are
936 * enabled. */
937 return 0;
938 }
939}
940
941/** This is the backbone function for building circuits.
942 *
943 * If circ's first hop is closed, then we need to build a create
944 * cell and send it forward.
945 *
946 * Otherwise, if circ's cpath still has any non-open hops, we need to
947 * build a relay extend cell and send it forward to the next non-open hop.
948 *
949 * If all hops on the cpath are open, we're done building the circuit
950 * and we should do housekeeping for the newly opened circuit.
951 *
952 * Return -reason if we want to tear down circ, else return 0.
953 */
954int
956{
957 tor_assert(circ);
958
959 if (circ->cpath->state == CPATH_STATE_CLOSED) {
960 /* Case one: we're on the first hop. */
962 }
963
964 tor_assert(circ->cpath->state == CPATH_STATE_OPEN);
966
969
971
972 if (hop) {
973 /* Case two: we're on a hop after the first. */
974 return circuit_send_intermediate_onion_skin(circ, hop);
975 }
976
977 /* Case three: the circuit is finished. Do housekeeping tasks on it. */
979 return circuit_build_no_more_hops(circ);
980}
981
982/**
983 * Called from circuit_send_next_onion_skin() when we find ourselves connected
984 * to the first hop in <b>circ</b>: Send a CREATE or CREATE2 or CREATE_FAST
985 * cell to that hop. Return 0 on success; -reason on failure (if the circuit
986 * should be torn down).
987 */
988static int
990{
991 int fast;
992 int len;
993 const node_t *node;
994 create_cell_t cc;
995 memset(&cc, 0, sizeof(cc));
996
997 log_debug(LD_CIRC,"First skin; sending create cell.");
998
999 if (circ->build_state->onehop_tunnel) {
1000 control_event_bootstrap(BOOTSTRAP_STATUS_ONEHOP_CREATE, 0);
1001 } else {
1002 control_event_bootstrap(BOOTSTRAP_STATUS_CIRCUIT_CREATE, 0);
1003
1004 /* If this is not a one-hop tunnel, the channel is being used
1005 * for traffic that wants anonymity and protection from traffic
1006 * analysis (such as netflow record retention). That means we want
1007 * to pad it.
1008 */
1009 if (circ->base_.n_chan->channel_usage < CHANNEL_USED_FOR_FULL_CIRCS)
1010 circ->base_.n_chan->channel_usage = CHANNEL_USED_FOR_FULL_CIRCS;
1011 }
1012
1013 node = node_get_by_id(circ->base_.n_chan->identity_digest);
1015 if (!fast) {
1016 /* We know the right onion key: we should send a create cell. */
1018 circ->cpath->extend_info);
1019 } else {
1020 /* We don't know an onion key, so we need to fall back to CREATE_FAST. */
1021 cc.cell_type = CELL_CREATE_FAST;
1022 cc.handshake_type = ONION_HANDSHAKE_TYPE_FAST;
1023 }
1024
1026 circ->cpath->extend_info,
1027 &circ->cpath->handshake_state,
1028 cc.onionskin,
1029 sizeof(cc.onionskin));
1030 if (len < 0) {
1031 log_warn(LD_CIRC,"onion_skin_create (first hop) failed.");
1032 return - END_CIRC_REASON_INTERNAL;
1033 }
1034 cc.handshake_len = len;
1035
1036 if (circuit_deliver_create_cell(TO_CIRCUIT(circ), &cc, 0) < 0)
1037 return - END_CIRC_REASON_RESOURCELIMIT;
1038 tor_trace(TR_SUBSYS(circuit), TR_EV(first_onion_skin), circ, circ->cpath);
1039
1040 circ->cpath->state = CPATH_STATE_AWAITING_KEYS;
1042 log_info(LD_CIRC,"First hop: finished sending %s cell to '%s'",
1043 fast ? "CREATE_FAST" : "CREATE",
1044 node ? node_describe(node) : "<unnamed>");
1045 return 0;
1046}
1047
1048/**
1049 * Called from circuit_send_next_onion_skin() when we find that we have no
1050 * more hops: mark the circuit as finished, and perform the necessary
1051 * bookkeeping. Return 0 on success; -reason on failure (if the circuit
1052 * should be torn down).
1053 */
1054static int
1056{
1057 guard_usable_t r;
1058 if (! circ->guard_state) {
1059 if (circuit_get_cpath_len(circ) != 1 &&
1060 ! circuit_may_omit_guard(circ) &&
1061 get_options()->UseEntryGuards) {
1062 log_warn(LD_BUG, "%d-hop circuit %p with purpose %d has no "
1063 "guard state",
1064 circuit_get_cpath_len(circ), circ, circ->base_.purpose);
1065 }
1066 r = GUARD_USABLE_NOW;
1067 } else {
1069 }
1070 const int is_usable_for_streams = (r == GUARD_USABLE_NOW);
1071 if (r == GUARD_USABLE_NOW) {
1073 } else if (r == GUARD_MAYBE_USABLE_LATER) {
1074 // Wait till either a better guard succeeds, or till
1075 // all better guards fail.
1077 } else {
1078 tor_assert_nonfatal(r == GUARD_USABLE_NEVER);
1079 return - END_CIRC_REASON_INTERNAL;
1080 }
1081
1082 /* XXXX #21422 -- the rest of this branch needs careful thought!
1083 * Some of the things here need to happen when a circuit becomes
1084 * mechanically open; some need to happen when it is actually usable.
1085 * I think I got them right, but more checking would be wise. -NM
1086 */
1087
1088 log_info(LD_CIRC,"circuit built!");
1090
1091 if (circ->build_state->onehop_tunnel || circ->has_opened) {
1092 control_event_bootstrap(BOOTSTRAP_STATUS_REQUESTING_STATUS, 0);
1093 }
1094
1096 if (is_usable_for_streams)
1097 circuit_has_opened(circ); /* do other actions as necessary */
1098
1100 const or_options_t *options = get_options();
1102 /* FFFF Log a count of known routers here */
1103 log_info(LD_GENERAL,
1104 "Tor has successfully opened a circuit. "
1105 "Looks like client functionality is working.");
1106 control_event_bootstrap(BOOTSTRAP_STATUS_DONE, 0);
1107 control_event_client_status(LOG_NOTICE, "CIRCUIT_ESTABLISHED");
1109 if (server_mode(options) &&
1110 !router_all_orports_seem_reachable(options)) {
1112 }
1113 }
1114
1115 /* We're done with measurement circuits here. Just close them */
1116 if (circ->base_.purpose == CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1117 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
1118 }
1119 return 0;
1120}
1121
1122/**
1123 * Called from circuit_send_next_onion_skin() when we find that we have a hop
1124 * other than the first that we need to extend to: use <b>hop</b>'s
1125 * information to extend the circuit another step. Return 0 on success;
1126 * -reason on failure (if the circuit should be torn down).
1127 */
1128static int
1130 crypt_path_t *hop)
1131{
1132 int len;
1133 extend_cell_t ec;
1134 /* Relays and bridges can send IPv6 extends. But for clients, it's an
1135 * obvious version distinguisher. */
1136 const bool include_ipv6 = server_mode(get_options());
1137 memset(&ec, 0, sizeof(ec));
1140
1141 log_debug(LD_CIRC,"starting to send subsequent skin.");
1142
1146 hop->extend_info);
1147
1148 const tor_addr_port_t *orport4 =
1149 extend_info_get_orport(hop->extend_info, AF_INET);
1150 const tor_addr_port_t *orport6 =
1151 extend_info_get_orport(hop->extend_info, AF_INET6);
1152 int n_addrs_set = 0;
1153 if (orport4) {
1154 tor_addr_copy(&ec.orport_ipv4.addr, &orport4->addr);
1155 ec.orport_ipv4.port = orport4->port;
1156 ++n_addrs_set;
1157 }
1158 if (orport6 && include_ipv6) {
1159 tor_addr_copy(&ec.orport_ipv6.addr, &orport6->addr);
1160 ec.orport_ipv6.port = orport6->port;
1161 ++n_addrs_set;
1162 }
1163
1164 if (n_addrs_set == 0) {
1165 log_warn(LD_BUG, "No supported address family found in extend_info.");
1166 return - END_CIRC_REASON_INTERNAL;
1167 }
1168 memcpy(ec.node_id, hop->extend_info->identity_digest, DIGEST_LEN);
1169 /* Set the ED25519 identity too -- it will only get included
1170 * in the extend2 cell if we're configured to use it, though. */
1172
1174 hop->extend_info,
1175 &hop->handshake_state,
1177 sizeof(ec.create_cell.onionskin));
1178 if (len < 0) {
1179 log_warn(LD_CIRC,"onion_skin_create failed.");
1180 return - END_CIRC_REASON_INTERNAL;
1181 }
1182 ec.create_cell.handshake_len = len;
1183
1184 log_info(LD_CIRC,"Sending extend relay cell.");
1185 {
1186 uint8_t command = 0;
1187 uint16_t payload_len=0;
1188 uint8_t payload[RELAY_PAYLOAD_SIZE_MAX];
1189 if (extend_cell_format(&command, &payload_len, payload, &ec)<0) {
1190 log_warn(LD_CIRC,"Couldn't format extend cell");
1191 return -END_CIRC_REASON_INTERNAL;
1192 }
1193
1194 if (payload_len > circuit_max_relay_payload(
1195 TO_CIRCUIT(circ), hop->prev, command)) {
1196 log_warn(LD_BUG, "Generated a too-long extend cell");
1197 return -END_CIRC_REASON_INTERNAL;
1198 }
1199
1200 /* send it to hop->prev, because that relay will transfer
1201 * it to a create cell and then send to hop */
1202 if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
1203 command,
1204 (char*)payload, payload_len,
1205 hop->prev) < 0)
1206 return 0; /* circuit is closed */
1207 }
1208 hop->state = CPATH_STATE_AWAITING_KEYS;
1209 tor_trace(TR_SUBSYS(circuit), TR_EV(intermediate_onion_skin), circ, hop);
1210 return 0;
1211}
1212
1213/** Our clock just jumped by <b>seconds_elapsed</b>. If <b>was_idle</b> is
1214 * true, then the monotonic time matches; otherwise it doesn't. Assume
1215 * something has also gone wrong with our network: notify the user, and
1216 * abandon all not-yet-used circuits. */
1217void
1218circuit_note_clock_jumped(int64_t seconds_elapsed, bool was_idle)
1219{
1220 int severity = server_mode(get_options()) ? LOG_WARN : LOG_NOTICE;
1221 if (was_idle) {
1222 tor_log(severity, LD_GENERAL, "Tor has been idle for %"PRId64
1223 " seconds; assuming established circuits no longer work.",
1224 (seconds_elapsed));
1225 } else {
1226 tor_log(severity, LD_GENERAL,
1227 "Your system clock just jumped %"PRId64" seconds %s; "
1228 "assuming established circuits no longer work.",
1229 (
1230 seconds_elapsed >=0 ? seconds_elapsed : -seconds_elapsed),
1231 seconds_elapsed >=0 ? "forward" : "backward");
1232 }
1233 control_event_general_status(LOG_WARN, "CLOCK_JUMPED TIME=%"PRId64
1234 " IDLE=%d",
1235 (seconds_elapsed), was_idle?1:0);
1236 /* so we log when it works again */
1238 control_event_client_status(severity, "CIRCUIT_NOT_ESTABLISHED REASON=%s",
1239 "CLOCK_JUMPED");
1242 if (seconds_elapsed < 0) {
1243 /* Restart all the timers in case we jumped a long way into the past. */
1245 }
1246}
1247
1248/** A "created" cell <b>reply</b> came back to us on circuit <b>circ</b>.
1249 * (The body of <b>reply</b> varies depending on what sort of handshake
1250 * this is.)
1251 *
1252 * Calculate the appropriate keys and digests, make sure KH is
1253 * correct, and initialize this hop of the cpath.
1254 *
1255 * Return - reason if we want to mark circ for close, else return 0.
1256 */
1257int
1259 const created_cell_t *reply)
1260{
1261 char keys[CPATH_KEY_MATERIAL_LEN];
1262 crypt_path_t *hop;
1263 int rv;
1264
1265 if ((rv = pathbias_count_build_attempt(circ)) < 0) {
1266 log_warn(LD_CIRC, "pathbias_count_build_attempt failed: %d", rv);
1267 return rv;
1268 }
1269
1270 if (circ->cpath->state == CPATH_STATE_AWAITING_KEYS) {
1271 hop = circ->cpath;
1272 } else {
1274 if (!hop) { /* got an extended when we're all done? */
1275 log_warn(LD_PROTOCOL,"got extended when circ already built? Closing.");
1276 return - END_CIRC_REASON_TORPROTOCOL;
1277 }
1278 }
1279 tor_assert(hop->state == CPATH_STATE_AWAITING_KEYS);
1280
1281 circuit_params_t params;
1282 {
1283 const char *msg = NULL;
1285 &hop->handshake_state,
1286 reply->reply, reply->handshake_len,
1287 (uint8_t*)keys, sizeof(keys),
1288 (uint8_t*)hop->rend_circ_nonce,
1289 &params,
1290 &msg) < 0) {
1291 if (msg)
1292 log_warn(LD_CIRC,"onion_skin_client_handshake failed: %s", msg);
1293 return -END_CIRC_REASON_TORPROTOCOL;
1294 }
1295 }
1296
1298
1299 if (cpath_init_circuit_crypto(hop, keys, sizeof(keys), 0, 0)<0) {
1300 return -END_CIRC_REASON_TORPROTOCOL;
1301 }
1302
1303 if (params.cc_enabled) {
1304 int circ_len = circuit_get_cpath_len(circ);
1305
1306 if (circ_len == DEFAULT_ROUTE_LEN &&
1308 hop->ccontrol = congestion_control_new(&params, CC_PATH_EXIT);
1309 } else if (circ_len == SBWS_ROUTE_LEN &&
1310 circuit_get_cpath_hop(circ, SBWS_ROUTE_LEN) == hop) {
1311 hop->ccontrol = congestion_control_new(&params, CC_PATH_SBWS);
1312 } else {
1313 if (circ_len > DEFAULT_ROUTE_LEN) {
1314 /* This can happen for unknown reasons; cannibalization codepaths
1315 * don't seem able to do it, so there is some magic way that hops can
1316 * still get added. Perhaps some cases of circuit pre-build that change
1317 * purpose? */
1318 log_info(LD_CIRC,
1319 "Unexpected path length %d for exit circuit %d, purpose %d",
1320 circ_len, circ->global_identifier,
1321 TO_CIRCUIT(circ)->purpose);
1322 hop->ccontrol = congestion_control_new(&params, CC_PATH_EXIT);
1323 } else {
1324 /* This is likely directory requests, which should block on orconn
1325 * before congestion control, but let's give them the lower sbws
1326 * param set anyway just in case. */
1327 log_info(LD_CIRC,
1328 "Unexpected path length %d for exit circuit %d, purpose %d",
1329 circ_len, circ->global_identifier,
1330 TO_CIRCUIT(circ)->purpose);
1331
1332 hop->ccontrol = congestion_control_new(&params, CC_PATH_SBWS);
1333 }
1334 }
1335 }
1336
1337 hop->state = CPATH_STATE_OPEN;
1338 log_info(LD_CIRC,"Finished building circuit hop:");
1340 circuit_event_status(circ, CIRC_EVENT_EXTENDED, 0);
1341
1342 return 0;
1343}
1344
1345/** We received a relay truncated cell on circ.
1346 *
1347 * Since we don't send truncates currently, getting a truncated
1348 * means that a connection broke or an extend failed. For now,
1349 * just give up: force circ to close, and return 0.
1350 */
1351int
1353{
1354// crypt_path_t *victim;
1355// connection_t *stream;
1356
1357 tor_assert(circ);
1358
1359 /* XXX Since we don't send truncates currently, getting a truncated
1360 * means that a connection broke or an extend failed. For now,
1361 * just give up.
1362 */
1363 circuit_mark_for_close(TO_CIRCUIT(circ),
1365 return 0;
1366
1367#if 0
1368 while (layer->next != circ->cpath) {
1369 /* we need to clear out layer->next */
1370 victim = layer->next;
1371 log_debug(LD_CIRC, "Killing a layer of the cpath.");
1372
1373 for (stream = circ->p_streams; stream; stream=stream->next_stream) {
1374 if (stream->cpath_layer == victim) {
1375 log_info(LD_APP, "Marking stream %d for close because of truncate.",
1376 stream->stream_id);
1377 /* no need to send 'end' relay cells,
1378 * because the other side's already dead
1379 */
1380 connection_mark_unattached_ap(stream, END_STREAM_REASON_DESTROY);
1381 }
1382 }
1383
1384 layer->next = victim->next;
1385 cpath_free(victim);
1386 }
1387
1388 log_info(LD_CIRC, "finished");
1389 return 0;
1390#endif /* 0 */
1391}
1392
1393/** Helper for new_route_len(). Choose a circuit length for purpose
1394 * <b>purpose</b>: DEFAULT_ROUTE_LEN (+ 1 if someone else chose the
1395 * exit). If someone else chose the exit, they could be colluding
1396 * with the exit, so add a randomly selected node to preserve
1397 * anonymity.
1398 *
1399 * Here, "exit node" sometimes means an OR acting as an internal
1400 * endpoint, rather than as a relay to an external endpoint. This
1401 * means there need to be at least DEFAULT_ROUTE_LEN routers between
1402 * us and the internal endpoint to preserve the same anonymity
1403 * properties that we would get when connecting to an external
1404 * endpoint. These internal endpoints can include:
1405 *
1406 * - Connections to a directory of hidden services
1407 * (CIRCUIT_PURPOSE_C_GENERAL)
1408 *
1409 * - A client connecting to an introduction point, which the hidden
1410 * service picked (CIRCUIT_PURPOSE_C_INTRODUCING, via
1411 * circuit_get_open_circ_or_launch() which rewrites it from
1412 * CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT)
1413 *
1414 * - A hidden service connecting to a rendezvous point, which the
1415 * client picked (CIRCUIT_PURPOSE_S_CONNECT_REND.
1416 *
1417 * There are currently two situations where we picked the exit node
1418 * ourselves, making DEFAULT_ROUTE_LEN a safe circuit length:
1419 *
1420 * - We are a hidden service connecting to an introduction point
1421 * (CIRCUIT_PURPOSE_S_ESTABLISH_INTRO).
1422 *
1423 * - We are a router testing its own reachabiity
1424 * (CIRCUIT_PURPOSE_TESTING, via router_do_reachability_checks())
1425 *
1426 * onion_pick_cpath_exit() bypasses us (by not calling
1427 * new_route_len()) in the one-hop tunnel case, so we don't need to
1428 * handle that.
1429 */
1430int
1431route_len_for_purpose(uint8_t purpose, extend_info_t *exit_ei)
1432{
1433 int routelen = DEFAULT_ROUTE_LEN;
1434 int known_purpose = 0;
1435
1436 /* If we're using L3 vanguards, we need longer paths for onion services */
1437 if (circuit_purpose_is_hidden_service(purpose) &&
1438 get_options()->HSLayer3Nodes) {
1439 /* Clients want an extra hop for rends to avoid linkability.
1440 * Services want it for intro points to avoid publishing their
1441 * layer3 guards. They want it for hsdir posts to use
1442 * their full layer3 guard set for those connections.
1443 * Ex: C - G - L2 - L3 - R
1444 * S - G - L2 - L3 - HSDIR
1445 * S - G - L2 - L3 - I
1446 */
1447 if (purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND ||
1448 purpose == CIRCUIT_PURPOSE_S_HSDIR_POST ||
1449 purpose == CIRCUIT_PURPOSE_HS_VANGUARDS ||
1451 return routelen+1;
1452
1453 /* For connections to hsdirs, clients want two extra hops
1454 * when using layer3 guards, to avoid linkability.
1455 * Same goes for intro points. Note that the route len
1456 * includes the intro point or hsdir, hence the +2.
1457 * Ex: C - G - L2 - L3 - M - I
1458 * C - G - L2 - L3 - M - HSDIR
1459 * S - G - L2 - L3 - M - R
1460 */
1461 if (purpose == CIRCUIT_PURPOSE_S_CONNECT_REND ||
1462 purpose == CIRCUIT_PURPOSE_C_HSDIR_GET ||
1464 return routelen+2;
1465 }
1466
1467 if (!exit_ei)
1468 return routelen;
1469
1470 switch (purpose) {
1471 /* These purposes connect to a router that we chose, so DEFAULT_ROUTE_LEN
1472 * is safe: */
1475 /* router reachability testing */
1476 known_purpose = 1;
1477 break;
1478
1479 /* These purposes connect to a router that someone else
1480 * might have chosen, so add an extra hop to protect anonymity. */
1484 /* connecting to hidden service directory */
1486 /* client connecting to introduction point */
1488 /* hidden service connecting to rendezvous point */
1490 /* hidden service connecting to intro point. In this case we want an extra
1491 hop to avoid linkability attacks by the introduction point. */
1492 known_purpose = 1;
1493 routelen++;
1494 break;
1495
1496 default:
1497 /* Got a purpose not listed above along with a chosen exit.
1498 * Increase the circuit length by one anyway for safety. */
1499 routelen++;
1500 break;
1501 }
1502
1503 if (BUG(exit_ei && !known_purpose)) {
1504 log_warn(LD_BUG, "Unhandled purpose %d with a chosen exit; "
1505 "assuming routelen %d.", purpose, routelen);
1506 }
1507 return routelen;
1508}
1509
1510/** Choose a length for a circuit of purpose <b>purpose</b> and check
1511 * if enough routers are available.
1512 *
1513 * If the routerlist <b>nodes</b> doesn't have enough routers
1514 * to handle the desired path length, return -1.
1515 */
1516STATIC int
1517new_route_len(uint8_t purpose, extend_info_t *exit_ei,
1518 const smartlist_t *nodes)
1519{
1520 int routelen;
1521
1522 tor_assert(nodes);
1523
1524 routelen = route_len_for_purpose(purpose, exit_ei);
1525
1526 int num_acceptable_direct = count_acceptable_nodes(nodes, 1);
1527 int num_acceptable_indirect = count_acceptable_nodes(nodes, 0);
1528
1529 log_debug(LD_CIRC,"Chosen route length %d (%d direct and %d indirect "
1530 "routers suitable).", routelen, num_acceptable_direct,
1531 num_acceptable_indirect);
1532
1533 if (num_acceptable_direct < 1 || num_acceptable_indirect < routelen - 1) {
1534 log_info(LD_CIRC,
1535 "Not enough acceptable routers (%d/%d direct and %d/%d "
1536 "indirect routers suitable). Discarding this circuit.",
1537 num_acceptable_direct, routelen,
1538 num_acceptable_indirect, routelen);
1539 return -1;
1540 }
1541
1542 return routelen;
1543}
1544
1545/** Return a newly allocated list of uint16_t * for each predicted port not
1546 * handled by a current circuit. */
1547static smartlist_t *
1549{
1552 return dest;
1553}
1554
1555/** Return 1 if we already have circuits present or on the way for
1556 * all anticipated ports. Return 0 if we should make more.
1557 *
1558 * If we're returning 0, set need_uptime and need_capacity to
1559 * indicate any requirements that the unhandled ports have.
1560 */
1561MOCK_IMPL(int,
1562circuit_all_predicted_ports_handled, (time_t now, int *need_uptime,
1563 int *need_capacity))
1564{
1565 int i, enough;
1566 uint16_t *port;
1568 smartlist_t *LongLivedServices = get_options()->LongLivedPorts;
1569 tor_assert(need_uptime);
1570 tor_assert(need_capacity);
1571 // Always predict need_capacity
1572 *need_capacity = 1;
1573 enough = (smartlist_len(sl) == 0);
1574 for (i = 0; i < smartlist_len(sl); ++i) {
1575 port = smartlist_get(sl, i);
1576 if (smartlist_contains_int_as_string(LongLivedServices, *port))
1577 *need_uptime = 1;
1578 tor_free(port);
1579 }
1580 smartlist_free(sl);
1581 return enough;
1582}
1583
1584/** Return 1 if <b>node</b> can handle one or more of the ports in
1585 * <b>needed_ports</b>, else return 0.
1586 */
1587static int
1588node_handles_some_port(const node_t *node, smartlist_t *needed_ports)
1589{ /* XXXX MOVE */
1590 int i;
1591 uint16_t port;
1592
1593 for (i = 0; i < smartlist_len(needed_ports); ++i) {
1595 /* alignment issues aren't a worry for this dereference, since
1596 needed_ports is explicitly a smartlist of uint16_t's */
1597 port = *(uint16_t *)smartlist_get(needed_ports, i);
1598 tor_assert(port);
1599 if (node)
1600 r = compare_tor_addr_to_node_policy(NULL, port, node);
1601 else
1602 continue;
1604 return 1;
1605 }
1606 return 0;
1607}
1608
1609/** Return true iff <b>conn</b> needs another general circuit to be
1610 * built. */
1611static int
1613{
1614 entry_connection_t *entry;
1615 if (conn->type != CONN_TYPE_AP)
1616 return 0;
1617 entry = TO_ENTRY_CONN(conn);
1618
1619 if (conn->state == AP_CONN_STATE_CIRCUIT_WAIT &&
1620 !conn->marked_for_close &&
1621 !(entry->want_onehop) && /* ignore one-hop streams */
1622 !(entry->use_begindir) && /* ignore targeted dir fetches */
1623 !(entry->chosen_exit_name) && /* ignore defined streams */
1627 return 1;
1628 return 0;
1629}
1630
1631/** Return a pointer to a suitable router to be the exit node for the
1632 * general-purpose circuit we're about to build.
1633 *
1634 * Look through the connection array, and choose a router that maximizes
1635 * the number of pending streams that can exit from this router.
1636 *
1637 * Return NULL if we can't find any suitable routers.
1638 */
1639static const node_t *
1641{
1642 int *n_supported;
1643 int n_pending_connections = 0;
1644 smartlist_t *connections;
1645 int best_support = -1;
1646 int n_best_support=0;
1647 const or_options_t *options = get_options();
1648 const smartlist_t *the_nodes;
1649 const node_t *selected_node=NULL;
1650 const int need_uptime = (flags & CRN_NEED_UPTIME) != 0;
1651 const int need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
1652
1653 /* We should not require guard flags on exits. */
1654 IF_BUG_ONCE(flags & CRN_NEED_GUARD)
1655 return NULL;
1656
1657 /* We reject single-hop exits for all node positions. */
1658 IF_BUG_ONCE(flags & CRN_DIRECT_CONN)
1659 return NULL;
1660
1661 /* We only want exits to extend if we cannibalize the circuit.
1662 * But we don't require IPv6 extends yet. */
1663 IF_BUG_ONCE(flags & CRN_INITIATE_IPV6_EXTEND)
1664 return NULL;
1665
1666 connections = get_connection_array();
1667
1668 /* Count how many connections are waiting for a circuit to be built.
1669 * We use this for log messages now, but in the future we may depend on it.
1670 */
1671 SMARTLIST_FOREACH(connections, connection_t *, conn,
1672 {
1674 ++n_pending_connections;
1675 });
1676// log_fn(LOG_DEBUG, "Choosing exit node; %d connections are pending",
1677// n_pending_connections);
1678 /* Now we count, for each of the routers in the directory, how many
1679 * of the pending connections could possibly exit from that
1680 * router (n_supported[i]). (We can't be sure about cases where we
1681 * don't know the IP address of the pending connection.)
1682 *
1683 * -1 means "Don't use this router at all."
1684 */
1685 the_nodes = nodelist_get_list();
1686 n_supported = tor_calloc(smartlist_len(the_nodes), sizeof(int));
1687 SMARTLIST_FOREACH_BEGIN(the_nodes, const node_t *, node) {
1688 const int i = node_sl_idx;
1689 if (router_digest_is_me(node->identity)) {
1690 n_supported[i] = -1;
1691// log_fn(LOG_DEBUG,"Skipping node %s -- it's me.", router->nickname);
1692 /* XXX there's probably a reverse predecessor attack here, but
1693 * it's slow. should we take this out? -RD
1694 */
1695 continue;
1696 }
1697 if (!router_can_choose_node(node, flags)) {
1698 n_supported[i] = -1;
1699 continue;
1700 }
1701 if (node->is_bad_exit) {
1702 n_supported[i] = -1;
1703 continue; /* skip routers that are known to be down or bad exits */
1704 }
1705 if (routerset_contains_node(options->ExcludeExitNodesUnion_, node)) {
1706 n_supported[i] = -1;
1707 continue; /* user asked us not to use it, no matter what */
1708 }
1709 if (options->ExitNodes &&
1710 !routerset_contains_node(options->ExitNodes, node)) {
1711 n_supported[i] = -1;
1712 continue; /* not one of our chosen exit nodes */
1713 }
1714 if (node_exit_policy_rejects_all(node)) {
1715 n_supported[i] = -1;
1716// log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- it rejects all.",
1717// router->nickname, i);
1718 continue; /* skip routers that reject all */
1719 }
1720 n_supported[i] = 0;
1721 /* iterate over connections */
1722 SMARTLIST_FOREACH_BEGIN(connections, connection_t *, conn) {
1724 continue; /* Skip everything but APs in CIRCUIT_WAIT */
1725 if (connection_ap_can_use_exit(TO_ENTRY_CONN(conn), node)) {
1726 ++n_supported[i];
1727// log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.",
1728// router->nickname, i, n_supported[i]);
1729 } else {
1730// log_fn(LOG_DEBUG,"%s (index %d) would reject this stream.",
1731// router->nickname, i);
1732 }
1733 } SMARTLIST_FOREACH_END(conn);
1734 if (n_pending_connections > 0 && n_supported[i] == 0) {
1735 /* Leave best_support at -1 if that's where it is, so we can
1736 * distinguish it later. */
1737 continue;
1738 }
1739 if (n_supported[i] > best_support) {
1740 /* If this router is better than previous ones, remember its index
1741 * and goodness, and start counting how many routers are this good. */
1742 best_support = n_supported[i]; n_best_support=1;
1743// log_fn(LOG_DEBUG,"%s is new best supported option so far.",
1744// router->nickname);
1745 } else if (n_supported[i] == best_support) {
1746 /* If this router is _as good_ as the best one, just increment the
1747 * count of equally good routers.*/
1748 ++n_best_support;
1749 }
1750 } SMARTLIST_FOREACH_END(node);
1751 log_info(LD_CIRC,
1752 "Found %d servers that might support %d/%d pending connections.",
1753 n_best_support, best_support >= 0 ? best_support : 0,
1754 n_pending_connections);
1755
1756 /* If any routers definitely support any pending connections, choose one
1757 * at random. */
1758 if (best_support > 0) {
1759 smartlist_t *supporting = smartlist_new();
1760
1761 SMARTLIST_FOREACH(the_nodes, const node_t *, node, {
1762 if (n_supported[node_sl_idx] == best_support)
1763 smartlist_add(supporting, (void*)node);
1764 });
1765
1766 selected_node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
1767 smartlist_free(supporting);
1768 } else {
1769 /* Either there are no pending connections, or no routers even seem to
1770 * possibly support any of them. Choose a router at random that satisfies
1771 * at least one predicted exit port. */
1772
1773 int attempt;
1774 smartlist_t *needed_ports, *supporting;
1775
1776 if (best_support == -1) {
1777 if (need_uptime || need_capacity) {
1778 log_info(LD_CIRC,
1779 "We couldn't find any live%s%s routers; falling back "
1780 "to list of all routers.",
1781 need_capacity?", fast":"",
1782 need_uptime?", stable":"");
1783 tor_free(n_supported);
1784 flags &= ~(CRN_NEED_UPTIME|CRN_NEED_CAPACITY);
1785 return choose_good_exit_server_general(flags);
1786 }
1787 log_notice(LD_CIRC, "All routers are down or won't exit%s -- "
1788 "choosing a doomed exit at random.",
1789 options->ExcludeExitNodesUnion_ ? " or are Excluded" : "");
1790 }
1791 supporting = smartlist_new();
1792 needed_ports = circuit_get_unhandled_ports(time(NULL));
1793 for (attempt = 0; attempt < 2; attempt++) {
1794 /* try once to pick only from routers that satisfy a needed port,
1795 * then if there are none, pick from any that support exiting. */
1796 SMARTLIST_FOREACH_BEGIN(the_nodes, const node_t *, node) {
1797 if (n_supported[node_sl_idx] != -1 &&
1798 (attempt || node_handles_some_port(node, needed_ports))) {
1799// log_fn(LOG_DEBUG,"Try %d: '%s' is a possibility.",
1800// try, router->nickname);
1801 smartlist_add(supporting, (void*)node);
1802 }
1803 } SMARTLIST_FOREACH_END(node);
1804
1805 selected_node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
1806 if (selected_node)
1807 break;
1808 smartlist_clear(supporting);
1809 /* If we reach this point, we can't actually support any unhandled
1810 * predicted ports, so clear all the remaining ones. */
1811 if (smartlist_len(needed_ports))
1812 rep_hist_remove_predicted_ports(needed_ports);
1813 }
1814 SMARTLIST_FOREACH(needed_ports, uint16_t *, cp, tor_free(cp));
1815 smartlist_free(needed_ports);
1816 smartlist_free(supporting);
1817 }
1818
1819 tor_free(n_supported);
1820 if (selected_node) {
1821 log_info(LD_CIRC, "Chose exit server '%s'", node_describe(selected_node));
1822 return selected_node;
1823 }
1824 if (options->ExitNodes) {
1825 log_warn(LD_CIRC,
1826 "No exits in ExitNodes%s seem to be running: "
1827 "can't choose an exit.",
1828 options->ExcludeExitNodesUnion_ ?
1829 ", except possibly those excluded by your configuration, " : "");
1830 }
1831 return NULL;
1832}
1833
1834/*
1835 * Helper function to pick a configured restricted middle node
1836 * (either HSLayer2Nodes or HSLayer3Nodes).
1837 *
1838 * Make sure that the node we chose is alive, and not excluded,
1839 * and return it.
1840 *
1841 * The exclude_set is a routerset of nodes that the selected node
1842 * must not match, and the exclude_list is a simple list of nodes
1843 * that the selected node must not be in. Either or both may be
1844 * NULL.
1845 *
1846 * Return NULL if no usable nodes could be found. */
1847static const node_t *
1849 const routerset_t *pick_from,
1850 const routerset_t *exclude_set,
1851 const smartlist_t *exclude_list,
1852 int position_hint)
1853{
1854 const node_t *middle_node = NULL;
1855
1856 smartlist_t *allowlisted_live_middles = smartlist_new();
1857 smartlist_t *all_live_nodes = smartlist_new();
1858
1859 tor_assert(pick_from);
1860
1861 /* Add all running nodes to all_live_nodes */
1862 router_add_running_nodes_to_smartlist(all_live_nodes, flags);
1863
1864 /* Filter all_live_nodes to only add live *and* allowlisted middles
1865 * to the list allowlisted_live_middles. */
1866 SMARTLIST_FOREACH_BEGIN(all_live_nodes, node_t *, live_node) {
1867 if (routerset_contains_node(pick_from, live_node)) {
1868 smartlist_add(allowlisted_live_middles, live_node);
1869 }
1870 } SMARTLIST_FOREACH_END(live_node);
1871
1872 /* Honor ExcludeNodes */
1873 if (exclude_set) {
1874 routerset_subtract_nodes(allowlisted_live_middles, exclude_set);
1875 }
1876
1877 if (exclude_list) {
1878 smartlist_subtract(allowlisted_live_middles, exclude_list);
1879 }
1880
1881 /**
1882 * Max number of restricted nodes before we alert the user and try
1883 * to load balance for them.
1884 *
1885 * The most aggressive vanguard design had 16 nodes at layer3.
1886 * Let's give a small ceiling above that. */
1887#define MAX_SANE_RESTRICTED_NODES 20
1888 /* If the user (or associated tor controller) selected only a few nodes,
1889 * assume they took load balancing into account and don't do it for them.
1890 *
1891 * If there are a lot of nodes in here, assume they did not load balance
1892 * and do it for them, but also warn them that they may be Doing It Wrong.
1893 */
1894 if (smartlist_len(allowlisted_live_middles) <=
1895 MAX_SANE_RESTRICTED_NODES) {
1896 middle_node = smartlist_choose(allowlisted_live_middles);
1897 } else {
1898 static ratelim_t pinned_notice_limit = RATELIM_INIT(24*3600);
1899 log_fn_ratelim(&pinned_notice_limit, LOG_NOTICE, LD_CIRC,
1900 "Your _HSLayer%dNodes setting has resulted "
1901 "in %d total nodes. This is a lot of nodes. "
1902 "You may want to consider using a Tor controller "
1903 "to select and update a smaller set of nodes instead.",
1904 position_hint, smartlist_len(allowlisted_live_middles));
1905
1906 /* NO_WEIGHTING here just means don't take node flags into account
1907 * (ie: use consensus measurement only). This is done so that
1908 * we don't further surprise the user by not using Exits that they
1909 * specified at all */
1910 middle_node = node_sl_choose_by_bandwidth(allowlisted_live_middles,
1911 NO_WEIGHTING);
1912 }
1913
1914 smartlist_free(allowlisted_live_middles);
1915 smartlist_free(all_live_nodes);
1916
1917 return middle_node;
1918}
1919
1920/** Return a pointer to a suitable router to be the exit node for the
1921 * circuit of purpose <b>purpose</b> that we're about to build (or NULL
1922 * if no router is suitable).
1923 *
1924 * For general-purpose circuits, pass it off to
1925 * choose_good_exit_server_general()
1926 *
1927 * For client-side rendezvous circuits, choose a random node, weighted
1928 * toward the preferences in 'options'.
1929 */
1930static const node_t *
1932 router_crn_flags_t flags, int is_internal)
1933{
1934 const or_options_t *options = get_options();
1935 flags |= CRN_NEED_DESC;
1936
1937 switch (TO_CIRCUIT(circ)->purpose) {
1942 /* For these three, we want to pick the exit like a middle hop,
1943 * since it should be random. */
1944 tor_assert_nonfatal(is_internal);
1945 /* We want to avoid picking certain nodes for HS purposes. */
1946 flags |= CRN_FOR_HS;
1947 FALLTHROUGH;
1950 if (is_internal) /* pick it like a middle hop */
1951 return router_choose_random_node(NULL, options->ExcludeNodes, flags);
1952 else
1953 return choose_good_exit_server_general(flags);
1954 }
1955 log_warn(LD_BUG,"Unhandled purpose %d", TO_CIRCUIT(circ)->purpose);
1957 return NULL;
1958}
1959
1960/** Log a warning if the user specified an exit for the circuit that
1961 * has been excluded from use by ExcludeNodes or ExcludeExitNodes. */
1962static void
1964 const extend_info_t *exit_ei)
1965{
1966 const or_options_t *options = get_options();
1967 routerset_t *rs = options->ExcludeNodes;
1968 const char *description;
1969 uint8_t purpose = circ->base_.purpose;
1970
1971 if (circ->build_state->onehop_tunnel)
1972 return;
1973
1974 switch (purpose)
1975 {
1976 default:
1977 case CIRCUIT_PURPOSE_OR:
1981 log_warn(LD_BUG, "Called on non-origin circuit (purpose %d, %s)",
1982 (int)purpose,
1983 circuit_purpose_to_string(purpose));
1984 return;
1989 case CIRCUIT_PURPOSE_CONFLUX_LINKED:
1990 if (circ->build_state->is_internal)
1991 return;
1992 description = "requested exit node";
1993 rs = options->ExcludeExitNodesUnion_;
1994 break;
2002 return;
2007 description = "chosen rendezvous point";
2008 break;
2010 rs = options->ExcludeExitNodesUnion_;
2011 description = "controller-selected circuit target";
2012 break;
2013 }
2014
2015 if (routerset_contains_extendinfo(rs, exit_ei)) {
2016 /* We should never get here if StrictNodes is set to 1. */
2017 if (options->StrictNodes) {
2018 log_warn(LD_BUG, "Using %s '%s' which is listed in ExcludeNodes%s, "
2019 "even though StrictNodes is set. Please report. "
2020 "(Circuit purpose: %s)",
2021 description, extend_info_describe(exit_ei),
2022 rs==options->ExcludeNodes?"":" or ExcludeExitNodes",
2023 circuit_purpose_to_string(purpose));
2024 } else {
2025 log_warn(LD_CIRC, "Using %s '%s' which is listed in "
2026 "ExcludeNodes%s, because no better options were available. To "
2027 "prevent this (and possibly break your Tor functionality), "
2028 "set the StrictNodes configuration option. "
2029 "(Circuit purpose: %s)",
2030 description, extend_info_describe(exit_ei),
2031 rs==options->ExcludeNodes?"":" or ExcludeExitNodes",
2032 circuit_purpose_to_string(purpose));
2033 }
2035 }
2036
2037 return;
2038}
2039
2040/* Return a set of generic CRN_* flags based on <b>state</b>.
2041 *
2042 * Called for every position in the circuit. */
2043STATIC int
2044cpath_build_state_to_crn_flags(const cpath_build_state_t *state)
2045{
2046 router_crn_flags_t flags = 0;
2047 /* These flags apply to entry, middle, and exit nodes.
2048 * If a flag only applies to a specific position, it should be checked in
2049 * that function. */
2050 if (state->need_uptime)
2051 flags |= CRN_NEED_UPTIME;
2052 if (state->need_capacity)
2053 flags |= CRN_NEED_CAPACITY;
2054 return flags;
2055}
2056
2057/* Return the CRN_INITIATE_IPV6_EXTEND flag, based on <b>state</b> and
2058 * <b>cur_len</b>.
2059 *
2060 * Only called for middle nodes (for now). Must not be called on single-hop
2061 * circuits. */
2062STATIC int
2063cpath_build_state_to_crn_ipv6_extend_flag(const cpath_build_state_t *state,
2064 int cur_len)
2065{
2066 IF_BUG_ONCE(state->desired_path_len < 2)
2067 return 0;
2068
2069 /* The last node is the relay doing the self-test. So we want to extend over
2070 * IPv6 from the second-last node. */
2071 if (state->is_ipv6_selftest && cur_len == state->desired_path_len - 2)
2072 return CRN_INITIATE_IPV6_EXTEND;
2073 else
2074 return 0;
2075}
2076
2077/** Decide a suitable length for circ's cpath, and pick an exit
2078 * router (or use <b>exit_ei</b> if provided). Store these in the
2079 * cpath.
2080 *
2081 * If <b>is_hs_v3_rp_circuit</b> is set, then this exit should be suitable to
2082 * be used as an HS v3 rendezvous point.
2083 *
2084 * Return 0 if ok, -1 if circuit should be closed. */
2085STATIC int
2087{
2088 cpath_build_state_t *state = circ->build_state;
2089
2090 if (state->onehop_tunnel) {
2091 log_debug(LD_CIRC, "Launching a one-hop circuit for dir tunnel%s.",
2092 (hs_service_allow_non_anonymous_connection(get_options()) ?
2093 ", or intro or rendezvous connection" : ""));
2094 state->desired_path_len = 1;
2095 } else {
2096 int r = new_route_len(circ->base_.purpose, exit_ei, nodelist_get_list());
2097 if (r < 1) /* must be at least 1 */
2098 return -1;
2099 state->desired_path_len = r;
2100 }
2101
2102 if (exit_ei) { /* the circuit-builder pre-requested one */
2103 warn_if_last_router_excluded(circ, exit_ei);
2104 log_info(LD_CIRC,"Using requested exit node '%s'",
2105 extend_info_describe(exit_ei));
2106 exit_ei = extend_info_dup(exit_ei);
2107 } else { /* we have to decide one */
2108 router_crn_flags_t flags = CRN_NEED_DESC;
2109 flags |= cpath_build_state_to_crn_flags(state);
2110 /* Some internal exits are one hop, for example directory connections.
2111 * (Guards are always direct, middles are never direct.) */
2112 if (state->onehop_tunnel)
2113 flags |= CRN_DIRECT_CONN;
2114 if (state->need_conflux)
2115 flags |= CRN_CONFLUX;
2116 const node_t *node =
2117 choose_good_exit_server(circ, flags, state->is_internal);
2118 if (!node) {
2119 log_warn(LD_CIRC,"Failed to choose an exit server");
2120 return -1;
2121 }
2122 exit_ei = extend_info_from_node(node, state->onehop_tunnel,
2123 /* for_exit_use */
2124 !state->is_internal && (
2125 TO_CIRCUIT(circ)->purpose ==
2127 TO_CIRCUIT(circ)->purpose ==
2129 if (BUG(exit_ei == NULL))
2130 return -1;
2131 }
2132 state->chosen_exit = exit_ei;
2133 return 0;
2134}
2135
2136/** Give <b>circ</b> a new exit destination to <b>exit_ei</b>, and add a
2137 * hop to the cpath reflecting this. Don't send the next extend cell --
2138 * the caller will do this if it wants to.
2139 */
2140int
2142{
2143 cpath_build_state_t *state;
2144 tor_assert(exit_ei);
2145 tor_assert(circ);
2146
2147 state = circ->build_state;
2148 tor_assert(state);
2149 extend_info_free(state->chosen_exit);
2150 state->chosen_exit = extend_info_dup(exit_ei);
2151
2153 cpath_append_hop(&circ->cpath, exit_ei);
2154 return 0;
2155}
2156
2157/** Take an open <b>circ</b>, and add a new hop at the end, based on
2158 * <b>info</b>. Set its state back to CIRCUIT_STATE_BUILDING, and then
2159 * send the next extend cell to begin connecting to that hop.
2160 */
2161int
2163{
2164 int err_reason = 0;
2165 warn_if_last_router_excluded(circ, exit_ei);
2166
2167 tor_gettimeofday(&circ->base_.timestamp_began);
2168
2169 circuit_append_new_exit(circ, exit_ei);
2171 if ((err_reason = circuit_send_next_onion_skin(circ))<0) {
2172 log_warn(LD_CIRC, "Couldn't extend circuit to new point %s.",
2173 extend_info_describe(exit_ei));
2174 circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
2175 return -1;
2176 }
2177
2178 return 0;
2179}
2180
2181/** Return the number of routers in <b>nodes</b> that are currently up and
2182 * available for building circuits through.
2183 *
2184 * If <b>direct</b> is true, only count nodes that are suitable for direct
2185 * connections. Counts nodes regardless of whether their addresses are
2186 * preferred.
2187 */
2188MOCK_IMPL(STATIC int,
2189count_acceptable_nodes, (const smartlist_t *nodes, int direct))
2190{
2191 int num=0;
2192 int flags = CRN_NEED_DESC;
2193
2194 if (direct)
2195 flags |= CRN_DIRECT_CONN;
2196
2197 SMARTLIST_FOREACH_BEGIN(nodes, const node_t *, node) {
2198 // log_debug(LD_CIRC,
2199 // "Contemplating whether router %d (%s) is a new option.",
2200 // i, r->nickname);
2201 if (!router_can_choose_node(node, flags))
2202 continue;
2203 ++num;
2204 } SMARTLIST_FOREACH_END(node);
2205
2206// log_debug(LD_CIRC,"I like %d. num_acceptable_routers now %d.",i, num);
2207
2208 return num;
2209}
2210
2211/**
2212 * Build the exclude list for vanguard circuits.
2213 *
2214 * For vanguard circuits we exclude all the already chosen nodes (including the
2215 * exit) from being middle hops to prevent the creation of A - B - A subpaths.
2216 * We also allow the 4th hop to be the same as the guard node so as to not leak
2217 * guard information to RP/IP/HSDirs.
2218 *
2219 * For vanguard circuits, we don't apply any subnet or family restrictions.
2220 * This is to avoid impossible-to-build circuit paths, or just situations where
2221 * our earlier guards prevent us from using most of our later ones.
2222 *
2223 * The alternative is building the circuit in reverse. Reverse calls to
2224 * onion_extend_cpath() (ie: select outer hops first) would then have the
2225 * property that you don't gain information about inner hops by observing
2226 * outer ones. See https://bugs.torproject.org/tpo/core/tor/24487
2227 * for this.
2228 *
2229 * (Note further that we still exclude the exit to prevent A - B - A
2230 * at the end of the path. */
2231static smartlist_t *
2233 cpath_build_state_t *state,
2234 crypt_path_t *head,
2235 int cur_len)
2236{
2237 smartlist_t *excluded;
2238 const node_t *r;
2239 crypt_path_t *cpath;
2240 int i;
2241
2242 (void) purpose;
2243
2244 excluded = smartlist_new();
2245
2246 /* Add the exit to the exclude list (note that the exit/last hop is always
2247 * chosen first in circuit_establish_circuit()). */
2248 if ((r = build_state_get_exit_node(state))) {
2249 smartlist_add(excluded, (node_t*)r);
2250 }
2251
2252 /* If we are picking the 4th hop, allow that node to be the guard too.
2253 * This prevents us from avoiding the Guard for those hops, which
2254 * gives the adversary information about our guard if they control
2255 * the RP, IP, or HSDIR. We don't do this check based on purpose
2256 * because we also want to allow HS_VANGUARDS pre-build circuits
2257 * to use the guard for that last hop.
2258 */
2259 if (cur_len == DEFAULT_ROUTE_LEN+1) {
2260 /* Skip the first hop for the exclude list below */
2261 head = head->next;
2262 cur_len--;
2263 }
2264
2265 for (i = 0, cpath = head; cpath && i < cur_len; ++i, cpath=cpath->next) {
2266 if ((r = node_get_by_id(cpath->extend_info->identity_digest))) {
2267 smartlist_add(excluded, (node_t*)r);
2268 }
2269 }
2270
2271 return excluded;
2272}
2273
2274/**
2275 * Build a list of nodes to exclude from the choice of this middle
2276 * hop, based on already chosen nodes.
2277 */
2278static smartlist_t *
2280 uint8_t purpose,
2281 cpath_build_state_t *state,
2282 crypt_path_t *head,
2283 int cur_len)
2284{
2285 smartlist_t *excluded;
2286 const node_t *r;
2287 crypt_path_t *cpath;
2288 int i;
2289
2290 /** Vanguard circuits have their own path selection rules */
2291 if (circuit_should_use_vanguards(purpose)) {
2292 return build_vanguard_middle_exclude_list(purpose, state, head, cur_len);
2293 }
2294
2295 excluded = smartlist_new();
2296
2297 // Exclude other middles on pending and built conflux circs
2299
2300 /* For non-vanguard circuits, add the exit and its family to the exclude list
2301 * (note that the exit/last hop is always chosen first in
2302 * circuit_establish_circuit()). */
2303 if ((r = build_state_get_exit_node(state))) {
2304 nodelist_add_node_and_family(excluded, r);
2305 }
2306
2307 /* also exclude all other already chosen nodes and their family */
2308 for (i = 0, cpath = head; cpath && i < cur_len; ++i, cpath=cpath->next) {
2309 if ((r = node_get_by_id(cpath->extend_info->identity_digest))) {
2310 nodelist_add_node_and_family(excluded, r);
2311 }
2312 }
2313
2314 return excluded;
2315}
2316
2317/** Return true if we MUST use vanguards for picking this middle node. */
2318static int
2320 uint8_t purpose, int cur_len)
2321{
2322 /* If this is not a hidden service circuit, don't use vanguards */
2323 if (!circuit_purpose_is_hidden_service(purpose)) {
2324 return 0;
2325 }
2326
2327 /* Don't even bother if the feature is disabled */
2329 return 0;
2330 }
2331
2332 /* If we are a hidden service circuit, always use either vanguards-lite
2333 * or HSLayer2Nodes for 2nd hop. */
2334 if (cur_len == 1) {
2335 return 1;
2336 }
2337
2338 /* If we have sticky L3 nodes, and this is an L3 pick, use vanguards */
2339 if (options->HSLayer3Nodes && cur_len == 2) {
2340 return 1;
2341 }
2342
2343 return 0;
2344}
2345
2346/** Pick a sticky vanguard middle node or return NULL if not found.
2347 * See doc of pick_restricted_middle_node() for argument details. */
2348static const node_t *
2350 router_crn_flags_t flags, int cur_len,
2351 const smartlist_t *excluded)
2352{
2353 const routerset_t *vanguard_routerset = NULL;
2354 const node_t *node = NULL;
2355
2356 /* Pick the right routerset based on the current hop */
2357 if (cur_len == 1) {
2358 vanguard_routerset = options->HSLayer2Nodes ?
2359 options->HSLayer2Nodes : get_layer2_guards();
2360 } else if (cur_len == 2) {
2361 vanguard_routerset = options->HSLayer3Nodes;
2362 } else {
2363 /* guaranteed by middle_node_should_be_vanguard() */
2365 return NULL;
2366 }
2367
2368 if (BUG(!vanguard_routerset)) {
2369 return NULL;
2370 }
2371
2372 node = pick_restricted_middle_node(flags, vanguard_routerset,
2373 options->ExcludeNodes, excluded,
2374 cur_len+1);
2375
2376 if (!node) {
2377 static ratelim_t pinned_warning_limit = RATELIM_INIT(300);
2378 log_fn_ratelim(&pinned_warning_limit, LOG_WARN, LD_CIRC,
2379 "Could not find a node that matches the configured "
2380 "_HSLayer%dNodes set", cur_len+1);
2381 }
2382
2383 return node;
2384}
2385
2386/** A helper function used by onion_extend_cpath(). Use <b>purpose</b>
2387 * and <b>state</b> and the cpath <b>head</b> (currently populated only
2388 * to length <b>cur_len</b> to decide a suitable middle hop for a
2389 * circuit. In particular, make sure we don't pick the exit node or its
2390 * family, and make sure we don't duplicate any previous nodes or their
2391 * families. */
2392static const node_t *
2394 uint8_t purpose,
2395 cpath_build_state_t *state,
2396 crypt_path_t *head,
2397 int cur_len)
2398{
2399 const node_t *choice;
2400 smartlist_t *excluded;
2401 const or_options_t *options = get_options();
2402 router_crn_flags_t flags = CRN_NEED_DESC;
2403 tor_assert(CIRCUIT_PURPOSE_MIN_ <= purpose &&
2404 purpose <= CIRCUIT_PURPOSE_MAX_);
2405
2406 log_debug(LD_CIRC, "Contemplating intermediate hop #%d: random choice.",
2407 cur_len+1);
2408
2409 excluded = build_middle_exclude_list(circ, purpose, state, head, cur_len);
2410
2411 flags |= cpath_build_state_to_crn_flags(state);
2412 flags |= cpath_build_state_to_crn_ipv6_extend_flag(state, cur_len);
2413
2414 /** If a hidden service circuit wants a specific middle node, pin it. */
2415 if (middle_node_must_be_vanguard(options, purpose, cur_len)) {
2416 log_debug(LD_GENERAL, "Picking a sticky node (cur_len = %d)", cur_len);
2417 choice = pick_vanguard_middle_node(options, flags, cur_len, excluded);
2418 smartlist_free(excluded);
2419 return choice;
2420 }
2421
2422 if (options->MiddleNodes) {
2423 smartlist_t *sl = smartlist_new();
2425 options->ExcludeNodes, 1);
2426
2427 smartlist_subtract(sl, excluded);
2428
2429 choice = node_sl_choose_by_bandwidth(sl, WEIGHT_FOR_MID);
2430 smartlist_free(sl);
2431 if (choice) {
2432 log_fn(LOG_INFO, LD_CIRC, "Chose fixed middle node: %s",
2433 hex_str(choice->identity, DIGEST_LEN));
2434 } else {
2435 log_fn(LOG_NOTICE, LD_CIRC, "Restricted middle not available");
2436 }
2437 } else {
2438 choice = router_choose_random_node(excluded, options->ExcludeNodes, flags);
2439 }
2440 smartlist_free(excluded);
2441 return choice;
2442}
2443
2444/** Pick a good entry server for the circuit to be built according to
2445 * <b>state</b>. Don't reuse a chosen exit (if any), don't use this
2446 * router (if we're an OR), and respect firewall settings; if we're
2447 * configured to use entry guards, return one.
2448 *
2449 * Set *<b>guard_state_out</b> to information about the guard that
2450 * we're selecting, which we'll use later to remember whether the
2451 * guard worked or not.
2452 */
2453const node_t *
2455 uint8_t purpose, cpath_build_state_t *state,
2456 circuit_guard_state_t **guard_state_out)
2457{
2458 const node_t *choice;
2459 smartlist_t *excluded;
2460 const or_options_t *options = get_options();
2461 /* If possible, choose an entry server with a preferred address,
2462 * otherwise, choose one with an allowed address */
2463 router_crn_flags_t flags = (CRN_NEED_GUARD|CRN_NEED_DESC|CRN_PREF_ADDR|
2464 CRN_DIRECT_CONN);
2465 const node_t *node;
2466
2467 /* Once we used this function to select a node to be a guard. We had
2468 * 'state == NULL' be the signal for that. But we don't do that any more.
2469 */
2470 tor_assert_nonfatal(state);
2471
2472 if (state && options->UseEntryGuards &&
2473 (purpose != CIRCUIT_PURPOSE_TESTING || options->BridgeRelay)) {
2474 /* This request is for an entry server to use for a regular circuit,
2475 * and we use entry guard nodes. Just return one of the guard nodes. */
2476 tor_assert(guard_state_out);
2477 return guards_choose_guard(circ, state, purpose, guard_state_out);
2478 }
2479
2480 excluded = smartlist_new();
2481
2482 if (state && (node = build_state_get_exit_node(state))) {
2483 /* Exclude the exit node from the state, if we have one. Also exclude its
2484 * family. */
2485 nodelist_add_node_and_family(excluded, node);
2486 }
2487
2488 if (state) {
2489 flags |= cpath_build_state_to_crn_flags(state);
2490 }
2491
2492 choice = router_choose_random_node(excluded, options->ExcludeNodes, flags);
2493 smartlist_free(excluded);
2494 return choice;
2495}
2496
2497/** Choose a suitable next hop for the circuit <b>circ</b>.
2498 * Append the hop info to circ->cpath.
2499 *
2500 * Return 1 if the path is complete, 0 if we successfully added a hop,
2501 * and -1 on error.
2502 */
2503STATIC int
2505{
2506 uint8_t purpose = circ->base_.purpose;
2507 cpath_build_state_t *state = circ->build_state;
2508 int cur_len = circuit_get_cpath_len(circ);
2509 extend_info_t *info = NULL;
2510
2511 if (cur_len >= state->desired_path_len) {
2512 log_debug(LD_CIRC, "Path is complete: %d steps long",
2513 state->desired_path_len);
2514 return 1;
2515 }
2516
2517 log_debug(LD_CIRC, "Path is %d long; we want %d", cur_len,
2518 state->desired_path_len);
2519
2520 if (cur_len == state->desired_path_len - 1) { /* Picking last node */
2521 info = extend_info_dup(state->chosen_exit);
2522 } else if (cur_len == 0) { /* picking first node */
2523 const node_t *r = choose_good_entry_server(circ, purpose, state,
2524 &circ->guard_state);
2525 if (r) {
2526 /* If we're a client, use the preferred address rather than the
2527 primary address, for potentially connecting to an IPv6 OR
2528 port. Servers always want the primary (IPv4) address. */
2529 int client = (server_mode(get_options()) == 0);
2530 info = extend_info_from_node(r, client, false);
2531 /* Clients can fail to find an allowed address */
2532 tor_assert_nonfatal(info || client);
2533 }
2534 } else {
2535 const node_t *r =
2536 choose_good_middle_server(circ, purpose, state, circ->cpath, cur_len);
2537 if (r) {
2538 info = extend_info_from_node(r, 0, false);
2539 }
2540 }
2541
2542 if (!info) {
2543 /* This can happen on first startup, possibly due to insufficient relays
2544 * downloaded to pick vanguards-lite layer2 nodes, or other ephemeral
2545 * reasons. It only happens briefly, is hard to reproduce, and then goes
2546 * away for ever. :/ */
2548 log_info(LD_CIRC,
2549 "Failed to find node for hop #%d of our path. Discarding "
2550 "this circuit.", cur_len+1);
2551 } else {
2552 log_notice(LD_CIRC,
2553 "Failed to find node for hop #%d of our path. Discarding "
2554 "this circuit.", cur_len+1);
2555 }
2556 return -1;
2557 }
2558
2559 log_debug(LD_CIRC,"Chose router %s for hop #%d (exit is %s)",
2561 cur_len+1, build_state_get_exit_nickname(state));
2562
2563 cpath_append_hop(&circ->cpath, info);
2564 extend_info_free(info);
2565 return 0;
2566}
2567
2568/** Return the node_t for the chosen exit router in <b>state</b>.
2569 * If there is no chosen exit, or if we don't know the node_t for
2570 * the chosen exit, return NULL.
2571 */
2572MOCK_IMPL(const node_t *,
2574{
2575 if (!state || !state->chosen_exit)
2576 return NULL;
2578}
2579
2580/** Return the RSA ID digest for the chosen exit router in <b>state</b>.
2581 * If there is no chosen exit, return NULL.
2582 */
2583const uint8_t *
2585{
2586 if (!state || !state->chosen_exit)
2587 return NULL;
2588 return (const uint8_t *) state->chosen_exit->identity_digest;
2589}
2590
2591/** Return the nickname for the chosen exit router in <b>state</b>. If
2592 * there is no chosen exit, or if we don't know the routerinfo_t for the
2593 * chosen exit, return NULL.
2594 */
2595const char *
2597{
2598 if (!state || !state->chosen_exit)
2599 return NULL;
2600 return state->chosen_exit->nickname;
2601}
2602
2603/* Does circ have an onion key which it's allowed to use? */
2604int
2605circuit_has_usable_onion_key(const origin_circuit_t *circ)
2606{
2607 tor_assert(circ);
2608 tor_assert(circ->cpath);
2610 return extend_info_supports_ntor(circ->cpath->extend_info);
2611}
2612
2613/** Find the circuits that are waiting to find out whether their guards are
2614 * usable, and if any are ready to become usable, mark them open and try
2615 * attaching streams as appropriate. */
2616void
2618{
2619 smartlist_t *to_upgrade =
2621
2622 if (to_upgrade == NULL)
2623 return;
2624
2625 log_info(LD_GUARD, "Upgrading %d circuits from 'waiting for better guard' "
2626 "to 'open'.", smartlist_len(to_upgrade));
2627
2628 SMARTLIST_FOREACH_BEGIN(to_upgrade, origin_circuit_t *, circ) {
2630 circuit_has_opened(circ);
2631 } SMARTLIST_FOREACH_END(circ);
2632
2633 smartlist_free(to_upgrade);
2634}
2635
2636/**
2637 * Try to generate a circuit-negotiation message for communication with a
2638 * given relay. Assumes we are using ntor v3, or some later version that
2639 * supports parameter negotiatoin.
2640 *
2641 * On success, return 0 and pass back a message in the `out` parameters.
2642 * Otherwise, return -1.
2643 **/
2644int
2646 uint8_t **msg_out,
2647 size_t *msg_len_out)
2648{
2649 tor_assert(ei && msg_out && msg_len_out);
2650
2652 return -1;
2653 }
2654
2655 return congestion_control_build_ext_request(msg_out, msg_len_out);
2656}
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
Definition: address.c:933
void tor_addr_make_unspec(tor_addr_t *a)
Definition: address.c:225
time_t approx_time(void)
Definition: approx_time.c:32
const char * hex_str(const char *from, size_t fromlen)
Definition: binascii.c:34
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:478
int extend_info_is_a_configured_bridge(const extend_info_t *ei)
Definition: bridges.c:326
Header file for circuitbuild.c.
Fixed-size cell structure.
void channel_timestamp_client(channel_t *chan)
Definition: channel.c:3198
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)
Definition: channel.c:2416
const char * channel_state_to_string(channel_state_t state)
Definition: channel.c:316
int channel_matches_extend_info(channel_t *chan, extend_info_t *extend_info)
Definition: channel.c:3295
int channel_remote_identity_matches(const channel_t *chan, const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:668
channel_t * channel_connect(const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id)
Definition: channel.c:2326
const char * channel_describe_peer(channel_t *chan)
Definition: channel.c:2840
void channel_dump_statistics(channel_t *chan, int severity)
Definition: channel.c:2544
Header file for channel.c.
void channel_mark_as_used_for_origin_circuit(channel_t *chan)
Definition: channeltls.c:391
@ CIRC_ID_TYPE_NEITHER
Definition: channel.h:44
@ CIRC_ID_TYPE_HIGHER
Definition: channel.h:41
int pathbias_count_build_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:446
void pathbias_count_build_success(origin_circuit_t *circ)
Definition: circpathbias.c:534
static int circuit_send_first_onion_skin(origin_circuit_t *circ)
Definition: circuitbuild.c:989
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)
Definition: circuitbuild.c:900
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)
const char * build_state_get_exit_nickname(cpath_build_state_t *state)
int circuit_handle_first_hop(origin_circuit_t *circ)
Definition: circuitbuild.c:575
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)
Definition: circuitbuild.c:356
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)
Definition: circuitbuild.c:126
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)
Definition: circuitbuild.c:874
char * circuit_list_path_for_controller(origin_circuit_t *circ)
Definition: circuitbuild.c:346
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)
Definition: circuitbuild.c:544
static int onion_populate_cpath(origin_circuit_t *circ)
Definition: circuitbuild.c:389
int circuit_deliver_create_cell(circuit_t *circ, const struct create_cell_t *create_cell, int relayed)
Definition: circuitbuild.c:772
static int circuit_may_omit_guard(const origin_circuit_t *circ)
Definition: circuitbuild.c:918
static int ap_stream_wants_exit_attention(connection_t *conn)
STATIC int onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit_ei)
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)
Definition: circuitbuild.c:670
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)
Definition: circuitbuild.c:365
int circuit_timeout_want_to_count_circ(const origin_circuit_t *circ)
Definition: circuitbuild.c:859
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)
Definition: circuitbuild.c:513
channel_t * channel_connect_for_circuit(const extend_info_t *ei)
Definition: circuitbuild.c:103
char * circuit_list_path(origin_circuit_t *circ, int verbose)
Definition: circuitbuild.c:337
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)
Definition: circuitbuild.c:955
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)
Definition: circuitbuild.c:477
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)
Definition: circuitbuild.c:559
static bool should_use_create_fast_for_circuit(origin_circuit_t *circ)
Definition: circuitbuild.c:837
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)
Definition: circuitbuild.c:263
void circuit_upgrade_circuits_from_guard_wait(void)
origin_circuit_t * origin_circuit_init(uint8_t purpose, int flags)
Definition: circuitbuild.c:446
Header file for circuitbuild.c.
int circuit_id_in_use_on_channel(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1574
void circuit_set_n_circid_chan(circuit_t *circ, circid_t id, channel_t *chan)
Definition: circuitlist.c:493
void circuit_mark_all_dirty_circs_as_unusable(void)
Definition: circuitlist.c:2075
void circuit_set_state(circuit_t *circ, uint8_t state)
Definition: circuitlist.c:562
smartlist_t * circuit_find_circuits_to_upgrade_from_guard_wait(void)
Definition: circuitlist.c:1976
origin_circuit_t * origin_circuit_new(void)
Definition: circuitlist.c:1050
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
Definition: circuitlist.c:185
int circuit_get_cpath_len(origin_circuit_t *circ)
Definition: circuitlist.c:2004
int circuit_get_cpath_opened_len(const origin_circuit_t *circ)
Definition: circuitlist.c:2020
void circuit_get_all_pending_on_channel(smartlist_t *out, channel_t *chan)
Definition: circuitlist.c:597
int circuit_event_status(origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
Definition: circuitlist.c:518
time_t circuit_id_when_marked_unusable_on_channel(circid_t circ_id, channel_t *chan)
Definition: circuitlist.c:1587
crypt_path_t * circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum)
Definition: circuitlist.c:2040
const char * circuit_purpose_to_string(uint8_t purpose)
Definition: circuitlist.c:929
void circuit_mark_all_unused_circs(void)
Definition: circuitlist.c:2056
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_S_CONNECT_REND
Definition: circuitlist.h:107
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT
Definition: circuitlist.h:93
#define CIRCUIT_PURPOSE_REND_POINT_WAITING
Definition: circuitlist.h:45
#define CIRCUIT_STATE_OPEN
Definition: circuitlist.h:32
#define CIRCUIT_STATE_BUILDING
Definition: circuitlist.h:21
#define CIRCUIT_PURPOSE_C_REND_JOINED
Definition: circuitlist.h:88
#define CIRCUIT_PURPOSE_INTRO_POINT
Definition: circuitlist.h:42
#define CIRCUIT_PURPOSE_CONTROLLER
Definition: circuitlist.h:121
#define CIRCUIT_IS_ORIGIN(c)
Definition: circuitlist.h:154
#define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
Definition: circuitlist.h:86
#define CIRCUIT_STATE_GUARD_WAIT
Definition: circuitlist.h:30
#define CIRCUIT_PURPOSE_TESTING
Definition: circuitlist.h:118
#define CIRCUIT_PURPOSE_OR
Definition: circuitlist.h:39
#define CIRCUIT_STATE_CHAN_WAIT
Definition: circuitlist.h:26
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
Definition: circuitlist.h:76
#define CIRCUIT_PURPOSE_S_REND_JOINED
Definition: circuitlist.h:110
#define CIRCUIT_PURPOSE_C_REND_READY
Definition: circuitlist.h:83
#define CIRCUIT_PURPOSE_S_HSDIR_POST
Definition: circuitlist.h:112
#define CIRCUIT_PURPOSE_C_HSDIR_GET
Definition: circuitlist.h:90
#define CIRCUIT_PURPOSE_REND_ESTABLISHED
Definition: circuitlist.h:47
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED
Definition: circuitlist.h:79
#define CIRCUIT_PURPOSE_C_INTRODUCING
Definition: circuitlist.h:73
#define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO
Definition: circuitlist.h:101
#define CIRCUIT_PURPOSE_C_ESTABLISH_REND
Definition: circuitlist.h:81
#define CIRCUIT_PURPOSE_C_GENERAL
Definition: circuitlist.h:70
#define CIRCUIT_PURPOSE_CONFLUX_UNLINKED
Definition: circuitlist.h:137
#define CIRCUIT_PURPOSE_HS_VANGUARDS
Definition: circuitlist.h:131
unsigned int circuitmux_num_active_circuits(circuitmux_t *cmux)
Definition: circuitmux.c:702
unsigned int circuitmux_num_circuits(circuitmux_t *cmux)
Definition: circuitmux.c:714
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)
Definition: circuitstats.c:679
Header file for circuitstats.c.
int circuit_should_use_vanguards(uint8_t purpose)
Definition: circuituse.c:2018
void circuit_has_opened(origin_circuit_t *circ)
Definition: circuituse.c:1664
void circuit_reset_failure_count(int timeout)
Definition: circuituse.c:2223
int circuit_stream_is_being_handled(entry_connection_t *conn, uint16_t port, int min)
Definition: circuituse.c:1009
void circuit_remove_handled_ports(smartlist_t *needed_ports)
Definition: circuituse.c:984
int circuit_purpose_is_hidden_service(uint8_t purpose)
Definition: circuituse.c:1956
Header file for circuituse.c.
#define CIRCLAUNCH_NEED_CAPACITY
Definition: circuituse.h:43
#define CIRCLAUNCH_IS_IPV6_SELFTEST
Definition: circuituse.h:51
#define CIRCLAUNCH_ONEHOP_TUNNEL
Definition: circuituse.h:39
#define CIRCLAUNCH_IS_INTERNAL
Definition: circuituse.h:46
#define CIRCLAUNCH_NEED_UPTIME
Definition: circuituse.h:41
#define CIRCLAUNCH_NEED_CONFLUX
Definition: circuituse.h:53
void command_setup_channel(channel_t *chan)
Definition: command.c:710
Header file for command.c.
const or_options_t * get_options(void)
Definition: config.c:947
tor_cmdline_mode_t command
Definition: config.c:2477
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.
Header for confmgt.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.
#define SBWS_ROUTE_LEN
Header file for connection.c.
#define CONN_TYPE_AP
Definition: connection.h:51
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)
Definition: crypt_path.c:230
int cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
Definition: crypt_path.c:59
int cpath_init_circuit_crypto(crypt_path_t *cpath, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3)
Definition: crypt_path.c:151
void cpath_free(crypt_path_t *victim)
Definition: crypt_path.c:163
Header file for crypt_path.c.
#define HEX_DIGEST_LEN
Definition: crypto_digest.h:35
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)
Definition: crypto_rand.c:594
void crypto_rand(char *to, size_t n)
Definition: crypto_rand.c:479
Common functions for using (pseudo-)random number generators.
const char * extend_info_describe(const extend_info_t *ei)
Definition: describe.c:224
const char * node_describe(const node_t *node)
Definition: describe.c:160
Header file for describe.c.
#define DIGEST_LEN
Definition: digest_sizes.h:20
#define DIGEST256_LEN
Definition: digest_sizes.h:23
Header file for directory.c.
Entry connection structure.
const routerset_t * get_layer2_guards(void)
Definition: entrynodes.c:4315
guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2609
bool vanguards_lite_is_enabled(void)
Definition: entrynodes.c:4086
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)
Definition: entrynodes.c:3872
Header file for circuitbuild.c.
Header file for Tor tracing instrumentation definition.
#define TR_SUBSYS(name)
Definition: events.h:45
Extend-info structure.
extend_info_t * extend_info_dup(extend_info_t *info)
Definition: extendinfo.c:184
extend_info_t * extend_info_from_node(const node_t *node, int for_direct_connect, bool for_exit)
Definition: extendinfo.c:97
const tor_addr_port_t * extend_info_pick_orport(const extend_info_t *ei)
Definition: extendinfo.c:278
const tor_addr_port_t * extend_info_get_orport(const extend_info_t *ei, int family)
Definition: extendinfo.c:263
bool extend_info_any_orport_addr_is_internal(const extend_info_t *ei)
Definition: extendinfo.c:318
Header for core/or/extendinfo.c.
Header for hs_ntor.c.
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
Definition: log.c:591
#define log_fn(severity, domain, args,...)
Definition: log.h:283
#define log_fn_ratelim(ratelim, severity, domain, args,...)
Definition: log.h:288
#define LD_APP
Definition: log.h:78
#define LD_PROTOCOL
Definition: log.h:72
#define LD_BUG
Definition: log.h:86
#define LD_GUARD
Definition: log.h:109
#define LD_GENERAL
Definition: log.h:62
#define LOG_NOTICE
Definition: log.h:50
#define LD_CIRC
Definition: log.h:82
#define LOG_WARN
Definition: log.h:53
#define LOG_INFO
Definition: log.h:45
void note_that_we_maybe_cant_complete_circuits(void)
Definition: mainloop.c:234
int have_completed_a_circuit(void)
Definition: mainloop.c:218
void note_that_we_completed_a_circuit(void)
Definition: mainloop.c:226
smartlist_t * get_connection_array(void)
Definition: mainloop.c:443
void reset_all_main_loop_timers(void)
Definition: mainloop.c:1466
Header file for mainloop.c.
#define tor_free(p)
Definition: malloc.h:56
Header file for microdesc.c.
Header file for networkstatus.c.
int is_legal_nickname(const char *s)
Definition: nickname.c:19
Header file for nickname.c.
const node_t * router_choose_random_node(smartlist_t *excludedsmartlist, routerset_t *excludedset, router_crn_flags_t flags)
Definition: node_select.c:979
const node_t * node_sl_choose_by_bandwidth(const smartlist_t *sl, bandwidth_weight_rule_t rule)
Definition: node_select.c:856
Header file for node_select.c.
router_crn_flags_t
Definition: node_select.h:16
Node information structure.
const node_t * node_get_by_id(const char *identity_digest)
Definition: nodelist.c:226
void nodelist_add_node_and_family(smartlist_t *sl, const node_t *node)
Definition: nodelist.c:2294
const smartlist_t * nodelist_get_list(void)
Definition: nodelist.c:1081
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
Definition: nodelist.c:1543
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
Definition: nodelist.c:1576
int router_have_minimum_dir_info(void)
Definition: nodelist.c:2490
int node_exit_policy_rejects_all(const node_t *node)
Definition: nodelist.c:1622
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)
Definition: onion.c:551
Header file for onion.c.
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)
Definition: onion_crypto.c:437
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)
Definition: onion_crypto.c:129
void onion_handshake_state_release(onion_handshake_state_t *state)
Definition: onion_crypto.c:96
Header file for onion_crypto.c.
Header file for onion_fast.c.
Master header file for Tor-specific functionality.
#define MAX_NICKNAME_LEN
Definition: or.h:112
#define MIN_CIRCUITS_HANDLING_STREAM
Definition: or.h:180
#define DEFAULT_ROUTE_LEN
Definition: or.h:990
uint32_t circid_t
Definition: or.h:579
#define END_CIRC_REASON_NOPATH
Definition: or.h:364
#define TO_CIRCUIT(x)
Definition: or.h:936
#define MAX_VERBOSE_NICKNAME_LEN
Definition: or.h:118
#define END_CIRC_REASON_FLAG_REMOTE
Definition: or.h:389
@ CELL_DIRECTION_OUT
Definition: or.h:425
#define RELAY_PAYLOAD_SIZE_MAX
Definition: or.h:567
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)
Definition: policies.c:2907
Header file for policies.c.
addr_policy_result_t
Definition: policies.h:38
@ ADDR_POLICY_PROBABLY_REJECTED
Definition: policies.h:48
@ ADDR_POLICY_REJECTED
Definition: policies.h:42
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)
Definition: ratelim.c:42
int append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan, cell_t *cell, cell_direction_t direction, streamid_t fromstream)
Definition: relay.c:3352
size_t circuit_max_relay_payload(const circuit_t *circ, const crypt_path_t *cpath, uint8_t relay_command)
Definition: relay.c:3555
Header file for relay.c.
int router_digest_is_me(const char *digest)
Definition: router.c:1775
Header file for router.c.
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
Definition: routerlist.c:617
Header file for routerlist.c.
int server_mode(const or_options_t *options)
Definition: routermode.c:34
Header file for routermode.c.
int routerset_contains_node(const routerset_t *set, const node_t *node)
Definition: routerset.c:353
void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset, const routerset_t *excludeset, int running_only)
Definition: routerset.c:379
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
Definition: routerset.c:308
void routerset_subtract_nodes(smartlist_t *lst, const routerset_t *routerset)
Definition: routerset.c:413
Header file for routerset.c.
void router_do_reachability_checks(void)
Definition: selftest.c:290
Header file for selftest.c.
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
Definition: smartlist.c:36
int smartlist_contains_int_as_string(const smartlist_t *sl, int num)
Definition: smartlist.c:147
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2)
Definition: smartlist.c:264
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
Definition: smartlist.c:279
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)
Definition: cell_st.h:17
circid_t circ_id
Definition: cell_st.h:18
channel_state_t state
Definition: channel.h:192
int(* is_canonical)(channel_t *)
Definition: channel.h:353
unsigned int num_n_circuits
Definition: channel.h:410
circ_id_type_bitfield_t circ_id_type
Definition: channel.h:405
char identity_digest[DIGEST_LEN]
Definition: channel.h:378
uint64_t global_identifier
Definition: channel.h:197
channel_usage_info_t channel_usage
Definition: channel.h:228
time_t timestamp_created
Definition: channel.h:298
circuitmux_t * cmux
Definition: channel.h:397
ratelim_t last_warned_circ_ids_exhausted
Definition: channel.h:438
uint8_t state
Definition: circuit_st.h:111
uint8_t purpose
Definition: circuit_st.h:112
struct timeval timestamp_began
Definition: circuit_st.h:166
channel_t * n_chan
Definition: circuit_st.h:70
extend_info_t * n_hop
Definition: circuit_st.h:88
circid_t n_circ_id
Definition: circuit_st.h:79
uint8_t state
Definition: connection_st.h:49
unsigned int type
Definition: connection_st.h:50
uint16_t marked_for_close
extend_info_t * chosen_exit
uint16_t handshake_len
Definition: onion.h:33
uint16_t handshake_type
Definition: onion.h:31
uint8_t onionskin[MAX_CREATE_LEN]
Definition: onion.h:35
uint8_t cell_type
Definition: onion.h:29
uint16_t handshake_len
Definition: onion.h:43
uint8_t reply[MAX_CREATED_LEN]
Definition: onion.h:45
struct crypt_path_t * prev
Definition: crypt_path_st.h:79
uint8_t state
Definition: crypt_path_st.h:72
struct crypt_path_t * next
Definition: crypt_path_st.h:76
extend_info_t * extend_info
Definition: crypt_path_st.h:65
char rend_circ_nonce[DIGEST_LEN]
Definition: crypt_path_st.h:62
onion_handshake_state_t handshake_state
Definition: crypt_path_st.h:56
struct congestion_control_t * ccontrol
Definition: crypt_path_st.h:88
struct edge_connection_t * next_stream
tor_addr_port_t orport_ipv4
Definition: onion.h:53
create_cell_t create_cell
Definition: onion.h:63
struct ed25519_public_key_t ed_pubkey
Definition: onion.h:59
uint8_t node_id[DIGEST_LEN]
Definition: onion.h:57
tor_addr_port_t orport_ipv6
Definition: onion.h:55
uint8_t cell_type
Definition: onion.h:51
ed25519_public_key_t ed_identity
char identity_digest[DIGEST_LEN]
char nickname[MAX_HEX_NICKNAME_LEN+1]
bool exit_supports_congestion_control
Definition: node_st.h:34
char identity[DIGEST_LEN]
Definition: node_st.h:46
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
edge_connection_t * p_streams
unsigned int has_opened
crypt_path_t * cpath
cpath_build_state_t * build_state
struct circuit_guard_state_t * guard_state
unsigned first_hop_from_controller
#define STATIC
Definition: testsupport.h:32
#define MOCK_IMPL(rv, funcname, arglist)
Definition: testsupport.h:133
void tor_gettimeofday(struct timeval *timeval)
Headers for transports.c.
#define tor_assert_nonfatal_unreached()
Definition: util_bug.h:177
#define tor_assert(expr)
Definition: util_bug.h:103
#define tor_fragile_assert()
Definition: util_bug.h:278
#define IF_BUG_ONCE(cond)
Definition: util_bug.h:254
int tor_digest_is_zero(const char *digest)
Definition: util_string.c:98