12#ifndef TOR_ENTRYNODES_H
13#define TOR_ENTRYNODES_H
18struct entry_guard_handle_t;
21typedef struct guard_selection_t guard_selection_t;
24typedef struct entry_guard_t entry_guard_t;
28typedef struct circuit_guard_state_t circuit_guard_state_t;
32typedef struct entry_guard_restriction_t entry_guard_restriction_t;
69#if defined(ENTRYNODES_PRIVATE)
78#define GUARD_REACHABLE_NO 0
79#define GUARD_REACHABLE_YES 1
80#define GUARD_REACHABLE_MAYBE 2
88 HANDLE_ENTRY(entry_guard, entry_guard_t);
105 time_t sampled_on_date;
110 time_t unlisted_since_date;
112 char *sampled_by_version;
115 unsigned currently_listed : 1;
121 time_t confirmed_on_date;
143 char *selection_name;
152 time_t last_tried_to_connect;
155 unsigned is_reachable : 2;
160 unsigned is_pending : 1;
163 unsigned is_persistent : 1;
168 time_t failing_since;
173 unsigned is_filtered_guard : 1;
178 unsigned is_usable_filtered_guard : 1;
179 unsigned is_primary:1;
183 char *extra_state_fields;
187 guard_selection_t *in_selection;
197typedef enum guard_selection_type_t {
210} guard_selection_type_t;
223struct guard_selection_t {
232 guard_selection_type_t type;
240 int primary_guards_up_to_date;
279 time_t last_time_on_internet;
283 int next_confirmed_idx;
289 int next_sampled_idx;
294typedef enum guard_restriction_type_t {
298 RST_OUTDATED_MD_DIRSERVER = 1,
301} guard_restriction_type_t;
310struct entry_guard_restriction_t {
312 guard_restriction_type_t type;
327struct circuit_guard_state_t {
329 struct entry_guard_handle_t *guard;
341 entry_guard_restriction_t *restrictions;
350 circuit_guard_state_t **guard_state_out);
352 circuit_guard_state_t **guard_state_out);
358 guard_selection_t *gs,
const char *digest);
361circuit_guard_state_t *
367int num_live_entry_guards_for_guard_selection(
368 guard_selection_t *gs,
370int num_live_entry_guards(
int for_directory);
381 GUARD_USAGE_TRAFFIC = 0,
382 GUARD_USAGE_DIRGUARD = 1
385#define circuit_guard_state_free(val) \
386 FREE_AND_NULL(circuit_guard_state_t, circuit_guard_state_free_, (val))
391 entry_guard_restriction_t *rst,
392 const node_t **chosen_node_out,
393 circuit_guard_state_t **guard_state_out);
397 GUARD_USABLE_NEVER = -1,
398 GUARD_MAYBE_USABLE_LATER = 0,
399 GUARD_USABLE_NOW = 1,
405 const circuit_guard_state_t *state);
421#ifdef ENTRYNODES_PRIVATE
431#define DFLT_MAX_SAMPLE_THRESHOLD_PERCENT 20
436#define DFLT_MAX_SAMPLE_SIZE 60
440#define DFLT_MIN_FILTERED_SAMPLE_SIZE 20
444#define DFLT_REMOVE_UNLISTED_GUARDS_AFTER_DAYS 20
449#define DFLT_GUARD_LIFETIME_DAYS 120
454#define DFLT_GUARD_CONFIRMED_MIN_LIFETIME_DAYS 60
458#define DFLT_N_PRIMARY_GUARDS 3
463#define DFLT_N_PRIMARY_GUARDS_TO_USE 1
467#define DFLT_N_PRIMARY_DIR_GUARDS_TO_USE 3
472#define DFLT_INTERNET_LIKELY_DOWN_INTERVAL (10*60)
478#define DFLT_NONPRIMARY_GUARD_CONNECT_TIMEOUT 15
483#define DFLT_NONPRIMARY_GUARD_IDLE_TIMEOUT (10*60)
488#define DFLT_MEANINGFUL_RESTRICTION_PERCENT 20
493#define DFLT_EXTREME_RESTRICTION_PERCENT 1
510HANDLE_DECL(entry_guard, entry_guard_t,
STATIC)
511#define entry_guard_handle_free(h) \
512 FREE_AND_NULL(entry_guard_handle_t, entry_guard_handle_free_, (h))
515 guard_selection_type_t type_in,
518 guard_selection_type_t type);
520 const char *
name, guard_selection_type_t type,
int create_if_absent);
522#define guard_selection_free(gs) \
523 FREE_AND_NULL(guard_selection_t, guard_selection_free_, (gs))
525 (guard_selection_t *gs,
const entry_guard_t *guard));
528 const guard_selection_t *old_selection,
529 guard_selection_type_t *type_out);
531 const uint8_t *rsa_id);
537 entry_guard_restriction_t *rst));
543 dense_sampled_index);
545#define entry_guard_free(e) \
546 FREE_AND_NULL(entry_guard_t, entry_guard_free_, (e))
554#define SAMPLE_EXCLUDE_CONFIRMED (1u<<0)
555#define SAMPLE_EXCLUDE_PRIMARY (1u<<1)
556#define SAMPLE_EXCLUDE_PENDING (1u<<2)
557#define SAMPLE_NO_UPDATE_PRIMARY (1u<<3)
558#define SAMPLE_EXCLUDE_NO_DESCRIPTOR (1u<<4)
561 guard_selection_t *gs,
562 const entry_guard_restriction_t *rst,
569 const entry_guard_restriction_t *rst);
578#define GUARD_CIRC_STATE_USABLE_ON_COMPLETION 1
582#define GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD 2
585#define GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD 3
588#define GUARD_CIRC_STATE_COMPLETE 4
590#define GUARD_CIRC_STATE_DEAD 5
593 entry_guard_t *guard);
596 const entry_guard_restriction_t *rst,
597 unsigned *state_out);
600 entry_guard_t *guard,
605STATIC entry_guard_restriction_t *guard_create_exit_restriction(
606 const uint8_t *exit_id);
610STATIC entry_guard_restriction_t * guard_create_conflux_restriction(
614#define entry_guard_restriction_free(rst) \
615 FREE_AND_NULL(entry_guard_restriction_t, \
616 entry_guard_restriction_free_, (rst))
625 const uint8_t *rsa_id_digest);
629int entry_guards_parse_state_for_guard_selection(
630 guard_selection_t *gs,
or_state_t *state,
int set,
char **msg);
634 const char *question,
char **answer,
635 const char **errmsg);
641 int num_present,
int num_usable);
644 int num_present,
int num_usable);
665 uint32_t guardfraction_percentage);
Header for crypto_ed25519.c.
STATIC int get_n_primary_guards(void)
STATIC void entry_guards_update_primary(guard_selection_t *gs)
STATIC void entry_guards_note_guard_failure(guard_selection_t *gs, entry_guard_t *guard)
STATIC void guard_selection_free_(guard_selection_t *gs)
STATIC guard_selection_t * guard_selection_new(const char *name, guard_selection_type_t type)
STATIC guard_selection_t * get_guard_selection_by_name(const char *name, guard_selection_type_t type, int create_if_absent)
STATIC double get_meaningful_restriction_threshold(void)
STATIC guard_selection_type_t guard_selection_infer_type(guard_selection_type_t type, const char *name)
STATIC int get_nonprimary_guard_idle_timeout(void)
STATIC void mark_primary_guards_maybe_reachable(guard_selection_t *gs)
STATIC double get_extreme_restriction_threshold(void)
STATIC circuit_guard_state_t * circuit_guard_state_new(entry_guard_t *guard, unsigned state, entry_guard_restriction_t *rst)
STATIC entry_guard_t * first_reachable_filtered_entry_guard(guard_selection_t *gs, const entry_guard_restriction_t *rst, unsigned flags)
STATIC int get_min_filtered_sample_size(void)
STATIC void entry_guard_free_(entry_guard_t *e)
STATIC void entry_guard_restriction_free_(entry_guard_restriction_t *rst)
STATIC int get_guard_confirmed_min_lifetime(void)
STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b)
STATIC void entry_guards_update_confirmed(guard_selection_t *gs)
STATIC char * entry_guard_encode_for_state(entry_guard_t *guard, int dense_sampled_idx)
STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs)
STATIC entry_guard_restriction_t * guard_create_dirserver_md_restriction(void)
STATIC int get_remove_unlisted_guards_after_days(void)
STATIC int get_max_sample_size_absolute(void)
STATIC int get_nonprimary_guard_connect_timeout(void)
STATIC entry_guard_t * get_sampled_guard_with_id(guard_selection_t *gs, const uint8_t *rsa_id)
STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs, entry_guard_t *guard, unsigned old_state)
STATIC int entry_guard_is_listed(guard_selection_t *gs, const entry_guard_t *guard)
STATIC void entry_guard_consider_retry(entry_guard_t *guard)
STATIC double get_max_sample_threshold(void)
STATIC entry_guard_t * entry_guard_add_to_sample(guard_selection_t *gs, const node_t *node)
STATIC int num_reachable_filtered_guards(const guard_selection_t *gs, const entry_guard_restriction_t *rst)
STATIC int entry_guards_all_primary_guards_are_down(guard_selection_t *gs)
STATIC time_t randomize_time(time_t now, time_t max_backdate)
STATIC int get_n_primary_guards_to_use(guard_usage_t usage)
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)
circuit_guard_state_t * get_guard_state_for_bridge_desc_fetch(const bridge_info_t *bridge)
STATIC char * getinfo_helper_format_single_entry_guard(const entry_guard_t *e)
STATIC void make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard)
STATIC entry_guard_t * entry_guard_parse_from_state(const char *s)
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)
STATIC int get_guard_lifetime(void)
STATIC void sampled_guards_update_from_consensus(guard_selection_t *gs)
STATIC entry_guard_t * entry_guards_expand_sample(guard_selection_t *gs)
STATIC int get_internet_likely_down_interval(void)
char * guard_selection_get_err_str_if_dir_info_missing(guard_selection_t *gs, int using_mds, int num_present, int num_usable)
const node_t * entry_guard_find_node(const entry_guard_t *guard)
void entry_guard_learned_bridge_identity(const tor_addr_port_t *addrport, const uint8_t *rsa_id_digest)
const routerset_t * get_layer2_guards(void)
void entry_guards_changed(void)
void remove_all_entry_guards(void)
void purge_vanguards_lite(void)
void entry_guard_cancel(circuit_guard_state_t **guard_state_p)
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs)
int num_bridges_usable(int use_maybe_reachable)
void entry_guard_connection_failed(struct entry_guard_handle_t *handle)
int entry_guards_update_all(guard_selection_t *gs)
int entry_list_is_constrained(const or_options_t *options)
guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p)
void entry_guards_note_internet_connectivity(guard_selection_t *gs)
const char * entry_guard_get_rsa_id_digest(const entry_guard_t *guard)
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)
void entry_guards_update_state(or_state_t *state)
bool vanguards_lite_is_enabled(void)
struct entry_guard_handle_t * entry_guard_handle_from_state(const circuit_guard_state_t *state)
int update_guard_selection_choice(const or_options_t *options)
void entry_guard_handle_release(struct entry_guard_handle_t *handle)
void circuit_guard_state_free_(circuit_guard_state_t *state)
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)
void maintain_layer2_guards(void)
int entry_guards_parse_state(or_state_t *state, int set, char **msg)
int entry_guard_state_should_expire(circuit_guard_state_t *guard_state)
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
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)
int entry_guard_could_succeed(const circuit_guard_state_t *guard_state)
int guards_retry_optimistic(const or_options_t *options)
const node_t * guards_choose_dirguard(uint8_t dir_purpose, circuit_guard_state_t **guard_state_out)
int should_apply_guardfraction(const networkstatus_t *ns)
void entry_guards_changed_for_guard_selection(guard_selection_t *gs)
int getinfo_helper_entry_guards(control_connection_t *conn, const char *question, char **answer, const char **errmsg)
guard_selection_t * get_guard_selection_info(void)
int guards_update_all(void)
entry_guard_t * entry_guard_get_by_id_digest_for_guard_selection(guard_selection_t *gs, const char *digest)
const char * entry_guard_describe(const entry_guard_t *guard)
int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs, const smartlist_t *all_circuits, smartlist_t *newly_complete_out)
void entry_guards_free_all(void)
double pathbias_get_close_success_count(entry_guard_t *guard)
Macros for C weak-handle implementation.
#define MAX_HEX_NICKNAME_LEN
unsigned int path_bias_use_noticed
unsigned int path_bias_use_extreme
unsigned int path_bias_warned
unsigned int path_bias_extreme
double collapsed_circuits
unsigned int path_bias_disabled
double successful_circuits_closed
unsigned int path_bias_noticed
#define MOCK_DECL(rv, funcname, arglist)