12 #ifndef TOR_ENTRYNODES_H 13 #define TOR_ENTRYNODES_H 18 typedef struct guard_selection_s guard_selection_t;
21 typedef struct entry_guard_t entry_guard_t;
25 typedef struct circuit_guard_state_t circuit_guard_state_t;
29 typedef struct entry_guard_restriction_t entry_guard_restriction_t;
66 #if defined(ENTRYNODES_PRIVATE) 73 #define GUARD_REACHABLE_NO 0 74 #define GUARD_REACHABLE_YES 1 75 #define GUARD_REACHABLE_MAYBE 2 82 struct entry_guard_t {
83 HANDLE_ENTRY(entry_guard, entry_guard_t);
100 time_t sampled_on_date;
105 time_t unlisted_since_date;
107 char *sampled_by_version;
110 unsigned currently_listed : 1;
116 time_t confirmed_on_date;
131 char *selection_name;
140 time_t last_tried_to_connect;
143 unsigned is_reachable : 2;
148 unsigned is_pending : 1;
151 unsigned is_persistent : 1;
156 time_t failing_since;
161 unsigned is_filtered_guard : 1;
166 unsigned is_usable_filtered_guard : 1;
167 unsigned is_primary:1;
171 char *extra_state_fields;
175 guard_selection_t *in_selection;
185 typedef enum guard_selection_type_t {
198 } guard_selection_type_t;
211 struct guard_selection_s {
220 guard_selection_type_t type;
228 int primary_guards_up_to_date;
266 time_t last_time_on_internet;
270 int next_confirmed_idx;
274 struct entry_guard_handle_t;
277 typedef enum guard_restriction_type_t {
281 RST_OUTDATED_MD_DIRSERVER = 1
282 } guard_restriction_type_t;
291 struct entry_guard_restriction_t {
293 guard_restriction_type_t type;
304 struct circuit_guard_state_t {
306 struct entry_guard_handle_t *guard;
318 entry_guard_restriction_t *restrictions;
326 circuit_guard_state_t **guard_state_out);
328 circuit_guard_state_t **guard_state_out);
334 guard_selection_t *gs,
const char *digest);
337 circuit_guard_state_t *
343 int num_live_entry_guards_for_guard_selection(
344 guard_selection_t *gs,
346 int num_live_entry_guards(
int for_directory);
357 GUARD_USAGE_TRAFFIC = 0,
358 GUARD_USAGE_DIRGUARD = 1
361 #define circuit_guard_state_free(val) \ 362 FREE_AND_NULL(circuit_guard_state_t, circuit_guard_state_free_, (val)) 367 entry_guard_restriction_t *rst,
368 const node_t **chosen_node_out,
369 circuit_guard_state_t **guard_state_out);
373 GUARD_USABLE_NEVER = -1,
374 GUARD_MAYBE_USABLE_LATER = 0,
375 GUARD_USABLE_NOW = 1,
393 MOCK_DECL(
int,num_bridges_usable,(
int use_maybe_reachable));
395 #ifdef ENTRYNODES_PRIVATE 405 #define DFLT_MAX_SAMPLE_THRESHOLD_PERCENT 20 410 #define DFLT_MAX_SAMPLE_SIZE 60 414 #define DFLT_MIN_FILTERED_SAMPLE_SIZE 20 418 #define DFLT_REMOVE_UNLISTED_GUARDS_AFTER_DAYS 20 423 #define DFLT_GUARD_LIFETIME_DAYS 120 428 #define DFLT_GUARD_CONFIRMED_MIN_LIFETIME_DAYS 60 432 #define DFLT_N_PRIMARY_GUARDS 3 437 #define DFLT_N_PRIMARY_GUARDS_TO_USE 1 441 #define DFLT_N_PRIMARY_DIR_GUARDS_TO_USE 3 446 #define DFLT_INTERNET_LIKELY_DOWN_INTERVAL (10*60) 452 #define DFLT_NONPRIMARY_GUARD_CONNECT_TIMEOUT 15 457 #define DFLT_NONPRIMARY_GUARD_IDLE_TIMEOUT (10*60) 462 #define DFLT_MEANINGFUL_RESTRICTION_PERCENT 20 467 #define DFLT_EXTREME_RESTRICTION_PERCENT 1 484 HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
485 #define entry_guard_handle_free(h) \ 486 FREE_AND_NULL(entry_guard_handle_t, entry_guard_handle_free_, (h)) 489 guard_selection_type_t type_in,
492 guard_selection_type_t type);
494 const char *name, guard_selection_type_t type,
int create_if_absent);
496 #define guard_selection_free(gs) \ 497 FREE_AND_NULL(guard_selection_t, guard_selection_free_, (gs)) 498 MOCK_DECL(STATIC
int, entry_guard_is_listed,
499 (guard_selection_t *gs,
const entry_guard_t *guard));
502 const guard_selection_t *old_selection,
503 guard_selection_type_t *type_out);
505 const uint8_t *rsa_id);
507 MOCK_DECL(STATIC time_t, randomize_time, (time_t now, time_t max_backdate));
509 MOCK_DECL(STATIC circuit_guard_state_t *,
510 circuit_guard_state_new,(entry_guard_t *guard,
unsigned state,
511 entry_guard_restriction_t *rst));
518 #define entry_guard_free(e) \ 519 FREE_AND_NULL(entry_guard_t, entry_guard_free_, (e)) 527 #define SAMPLE_EXCLUDE_CONFIRMED (1u<<0) 528 #define SAMPLE_EXCLUDE_PRIMARY (1u<<1) 529 #define SAMPLE_EXCLUDE_PENDING (1u<<2) 530 #define SAMPLE_NO_UPDATE_PRIMARY (1u<<3) 531 #define SAMPLE_EXCLUDE_NO_DESCRIPTOR (1u<<4) 534 guard_selection_t *gs,
535 const entry_guard_restriction_t *rst,
542 const entry_guard_restriction_t *rst);
551 #define GUARD_CIRC_STATE_USABLE_ON_COMPLETION 1 555 #define GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD 2 558 #define GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD 3 561 #define GUARD_CIRC_STATE_COMPLETE 4 563 #define GUARD_CIRC_STATE_DEAD 5 566 entry_guard_t *guard);
569 const entry_guard_restriction_t *rst,
570 unsigned *state_out);
573 entry_guard_t *guard,
578 STATIC entry_guard_restriction_t *guard_create_exit_restriction(
579 const uint8_t *exit_id);
584 #define entry_guard_restriction_free(rst) \ 585 FREE_AND_NULL(entry_guard_restriction_t, \ 586 entry_guard_restriction_free_, (rst)) 595 const uint8_t *rsa_id_digest);
599 int entry_guards_parse_state_for_guard_selection(
600 guard_selection_t *gs,
or_state_t *state,
int set,
char **msg);
604 const char *question,
char **answer,
605 const char **errmsg);
607 int entries_known_but_down(
const or_options_t *options);
611 int num_present,
int num_usable);
614 int num_present,
int num_usable);
635 uint32_t guardfraction_percentage);
int should_apply_guardfraction(const networkstatus_t *ns)
Definition: entrynodes.c:172
void entry_guard_learned_bridge_identity(const tor_addr_port_t *addrport, const uint8_t *rsa_id_digest)
Definition: entrynodes.c:927
STATIC int get_guard_lifetime(void)
Definition: entrynodes.c:406
STATIC double get_max_sample_threshold(void)
Definition: entrynodes.c:362
STATIC guard_selection_type_t guard_selection_infer_type(guard_selection_type_t type, const char *name)
Definition: entrynodes.c:205
#define MAX_HEX_NICKNAME_LEN
Definition: or.h:127
void entry_guards_update_state(or_state_t *state)
Definition: entrynodes.c:3303
Definition: entrynodes.h:35
double pathbias_get_use_success_count(entry_guard_t *guard)
Definition: circpathbias.c:1230
const node_t * guards_choose_guard(cpath_build_state_t *state, uint8_t purpose, circuit_guard_state_t **guard_state_out)
Definition: entrynodes.c:3482
Definition: entrynodes.h:623
#define DIGEST_LEN
Definition: crypto_digest.h:22
double use_attempts
Definition: entrynodes.h:61
int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs, const smartlist_t *all_circuits, smartlist_t *newly_complete_out)
Definition: entrynodes.c:2453
const node_t * guards_choose_dirguard(uint8_t dir_purpose, circuit_guard_state_t **guard_state_out)
Definition: entrynodes.c:3551
STATIC void make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard)
Definition: entrynodes.c:1753
void entry_guard_chan_failed(channel_t *chan)
Definition: entrynodes.c:2369
double timeouts
Definition: entrynodes.h:59
STATIC void entry_guard_consider_retry(entry_guard_t *guard)
Definition: entrynodes.c:1932
Definition: crypto_ed25519.h:23
STATIC guard_selection_t * get_guard_selection_by_name(const char *name, guard_selection_type_t type, int create_if_absent)
Definition: entrynodes.c:246
STATIC void entry_guards_update_primary(guard_selection_t *gs)
Definition: entrynodes.c:1783
int getinfo_helper_entry_guards(control_connection_t *conn, const char *question, char **answer, const char **errmsg)
Definition: entrynodes.c:3395
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
Definition: entrynodes.c:324
STATIC guard_selection_t * guard_selection_new(const char *name, guard_selection_type_t type)
Definition: entrynodes.c:223
int entry_guards_parse_state(or_state_t *state, int set, char **msg)
Definition: entrynodes.c:3241
double unusable_circuits
Definition: entrynodes.h:57
double circ_attempts
Definition: entrynodes.h:49
unsigned int path_bias_extreme
Definition: entrynodes.h:40
STATIC int get_guard_confirmed_min_lifetime(void)
Definition: entrynodes.c:421
Macros for C weak-handle implementation.
void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs)
Definition: entrynodes.c:3515
STATIC void entry_guards_note_guard_failure(guard_selection_t *gs, entry_guard_t *guard)
Definition: entrynodes.c:2078
unsigned int path_bias_warned
Definition: entrynodes.h:38
MOCK_DECL(int, router_have_minimum_dir_info,(void))
struct guardfraction_bandwidth_t guardfraction_bandwidth_t
STATIC int num_reachable_filtered_guards(const guard_selection_t *gs, const entry_guard_restriction_t *rst)
Definition: entrynodes.c:976
Definition: container.h:18
STATIC int entry_guards_all_primary_guards_are_down(guard_selection_t *gs)
Definition: entrynodes.c:2395
int non_guard_bw
Definition: entrynodes.h:627
double successful_circuits_closed
Definition: entrynodes.h:52
unsigned int path_bias_use_noticed
Definition: entrynodes.h:44
STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs, entry_guard_t *guard, unsigned old_state)
Definition: entrynodes.c:2105
int guards_update_all(void)
Definition: entrynodes.c:3465
STATIC void mark_primary_guards_maybe_reachable(guard_selection_t *gs)
Definition: entrynodes.c:562
guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2301
STATIC entry_guard_restriction_t * guard_create_dirserver_md_restriction(void)
Definition: entrynodes.c:1513
unsigned int path_bias_noticed
Definition: entrynodes.h:36
STATIC void entry_guard_free_(entry_guard_t *e)
Definition: entrynodes.c:3122
STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs)
Definition: entrynodes.c:1618
STATIC char * entry_guard_encode_for_state(entry_guard_t *guard)
Definition: entrynodes.c:2642
STATIC int get_max_sample_size_absolute(void)
Definition: entrynodes.c:374
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:1977
const char * entry_guard_describe(const entry_guard_t *guard)
Definition: entrynodes.c:305
entry_guard_t * entry_guard_get_by_id_digest_for_guard_selection(guard_selection_t *gs, const char *digest)
Definition: entrynodes.c:3069
STATIC int get_n_primary_guards_to_use(guard_usage_t usage)
Definition: entrynodes.c:455
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:594
void entry_guards_changed(void)
Definition: entrynodes.c:3292
STATIC entry_guard_t * entry_guard_add_to_sample(guard_selection_t *gs, const node_t *node)
Definition: entrynodes.c:820
STATIC int get_remove_unlisted_guards_after_days(void)
Definition: entrynodes.c:394
unsigned int path_bias_disabled
Definition: entrynodes.h:42
STATIC int get_n_primary_guards(void)
Definition: entrynodes.c:435
void circuit_guard_state_free_(circuit_guard_state_t *state)
Definition: entrynodes.c:2218
void entry_guard_failed(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2349
STATIC char * getinfo_helper_format_single_entry_guard(const entry_guard_t *e)
Definition: entrynodes.c:3338
STATIC entry_guard_t * entry_guard_parse_from_state(const char *s)
Definition: entrynodes.c:2732
const node_t * entry_guard_find_node(const entry_guard_t *guard)
Definition: entrynodes.c:3078
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:3594
void entry_guards_free_all(void)
Definition: entrynodes.c:3673
STATIC double get_extreme_restriction_threshold(void)
Definition: entrynodes.c:532
double circ_successes
Definition: entrynodes.h:50
STATIC int get_min_filtered_sample_size(void)
Definition: entrynodes.c:384
int entry_guard_could_succeed(const circuit_guard_state_t *guard_state)
Definition: entrynodes.c:3319
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:2255
int entry_guard_state_should_expire(circuit_guard_state_t *guard_state)
Definition: entrynodes.c:2613
STATIC void entry_guards_update_confirmed(guard_selection_t *gs)
Definition: entrynodes.c:1723
double pathbias_get_close_success_count(entry_guard_t *guard)
Definition: circpathbias.c:1212
STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b)
Definition: entrynodes.c:2171
STATIC int get_internet_likely_down_interval(void)
Definition: entrynodes.c:483
STATIC int get_nonprimary_guard_idle_timeout(void)
Definition: entrynodes.c:507
circuit_guard_state_t * get_guard_state_for_bridge_desc_fetch(const char *digest)
Definition: entrynodes.c:3097
STATIC void guard_selection_free_(guard_selection_t *gs)
Definition: entrynodes.c:3651
int guards_retry_optimistic(const or_options_t *options)
Definition: entrynodes.c:3577
STATIC entry_guard_t * get_sampled_guard_with_id(guard_selection_t *gs, const uint8_t *rsa_id)
Definition: entrynodes.c:757
int entry_list_is_constrained(const or_options_t *options)
Definition: entrynodes.c:3139
void remove_all_entry_guards(void)
Definition: entrynodes.c:3544
void entry_guards_note_internet_connectivity(guard_selection_t *gs)
Definition: entrynodes.c:1963
int update_guard_selection_choice(const or_options_t *options)
Definition: entrynodes.c:700
STATIC double get_meaningful_restriction_threshold(void)
Definition: entrynodes.c:519
guard_selection_t * get_guard_selection_info(void)
Definition: entrynodes.c:293
int entry_guards_update_all(guard_selection_t *gs)
Definition: entrynodes.c:2628
STATIC void sampled_guards_update_from_consensus(guard_selection_t *gs)
Definition: entrynodes.c:1236
char * entry_guards_get_err_str_if_dir_info_missing(int using_mds, int num_present, int num_usable)
Definition: entrynodes.c:3640
int guard_bw
Definition: entrynodes.h:625
unsigned int path_bias_use_extreme
Definition: entrynodes.h:46
guard_usage_t
Definition: entrynodes.h:356
const char * entry_guard_get_rsa_id_digest(const entry_guard_t *guard)
Definition: entrynodes.c:317
void entry_guard_cancel(circuit_guard_state_t **guard_state_p)
Definition: entrynodes.c:2328
STATIC entry_guard_t * entry_guards_expand_sample(guard_selection_t *gs)
Definition: entrynodes.c:1126
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
Definition: entrynodes.c:3088
STATIC void entry_guard_restriction_free_(entry_guard_restriction_t *rst)
Definition: entrynodes.c:2209
double collapsed_circuits
Definition: entrynodes.h:54
STATIC int get_nonprimary_guard_connect_timeout(void)
Definition: entrynodes.c:495
STATIC entry_guard_t * sample_reachable_filtered_entry_guards(guard_selection_t *gs, const entry_guard_restriction_t *rst, unsigned flags)
Definition: entrynodes.c:1639
void entry_guards_changed_for_guard_selection(guard_selection_t *gs)
Definition: entrynodes.c:3268
double use_successes
Definition: entrynodes.h:62