2012-10-15 20:28:23 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2016-02-27 18:48:19 +01:00
|
|
|
* Copyright (c) 2007-2016, The Tor Project, Inc. */
|
2012-10-15 20:28:23 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
2014-03-25 16:16:18 +01:00
|
|
|
* \file entrynodes.h
|
2012-10-15 20:28:23 +02:00
|
|
|
* \brief Header file for circuitbuild.c.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef TOR_ENTRYNODES_H
|
|
|
|
#define TOR_ENTRYNODES_H
|
|
|
|
|
2016-09-25 04:11:44 +02:00
|
|
|
/* Forward declare for guard_selection_t; entrynodes.c has the real struct */
|
|
|
|
typedef struct guard_selection_s guard_selection_t;
|
|
|
|
|
2016-11-14 17:41:37 +01:00
|
|
|
/* Forward declare for entry_guard_t; the real declaration is private. */
|
|
|
|
typedef struct entry_guard_t entry_guard_t;
|
|
|
|
|
|
|
|
#if defined(ENTRYNODES_PRIVATE) || defined(ENTRYNODES_EXPOSE_STRUCT)
|
2012-10-15 20:28:23 +02:00
|
|
|
/** An entry_guard_t represents our information about a chosen long-term
|
|
|
|
* first hop, known as a "helper" node in the literature. We can't just
|
|
|
|
* use a node_t, since we want to remember these even when we
|
|
|
|
* don't have any directory info. */
|
2016-11-14 17:41:37 +01:00
|
|
|
struct entry_guard_t {
|
2012-10-15 20:28:23 +02:00
|
|
|
char nickname[MAX_NICKNAME_LEN+1];
|
|
|
|
char identity[DIGEST_LEN];
|
|
|
|
time_t chosen_on_date; /**< Approximately when was this guard added?
|
|
|
|
* "0" if we don't know. */
|
|
|
|
char *chosen_by_version; /**< What tor version added this guard? NULL
|
|
|
|
* if we don't know. */
|
|
|
|
unsigned int made_contact : 1; /**< 0 if we have never connected to this
|
|
|
|
* router, 1 if we have. */
|
|
|
|
unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
|
|
|
|
* in spite of having it marked as unreachable?*/
|
2012-10-25 23:14:28 +02:00
|
|
|
unsigned int path_bias_noticed : 1; /**< Did we alert the user about path
|
|
|
|
* bias for this node already? */
|
2012-10-25 03:15:41 +02:00
|
|
|
unsigned int path_bias_warned : 1; /**< Did we alert the user about path bias
|
2012-10-15 20:28:23 +02:00
|
|
|
* for this node already? */
|
2012-11-01 02:49:49 +01:00
|
|
|
unsigned int path_bias_extreme : 1; /**< Did we alert the user about path
|
|
|
|
* bias for this node already? */
|
2012-10-15 20:28:23 +02:00
|
|
|
unsigned int path_bias_disabled : 1; /**< Have we disabled this node because
|
|
|
|
* of path bias issues? */
|
2013-02-05 01:59:28 +01:00
|
|
|
unsigned int path_bias_use_noticed : 1; /**< Did we alert the user about path
|
|
|
|
* use bias for this node already? */
|
|
|
|
unsigned int path_bias_use_extreme : 1; /**< Did we alert the user about path
|
|
|
|
* use bias for this node already? */
|
2012-12-11 18:44:18 +01:00
|
|
|
unsigned int is_dir_cache : 1; /**< Is this node a directory cache? */
|
2012-10-15 20:28:23 +02:00
|
|
|
time_t bad_since; /**< 0 if this guard is currently usable, or the time at
|
|
|
|
* which it was observed to become (according to the
|
|
|
|
* directory or the user configuration) unusable. */
|
|
|
|
time_t unreachable_since; /**< 0 if we can connect to this guard, or the
|
|
|
|
* time at which we first noticed we couldn't
|
|
|
|
* connect to it. */
|
|
|
|
time_t last_attempted; /**< 0 if we can connect to this guard, or the time
|
|
|
|
* at which we last failed to connect to it. */
|
|
|
|
|
2016-10-26 18:38:50 +02:00
|
|
|
/**
|
|
|
|
* @name circpathbias fields
|
|
|
|
*
|
|
|
|
* These fields are used in circpathbias.c to try to detect entry
|
|
|
|
* nodes that are failing circuits at a suspicious frequency.
|
|
|
|
*/
|
|
|
|
/**@{*/
|
|
|
|
|
2012-12-10 05:53:22 +01:00
|
|
|
double circ_attempts; /**< Number of circuits this guard has "attempted" */
|
|
|
|
double circ_successes; /**< Number of successfully built circuits using
|
2012-10-15 20:28:23 +02:00
|
|
|
* this guard as first hop. */
|
2012-12-10 05:53:22 +01:00
|
|
|
double successful_circuits_closed; /**< Number of circuits that carried
|
2012-11-18 01:30:50 +01:00
|
|
|
* streams successfully. */
|
2012-12-10 05:53:22 +01:00
|
|
|
double collapsed_circuits; /**< Number of fully built circuits that were
|
2012-11-18 01:30:50 +01:00
|
|
|
* remotely closed before any streams were
|
|
|
|
* attempted. */
|
2012-12-10 08:47:04 +01:00
|
|
|
double unusable_circuits; /**< Number of circuits for which streams were
|
2012-11-18 01:30:50 +01:00
|
|
|
* attempted, but none succeeded. */
|
2012-12-10 05:53:22 +01:00
|
|
|
double timeouts; /**< Number of 'right-censored' circuit timeouts for this
|
2012-11-18 01:30:50 +01:00
|
|
|
* guard. */
|
2013-01-19 04:37:16 +01:00
|
|
|
double use_attempts; /**< Number of circuits we tried to use with streams */
|
|
|
|
double use_successes; /**< Number of successfully used circuits using
|
|
|
|
* this guard as first hop. */
|
2016-10-26 18:38:50 +02:00
|
|
|
/**@}*/
|
2016-11-14 17:41:37 +01:00
|
|
|
};
|
|
|
|
#endif
|
2012-10-15 20:28:23 +02:00
|
|
|
|
2016-11-14 17:41:37 +01:00
|
|
|
#if 1
|
|
|
|
/* XXXX NM I would prefer that all of this stuff be private to
|
|
|
|
* entrynodes.c. */
|
2016-09-25 04:11:44 +02:00
|
|
|
entry_guard_t *entry_guard_get_by_id_digest_for_guard_selection(
|
|
|
|
guard_selection_t *gs, const char *digest);
|
2012-10-15 20:28:23 +02:00
|
|
|
entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
|
2016-09-25 04:11:44 +02:00
|
|
|
void entry_guards_changed_for_guard_selection(guard_selection_t *gs);
|
2012-10-15 20:28:23 +02:00
|
|
|
void entry_guards_changed(void);
|
2016-09-25 04:11:44 +02:00
|
|
|
guard_selection_t * get_guard_selection_info(void);
|
|
|
|
const smartlist_t *get_entry_guards_for_guard_selection(
|
|
|
|
guard_selection_t *gs);
|
2012-10-15 20:28:23 +02:00
|
|
|
const smartlist_t *get_entry_guards(void);
|
2016-09-25 04:11:44 +02:00
|
|
|
int num_live_entry_guards_for_guard_selection(
|
|
|
|
guard_selection_t *gs,
|
|
|
|
int for_directory);
|
2012-12-11 18:44:18 +01:00
|
|
|
int num_live_entry_guards(int for_directory);
|
2012-10-15 20:28:23 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-11-14 17:41:37 +01:00
|
|
|
const node_t *entry_guard_find_node(const entry_guard_t *guard);
|
|
|
|
|
2014-06-16 03:38:52 +02:00
|
|
|
#ifdef ENTRYNODES_PRIVATE
|
2016-09-25 04:11:44 +02:00
|
|
|
STATIC const node_t *add_an_entry_guard(guard_selection_t *gs,
|
|
|
|
const node_t *chosen,
|
2014-06-16 03:38:52 +02:00
|
|
|
int reset_status, int prepend,
|
|
|
|
int for_discovery, int for_directory);
|
|
|
|
STATIC int populate_live_entry_guards(smartlist_t *live_entry_guards,
|
|
|
|
const smartlist_t *all_entry_guards,
|
|
|
|
const node_t *chosen_exit,
|
|
|
|
dirinfo_type_t dirinfo_type,
|
|
|
|
int for_directory,
|
|
|
|
int need_uptime, int need_capacity);
|
|
|
|
STATIC int decide_num_guards(const or_options_t *options, int for_directory);
|
|
|
|
|
2016-09-25 04:11:44 +02:00
|
|
|
STATIC void entry_guards_set_from_config(guard_selection_t *gs,
|
|
|
|
const or_options_t *options);
|
2014-06-25 21:39:00 +02:00
|
|
|
|
2014-06-25 21:44:36 +02:00
|
|
|
/** Flags to be passed to entry_is_live() to indicate what kind of
|
|
|
|
* entry nodes we are looking for. */
|
|
|
|
typedef enum {
|
|
|
|
ENTRY_NEED_UPTIME = 1<<0,
|
|
|
|
ENTRY_NEED_CAPACITY = 1<<1,
|
|
|
|
ENTRY_ASSUME_REACHABLE = 1<<2,
|
|
|
|
ENTRY_NEED_DESCRIPTOR = 1<<3,
|
|
|
|
} entry_is_live_flags_t;
|
|
|
|
|
2014-07-16 16:52:16 +02:00
|
|
|
STATIC const node_t *entry_is_live(const entry_guard_t *e,
|
|
|
|
entry_is_live_flags_t flags,
|
|
|
|
const char **msg);
|
2014-08-20 21:07:08 +02:00
|
|
|
|
|
|
|
STATIC int entry_is_time_to_retry(const entry_guard_t *e, time_t now);
|
|
|
|
|
2014-06-16 03:38:52 +02:00
|
|
|
#endif
|
|
|
|
|
2016-09-25 04:11:44 +02:00
|
|
|
void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs);
|
2013-10-21 19:02:25 +02:00
|
|
|
void remove_all_entry_guards(void);
|
|
|
|
|
2016-09-25 04:11:44 +02:00
|
|
|
void entry_guards_compute_status_for_guard_selection(
|
|
|
|
guard_selection_t *gs, const or_options_t *options, time_t now);
|
2012-10-15 20:28:23 +02:00
|
|
|
void entry_guards_compute_status(const or_options_t *options, time_t now);
|
2016-09-25 04:11:44 +02:00
|
|
|
int entry_guard_register_connect_status_for_guard_selection(
|
|
|
|
guard_selection_t *gs, const char *digest, int succeeded,
|
|
|
|
int mark_relay_status, time_t now);
|
2012-10-15 20:28:23 +02:00
|
|
|
int entry_guard_register_connect_status(const char *digest, int succeeded,
|
|
|
|
int mark_relay_status, time_t now);
|
2016-09-25 04:11:44 +02:00
|
|
|
void entry_nodes_should_be_added_for_guard_selection(guard_selection_t *gs);
|
2012-10-15 20:28:23 +02:00
|
|
|
void entry_nodes_should_be_added(void);
|
|
|
|
int entry_list_is_constrained(const or_options_t *options);
|
|
|
|
const node_t *choose_random_entry(cpath_build_state_t *state);
|
2012-12-11 18:44:18 +01:00
|
|
|
const node_t *choose_random_dirguard(dirinfo_type_t t);
|
2016-09-25 04:11:44 +02:00
|
|
|
int entry_guards_parse_state_for_guard_selection(
|
|
|
|
guard_selection_t *gs, or_state_t *state, int set, char **msg);
|
2012-10-15 20:28:23 +02:00
|
|
|
int entry_guards_parse_state(or_state_t *state, int set, char **msg);
|
|
|
|
void entry_guards_update_state(or_state_t *state);
|
|
|
|
int getinfo_helper_entry_guards(control_connection_t *conn,
|
|
|
|
const char *question, char **answer,
|
|
|
|
const char **errmsg);
|
2016-09-25 04:11:44 +02:00
|
|
|
int is_node_used_as_guard_for_guard_selection(guard_selection_t *gs,
|
|
|
|
const node_t *node);
|
|
|
|
MOCK_DECL(int, is_node_used_as_guard, (const node_t *node));
|
2012-10-15 20:28:23 +02:00
|
|
|
|
|
|
|
void mark_bridge_list(void);
|
|
|
|
void sweep_bridge_list(void);
|
|
|
|
|
2016-03-23 03:37:35 +01:00
|
|
|
int addr_is_a_configured_bridge(const tor_addr_t *addr, uint16_t port,
|
|
|
|
const char *digest);
|
|
|
|
int extend_info_is_a_configured_bridge(const extend_info_t *ei);
|
2012-10-15 20:28:23 +02:00
|
|
|
int routerinfo_is_a_configured_bridge(const routerinfo_t *ri);
|
|
|
|
int node_is_a_configured_bridge(const node_t *node);
|
|
|
|
void learned_router_identity(const tor_addr_t *addr, uint16_t port,
|
|
|
|
const char *digest);
|
2013-02-11 14:43:20 +01:00
|
|
|
struct bridge_line_t;
|
|
|
|
void bridge_add_from_config(struct bridge_line_t *bridge_line);
|
2012-10-15 20:28:23 +02:00
|
|
|
void retry_bridge_descriptor_fetch_directly(const char *digest);
|
|
|
|
void fetch_bridge_descriptors(const or_options_t *options, time_t now);
|
|
|
|
void learned_bridge_descriptor(routerinfo_t *ri, int from_cache);
|
|
|
|
int any_bridge_descriptors_known(void);
|
|
|
|
int entries_known_but_down(const or_options_t *options);
|
|
|
|
void entries_retry_all(const or_options_t *options);
|
|
|
|
|
2012-12-17 14:01:31 +01:00
|
|
|
const smartlist_t *get_socks_args_by_bridge_addrport(const tor_addr_t *addr,
|
|
|
|
uint16_t port);
|
|
|
|
|
2012-10-15 20:28:23 +02:00
|
|
|
int any_bridges_dont_support_microdescriptors(void);
|
|
|
|
|
|
|
|
void entry_guards_free_all(void);
|
|
|
|
|
|
|
|
const char *find_transport_name_by_bridge_addrport(const tor_addr_t *addr,
|
|
|
|
uint16_t port);
|
|
|
|
struct transport_t;
|
2012-12-17 14:07:26 +01:00
|
|
|
int get_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port,
|
2012-10-15 20:28:23 +02:00
|
|
|
const struct transport_t **transport);
|
|
|
|
|
2014-07-26 06:41:03 +02:00
|
|
|
MOCK_DECL(int, transport_is_needed, (const char *transport_name));
|
2012-10-15 20:28:23 +02:00
|
|
|
int validate_pluggable_transports_config(void);
|
|
|
|
|
2013-01-19 04:37:16 +01:00
|
|
|
double pathbias_get_close_success_count(entry_guard_t *guard);
|
|
|
|
double pathbias_get_use_success_count(entry_guard_t *guard);
|
2012-11-19 20:31:35 +01:00
|
|
|
|
2015-01-29 16:05:30 +01:00
|
|
|
/** Contains the bandwidth of a relay as a guard and as a non-guard
|
2015-02-19 01:27:02 +01:00
|
|
|
* after the guardfraction has been considered. */
|
2015-01-29 16:05:30 +01:00
|
|
|
typedef struct guardfraction_bandwidth_t {
|
2015-02-19 01:27:02 +01:00
|
|
|
/** Bandwidth as a guard after guardfraction has been considered. */
|
2015-01-29 16:05:30 +01:00
|
|
|
int guard_bw;
|
2015-02-19 01:27:02 +01:00
|
|
|
/** Bandwidth as a non-guard after guardfraction has been considered. */
|
2015-01-29 16:05:30 +01:00
|
|
|
int non_guard_bw;
|
|
|
|
} guardfraction_bandwidth_t;
|
|
|
|
|
2015-01-29 15:57:00 +01:00
|
|
|
int should_apply_guardfraction(const networkstatus_t *ns);
|
|
|
|
|
2015-01-29 16:05:30 +01:00
|
|
|
void
|
|
|
|
guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
|
|
|
|
int orig_bandwidth,
|
|
|
|
uint32_t guardfraction_percentage);
|
|
|
|
|
2016-06-28 23:30:57 +02:00
|
|
|
MOCK_DECL(smartlist_t *, list_bridge_identities, (void));
|
|
|
|
MOCK_DECL(download_status_t *, get_bridge_dl_status_by_id,
|
|
|
|
(const char *digest));
|
2016-06-28 18:12:58 +02:00
|
|
|
|
2012-10-15 20:28:23 +02:00
|
|
|
#endif
|
|
|
|
|