entrynodes.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. #if 1
  13. /* XXXX NM I would prefer that all of this stuff be private to
  14. * entrynodes.c. */
  15. /* Forward declare for guard_selection_t; entrynodes.c has the real struct */
  16. typedef struct guard_selection_s guard_selection_t;
  17. /** An entry_guard_t represents our information about a chosen long-term
  18. * first hop, known as a "helper" node in the literature. We can't just
  19. * use a node_t, since we want to remember these even when we
  20. * don't have any directory info. */
  21. typedef struct entry_guard_t {
  22. char nickname[MAX_NICKNAME_LEN+1];
  23. char identity[DIGEST_LEN];
  24. time_t chosen_on_date; /**< Approximately when was this guard added?
  25. * "0" if we don't know. */
  26. char *chosen_by_version; /**< What tor version added this guard? NULL
  27. * if we don't know. */
  28. unsigned int made_contact : 1; /**< 0 if we have never connected to this
  29. * router, 1 if we have. */
  30. unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
  31. * in spite of having it marked as unreachable?*/
  32. unsigned int path_bias_noticed : 1; /**< Did we alert the user about path
  33. * bias for this node already? */
  34. unsigned int path_bias_warned : 1; /**< Did we alert the user about path bias
  35. * for this node already? */
  36. unsigned int path_bias_extreme : 1; /**< Did we alert the user about path
  37. * bias for this node already? */
  38. unsigned int path_bias_disabled : 1; /**< Have we disabled this node because
  39. * of path bias issues? */
  40. unsigned int path_bias_use_noticed : 1; /**< Did we alert the user about path
  41. * use bias for this node already? */
  42. unsigned int path_bias_use_extreme : 1; /**< Did we alert the user about path
  43. * use bias for this node already? */
  44. unsigned int is_dir_cache : 1; /**< Is this node a directory cache? */
  45. time_t bad_since; /**< 0 if this guard is currently usable, or the time at
  46. * which it was observed to become (according to the
  47. * directory or the user configuration) unusable. */
  48. time_t unreachable_since; /**< 0 if we can connect to this guard, or the
  49. * time at which we first noticed we couldn't
  50. * connect to it. */
  51. time_t last_attempted; /**< 0 if we can connect to this guard, or the time
  52. * at which we last failed to connect to it. */
  53. double circ_attempts; /**< Number of circuits this guard has "attempted" */
  54. double circ_successes; /**< Number of successfully built circuits using
  55. * this guard as first hop. */
  56. double successful_circuits_closed; /**< Number of circuits that carried
  57. * streams successfully. */
  58. double collapsed_circuits; /**< Number of fully built circuits that were
  59. * remotely closed before any streams were
  60. * attempted. */
  61. double unusable_circuits; /**< Number of circuits for which streams were
  62. * attempted, but none succeeded. */
  63. double timeouts; /**< Number of 'right-censored' circuit timeouts for this
  64. * guard. */
  65. double use_attempts; /**< Number of circuits we tried to use with streams */
  66. double use_successes; /**< Number of successfully used circuits using
  67. * this guard as first hop. */
  68. } entry_guard_t;
  69. entry_guard_t *entry_guard_get_by_id_digest_for_guard_selection(
  70. guard_selection_t *gs, const char *digest);
  71. entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
  72. void entry_guards_changed_for_guard_selection(guard_selection_t *gs);
  73. void entry_guards_changed(void);
  74. guard_selection_t * get_guard_selection_info(void);
  75. const smartlist_t *get_entry_guards_for_guard_selection(
  76. guard_selection_t *gs);
  77. const smartlist_t *get_entry_guards(void);
  78. int num_live_entry_guards_for_guard_selection(
  79. guard_selection_t *gs,
  80. int for_directory);
  81. int num_live_entry_guards(int for_directory);
  82. #endif
  83. #ifdef ENTRYNODES_PRIVATE
  84. STATIC const node_t *add_an_entry_guard(guard_selection_t *gs,
  85. const node_t *chosen,
  86. int reset_status, int prepend,
  87. int for_discovery, int for_directory);
  88. STATIC int populate_live_entry_guards(smartlist_t *live_entry_guards,
  89. const smartlist_t *all_entry_guards,
  90. const node_t *chosen_exit,
  91. dirinfo_type_t dirinfo_type,
  92. int for_directory,
  93. int need_uptime, int need_capacity);
  94. STATIC int decide_num_guards(const or_options_t *options, int for_directory);
  95. STATIC void entry_guards_set_from_config(guard_selection_t *gs,
  96. const or_options_t *options);
  97. /** Flags to be passed to entry_is_live() to indicate what kind of
  98. * entry nodes we are looking for. */
  99. typedef enum {
  100. ENTRY_NEED_UPTIME = 1<<0,
  101. ENTRY_NEED_CAPACITY = 1<<1,
  102. ENTRY_ASSUME_REACHABLE = 1<<2,
  103. ENTRY_NEED_DESCRIPTOR = 1<<3,
  104. } entry_is_live_flags_t;
  105. STATIC const node_t *entry_is_live(const entry_guard_t *e,
  106. entry_is_live_flags_t flags,
  107. const char **msg);
  108. STATIC int entry_is_time_to_retry(const entry_guard_t *e, time_t now);
  109. #endif
  110. void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs);
  111. void remove_all_entry_guards(void);
  112. void entry_guards_compute_status_for_guard_selection(
  113. guard_selection_t *gs, const or_options_t *options, time_t now);
  114. void entry_guards_compute_status(const or_options_t *options, time_t now);
  115. int entry_guard_register_connect_status_for_guard_selection(
  116. guard_selection_t *gs, const char *digest, int succeeded,
  117. int mark_relay_status, time_t now);
  118. int entry_guard_register_connect_status(const char *digest, int succeeded,
  119. int mark_relay_status, time_t now);
  120. void entry_nodes_should_be_added_for_guard_selection(guard_selection_t *gs);
  121. void entry_nodes_should_be_added(void);
  122. int entry_list_is_constrained(const or_options_t *options);
  123. const node_t *choose_random_entry(cpath_build_state_t *state);
  124. const node_t *choose_random_dirguard(dirinfo_type_t t);
  125. int entry_guards_parse_state_for_guard_selection(
  126. guard_selection_t *gs, or_state_t *state, int set, char **msg);
  127. int entry_guards_parse_state(or_state_t *state, int set, char **msg);
  128. void entry_guards_update_state(or_state_t *state);
  129. int getinfo_helper_entry_guards(control_connection_t *conn,
  130. const char *question, char **answer,
  131. const char **errmsg);
  132. int is_node_used_as_guard_for_guard_selection(guard_selection_t *gs,
  133. const node_t *node);
  134. MOCK_DECL(int, is_node_used_as_guard, (const node_t *node));
  135. void mark_bridge_list(void);
  136. void sweep_bridge_list(void);
  137. int addr_is_a_configured_bridge(const tor_addr_t *addr, uint16_t port,
  138. const char *digest);
  139. int extend_info_is_a_configured_bridge(const extend_info_t *ei);
  140. int routerinfo_is_a_configured_bridge(const routerinfo_t *ri);
  141. int node_is_a_configured_bridge(const node_t *node);
  142. void learned_router_identity(const tor_addr_t *addr, uint16_t port,
  143. const char *digest);
  144. struct bridge_line_t;
  145. void bridge_add_from_config(struct bridge_line_t *bridge_line);
  146. void retry_bridge_descriptor_fetch_directly(const char *digest);
  147. void fetch_bridge_descriptors(const or_options_t *options, time_t now);
  148. void learned_bridge_descriptor(routerinfo_t *ri, int from_cache);
  149. int any_bridge_descriptors_known(void);
  150. int entries_known_but_down(const or_options_t *options);
  151. void entries_retry_all(const or_options_t *options);
  152. int any_bridge_supports_microdescriptors(void);
  153. const smartlist_t *get_socks_args_by_bridge_addrport(const tor_addr_t *addr,
  154. uint16_t port);
  155. int any_bridges_dont_support_microdescriptors(void);
  156. void entry_guards_free_all(void);
  157. const char *find_transport_name_by_bridge_addrport(const tor_addr_t *addr,
  158. uint16_t port);
  159. struct transport_t;
  160. int get_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port,
  161. const struct transport_t **transport);
  162. MOCK_DECL(int, transport_is_needed, (const char *transport_name));
  163. int validate_pluggable_transports_config(void);
  164. double pathbias_get_close_success_count(entry_guard_t *guard);
  165. double pathbias_get_use_success_count(entry_guard_t *guard);
  166. /** Contains the bandwidth of a relay as a guard and as a non-guard
  167. * after the guardfraction has been considered. */
  168. typedef struct guardfraction_bandwidth_t {
  169. /** Bandwidth as a guard after guardfraction has been considered. */
  170. int guard_bw;
  171. /** Bandwidth as a non-guard after guardfraction has been considered. */
  172. int non_guard_bw;
  173. } guardfraction_bandwidth_t;
  174. int should_apply_guardfraction(const networkstatus_t *ns);
  175. void
  176. guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
  177. int orig_bandwidth,
  178. uint32_t guardfraction_percentage);
  179. MOCK_DECL(smartlist_t *, list_bridge_identities, (void));
  180. MOCK_DECL(download_status_t *, get_bridge_dl_status_by_id,
  181. (const char *digest));
  182. #endif