entrynodes.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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-2016, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file entrynodes.h
  8. * \brief Header file for circuitbuild.c.
  9. **/
  10. #ifndef TOR_ENTRYNODES_H
  11. #define TOR_ENTRYNODES_H
  12. #include "handles.h"
  13. /* Forward declare for guard_selection_t; entrynodes.c has the real struct */
  14. typedef struct guard_selection_s guard_selection_t;
  15. /* Forward declare for entry_guard_t; the real declaration is private. */
  16. typedef struct entry_guard_t entry_guard_t;
  17. /* Forward declaration for circuit_guard_state_t; the real declaration is
  18. private. */
  19. typedef struct circuit_guard_state_t circuit_guard_state_t;
  20. /* Information about a guard's pathbias status.
  21. * These fields are used in circpathbias.c to try to detect entry
  22. * nodes that are failing circuits at a suspicious frequency.
  23. */
  24. typedef struct guard_pathbias_t {
  25. unsigned int path_bias_noticed : 1; /**< Did we alert the user about path
  26. * bias for this node already? */
  27. unsigned int path_bias_warned : 1; /**< Did we alert the user about path bias
  28. * for this node already? */
  29. unsigned int path_bias_extreme : 1; /**< Did we alert the user about path
  30. * bias for this node already? */
  31. unsigned int path_bias_disabled : 1; /**< Have we disabled this node because
  32. * of path bias issues? */
  33. unsigned int path_bias_use_noticed : 1; /**< Did we alert the user about path
  34. * use bias for this node already? */
  35. unsigned int path_bias_use_extreme : 1; /**< Did we alert the user about path
  36. * use bias for this node already? */
  37. double circ_attempts; /**< Number of circuits this guard has "attempted" */
  38. double circ_successes; /**< Number of successfully built circuits using
  39. * this guard as first hop. */
  40. double successful_circuits_closed; /**< Number of circuits that carried
  41. * streams successfully. */
  42. double collapsed_circuits; /**< Number of fully built circuits that were
  43. * remotely closed before any streams were
  44. * attempted. */
  45. double unusable_circuits; /**< Number of circuits for which streams were
  46. * attempted, but none succeeded. */
  47. double timeouts; /**< Number of 'right-censored' circuit timeouts for this
  48. * guard. */
  49. double use_attempts; /**< Number of circuits we tried to use with streams */
  50. double use_successes; /**< Number of successfully used circuits using
  51. * this guard as first hop. */
  52. } guard_pathbias_t;
  53. #if defined(ENTRYNODES_PRIVATE)
  54. /**
  55. * @name values for entry_guard_t.is_reachable.
  56. *
  57. * See entry_guard_t.is_reachable for more information.
  58. */
  59. /**@{*/
  60. #define GUARD_REACHABLE_NO 0
  61. #define GUARD_REACHABLE_YES 1
  62. #define GUARD_REACHABLE_MAYBE 2
  63. /**@}*/
  64. /** An entry_guard_t represents our information about a chosen long-term
  65. * first hop, known as a "helper" node in the literature. We can't just
  66. * use a node_t, since we want to remember these even when we
  67. * don't have any directory info. */
  68. struct entry_guard_t {
  69. HANDLE_ENTRY(entry_guard, entry_guard_t);
  70. char nickname[MAX_HEX_NICKNAME_LEN+1];
  71. char identity[DIGEST_LEN];
  72. ed25519_public_key_t ed_id;
  73. /**
  74. * @name new guard selection algorithm fields.
  75. *
  76. * Only the new (prop271) algorithm uses these. For a more full
  77. * description of the algorithm, see the module documentation for
  78. * entrynodes.c
  79. */
  80. /**@{*/
  81. /* == Persistent fields, present for all sampled guards. */
  82. /** When was this guard added to the sample? */
  83. time_t sampled_on_date;
  84. /** Since what date has this guard been "unlisted"? A guard counts as
  85. * unlisted if we have a live consensus that does not include it, or
  86. * if we have a live consensus that does not include it as a usable
  87. * guard. This field is zero when the guard is listed. */
  88. time_t unlisted_since_date; // can be zero
  89. /** What version of Tor added this guard to the sample? */
  90. char *sampled_by_version;
  91. /** Is this guard listed right now? If this is set, then
  92. * unlisted_since_date should be set too. */
  93. unsigned currently_listed : 1;
  94. /* == Persistent fields, for confirmed guards only */
  95. /** When was this guard confirmed? (That is, when did we first use it
  96. * successfully and decide to keep it?) This field is zero if this is not a
  97. * confirmed guard. */
  98. time_t confirmed_on_date; /* 0 if not confirmed */
  99. /**
  100. * In what order was this guard confirmed? Guards with lower indices
  101. * appear earlier on the confirmed list. If the confirmed list is compacted,
  102. * this field corresponds to the index of this guard on the confirmed list.
  103. *
  104. * This field is set to -1 if this guard is not confirmed.
  105. */
  106. int confirmed_idx; /* -1 if not confirmed; otherwise the order that this
  107. * item should occur in the CONFIRMED_GUARDS ordered
  108. * list */
  109. /* ==== Non-persistent fields. */
  110. /* == These are used by sampled guards */
  111. /** When did we last decide to try using this guard for a circuit? 0 for
  112. * "not since we started up." */
  113. time_t last_tried_to_connect;
  114. /** How reachable do we consider this guard to be? One of
  115. * GUARD_REACHABLE_NO, GUARD_REACHABLE_YES, or GUARD_REACHABLE_MAYBE. */
  116. unsigned is_reachable : 2;
  117. /** Boolean: true iff this guard is pending. A pending guard is one
  118. * that we have an in-progress circuit through, and which we do not plan
  119. * to try again until it either succeeds or fails. Primary guards can
  120. * never be pending. */
  121. unsigned is_pending : 1;
  122. /** When did we get the earliest connection failure for this guard?
  123. * We clear this field on a successful connect. We do _not_ clear it
  124. * when we mark the guard as "MAYBE" reachable.
  125. */
  126. time_t failing_since;
  127. /* == Set inclusion flags. */
  128. /** If true, this guard is in the filtered set. The filtered set includes
  129. * all sampled guards that our configuration allows us to use. */
  130. unsigned is_filtered_guard : 1;
  131. /** If true, this guard is in the usable filtered set. The usable filtered
  132. * set includes all filtered guards that are not believed to be
  133. * unreachable. (That is, those for which is_reachable is not
  134. * GUARD_REACHABLE_NO) */
  135. unsigned is_usable_filtered_guard : 1;
  136. unsigned is_primary:1;
  137. /** This string holds any fields that we are maintaining because
  138. * we saw them in the state, even if we don't understand them. */
  139. char *extra_state_fields;
  140. /**@}*/
  141. /**
  142. * @name legacy guard selection algorithm fields
  143. *
  144. * These are used and maintained by the legacy (pre-prop271) entry guard
  145. * algorithm. Most of them we will remove as prop271 gets implemented.
  146. * The rest we'll migrate over, if they are 100% semantically identical to
  147. * their prop271 equivalents. XXXXprop271
  148. */
  149. /**@{*/
  150. time_t chosen_on_date; /**< Approximately when was this guard added?
  151. * "0" if we don't know. */
  152. char *chosen_by_version; /**< What tor version added this guard? NULL
  153. * if we don't know. */
  154. unsigned int made_contact : 1; /**< 0 if we have never connected to this
  155. * router, 1 if we have. */
  156. unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
  157. * in spite of having it marked as unreachable?*/
  158. unsigned int is_dir_cache : 1; /**< Is this node a directory cache? */
  159. time_t bad_since; /**< 0 if this guard is currently usable, or the time at
  160. * which it was observed to become (according to the
  161. * directory or the user configuration) unusable. */
  162. time_t unreachable_since; /**< 0 if we can connect to this guard, or the
  163. * time at which we first noticed we couldn't
  164. * connect to it. */
  165. time_t last_attempted; /**< 0 if we can connect to this guard, or the time
  166. * at which we last failed to connect to it. */
  167. /**}@*/
  168. /** Path bias information for this guard. */
  169. guard_pathbias_t pb;
  170. };
  171. /**
  172. * All of the the context for guard selection on a particular client.
  173. *
  174. * (XXXX prop271 this paragraph below is not actually implemented yet.)
  175. * We maintain multiple guard selection contexts for a client, depending
  176. * aspects on its current configuration -- whether an extremely
  177. * restrictive EntryNodes is used, whether UseBridges is enabled, and so
  178. * on.)
  179. *
  180. * See the module documentation for entrynodes.c for more information
  181. * about guard selection algorithms.
  182. */
  183. struct guard_selection_s {
  184. /**
  185. * A value of 1 means that guard_selection_t structures have changed
  186. * and those changes need to be flushed to disk.
  187. *
  188. * XXX prop271 we don't know how to flush multiple guard contexts to
  189. * disk yet; fix that as soon as any way to change the default exists,
  190. * or at least make sure this gets set on change.
  191. */
  192. int dirty;
  193. /**
  194. * A list of the sampled entry guards, as entry_guard_t structures.
  195. * Not in any particular order. When we 'sample' a guard, we are
  196. * noting it as a possible guard to pick in the future. The use of
  197. * sampling here prevents us from being forced by an attacker to try
  198. * every guard on the network. This list is persistent.
  199. */
  200. smartlist_t *sampled_entry_guards;
  201. /**
  202. * Ordered list (from highest to lowest priority) of guards that we
  203. * have successfully contacted and decided to use. Every member of
  204. * this list is a member of sampled_entry_guards. Every member should
  205. * have confirmed_on_date set, and have confirmed_idx greater than
  206. * any earlier member of the list.
  207. *
  208. * This list is persistent. It is a subset of the elements in
  209. * sampled_entry_guards, and its pointers point to elements of
  210. * sampled_entry_guards.
  211. */
  212. smartlist_t *confirmed_entry_guards;
  213. /**
  214. * Ordered list (from highest to lowest priority) of guards that we
  215. * are willing to use the most happily. These guards may or may not
  216. * yet be confirmed yet. If we can use one of these guards, we are
  217. * probably not on a network that is trying to restrict our guard
  218. * choices.
  219. *
  220. * This list is a subset of the elements in
  221. * sampled_entry_guards, and its pointers point to elements of
  222. * sampled_entry_guards.
  223. */
  224. smartlist_t *primary_entry_guards;
  225. /** When did we last successfully build a circuit or use a circuit? */
  226. time_t last_time_on_internet;
  227. /** What confirmed_idx value should the next-added member of
  228. * confirmed_entry_guards receive? */
  229. int next_confirmed_idx;
  230. /**
  231. * A list of our chosen entry guards, as entry_guard_t structures; this
  232. * preserves the pre-Prop271 behavior.
  233. */
  234. smartlist_t *chosen_entry_guards;
  235. /**
  236. * When we try to choose an entry guard, should we parse and add
  237. * config's EntryNodes first? This was formerly a global. This
  238. * preserves the pre-Prop271 behavior.
  239. */
  240. int should_add_entry_nodes;
  241. };
  242. struct entry_guard_handle_t;
  243. /**
  244. * Per-circuit state to track whether we'll be able to use the circuit.
  245. */
  246. struct circuit_guard_state_t {
  247. /** Handle to the entry guard object for this circuit. */
  248. struct entry_guard_handle_t *guard;
  249. /** The time at which <b>state</b> last changed. */
  250. time_t state_set_at;
  251. /** One of GUARD_CIRC_STATE_* */
  252. uint8_t state;
  253. };
  254. #endif
  255. /* Common entry points for old and new guard code */
  256. void guards_update_all(void);
  257. const node_t *guards_choose_guard(cpath_build_state_t *state,
  258. circuit_guard_state_t **guard_state_out);
  259. const node_t *guards_choose_dirguard(dirinfo_type_t info,
  260. circuit_guard_state_t **guard_state_out);
  261. #if 1
  262. /* XXXX NM I would prefer that all of this stuff be private to
  263. * entrynodes.c. */
  264. entry_guard_t *entry_guard_get_by_id_digest_for_guard_selection(
  265. guard_selection_t *gs, const char *digest);
  266. entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
  267. void entry_guards_changed_for_guard_selection(guard_selection_t *gs);
  268. void entry_guards_changed(void);
  269. guard_selection_t * get_guard_selection_info(void);
  270. const smartlist_t *get_entry_guards_for_guard_selection(
  271. guard_selection_t *gs);
  272. const smartlist_t *get_entry_guards(void);
  273. int num_live_entry_guards_for_guard_selection(
  274. guard_selection_t *gs,
  275. int for_directory);
  276. int num_live_entry_guards(int for_directory);
  277. #endif
  278. const node_t *entry_guard_find_node(const entry_guard_t *guard);
  279. void entry_guard_mark_bad(entry_guard_t *guard);
  280. const char *entry_guard_get_rsa_id_digest(const entry_guard_t *guard);
  281. const char *entry_guard_describe(const entry_guard_t *guard);
  282. guard_pathbias_t *entry_guard_get_pathbias_state(entry_guard_t *guard);
  283. void circuit_guard_state_free(circuit_guard_state_t *state);
  284. int entry_guard_pick_for_circuit(guard_selection_t *gs,
  285. const node_t **chosen_node_out,
  286. circuit_guard_state_t **guard_state_out);
  287. int entry_guard_succeeded(guard_selection_t *gs,
  288. circuit_guard_state_t **guard_state_p);
  289. void entry_guard_failed(guard_selection_t *gs,
  290. circuit_guard_state_t **guard_state_p);
  291. void entry_guard_cancel(guard_selection_t *gs,
  292. circuit_guard_state_t **guard_state_p);
  293. void entry_guard_chan_failed(guard_selection_t *gs,
  294. channel_t *chan);
  295. void entry_guards_update_all(guard_selection_t *gs);
  296. int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs,
  297. const smartlist_t *all_circuits,
  298. smartlist_t *newly_complete_out);
  299. void entry_guards_note_internet_connectivity(guard_selection_t *gs);
  300. /* Used by bridges.c only. */
  301. void add_bridge_as_entry_guard(guard_selection_t *gs,
  302. const node_t *chosen);
  303. int num_bridges_usable(void);
  304. #ifdef ENTRYNODES_PRIVATE
  305. /**
  306. * @name Parameters for the new (prop271) entry guard algorithm.
  307. */
  308. /* XXXX prop271 some of these should be networkstatus parameters */
  309. /**@{*/
  310. /**
  311. * We never let our sampled guard set grow larger than this fraction
  312. * of the guards on the network.
  313. */
  314. #define MAX_SAMPLE_THRESHOLD 0.30
  315. /**
  316. * We always try to make our sample contain at least this many guards.
  317. *
  318. * XXXX prop271 There was a MIN_SAMPLE_THRESHOLD in the proposal, but I
  319. * removed it in favor of MIN_FILTERED_SAMPLE_SIZE. -NM
  320. */
  321. #define MIN_FILTERED_SAMPLE_SIZE 20
  322. /**
  323. * If a guard is unlisted for this many days in a row, we remove it.
  324. */
  325. #define REMOVE_UNLISTED_GUARDS_AFTER_DAYS 20
  326. /**
  327. * We remove unconfirmed guards from the sample after this many days,
  328. * regardless of whether they are listed or unlisted.
  329. */
  330. #define GUARD_LIFETIME_DAYS 120
  331. /**
  332. * We remove confirmed guards from the sample if they were sampled
  333. * GUARD_LIFETIME_DAYS ago and confirmed this many days ago.
  334. */
  335. #define GUARD_CONFIRMED_MIN_LIFETIME_DAYS 60
  336. /**
  337. * How many guards do we try to keep on our primary guard list?
  338. */
  339. #define N_PRIMARY_GUARDS 3
  340. /**
  341. * If we haven't successfully built or used a circuit in this long, then
  342. * consider that the internet is probably down.
  343. */
  344. #define INTERNET_LIKELY_DOWN_INTERVAL (10*60)
  345. /**
  346. * DOCDOC. not yet used; see prop271.
  347. */
  348. #define NONPRIMARY_GUARD_CONNECT_TIMEOUT 15
  349. /**
  350. * DOCDOC. not yet used; see prop271.
  351. */
  352. #define NONPRIMARY_GUARD_IDLE_TIMEOUT (10*60)
  353. /**
  354. * DOCDOC. not yet used; see prop271.
  355. */
  356. #define MEANINGFUL_RESTRICTION_FRAC 0.2
  357. /**
  358. * DOCDOC. not yet used. see prop271.
  359. */
  360. #define EXTREME_RESTRICTION_FRAC 0.01
  361. /**@}*/
  362. // ---------- XXXX these functions and definitions are post-prop271.
  363. HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
  364. STATIC guard_selection_t *guard_selection_new(void);
  365. STATIC void guard_selection_free(guard_selection_t *gs);
  366. STATIC entry_guard_t *get_sampled_guard_with_id(guard_selection_t *gs,
  367. const uint8_t *rsa_id);
  368. MOCK_DECL(STATIC time_t, randomize_time, (time_t now, time_t max_backdate));
  369. STATIC entry_guard_t *entry_guard_add_to_sample(guard_selection_t *gs,
  370. const node_t *node);
  371. STATIC entry_guard_t *entry_guards_expand_sample(guard_selection_t *gs);
  372. STATIC char *entry_guard_encode_for_state(entry_guard_t *guard);
  373. STATIC entry_guard_t *entry_guard_parse_from_state(const char *s);
  374. STATIC void entry_guard_free(entry_guard_t *e);
  375. STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs);
  376. /**
  377. * @name Flags for sample_reachable_filtered_entry_guards()
  378. */
  379. /**@{*/
  380. #define SAMPLE_EXCLUDE_CONFIRMED (1u<<0)
  381. #define SAMPLE_EXCLUDE_PRIMARY (1u<<1)
  382. #define SAMPLE_EXCLUDE_PENDING (1u<<2)
  383. /**@}*/
  384. STATIC entry_guard_t *sample_reachable_filtered_entry_guards(
  385. guard_selection_t *gs,
  386. unsigned flags);
  387. STATIC void entry_guard_consider_retry(entry_guard_t *guard);
  388. STATIC void make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard);
  389. STATIC void entry_guards_update_confirmed(guard_selection_t *gs);
  390. STATIC void entry_guards_update_primary(guard_selection_t *gs);
  391. STATIC int num_reachable_filtered_guards(guard_selection_t *gs);
  392. STATIC void sampled_guards_update_from_consensus(guard_selection_t *gs);
  393. /**
  394. * @name Possible guard-states for a circuit.
  395. */
  396. /**@{*/
  397. /** State for a circuit that can (so far as the guard subsystem is
  398. * concerned) be used for actual traffic as soon as it is successfully
  399. * opened. */
  400. #define GUARD_CIRC_STATE_USABLE_ON_COMPLETION 1
  401. /** State for an non-open circuit that we shouldn't use for actual
  402. * traffic, when it completes, unless other circuits to preferable
  403. * guards fail. */
  404. #define GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD 2
  405. /** State for an open circuit that we shouldn't use for actual traffic
  406. * unless other circuits to preferable guards fail. */
  407. #define GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD 3
  408. /** State for a circuit that can (so far as the guard subsystem is
  409. * concerned) be used for actual traffic. */
  410. #define GUARD_CIRC_STATE_COMPLETE 4
  411. /** State for a circuit that is unusable, and will not become usable. */
  412. #define GUARD_CIRC_STATE_DEAD 5
  413. /**@}*/
  414. STATIC void entry_guards_note_guard_failure(guard_selection_t *gs,
  415. entry_guard_t *guard);
  416. STATIC entry_guard_t *select_entry_guard_for_circuit(guard_selection_t *gs,
  417. unsigned *state_out);
  418. STATIC void mark_primary_guards_maybe_reachable(guard_selection_t *gs);
  419. STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs,
  420. entry_guard_t *guard,
  421. unsigned old_state);
  422. STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b);
  423. void entry_guards_DUMMY_ENTRY_POINT(void);
  424. // ---------- XXXX this stuff is pre-prop271.
  425. STATIC const node_t *add_an_entry_guard(guard_selection_t *gs,
  426. const node_t *chosen,
  427. int reset_status, int prepend,
  428. int for_discovery, int for_directory);
  429. STATIC int populate_live_entry_guards(smartlist_t *live_entry_guards,
  430. const smartlist_t *all_entry_guards,
  431. const node_t *chosen_exit,
  432. dirinfo_type_t dirinfo_type,
  433. int for_directory,
  434. int need_uptime, int need_capacity);
  435. STATIC int decide_num_guards(const or_options_t *options, int for_directory);
  436. STATIC void entry_guards_set_from_config(guard_selection_t *gs,
  437. const or_options_t *options);
  438. /** Flags to be passed to entry_is_live() to indicate what kind of
  439. * entry nodes we are looking for. */
  440. typedef enum {
  441. ENTRY_NEED_UPTIME = 1<<0,
  442. ENTRY_NEED_CAPACITY = 1<<1,
  443. ENTRY_ASSUME_REACHABLE = 1<<2,
  444. ENTRY_NEED_DESCRIPTOR = 1<<3,
  445. } entry_is_live_flags_t;
  446. STATIC const node_t *entry_is_live(const entry_guard_t *e,
  447. entry_is_live_flags_t flags,
  448. const char **msg);
  449. STATIC int entry_is_time_to_retry(const entry_guard_t *e, time_t now);
  450. #endif
  451. void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs);
  452. void remove_all_entry_guards(void);
  453. void entry_guards_compute_status_for_guard_selection(
  454. guard_selection_t *gs, const or_options_t *options, time_t now);
  455. void entry_guards_compute_status(const or_options_t *options, time_t now);
  456. int entry_guard_register_connect_status_for_guard_selection(
  457. guard_selection_t *gs, const char *digest, int succeeded,
  458. int mark_relay_status, time_t now);
  459. int entry_guard_register_connect_status(const char *digest, int succeeded,
  460. int mark_relay_status, time_t now);
  461. void entry_nodes_should_be_added_for_guard_selection(guard_selection_t *gs);
  462. void entry_nodes_should_be_added(void);
  463. int entry_list_is_constrained(const or_options_t *options);
  464. const node_t *choose_random_entry(cpath_build_state_t *state);
  465. const node_t *choose_random_dirguard(dirinfo_type_t t);
  466. int entry_guards_parse_state_for_guard_selection(
  467. guard_selection_t *gs, or_state_t *state, int set, char **msg);
  468. int entry_guards_parse_state(or_state_t *state, int set, char **msg);
  469. void entry_guards_update_state(or_state_t *state);
  470. int getinfo_helper_entry_guards(control_connection_t *conn,
  471. const char *question, char **answer,
  472. const char **errmsg);
  473. int is_node_used_as_guard_for_guard_selection(guard_selection_t *gs,
  474. const node_t *node);
  475. MOCK_DECL(int, is_node_used_as_guard, (const node_t *node));
  476. int entries_known_but_down(const or_options_t *options);
  477. void entries_retry_all(const or_options_t *options);
  478. void entry_guards_free_all(void);
  479. double pathbias_get_close_success_count(entry_guard_t *guard);
  480. double pathbias_get_use_success_count(entry_guard_t *guard);
  481. /** Contains the bandwidth of a relay as a guard and as a non-guard
  482. * after the guardfraction has been considered. */
  483. typedef struct guardfraction_bandwidth_t {
  484. /** Bandwidth as a guard after guardfraction has been considered. */
  485. int guard_bw;
  486. /** Bandwidth as a non-guard after guardfraction has been considered. */
  487. int non_guard_bw;
  488. } guardfraction_bandwidth_t;
  489. int should_apply_guardfraction(const networkstatus_t *ns);
  490. void
  491. guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
  492. int orig_bandwidth,
  493. uint32_t guardfraction_percentage);
  494. #endif