Tor 0.4.9.0-alpha-dev
entrynodes.h
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 entrynodes.h
9 * \brief Header file for circuitbuild.c.
10 **/
11
12#ifndef TOR_ENTRYNODES_H
13#define TOR_ENTRYNODES_H
14
16
17/* Forward declare for guard_selection_t; entrynodes.c has the real struct */
18typedef struct guard_selection_t guard_selection_t;
19
20/* Forward declare for entry_guard_t; the real declaration is private. */
21typedef struct entry_guard_t entry_guard_t;
22
23/* Forward declaration for circuit_guard_state_t; the real declaration is
24 private. */
25typedef struct circuit_guard_state_t circuit_guard_state_t;
26
27/* Forward declaration for entry_guard_restriction_t; the real declaration is
28 private. */
29typedef struct entry_guard_restriction_t entry_guard_restriction_t;
30
31/** Information about a guard's pathbias status.
32 * These fields are used in circpathbias.c to try to detect entry
33 * nodes that are failing circuits at a suspicious frequency.
34 */
35typedef struct guard_pathbias_t {
36 unsigned int path_bias_noticed : 1; /**< Did we alert the user about path
37 * bias for this node already? */
38 unsigned int path_bias_warned : 1; /**< Did we alert the user about path bias
39 * for this node already? */
40 unsigned int path_bias_extreme : 1; /**< Did we alert the user about path
41 * bias for this node already? */
42 unsigned int path_bias_disabled : 1; /**< Have we disabled this node because
43 * of path bias issues? */
44 unsigned int path_bias_use_noticed : 1; /**< Did we alert the user about path
45 * use bias for this node already? */
46 unsigned int path_bias_use_extreme : 1; /**< Did we alert the user about path
47 * use bias for this node already? */
48
49 double circ_attempts; /**< Number of circuits this guard has "attempted" */
50 double circ_successes; /**< Number of successfully built circuits using
51 * this guard as first hop. */
52 double successful_circuits_closed; /**< Number of circuits that carried
53 * streams successfully. */
54 double collapsed_circuits; /**< Number of fully built circuits that were
55 * remotely closed before any streams were
56 * attempted. */
57 double unusable_circuits; /**< Number of circuits for which streams were
58 * attempted, but none succeeded. */
59 double timeouts; /**< Number of 'right-censored' circuit timeouts for this
60 * guard. */
61 double use_attempts; /**< Number of circuits we tried to use with streams */
62 double use_successes; /**< Number of successfully used circuits using
63 * this guard as first hop. */
65
66#if defined(ENTRYNODES_PRIVATE)
68
69/**
70 * @name values for entry_guard_t.is_reachable.
71 *
72 * See entry_guard_t.is_reachable for more information.
73 */
74/**@{*/
75#define GUARD_REACHABLE_NO 0
76#define GUARD_REACHABLE_YES 1
77#define GUARD_REACHABLE_MAYBE 2
78/**@}*/
79
80/** An entry_guard_t represents our information about a chosen long-term
81 * first hop, known as a "helper" node in the literature. We can't just
82 * use a node_t, since we want to remember these even when we
83 * don't have any directory info. */
84struct entry_guard_t {
85 HANDLE_ENTRY(entry_guard, entry_guard_t);
86
87 char nickname[MAX_HEX_NICKNAME_LEN+1];
88 char identity[DIGEST_LEN];
90
91 /**
92 * @name new guard selection algorithm fields.
93 *
94 * Only the new (prop271) algorithm uses these. For a more full
95 * description of the algorithm, see the module documentation for
96 * entrynodes.c
97 */
98 /**@{*/
99
100 /* == Persistent fields, present for all sampled guards. */
101 /** When was this guard added to the sample? */
102 time_t sampled_on_date;
103 /** Since what date has this guard been "unlisted"? A guard counts as
104 * unlisted if we have a live consensus that does not include it, or
105 * if we have a live consensus that does not include it as a usable
106 * guard. This field is zero when the guard is listed. */
107 time_t unlisted_since_date; // can be zero
108 /** What version of Tor added this guard to the sample? */
109 char *sampled_by_version;
110 /** Is this guard listed right now? If this is set, then
111 * unlisted_since_date should be set too. */
112 unsigned currently_listed : 1;
113
114 /* == Persistent fields, for confirmed guards only */
115 /** When was this guard confirmed? (That is, when did we first use it
116 * successfully and decide to keep it?) This field is zero if this is not a
117 * confirmed guard. */
118 time_t confirmed_on_date; /* 0 if not confirmed */
119 /**
120 * In what order was this guard sampled? Guards with
121 * lower indices appear earlier on the sampled list, the confirmed list and
122 * the primary list as a result of Prop 310
123 */
124 int sampled_idx;
125
126 /**
127 * In what order was this guard confirmed? Guards with lower indices
128 * appear earlier on the confirmed list. If the confirmed list is compacted,
129 * this field corresponds to the index of this guard on the confirmed list.
130 *
131 * This field is set to -1 if this guard is not confirmed.
132 */
133 int confirmed_idx; /* -1 if not confirmed; otherwise the order that this
134 * item should occur in the CONFIRMED_GUARDS ordered
135 * list */
136
137 /**
138 * Which selection does this guard belong to?
139 */
140 char *selection_name;
141
142 /** Bridges only: address of the bridge. */
143 tor_addr_port_t *bridge_addr;
144
145 /* ==== Non-persistent fields. */
146 /* == These are used by sampled guards */
147 /** When did we last decide to try using this guard for a circuit? 0 for
148 * "not since we started up." */
149 time_t last_tried_to_connect;
150 /** How reachable do we consider this guard to be? One of
151 * GUARD_REACHABLE_NO, GUARD_REACHABLE_YES, or GUARD_REACHABLE_MAYBE. */
152 unsigned is_reachable : 2;
153 /** Boolean: true iff this guard is pending. A pending guard is one
154 * that we have an in-progress circuit through, and which we do not plan
155 * to try again until it either succeeds or fails. Primary guards can
156 * never be pending. */
157 unsigned is_pending : 1;
158 /** If true, don't write this guard to disk. (Used for bridges with unknown
159 * identities) */
160 unsigned is_persistent : 1;
161 /** When did we get the earliest connection failure for this guard?
162 * We clear this field on a successful connect. We do _not_ clear it
163 * when we mark the guard as "MAYBE" reachable.
164 */
165 time_t failing_since;
166
167 /* == Set inclusion flags. */
168 /** If true, this guard is in the filtered set. The filtered set includes
169 * all sampled guards that our configuration allows us to use. */
170 unsigned is_filtered_guard : 1;
171 /** If true, this guard is in the usable filtered set. The usable filtered
172 * set includes all filtered guards that are not believed to be
173 * unreachable. (That is, those for which is_reachable is not
174 * GUARD_REACHABLE_NO) */
175 unsigned is_usable_filtered_guard : 1;
176 unsigned is_primary:1;
177
178 /** This string holds any fields that we are maintaining because
179 * we saw them in the state, even if we don't understand them. */
180 char *extra_state_fields;
181
182 /** Backpointer to the guard selection that this guard belongs to.
183 * The entry_guard_t must never outlive its guard_selection. */
184 guard_selection_t *in_selection;
185 /**@}*/
186
187 /** Path bias information for this guard. */
189};
190
191/**
192 * Possible rules for a guard selection to follow
193 */
194typedef enum guard_selection_type_t {
195 /** Infer the type of this selection from its name. */
196 GS_TYPE_INFER=0,
197 /** Use the normal guard selection algorithm, taking our sample from the
198 * complete list of guards in the consensus. */
199 GS_TYPE_NORMAL=1,
200 /** Use the normal guard selection algorithm, taking our sample from the
201 * configured bridges, and allowing it to grow as large as all the configured
202 * bridges */
203 GS_TYPE_BRIDGE,
204 /** Use the normal guard selection algorithm, taking our sample from the
205 * set of filtered nodes. */
206 GS_TYPE_RESTRICTED,
207} guard_selection_type_t;
208
209/**
210 * All of the the context for guard selection on a particular client.
211 *
212 * We maintain multiple guard selection contexts for a client, depending
213 * aspects on its current configuration -- whether an extremely
214 * restrictive EntryNodes is used, whether UseBridges is enabled, and so
215 * on.)
216 *
217 * See the module documentation for entrynodes.c for more information
218 * about guard selection algorithms.
219 */
220struct guard_selection_t {
221 /**
222 * The name for this guard-selection object. (Must not contain spaces).
223 */
224 char *name;
225
226 /**
227 * What rules does this guard-selection object follow?
228 */
229 guard_selection_type_t type;
230
231 /**
232 * A value of 1 means that primary_entry_guards is up-to-date with respect to
233 * the consensus and status info that we currently have; 0 means we need to
234 * recalculate it before using primary_entry_guards or the is_primary flag on
235 * any guard.
236 */
237 int primary_guards_up_to_date;
238
239 /**
240 * A list of the sampled entry guards, as entry_guard_t structures.
241 * Not in any particular order. When we 'sample' a guard, we are
242 * noting it as a possible guard to pick in the future. The use of
243 * sampling here prevents us from being forced by an attacker to try
244 * every guard on the network. This list is persistent.
245 */
246 smartlist_t *sampled_entry_guards;
247
248 /**
249 * Ordered list (from highest to lowest priority) of guards that we
250 * have successfully contacted and decided to use. Every member of
251 * this list is a member of sampled_entry_guards. Every member should
252 * have confirmed_on_date set.
253 * The ordering of the list should be by sampled idx. The reasoning behind
254 * it is linked to Proposal 310.
255 *
256 * This list is persistent. It is a subset of the elements in
257 * sampled_entry_guards, and its pointers point to elements of
258 * sampled_entry_guards.
259 */
260 smartlist_t *confirmed_entry_guards;
261
262 /**
263 * Ordered list (from highest to lowest priority) of guards that we
264 * are willing to use the most happily. These guards may or may not
265 * yet be confirmed yet. If we can use one of these guards, we are
266 * probably not on a network that is trying to restrict our guard
267 * choices.
268 *
269 * This list is a subset of the elements in
270 * sampled_entry_guards, and its pointers point to elements of
271 * sampled_entry_guards.
272 */
273 smartlist_t *primary_entry_guards;
274
275 /** When did we last successfully build a circuit or use a circuit? */
276 time_t last_time_on_internet;
277
278 /** What confirmed_idx value should the next-added member of
279 * confirmed_entry_guards receive? */
280 int next_confirmed_idx;
281
282 /** What sampled_idx value should the next-added member of
283 * sampled_entry_guards receive? This should follow the size of the sampled
284 * list until sampled relays get pruned for some reason
285 */
286 int next_sampled_idx;
287
288};
289
290struct entry_guard_handle_t;
291
292/** Types of restrictions we impose when picking guard nodes */
293typedef enum guard_restriction_type_t {
294 /* Don't pick the same guard node as our exit node (or its family) */
295 RST_EXIT_NODE = 0,
296 /* Don't pick dirguards that have previously shown to be outdated */
297 RST_OUTDATED_MD_DIRSERVER = 1,
298 /* Don't pick guards if they are in the exclusion list */
299 RST_EXCL_LIST = 2,
300} guard_restriction_type_t;
301
302/**
303 * A restriction to remember which entry guards are off-limits for a given
304 * circuit.
305 *
306 * Note: This mechanism is NOT for recording which guards are never to be
307 * used: only which guards cannot be used on <em>one particular circuit</em>.
308 */
309struct entry_guard_restriction_t {
310 /* What type of restriction are we imposing? */
311 guard_restriction_type_t type;
312
313 /* In case of restriction type RST_EXIT_NODE, the guard's RSA identity
314 * digest must not equal this; and it must not be in the same family as any
315 * node with this digest. */
316 uint8_t exclude_id[DIGEST_LEN];
317
318 /* In the case of RST_EXCL_LIST, any identity digests in this list
319 * must not be used. */
320 smartlist_t *excluded;
321};
322
323/**
324 * Per-circuit state to track whether we'll be able to use the circuit.
325 */
326struct circuit_guard_state_t {
327 /** Handle to the entry guard object for this circuit. */
328 struct entry_guard_handle_t *guard;
329 /** The time at which <b>state</b> last changed. */
330 time_t state_set_at;
331 /** One of GUARD_CIRC_STATE_* */
332 uint8_t state;
333
334 /**
335 * A set of restrictions that were placed on this guard when we selected it
336 * for this particular circuit. We need to remember the restrictions here,
337 * since any guard that breaks these restrictions will not block this
338 * circuit from becoming COMPLETE.
339 */
340 entry_guard_restriction_t *restrictions;
341};
342#endif /* defined(ENTRYNODES_PRIVATE) */
343
344/* Common entry points for old and new guard code */
345int guards_update_all(void);
347 cpath_build_state_t *state,
348 uint8_t purpose,
349 circuit_guard_state_t **guard_state_out);
350const node_t *guards_choose_dirguard(uint8_t dir_purpose,
351 circuit_guard_state_t **guard_state_out);
352
353#if 1
354/* XXXX NM I would prefer that all of this stuff be private to
355 * entrynodes.c. */
357 guard_selection_t *gs, const char *digest);
358entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
359
360circuit_guard_state_t *
361get_guard_state_for_bridge_desc_fetch(const char *digest);
362
363void entry_guards_changed_for_guard_selection(guard_selection_t *gs);
364void entry_guards_changed(void);
365guard_selection_t * get_guard_selection_info(void);
366int num_live_entry_guards_for_guard_selection(
367 guard_selection_t *gs,
368 int for_directory);
369int num_live_entry_guards(int for_directory);
370#endif /* 1 */
371
372const node_t *entry_guard_find_node(const entry_guard_t *guard);
373const char *entry_guard_get_rsa_id_digest(const entry_guard_t *guard);
374const char *entry_guard_describe(const entry_guard_t *guard);
376
377/** Enum to specify how we're going to use a given guard, when we're picking
378 * one for immediate use. */
379typedef enum {
380 GUARD_USAGE_TRAFFIC = 0,
381 GUARD_USAGE_DIRGUARD = 1
383
384#define circuit_guard_state_free(val) \
385 FREE_AND_NULL(circuit_guard_state_t, circuit_guard_state_free_, (val))
386
387void circuit_guard_state_free_(circuit_guard_state_t *state);
388int entry_guard_pick_for_circuit(guard_selection_t *gs,
389 guard_usage_t usage,
390 entry_guard_restriction_t *rst,
391 const node_t **chosen_node_out,
392 circuit_guard_state_t **guard_state_out);
393
394/* We just connected to an entry guard. What should we do with the circuit? */
395typedef enum {
396 GUARD_USABLE_NEVER = -1, /* Never use the circuit */
397 GUARD_MAYBE_USABLE_LATER = 0, /* Keep it. We might use it in the future */
398 GUARD_USABLE_NOW = 1, /* Use it right now */
399} guard_usable_t;
400
401guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p);
402void entry_guard_failed(circuit_guard_state_t **guard_state_p);
403void entry_guard_cancel(circuit_guard_state_t **guard_state_p);
405int entry_guards_update_all(guard_selection_t *gs);
406int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs,
407 const smartlist_t *all_circuits,
408 smartlist_t *newly_complete_out);
409int entry_guard_state_should_expire(circuit_guard_state_t *guard_state);
410void entry_guards_note_internet_connectivity(guard_selection_t *gs);
411
413
414int entry_guard_could_succeed(const circuit_guard_state_t *guard_state);
415
416MOCK_DECL(int,num_bridges_usable,(int use_maybe_reachable));
417
418#ifdef ENTRYNODES_PRIVATE
419/**
420 * @name Default values for the parameters for the new (prop271) entry guard
421 * algorithm.
422 */
423/**@{*/
424/**
425 * We never let our sampled guard set grow larger than this percentage
426 * of the guards on the network.
427 */
428#define DFLT_MAX_SAMPLE_THRESHOLD_PERCENT 20
429/**
430 * We never let our sampled guard set grow larger than this number of
431 * guards.
432 */
433#define DFLT_MAX_SAMPLE_SIZE 60
434/**
435 * We always try to make our sample contain at least this many guards.
436 */
437#define DFLT_MIN_FILTERED_SAMPLE_SIZE 20
438/**
439 * If a guard is unlisted for this many days in a row, we remove it.
440 */
441#define DFLT_REMOVE_UNLISTED_GUARDS_AFTER_DAYS 20
442/**
443 * We remove unconfirmed guards from the sample after this many days,
444 * regardless of whether they are listed or unlisted.
445 */
446#define DFLT_GUARD_LIFETIME_DAYS 120
447/**
448 * We remove confirmed guards from the sample if they were sampled
449 * GUARD_LIFETIME_DAYS ago and confirmed this many days ago.
450 */
451#define DFLT_GUARD_CONFIRMED_MIN_LIFETIME_DAYS 60
452/**
453 * How many guards do we try to keep on our primary guard list?
454 */
455#define DFLT_N_PRIMARY_GUARDS 3
456/**
457 * Of the live guards on the primary guard list, how many do we consider when
458 * choosing a guard to use?
459 */
460#define DFLT_N_PRIMARY_GUARDS_TO_USE 1
461/**
462 * As DFLT_N_PRIMARY_GUARDS, but for choosing which directory guard to use.
463 */
464#define DFLT_N_PRIMARY_DIR_GUARDS_TO_USE 3
465/**
466 * If we haven't successfully built or used a circuit in this long, then
467 * consider that the internet is probably down.
468 */
469#define DFLT_INTERNET_LIKELY_DOWN_INTERVAL (10*60)
470/**
471 * If we're trying to connect to a nonprimary guard for at least this
472 * many seconds, and we haven't gotten the connection to work, we will treat
473 * lower-priority guards as usable.
474 */
475#define DFLT_NONPRIMARY_GUARD_CONNECT_TIMEOUT 15
476/**
477 * If a circuit has been sitting around in 'waiting for better guard' state
478 * for at least this long, we'll expire it.
479 */
480#define DFLT_NONPRIMARY_GUARD_IDLE_TIMEOUT (10*60)
481/**
482 * If our configuration retains fewer than this fraction of guards from the
483 * torrc, we are in a restricted setting.
484 */
485#define DFLT_MEANINGFUL_RESTRICTION_PERCENT 20
486/**
487 * If our configuration retains fewer than this fraction of guards from the
488 * torrc, we are in an extremely restricted setting, and should warn.
489 */
490#define DFLT_EXTREME_RESTRICTION_PERCENT 1
491/**@}*/
492
497STATIC int get_guard_lifetime(void);
506
507HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
508#define entry_guard_handle_free(h) \
509 FREE_AND_NULL(entry_guard_handle_t, entry_guard_handle_free_, (h))
510
511STATIC guard_selection_type_t guard_selection_infer_type(
512 guard_selection_type_t type_in,
513 const char *name);
514STATIC guard_selection_t *guard_selection_new(const char *name,
515 guard_selection_type_t type);
516STATIC guard_selection_t *get_guard_selection_by_name(
517 const char *name, guard_selection_type_t type, int create_if_absent);
518STATIC void guard_selection_free_(guard_selection_t *gs);
519#define guard_selection_free(gs) \
520 FREE_AND_NULL(guard_selection_t, guard_selection_free_, (gs))
522 (guard_selection_t *gs, const entry_guard_t *guard));
523STATIC const char *choose_guard_selection(const or_options_t *options,
524 const networkstatus_t *ns,
525 const guard_selection_t *old_selection,
526 guard_selection_type_t *type_out);
527STATIC entry_guard_t *get_sampled_guard_with_id(guard_selection_t *gs,
528 const uint8_t *rsa_id);
529
530MOCK_DECL(STATIC time_t, randomize_time, (time_t now, time_t max_backdate));
531
532MOCK_DECL(STATIC circuit_guard_state_t *,
533 circuit_guard_state_new,(entry_guard_t *guard, unsigned state,
534 entry_guard_restriction_t *rst));
535
536STATIC entry_guard_t *entry_guard_add_to_sample(guard_selection_t *gs,
537 const node_t *node);
538STATIC entry_guard_t *entry_guards_expand_sample(guard_selection_t *gs);
539STATIC char *entry_guard_encode_for_state(entry_guard_t *guard, int
540 dense_sampled_index);
541STATIC entry_guard_t *entry_guard_parse_from_state(const char *s);
542#define entry_guard_free(e) \
543 FREE_AND_NULL(entry_guard_t, entry_guard_free_, (e))
544STATIC void entry_guard_free_(entry_guard_t *e);
545STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs);
546STATIC int entry_guards_all_primary_guards_are_down(guard_selection_t *gs);
547/**
548 * @name Flags for first_reachable_filtered_entry_guard()
549 */
550/**@{*/
551#define SAMPLE_EXCLUDE_CONFIRMED (1u<<0)
552#define SAMPLE_EXCLUDE_PRIMARY (1u<<1)
553#define SAMPLE_EXCLUDE_PENDING (1u<<2)
554#define SAMPLE_NO_UPDATE_PRIMARY (1u<<3)
555#define SAMPLE_EXCLUDE_NO_DESCRIPTOR (1u<<4)
556/**@}*/
558 guard_selection_t *gs,
559 const entry_guard_restriction_t *rst,
560 unsigned flags);
561STATIC void entry_guard_consider_retry(entry_guard_t *guard);
562STATIC void make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard);
563STATIC void entry_guards_update_confirmed(guard_selection_t *gs);
564STATIC void entry_guards_update_primary(guard_selection_t *gs);
565STATIC int num_reachable_filtered_guards(const guard_selection_t *gs,
566 const entry_guard_restriction_t *rst);
567STATIC void sampled_guards_update_from_consensus(guard_selection_t *gs);
568/**
569 * @name Possible guard-states for a circuit.
570 */
571/**@{*/
572/** State for a circuit that can (so far as the guard subsystem is
573 * concerned) be used for actual traffic as soon as it is successfully
574 * opened. */
575#define GUARD_CIRC_STATE_USABLE_ON_COMPLETION 1
576/** State for an non-open circuit that we shouldn't use for actual
577 * traffic, when it completes, unless other circuits to preferable
578 * guards fail. */
579#define GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD 2
580/** State for an open circuit that we shouldn't use for actual traffic
581 * unless other circuits to preferable guards fail. */
582#define GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD 3
583/** State for a circuit that can (so far as the guard subsystem is
584 * concerned) be used for actual traffic. */
585#define GUARD_CIRC_STATE_COMPLETE 4
586/** State for a circuit that is unusable, and will not become usable. */
587#define GUARD_CIRC_STATE_DEAD 5
588/**@}*/
589STATIC void entry_guards_note_guard_failure(guard_selection_t *gs,
590 entry_guard_t *guard);
591STATIC entry_guard_t *select_entry_guard_for_circuit(guard_selection_t *gs,
592 guard_usage_t usage,
593 const entry_guard_restriction_t *rst,
594 unsigned *state_out);
595STATIC void mark_primary_guards_maybe_reachable(guard_selection_t *gs);
596STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs,
597 entry_guard_t *guard,
598 unsigned old_state);
599STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b);
600STATIC char *getinfo_helper_format_single_entry_guard(const entry_guard_t *e);
601
602STATIC entry_guard_restriction_t *guard_create_exit_restriction(
603 const uint8_t *exit_id);
604
605STATIC entry_guard_restriction_t *guard_create_dirserver_md_restriction(void);
606
607STATIC entry_guard_restriction_t * guard_create_conflux_restriction(
608 const origin_circuit_t *circ);
609
610STATIC void entry_guard_restriction_free_(entry_guard_restriction_t *rst);
611#define entry_guard_restriction_free(rst) \
612 FREE_AND_NULL(entry_guard_restriction_t, \
613 entry_guard_restriction_free_, (rst))
614
615#endif /* defined(ENTRYNODES_PRIVATE) */
616
617void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs);
618void remove_all_entry_guards(void);
619
620struct bridge_info_t;
622 const uint8_t *rsa_id_digest);
623
624int entry_list_is_constrained(const or_options_t *options);
625int guards_retry_optimistic(const or_options_t *options);
626int entry_guards_parse_state_for_guard_selection(
627 guard_selection_t *gs, or_state_t *state, int set, char **msg);
628int entry_guards_parse_state(or_state_t *state, int set, char **msg);
631 const char *question, char **answer,
632 const char **errmsg);
633
634int entries_known_but_down(const or_options_t *options);
635void entries_retry_all(const or_options_t *options);
636
638 int num_present, int num_usable);
639char *guard_selection_get_err_str_if_dir_info_missing(guard_selection_t *gs,
640 int using_mds,
641 int num_present, int num_usable);
642
643void entry_guards_free_all(void);
644
645double pathbias_get_close_success_count(entry_guard_t *guard);
646double pathbias_get_use_success_count(entry_guard_t *guard);
647
648/** Contains the bandwidth of a relay as a guard and as a non-guard
649 * after the guardfraction has been considered. */
651 /** Bandwidth as a guard after guardfraction has been considered. */
653 /** Bandwidth as a non-guard after guardfraction has been considered. */
656
658
659void
660guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
661 int orig_bandwidth,
662 uint32_t guardfraction_percentage);
663
665const routerset_t *get_layer2_guards(void);
666void maintain_layer2_guards(void);
667void purge_vanguards_lite(void);
668
669#endif /* !defined(TOR_ENTRYNODES_H) */
const char * name
Definition: config.c:2462
Header for crypto_ed25519.c.
#define DIGEST_LEN
Definition: digest_sizes.h:20
STATIC int get_n_primary_guards(void)
Definition: entrynodes.c:465
STATIC void entry_guards_update_primary(guard_selection_t *gs)
Definition: entrynodes.c:1944
STATIC void entry_guards_note_guard_failure(guard_selection_t *gs, entry_guard_t *guard)
Definition: entrynodes.c:2356
STATIC void guard_selection_free_(guard_selection_t *gs)
Definition: entrynodes.c:4043
STATIC guard_selection_t * guard_selection_new(const char *name, guard_selection_type_t type)
Definition: entrynodes.c:240
STATIC guard_selection_t * get_guard_selection_by_name(const char *name, guard_selection_type_t type, int create_if_absent)
Definition: entrynodes.c:263
STATIC double get_meaningful_restriction_threshold(void)
Definition: entrynodes.c:549
STATIC guard_selection_type_t guard_selection_infer_type(guard_selection_type_t type, const char *name)
Definition: entrynodes.c:222
STATIC int get_nonprimary_guard_idle_timeout(void)
Definition: entrynodes.c:537
STATIC void mark_primary_guards_maybe_reachable(guard_selection_t *gs)
Definition: entrynodes.c:604
STATIC double get_extreme_restriction_threshold(void)
Definition: entrynodes.c:562
STATIC circuit_guard_state_t * circuit_guard_state_new(entry_guard_t *guard, unsigned state, entry_guard_restriction_t *rst)
Definition: entrynodes.c:2535
STATIC entry_guard_t * first_reachable_filtered_entry_guard(guard_selection_t *gs, const entry_guard_restriction_t *rst, unsigned flags)
Definition: entrynodes.c:1774
STATIC int get_min_filtered_sample_size(void)
Definition: entrynodes.c:403
STATIC void entry_guard_free_(entry_guard_t *e)
Definition: entrynodes.c:3494
STATIC void entry_guard_restriction_free_(entry_guard_restriction_t *rst)
Definition: entrynodes.c:2508
STATIC int get_guard_confirmed_min_lifetime(void)
Definition: entrynodes.c:451
STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b)
Definition: entrynodes.c:2470
STATIC void entry_guards_update_confirmed(guard_selection_t *gs)
Definition: entrynodes.c:1879
STATIC char * entry_guard_encode_for_state(entry_guard_t *guard, int dense_sampled_idx)
Definition: entrynodes.c:2952
STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs)
Definition: entrynodes.c:1753
STATIC entry_guard_restriction_t * guard_create_dirserver_md_restriction(void)
Definition: entrynodes.c:1635
STATIC int get_remove_unlisted_guards_after_days(void)
Definition: entrynodes.c:413
STATIC int get_max_sample_size_absolute(void)
Definition: entrynodes.c:393
STATIC int get_nonprimary_guard_connect_timeout(void)
Definition: entrynodes.c:525
STATIC entry_guard_t * get_sampled_guard_with_id(guard_selection_t *gs, const uint8_t *rsa_id)
Definition: entrynodes.c:801
STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs, entry_guard_t *guard, unsigned old_state)
Definition: entrynodes.c:2393
STATIC int entry_guard_is_listed(guard_selection_t *gs, const entry_guard_t *guard)
Definition: entrynodes.c:1272
STATIC void entry_guard_consider_retry(entry_guard_t *guard)
Definition: entrynodes.c:2082
STATIC double get_max_sample_threshold(void)
Definition: entrynodes.c:381
STATIC entry_guard_t * entry_guard_add_to_sample(guard_selection_t *gs, const node_t *node)
Definition: entrynodes.c:864
STATIC int num_reachable_filtered_guards(const guard_selection_t *gs, const entry_guard_restriction_t *rst)
Definition: entrynodes.c:1026
STATIC int entry_guards_all_primary_guards_are_down(guard_selection_t *gs)
Definition: entrynodes.c:2699
STATIC time_t randomize_time(time_t now, time_t max_backdate)
Definition: entrynodes.c:355
STATIC int get_n_primary_guards_to_use(guard_usage_t usage)
Definition: entrynodes.c:485
STATIC const char * choose_guard_selection(const or_options_t *options, const networkstatus_t *live_ns, const guard_selection_t *old_selection, guard_selection_type_t *type_out)
Definition: entrynodes.c:636
STATIC char * getinfo_helper_format_single_entry_guard(const entry_guard_t *e)
Definition: entrynodes.c:3724
STATIC void make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard)
Definition: entrynodes.c:1911
STATIC entry_guard_t * entry_guard_parse_from_state(const char *s)
Definition: entrynodes.c:3115
STATIC entry_guard_t * select_entry_guard_for_circuit(guard_selection_t *gs, guard_usage_t usage, const entry_guard_restriction_t *rst, unsigned *state_out)
Definition: entrynodes.c:2303
STATIC int get_guard_lifetime(void)
Definition: entrynodes.c:436
STATIC void sampled_guards_update_from_consensus(guard_selection_t *gs)
Definition: entrynodes.c:1427
STATIC entry_guard_t * entry_guards_expand_sample(guard_selection_t *gs)
Definition: entrynodes.c:1178
STATIC int get_internet_likely_down_interval(void)
Definition: entrynodes.c:513
void entry_guard_failed(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2653
char * guard_selection_get_err_str_if_dir_info_missing(guard_selection_t *gs, int using_mds, int num_present, int num_usable)
Definition: entrynodes.c:3985
const node_t * entry_guard_find_node(const entry_guard_t *guard)
Definition: entrynodes.c:3450
void entry_guard_learned_bridge_identity(const tor_addr_port_t *addrport, const uint8_t *rsa_id_digest)
Definition: entrynodes.c:977
void entry_guard_chan_failed(channel_t *chan)
Definition: entrynodes.c:2673
const routerset_t * get_layer2_guards(void)
Definition: entrynodes.c:4310
void entry_guards_changed(void)
Definition: entrynodes.c:3672
void remove_all_entry_guards(void)
Definition: entrynodes.c:3935
void purge_vanguards_lite(void)
Definition: entrynodes.c:4288
void entry_guard_cancel(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2632
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
Definition: entrynodes.c:3460
void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs)
Definition: entrynodes.c:3906
int num_bridges_usable(int use_maybe_reachable)
Definition: entrynodes.c:3531
int entry_guards_update_all(guard_selection_t *gs)
Definition: entrynodes.c:2936
int entry_list_is_constrained(const or_options_t *options)
Definition: entrynodes.c:3511
guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2605
circuit_guard_state_t * get_guard_state_for_bridge_desc_fetch(const char *digest)
Definition: entrynodes.c:3469
void entry_guards_note_internet_connectivity(guard_selection_t *gs)
Definition: entrynodes.c:2121
const char * entry_guard_get_rsa_id_digest(const entry_guard_t *guard)
Definition: entrynodes.c:336
double pathbias_get_use_success_count(entry_guard_t *guard)
char * entry_guards_get_err_str_if_dir_info_missing(int using_mds, int num_present, int num_usable)
Definition: entrynodes.c:4032
void entry_guards_update_state(or_state_t *state)
Definition: entrynodes.c:3683
bool vanguards_lite_is_enabled(void)
Definition: entrynodes.c:4081
int update_guard_selection_choice(const or_options_t *options)
Definition: entrynodes.c:742
void circuit_guard_state_free_(circuit_guard_state_t *state)
Definition: entrynodes.c:2522
int entry_guard_pick_for_circuit(guard_selection_t *gs, guard_usage_t usage, entry_guard_restriction_t *rst, const node_t **chosen_node_out, circuit_guard_state_t **guard_state_out)
Definition: entrynodes.c:2559
void maintain_layer2_guards(void)
Definition: entrynodes.c:4183
int entry_guards_parse_state(or_state_t *state, int set, char **msg)
Definition: entrynodes.c:3616
int entry_guard_state_should_expire(circuit_guard_state_t *guard_state)
Definition: entrynodes.c:2921
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
Definition: entrynodes.c:343
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:3868
int entry_guard_could_succeed(const circuit_guard_state_t *guard_state)
Definition: entrynodes.c:3699
int guards_retry_optimistic(const or_options_t *options)
Definition: entrynodes.c:3968
const node_t * guards_choose_dirguard(uint8_t dir_purpose, circuit_guard_state_t **guard_state_out)
Definition: entrynodes.c:3942
int should_apply_guardfraction(const networkstatus_t *ns)
Definition: entrynodes.c:189
void entry_guards_changed_for_guard_selection(guard_selection_t *gs)
Definition: entrynodes.c:3643
int getinfo_helper_entry_guards(control_connection_t *conn, const char *question, char **answer, const char **errmsg)
Definition: entrynodes.c:3781
guard_selection_t * get_guard_selection_info(void)
Definition: entrynodes.c:312
int guards_update_all(void)
Definition: entrynodes.c:3851
guard_usage_t
Definition: entrynodes.h:379
entry_guard_t * entry_guard_get_by_id_digest_for_guard_selection(guard_selection_t *gs, const char *digest)
Definition: entrynodes.c:3441
const char * entry_guard_describe(const entry_guard_t *guard)
Definition: entrynodes.c:324
int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs, const smartlist_t *all_circuits, smartlist_t *newly_complete_out)
Definition: entrynodes.c:2757
void entry_guards_free_all(void)
Definition: entrynodes.c:4324
double pathbias_get_close_success_count(entry_guard_t *guard)
Macros for C weak-handle implementation.
#define MAX_HEX_NICKNAME_LEN
Definition: or.h:115
unsigned int path_bias_use_noticed
Definition: entrynodes.h:44
unsigned int path_bias_use_extreme
Definition: entrynodes.h:46
double use_successes
Definition: entrynodes.h:62
unsigned int path_bias_warned
Definition: entrynodes.h:38
unsigned int path_bias_extreme
Definition: entrynodes.h:40
double circ_attempts
Definition: entrynodes.h:49
double collapsed_circuits
Definition: entrynodes.h:54
double circ_successes
Definition: entrynodes.h:50
unsigned int path_bias_disabled
Definition: entrynodes.h:42
double unusable_circuits
Definition: entrynodes.h:57
double successful_circuits_closed
Definition: entrynodes.h:52
double use_attempts
Definition: entrynodes.h:61
unsigned int path_bias_noticed
Definition: entrynodes.h:36
Definition: node_st.h:34
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127