116 #define ENTRYNODES_PRIVATE
131 #include "feature/client/circpathbias.h"
163 guard_selection_t *gs,
164 entry_guard_t *guard);
171 const uint8_t *rsa_id_digest,
172 const char *nickname,
177 const entry_guard_restriction_t *rst);
216 STATIC guard_selection_type_t
220 if (type == GS_TYPE_INFER) {
221 if (!strcmp(
name,
"bridges"))
222 type = GS_TYPE_BRIDGE;
223 else if (!strcmp(
name,
"restricted"))
224 type = GS_TYPE_RESTRICTED;
226 type = GS_TYPE_NORMAL;
234 STATIC guard_selection_t *
236 guard_selection_type_t type)
238 guard_selection_t *gs;
242 gs = tor_malloc_zero(
sizeof(*gs));
243 gs->name = tor_strdup(
name);
257 STATIC guard_selection_t *
259 guard_selection_type_t type,
260 int create_if_absent)
266 if (!strcmp(gs->name,
name))
268 } SMARTLIST_FOREACH_END(gs);
270 if (! create_if_absent)
273 log_debug(
LD_GUARD,
"Creating a guard selection called %s",
name);
277 return new_selection;
291 guard_selection_type_t type = GS_TYPE_INFER;
301 log_notice(
LD_GUARD,
"Starting with guard context \"%s\"",
name);
321 static char buf[256];
324 strlen(guard->nickname) ? guard->nickname :
"[bridge]",
333 return guard->identity;
343 HANDLE_IMPL(entry_guard, entry_guard_t, ATTR_UNUSED
STATIC)
354 time_t earliest = now - max_backdate;
358 if (latest <= earliest)
359 latest = earliest + 1;
380 DFLT_MAX_SAMPLE_THRESHOLD_PERCENT,
391 DFLT_MAX_SAMPLE_SIZE,
401 DFLT_MIN_FILTERED_SAMPLE_SIZE,
411 "guard-remove-unlisted-guards-after-days",
412 DFLT_REMOVE_UNLISTED_GUARDS_AFTER_DAYS,
437 "guard-lifetime-days",
438 DFLT_GUARD_LIFETIME_DAYS, 1, 365*10);
452 DFLT_GUARD_CONFIRMED_MIN_LIFETIME_DAYS,
465 if (configured_primaries) {
466 return configured_primaries;
472 "guard-n-primary-guards",
473 DFLT_N_PRIMARY_GUARDS, 1, INT32_MAX);
483 const char *param_name;
488 if (usage == GUARD_USAGE_DIRGUARD) {
490 param_name =
"guard-n-primary-dir-guards-to-use";
491 param_default = DFLT_N_PRIMARY_DIR_GUARDS_TO_USE;
494 param_name =
"guard-n-primary-guards-to-use";
495 param_default = DFLT_N_PRIMARY_GUARDS_TO_USE;
497 if (configured >= 1) {
501 param_name, param_default, 1, INT32_MAX);
511 DFLT_INTERNET_LIKELY_DOWN_INTERVAL,
523 "guard-nonprimary-guard-connect-timeout",
524 DFLT_NONPRIMARY_GUARD_CONNECT_TIMEOUT,
535 "guard-nonprimary-guard-idle-timeout",
536 DFLT_NONPRIMARY_GUARD_IDLE_TIMEOUT,
547 "guard-meaningful-restriction-percent",
548 DFLT_MEANINGFUL_RESTRICTION_PERCENT,
560 "guard-extreme-restriction-percent",
561 DFLT_EXTREME_RESTRICTION_PERCENT,
568 mark_guard_maybe_reachable(entry_guard_t *guard)
570 if (guard->is_reachable != GUARD_REACHABLE_NO) {
576 guard->is_reachable = GUARD_REACHABLE_MAYBE;
577 if (guard->is_filtered_guard)
578 guard->is_usable_filtered_guard = 1;
591 if (!gs->primary_guards_up_to_date)
595 mark_guard_maybe_reachable(guard);
596 } SMARTLIST_FOREACH_END(guard);
602 mark_all_guards_maybe_reachable(guard_selection_t *gs)
607 mark_guard_maybe_reachable(guard);
608 } SMARTLIST_FOREACH_END(guard);
621 const guard_selection_t *old_selection,
622 guard_selection_type_t *type_out)
628 *type_out = GS_TYPE_BRIDGE;
634 *type_out = GS_TYPE_NORMAL;
639 int n_guards = 0, n_passing_filter = 0;
647 } SMARTLIST_FOREACH_END(node);
651 const int meaningful_threshold_high =
653 const int meaningful_threshold_mid =
655 const int meaningful_threshold_low =
657 const int extreme_threshold =
674 static int have_warned_extreme_threshold = 0;
676 n_passing_filter < extreme_threshold &&
677 ! have_warned_extreme_threshold) {
678 have_warned_extreme_threshold = 1;
679 const double exclude_frac =
680 (n_guards - n_passing_filter) / (
double)n_guards;
681 log_warn(
LD_GUARD,
"Your configuration excludes %d%% of all possible "
682 "guards. That's likely to make you stand out from the "
683 "rest of the world.", (
int)(exclude_frac * 100));
688 if (old_selection == NULL) {
689 if (n_passing_filter >= meaningful_threshold_mid) {
690 *type_out = GS_TYPE_NORMAL;
693 *type_out = GS_TYPE_RESTRICTED;
703 if (n_passing_filter >= meaningful_threshold_high) {
704 *type_out = GS_TYPE_NORMAL;
706 }
else if (n_passing_filter < meaningful_threshold_low) {
707 *type_out = GS_TYPE_RESTRICTED;
711 *type_out = old_selection->type;
712 return old_selection->name;
732 guard_selection_type_t type = GS_TYPE_INFER;
744 if (! strcmp(cur_name, new_name)) {
746 "Staying with guard context \"%s\" (no change)", new_name);
750 log_notice(
LD_GUARD,
"Switching to guard context \"%s\" (was using \"%s\")",
752 guard_selection_t *new_guard_context;
785 const uint8_t *rsa_id)
792 } SMARTLIST_FOREACH_END(guard);
798 static entry_guard_t *
804 entry_guard_t *guard;
819 const uint8_t *identity = NULL;
821 identity = (
const uint8_t *)guard->
identity;
823 if (BUG(guard->bridge_addr == NULL))
827 &guard->bridge_addr->addr,
828 guard->bridge_addr->port,
829 (
const char*)identity);
850 log_info(
LD_GUARD,
"Adding %s to the entry guard sample set.",
869 static entry_guard_t *
871 const uint8_t *rsa_id_digest,
872 const char *nickname,
881 if (BUG(!rsa_id_digest && !bridge_addrport))
884 entry_guard_t *guard = tor_malloc_zero(
sizeof(entry_guard_t));
887 guard->is_persistent = (rsa_id_digest != NULL);
888 guard->selection_name = tor_strdup(gs->name);
890 memcpy(guard->identity, rsa_id_digest,
DIGEST_LEN);
892 strlcpy(guard->nickname, nickname,
sizeof(guard->nickname));
894 tor_free(guard->sampled_by_version);
895 guard->sampled_by_version = tor_strdup(VERSION);
896 guard->currently_listed = 1;
897 guard->sampled_idx = gs->next_sampled_idx++;
898 guard->confirmed_idx = -1;
901 guard->is_reachable = GUARD_REACHABLE_MAYBE;
903 guard->bridge_addr = tor_memdup(bridge_addrport,
sizeof(*bridge_addrport));
906 guard->in_selection = gs;
921 static entry_guard_t *
941 static entry_guard_t *
952 } SMARTLIST_FOREACH_END(g);
961 const uint8_t *rsa_id_digest)
973 int make_persistent = 0;
976 memcpy(g->identity, rsa_id_digest,
DIGEST_LEN);
980 if (BUG(! g->is_persistent))
984 base16_encode(old_id,
sizeof(old_id), g->identity,
sizeof(g->identity));
985 log_warn(
LD_BUG,
"We 'learned' an identity %s for a bridge at %s:%d, but "
986 "we already knew a different one (%s). Ignoring the new info as "
994 if (make_persistent) {
995 g->is_persistent = 1;
1010 const entry_guard_restriction_t *rst)
1012 int n_reachable_filtered_guards = 0;
1017 if (guard->is_usable_filtered_guard)
1018 ++n_reachable_filtered_guards;
1019 } SMARTLIST_FOREACH_END(guard);
1020 return n_reachable_filtered_guards;
1029 const int using_bridges = (gs->type == GS_TYPE_BRIDGE);
1040 const int max_sample = MIN(max_sample_by_pct, max_sample_absolute);
1041 if (max_sample < min_sample)
1057 guard_selection_t *gs,
1064 if (gs->type == GS_TYPE_BRIDGE) {
1072 } SMARTLIST_FOREACH_END(bridge);
1075 const int n_sampled = smartlist_len(gs->sampled_entry_guards);
1082 } SMARTLIST_FOREACH_END(guard);
1087 if (gs->type == GS_TYPE_RESTRICTED) {
1099 } SMARTLIST_FOREACH_END(node);
1102 digestset_free(sampled_guard_ids);
1105 *n_guards_out = n_guards;
1106 return eligible_guards;
1113 static entry_guard_t *
1117 entry_guard_t *added_guard;
1118 if (gs->type == GS_TYPE_BRIDGE) {
1145 if (gs->type == GS_TYPE_BRIDGE) {
1167 log_info(
LD_GUARD,
"Not expanding the sample guard set; we have "
1168 "no reasonably live consensus.");
1172 int n_sampled = smartlist_len(gs->sampled_entry_guards);
1173 entry_guard_t *added_guard = NULL;
1181 log_info(
LD_GUARD,
"Expanding the sample guard set. We have %d guards "
1182 "in the sample, and %d eligible guards to extend it with.",
1183 n_sampled, smartlist_len(eligible_guards));
1185 while (n_usable_filtered_guards < min_filtered_sample) {
1187 if (n_sampled >= max_sample) {
1188 log_info(
LD_GUARD,
"Not expanding the guard sample any further; "
1189 "just hit the maximum sample threshold of %d",
1195 if (smartlist_len(eligible_guards) == 0) {
1200 log_info(
LD_GUARD,
"Not expanding the guard sample any further; "
1201 "just ran out of eligible guards");
1213 if (added_guard->is_usable_filtered_guard)
1214 ++n_usable_filtered_guards;
1218 smartlist_free(eligible_guards);
1227 entry_guard_t *guard)
1229 if (guard->is_primary) {
1230 guard->is_primary = 0;
1238 if (guard->confirmed_idx >= 0) {
1240 guard->confirmed_idx = -1;
1241 guard->confirmed_on_date = 0;
1257 if (gs->type == GS_TYPE_BRIDGE) {
1282 size_t n_changes = 0;
1286 const time_t unlisted_since_slop =
1293 if (is_listed && ! guard->currently_listed) {
1295 guard->currently_listed = 1;
1296 guard->unlisted_since_date = 0;
1297 log_info(
LD_GUARD,
"Sampled guard %s is now listed again.",
1299 }
else if (!is_listed && guard->currently_listed) {
1301 guard->currently_listed = 0;
1303 unlisted_since_slop);
1304 log_info(
LD_GUARD,
"Sampled guard %s is now unlisted.",
1306 }
else if (is_listed && guard->currently_listed) {
1307 log_debug(
LD_GUARD,
"Sampled guard %s is still listed.",
1310 tor_assert(! is_listed && ! guard->currently_listed);
1311 log_debug(
LD_GUARD,
"Sampled guard %s is still unlisted.",
1316 if (guard->currently_listed && guard->unlisted_since_date) {
1318 guard->unlisted_since_date = 0;
1319 log_warn(
LD_BUG,
"Sampled guard %s was listed, but with "
1320 "unlisted_since_date set. Fixing.",
1322 }
else if (!guard->currently_listed && ! guard->unlisted_since_date) {
1325 unlisted_since_slop);
1326 log_warn(
LD_BUG,
"Sampled guard %s was unlisted, but with "
1327 "unlisted_since_date unset. Fixing.",
1330 } SMARTLIST_FOREACH_END(guard);
1351 const time_t remove_if_unlisted_since,
1352 const time_t maybe_remove_if_sampled_before,
1353 const time_t remove_if_confirmed_before)
1355 size_t n_changes = 0;
1362 if (guard->currently_listed == 0 &&
1363 guard->unlisted_since_date < remove_if_unlisted_since) {
1369 log_info(
LD_GUARD,
"Removing sampled guard %s: it has been unlisted "
1373 }
else if (guard->sampled_on_date < maybe_remove_if_sampled_before) {
1378 if (guard->confirmed_on_date == 0) {
1380 log_info(
LD_GUARD,
"Removing sampled guard %s: it was sampled "
1381 "over %d days ago, but never confirmed.",
1384 }
else if (guard->confirmed_on_date < remove_if_confirmed_before) {
1386 log_info(
LD_GUARD,
"Removing sampled guard %s: it was sampled "
1387 "over %d days ago, and confirmed over %d days ago.",
1398 entry_guard_free(guard);
1400 } SMARTLIST_FOREACH_END(guard);
1418 log_info(
LD_GUARD,
"Not updating the sample guard set; we have "
1419 "no reasonably live consensus.");
1422 log_info(
LD_GUARD,
"Updating sampled guard status based on received "
1428 const time_t remove_if_unlisted_since =
1430 const time_t maybe_remove_if_sampled_before =
1432 const time_t remove_if_confirmed_before =
1438 remove_if_unlisted_since,
1439 maybe_remove_if_sampled_before,
1440 remove_if_confirmed_before);
1443 gs->primary_guards_up_to_date = 0;
1497 FIREWALL_OR_CONNECTION,
1510 entry_guard_t *guard)
1512 if (guard->currently_listed == 0)
1514 if (guard->pb.path_bias_disabled)
1517 if (gs->type == GS_TYPE_BRIDGE) {
1554 if (
get_options()->EnforceDistinctSubnets && guard->bridge_addr) {
1558 &guard->bridge_addr->addr)) {
1568 STATIC entry_guard_restriction_t *
1569 guard_create_exit_restriction(
const uint8_t *exit_id)
1571 entry_guard_restriction_t *rst = NULL;
1572 rst = tor_malloc_zero(
sizeof(entry_guard_restriction_t));
1573 rst->type = RST_EXIT_NODE;
1574 memcpy(rst->exclude_id, exit_id,
DIGEST_LEN);
1580 #define MIN_GUARDS_FOR_MD_RESTRICTION 10
1593 log_info(
LD_GUARD,
"Not setting md restriction: only %d"
1594 " usable guards.", num_usable_guards);
1604 STATIC entry_guard_restriction_t *
1607 entry_guard_restriction_t *rst = NULL;
1610 log_debug(
LD_GUARD,
"Not setting md restriction: too few "
1611 "filtered guards.");
1615 rst = tor_malloc_zero(
sizeof(entry_guard_restriction_t));
1616 rst->type = RST_OUTDATED_MD_DIRSERVER;
1623 guard_obeys_exit_restriction(
const entry_guard_t *guard,
1624 const entry_guard_restriction_t *rst)
1643 log_info(
LD_GENERAL,
"Skipping %s dirserver: outdated",
1648 log_debug(
LD_GENERAL,
"%s dirserver obeys md restrictions",
1660 const entry_guard_restriction_t *rst)
1666 if (rst->type == RST_EXIT_NODE) {
1667 return guard_obeys_exit_restriction(guard, rst);
1668 }
else if (rst->type == RST_OUTDATED_MD_DIRSERVER) {
1681 guard_selection_t *gs,
1682 entry_guard_t *guard)
1684 unsigned was_filtered = guard->is_filtered_guard;
1685 guard->is_filtered_guard = 0;
1686 guard->is_usable_filtered_guard = 0;
1689 guard->is_filtered_guard = 1;
1691 if (guard->is_reachable != GUARD_REACHABLE_NO)
1692 guard->is_usable_filtered_guard = 1;
1696 log_debug(
LD_GUARD,
"Updated sampled guard %s: filtered=%d; "
1698 guard->is_filtered_guard, guard->is_usable_filtered_guard);
1700 if (!
bool_eq(was_filtered, guard->is_filtered_guard)) {
1702 gs->primary_guards_up_to_date = 0;
1716 } SMARTLIST_FOREACH_END(guard);
1732 const entry_guard_restriction_t *rst,
1736 entry_guard_t *result = NULL;
1737 const unsigned exclude_confirmed = flags & SAMPLE_EXCLUDE_CONFIRMED;
1738 const unsigned exclude_primary = flags & SAMPLE_EXCLUDE_PRIMARY;
1739 const unsigned exclude_pending = flags & SAMPLE_EXCLUDE_PENDING;
1740 const unsigned no_update_primary = flags & SAMPLE_NO_UPDATE_PRIMARY;
1741 const unsigned need_descriptor = flags & SAMPLE_EXCLUDE_NO_DESCRIPTOR;
1745 } SMARTLIST_FOREACH_END(guard);
1749 log_info(
LD_GUARD,
"Trying to sample a reachable guard: We know of %d "
1750 "in the USABLE_FILTERED set.", n_reachable_filtered);
1753 if (n_reachable_filtered < min_filtered_sample) {
1754 log_info(
LD_GUARD,
" (That isn't enough. Trying to expand the sample.)");
1758 if (exclude_primary && !gs->primary_guards_up_to_date && !no_update_primary)
1767 if (! guard->is_usable_filtered_guard)
1769 if (exclude_confirmed && guard->confirmed_idx >= 0)
1771 if (exclude_primary && guard->is_primary)
1773 if (exclude_pending && guard->is_pending)
1778 } SMARTLIST_FOREACH_END(guard);
1780 log_info(
LD_GUARD,
" (After filters [%x], we have %d guards to consider.)",
1781 flags, smartlist_len(reachable_filtered_sample));
1783 if (smartlist_len(reachable_filtered_sample)) {
1794 result = smartlist_get(reachable_filtered_sample, 0);
1795 log_info(
LD_GUARD,
" (Selected %s.)",
1798 smartlist_free(reachable_filtered_sample);
1804 compare_guards_by_confirmed_idx(
const void **a_,
const void **b_)
1806 const entry_guard_t *a = *a_, *b = *b_;
1807 if (a->confirmed_idx < b->confirmed_idx)
1809 else if (a->confirmed_idx > b->confirmed_idx)
1821 const entry_guard_t *a = *a_, *b = *b_;
1822 if (a->sampled_idx < b->sampled_idx)
1824 else if (a->sampled_idx > b->sampled_idx)
1840 if (guard->confirmed_idx >= 0)
1842 } SMARTLIST_FOREACH_END(guard);
1844 smartlist_sort(gs->confirmed_entry_guards, compare_guards_by_confirmed_idx);
1846 int any_changed = 0;
1848 if (guard->confirmed_idx != guard_sl_idx) {
1850 guard->confirmed_idx = guard_sl_idx;
1852 } SMARTLIST_FOREACH_END(guard);
1854 gs->next_confirmed_idx = smartlist_len(gs->confirmed_entry_guards);
1870 if (BUG(guard->confirmed_on_date && guard->confirmed_idx >= 0))
1879 log_info(
LD_GUARD,
"Marking %s as a confirmed guard (index %d)",
1881 gs->next_confirmed_idx);
1883 guard->confirmed_idx = gs->next_confirmed_idx++;
1891 gs->primary_guards_up_to_date = 0;
1906 static int running = 0;
1917 gs->primary_guards_up_to_date = 1;
1921 if (smartlist_len(new_primary_guards) >= N_PRIMARY_GUARDS)
1923 if (! guard->is_filtered_guard)
1925 guard->is_primary = 1;
1927 } SMARTLIST_FOREACH_END(guard);
1938 if (smartlist_len(new_primary_guards) < N_PRIMARY_GUARDS &&
1939 guard->is_filtered_guard) {
1940 guard->is_primary = 1;
1945 guard->is_primary = 0;
1947 } SMARTLIST_FOREACH_END(guard);
1950 while (smartlist_len(new_primary_guards) < N_PRIMARY_GUARDS) {
1952 SAMPLE_EXCLUDE_CONFIRMED|
1953 SAMPLE_EXCLUDE_PRIMARY|
1954 SAMPLE_NO_UPDATE_PRIMARY);
1957 guard->is_primary = 1;
1964 tor_assert_nonfatal(
1965 bool_eq(guard->is_primary,
1966 smartlist_contains(new_primary_guards, guard)));
1971 new_primary_guards);
1973 log_info(
LD_GUARD,
"Primary entry guards have changed. "
1974 "New primary guard list is: ");
1975 int n = smartlist_len(new_primary_guards);
1977 log_info(
LD_GUARD,
" %d/%d: %s%s%s",
1979 g->confirmed_idx >= 0 ?
" (confirmed)" :
"",
1980 g->is_filtered_guard ?
"" :
" (excluded by filter)");
1981 } SMARTLIST_FOREACH_END(g);
1985 smartlist_free(old_primary_guards);
1986 smartlist_free(gs->primary_entry_guards);
1987 gs->primary_entry_guards = new_primary_guards;
1988 gs->primary_guards_up_to_date = 1;
2000 const unsigned SIX_HOURS = 6 * 3600;
2001 const unsigned FOUR_DAYS = 4 * 86400;
2002 const unsigned SEVEN_DAYS = 7 * 86400;
2005 if (now > failing_since) {
2006 tdiff = now - failing_since;
2012 time_t maximum;
int primary_delay;
int nonprimary_delay;
2015 { SIX_HOURS, 10*60, 1*60*60 },
2016 { FOUR_DAYS, 90*60, 4*60*60 },
2017 { SEVEN_DAYS, 4*60*60, 18*60*60 },
2018 { TIME_MAX, 9*60*60, 36*60*60 }
2024 if (tdiff <= delays[i].maximum) {
2025 return is_primary ? delays[i].primary_delay : delays[i].nonprimary_delay;
2041 if (guard->is_reachable != GUARD_REACHABLE_NO)
2047 const time_t last_attempt = guard->last_tried_to_connect;
2049 if (BUG(last_attempt == 0) ||
2050 now >= last_attempt + delay) {
2052 char tbuf[ISO_TIME_LEN+1];
2054 log_info(
LD_GUARD,
"Marked %s%sguard %s for possible retry, since we "
2055 "haven't tried to use it since %s.",
2056 guard->is_primary?
"primary ":
"",
2057 guard->confirmed_idx>=0?
"confirmed ":
"",
2061 guard->is_reachable = GUARD_REACHABLE_MAYBE;
2062 if (guard->is_filtered_guard)
2063 guard->is_usable_filtered_guard = 1;
2081 static entry_guard_t *
2084 const entry_guard_restriction_t *rst,
2085 unsigned *state_out)
2087 const int need_descriptor = (usage == GUARD_USAGE_TRAFFIC);
2088 entry_guard_t *chosen_guard = NULL;
2096 log_info(
LD_GUARD,
"Entry guard %s doesn't obey restriction, we test the"
2100 if (guard->is_reachable != GUARD_REACHABLE_NO) {
2102 log_info(
LD_GUARD,
"Guard %s does not have a descriptor",
2106 *state_out = GUARD_CIRC_STATE_USABLE_ON_COMPLETION;
2109 if (smartlist_len(usable_primary_guards) >= num_entry_guards)
2112 } SMARTLIST_FOREACH_END(guard);
2114 if (smartlist_len(usable_primary_guards)) {
2117 "Selected primary guard %s for circuit from a list size of %d.",
2119 smartlist_len(usable_primary_guards));
2120 smartlist_free(usable_primary_guards);
2123 smartlist_free(usable_primary_guards);
2124 return chosen_guard;
2133 static entry_guard_t *
2136 const entry_guard_restriction_t *rst,
2137 unsigned *state_out)
2139 const int need_descriptor = (usage == GUARD_USAGE_TRAFFIC);
2142 if (guard->is_primary)
2147 if (guard->is_usable_filtered_guard && ! guard->is_pending) {
2150 guard->is_pending = 1;
2152 *state_out = GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD;
2153 log_info(
LD_GUARD,
"No primary guards available. Selected confirmed "
2154 "guard %s for circuit. Will try other guards before using "
2159 } SMARTLIST_FOREACH_END(guard);
2170 static entry_guard_t *
2173 const entry_guard_restriction_t *rst,
2174 unsigned *state_out)
2176 const int need_descriptor = (usage == GUARD_USAGE_TRAFFIC);
2177 entry_guard_t *chosen_guard = NULL;
2179 if (need_descriptor)
2180 flags |= SAMPLE_EXCLUDE_NO_DESCRIPTOR;
2183 SAMPLE_EXCLUDE_CONFIRMED |
2184 SAMPLE_EXCLUDE_PRIMARY |
2185 SAMPLE_EXCLUDE_PENDING |
2187 if (!chosen_guard) {
2191 chosen_guard->is_pending = 1;
2192 chosen_guard->last_tried_to_connect =
approx_time();
2193 *state_out = GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD;
2194 log_info(
LD_GUARD,
"No primary or confirmed guards available. Selected "
2195 "guard %s for circuit. Will try other guards before "
2196 "using this circuit.",
2198 return chosen_guard;
2212 const entry_guard_restriction_t *rst,
2213 unsigned *state_out)
2215 entry_guard_t *chosen_guard = NULL;
2219 if (!gs->primary_guards_up_to_date)
2226 return chosen_guard;
2234 return chosen_guard;
2240 if (chosen_guard == NULL) {
2241 log_info(
LD_GUARD,
"Absolutely no sampled guards were available. "
2242 "Marking all guards for retry and starting from top again.");
2243 mark_all_guards_maybe_reachable(gs);
2247 return chosen_guard;
2256 entry_guard_t *guard)
2260 guard->is_reachable = GUARD_REACHABLE_NO;
2261 guard->is_usable_filtered_guard = 0;
2263 guard->is_pending = 0;
2264 if (guard->failing_since == 0)
2270 log_info(
LD_GUARD,
"Recorded failure for %s%sguard %s",
2271 guard->is_primary?
"primary ":
"",
2272 guard->confirmed_idx>=0?
"confirmed ":
"",
2286 entry_guard_t *guard,
2292 const time_t last_time_on_internet = gs->last_time_on_internet;
2296 if (guard->is_reachable != GUARD_REACHABLE_YES) {
2300 guard->is_reachable = GUARD_REACHABLE_YES;
2301 guard->failing_since = 0;
2302 guard->is_pending = 0;
2303 if (guard->is_filtered_guard)
2304 guard->is_usable_filtered_guard = 1;
2306 if (guard->confirmed_idx < 0) {
2308 if (!gs->primary_guards_up_to_date)
2313 switch (old_state) {
2314 case GUARD_CIRC_STATE_COMPLETE:
2315 case GUARD_CIRC_STATE_USABLE_ON_COMPLETION:
2316 new_state = GUARD_CIRC_STATE_COMPLETE;
2321 case GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD:
2322 if (guard->is_primary) {
2330 new_state = GUARD_CIRC_STATE_COMPLETE;
2332 new_state = GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD;
2337 if (! guard->is_primary) {
2344 log_info(
LD_GUARD,
"Recorded success for %s%sguard %s",
2345 guard->is_primary?
"primary ":
"",
2346 guard->confirmed_idx>=0?
"confirmed ":
"",
2364 if (a->confirmed_idx < 0) {
2365 if (b->confirmed_idx >= 0)
2368 if (b->confirmed_idx < 0)
2372 return (a->confirmed_idx < b->confirmed_idx);
2377 if (a->is_pending) {
2378 if (! b->is_pending)
2382 return a->last_tried_to_connect < b->last_tried_to_connect;
2407 entry_guard_restriction_free(state->restrictions);
2408 entry_guard_handle_free(state->guard);
2416 entry_guard_restriction_t *rst))
2418 circuit_guard_state_t *result;
2420 result = tor_malloc_zero(
sizeof(circuit_guard_state_t));
2421 result->guard = entry_guard_handle_new(guard);
2422 result->state = state;
2424 result->restrictions = rst;
2442 entry_guard_restriction_t *rst,
2443 const node_t **chosen_node_out,
2444 circuit_guard_state_t **guard_state_out)
2449 *chosen_node_out = NULL;
2450 *guard_state_out = NULL;
2453 entry_guard_t *guard =
2457 if (BUG(state == 0))
2463 if (BUG(usage != GUARD_USAGE_DIRGUARD &&
2467 *chosen_node_out = node;
2472 entry_guard_restriction_free(rst);
2488 if (BUG(*guard_state_p == NULL))
2489 return GUARD_USABLE_NEVER;
2491 entry_guard_t *guard = entry_guard_handle_get((*guard_state_p)->guard);
2492 if (! guard || BUG(guard->in_selection == NULL))
2493 return GUARD_USABLE_NEVER;
2497 (*guard_state_p)->state);
2499 (*guard_state_p)->state = newstate;
2502 if (newstate == GUARD_CIRC_STATE_COMPLETE) {
2503 return GUARD_USABLE_NOW;
2505 return GUARD_MAYBE_USABLE_LATER;
2515 if (BUG(*guard_state_p == NULL))
2517 entry_guard_t *guard = entry_guard_handle_get((*guard_state_p)->guard);
2523 guard->is_pending = 0;
2524 circuit_guard_state_free(*guard_state_p);
2525 *guard_state_p = NULL;
2536 if (BUG(*guard_state_p == NULL))
2539 entry_guard_t *guard = entry_guard_handle_get((*guard_state_p)->guard);
2540 if (! guard || BUG(guard->in_selection == NULL))
2545 (*guard_state_p)->state = GUARD_CIRC_STATE_DEAD;
2571 } SMARTLIST_FOREACH_END(circ);
2572 smartlist_free(pending);
2583 if (!gs->primary_guards_up_to_date)
2587 if (guard->is_reachable != GUARD_REACHABLE_NO)
2589 } SMARTLIST_FOREACH_END(guard);
2602 const entry_guard_restriction_t *rst,
2611 entry_guard_t *guard_a = entry_guard_handle_get(state_a->guard);
2612 entry_guard_t *guard_b = entry_guard_handle_get(state_b->guard);
2617 }
else if (! guard_b) {
2649 log_debug(
LD_GUARD,
"Considered upgrading guard-stalled circuits, "
2650 "but not all primary guards were definitely down.");
2656 int n_complete_blocking = 0;
2665 entry_guard_t *guard = entry_guard_handle_get(state->guard);
2666 if (!guard || guard->in_selection != gs)
2674 } SMARTLIST_FOREACH_END(circ);
2678 if (BUG(state == NULL))
2681 if (state->state == GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD) {
2683 if (! best_waiting_circuit ||
2685 best_waiting_circuit = circ;
2688 } SMARTLIST_FOREACH_END(circ);
2690 if (! best_waiting_circuit) {
2691 log_debug(
LD_GUARD,
"Considered upgrading guard-stalled circuits, "
2692 "but didn't find any.");
2699 const entry_guard_restriction_t *rst_on_best_waiting =
2712 if BUG((state == NULL))
2714 if (state->state != GUARD_CIRC_STATE_COMPLETE)
2718 best_waiting_circuit))
2719 ++n_complete_blocking;
2720 } SMARTLIST_FOREACH_END(circ);
2722 if (n_complete_blocking) {
2723 log_debug(
LD_GUARD,
"Considered upgrading guard-stalled circuits: found "
2724 "%d complete and %d guard-stalled. At least one complete "
2725 "circuit had higher priority, so not upgrading.",
2726 n_complete, n_waiting);
2735 int n_blockers_found = 0;
2736 const time_t state_set_at_cutoff =
2740 if (BUG(state == NULL))
2742 if (state->state != GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD)
2744 if (state->state_set_at <= state_set_at_cutoff)
2747 best_waiting_circuit))
2749 } SMARTLIST_FOREACH_END(circ);
2751 if (n_blockers_found) {
2752 log_debug(
LD_GUARD,
"Considered upgrading guard-stalled circuits: found "
2753 "%d guard-stalled, but %d pending circuit(s) had higher "
2754 "guard priority, so not upgrading.",
2755 n_waiting, n_blockers_found);
2762 int n_succeeded = 0;
2765 if (BUG(state == NULL))
2767 if (circ != best_waiting_circuit && rst_on_best_waiting) {
2772 if (state->state != GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD)
2777 state->state = GUARD_CIRC_STATE_COMPLETE;
2781 } SMARTLIST_FOREACH_END(circ);
2783 log_info(
LD_GUARD,
"Considered upgrading guard-stalled circuits: found "
2784 "%d guard-stalled, %d complete. %d of the guard-stalled "
2785 "circuit(s) had high enough priority to upgrade.",
2786 n_waiting, n_complete, n_succeeded);
2788 tor_assert_nonfatal(n_succeeded >= 1);
2789 smartlist_free(all_circuits);
2793 smartlist_free(all_circuits);
2804 if (guard_state == NULL)
2806 const time_t expire_if_waiting_since =
2808 return (guard_state->state == GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD
2809 && guard_state->state_set_at < expire_if_waiting_since);
2844 char tbuf[ISO_TIME_LEN+1];
2851 if (guard->bridge_addr) {
2854 guard->bridge_addr->port);
2864 if (guard->sampled_by_version) {
2866 guard->sampled_by_version);
2869 if (guard->unlisted_since_date > 0) {
2875 (
int)guard->currently_listed);
2877 if (guard->confirmed_idx >= 0) {
2884 const double EPSILON = 1.0e-6;
2892 #define PB_FIELD(field) do { \
2893 if (pb->field >= EPSILON) { \
2894 smartlist_add_asprintf(result, "pb_" #field "=%f", pb->field); \
2897 PB_FIELD(use_attempts);
2898 PB_FIELD(use_successes);
2899 PB_FIELD(circ_attempts);
2900 PB_FIELD(circ_successes);
2901 PB_FIELD(successful_circuits_closed);
2902 PB_FIELD(collapsed_circuits);
2903 PB_FIELD(unusable_circuits);
2908 if (guard->extra_state_fields)
2913 smartlist_free(result);
2924 *extra, strmap_t *vals)
2927 SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
2930 const char *eq = strchr(entry,
'=');
2935 char *key = tor_strndup(entry, eq-entry);
2936 char **target = strmap_get(vals, key);
2937 if (target == NULL || *target != NULL) {
2944 *target = tor_strdup(eq+1);
2947 } SMARTLIST_FOREACH_END(entry);
2955 *unlisted_since,
char *confirmed_on)
2957 #define HANDLE_TIME(field) do { \
2959 int r = parse_iso_time_nospace(field, &field ## _time); \
2961 log_warn(LD_CIRC, "Unable to parse %s %s from guard", \
2962 #field, escaped(field)); \
2963 field##_time = -1; \
2968 time_t sampled_on_time = 0;
2969 time_t unlisted_since_time = 0;
2970 time_t confirmed_on_time = 0;
2972 HANDLE_TIME(sampled_on);
2973 HANDLE_TIME(unlisted_since);
2974 HANDLE_TIME(confirmed_on);
2976 if (sampled_on_time <= 0)
2978 if (unlisted_since_time < 0)
2979 unlisted_since_time = 0;
2980 if (confirmed_on_time < 0)
2981 confirmed_on_time = 0;
2985 guard->sampled_on_date = sampled_on_time;
2986 guard->unlisted_since_date = unlisted_since_time;
2987 guard->confirmed_on_date = confirmed_on_time;
3003 char *rsa_id = NULL;
3004 char *nickname = NULL;
3005 char *sampled_on = NULL;
3006 char *sampled_idx = NULL;
3007 char *sampled_by = NULL;
3008 char *unlisted_since = NULL;
3009 char *listed = NULL;
3010 char *confirmed_on = NULL;
3011 char *confirmed_idx = NULL;
3012 char *bridge_addr = NULL;
3015 char *pb_use_attempts = NULL;
3016 char *pb_use_successes = NULL;
3017 char *pb_circ_attempts = NULL;
3018 char *pb_circ_successes = NULL;
3019 char *pb_successful_circuits_closed = NULL;
3020 char *pb_collapsed_circuits = NULL;
3021 char *pb_unusable_circuits = NULL;
3022 char *pb_timeouts = NULL;
3030 strmap_t *vals = strmap_new();
3032 strmap_set(vals, #f, &f);
3039 FIELD(unlisted_since);
3041 FIELD(confirmed_on);
3042 FIELD(confirmed_idx);
3044 FIELD(pb_use_attempts);
3045 FIELD(pb_use_successes);
3046 FIELD(pb_circ_attempts);
3047 FIELD(pb_circ_successes);
3048 FIELD(pb_successful_circuits_closed);
3049 FIELD(pb_collapsed_circuits);
3050 FIELD(pb_unusable_circuits);
3056 smartlist_free(entries);
3057 strmap_free(vals, NULL);
3060 entry_guard_t *guard = tor_malloc_zero(
sizeof(entry_guard_t));
3061 guard->is_persistent = 1;
3064 log_warn(
LD_CIRC,
"Guard missing 'in' field");
3068 guard->selection_name = in;
3071 if (rsa_id == NULL) {
3072 log_warn(
LD_CIRC,
"Guard missing RSA ID field");
3079 log_warn(
LD_CIRC,
"Unable to decode guard identity %s",
escaped(rsa_id));
3084 strlcpy(guard->nickname, nickname,
sizeof(guard->nickname));
3086 guard->nickname[0]=
'$';
3093 memset(&res, 0,
sizeof(res));
3095 &res.addr, &res.port, -1);
3097 guard->bridge_addr = tor_memdup(&res,
sizeof(res));
3106 guard->sampled_by_version = sampled_by;
3109 if (listed && strcmp(listed,
"0"))
3110 guard->currently_listed = 1;
3113 guard->confirmed_idx = -1;
3114 if (confirmed_idx) {
3116 long idx =
tor_parse_long(confirmed_idx, 10, 0, INT_MAX, &ok, NULL);
3118 log_warn(
LD_GUARD,
"Guard has invalid confirmed_idx %s",
3121 guard->confirmed_idx = (int)idx;
3127 long idx =
tor_parse_long(sampled_idx, 10, 0, INT_MAX, &ok, NULL);
3129 log_warn(
LD_GUARD,
"Guard has invalid sampled_idx %s",
3132 guard->sampled_idx = invalid_sampled_idx++;
3134 guard->sampled_idx = (int)idx;
3136 }
else if (confirmed_idx) {
3140 guard->sampled_idx = guard->confirmed_idx;
3142 log_info(
LD_GUARD,
"The state file seems to be into a status that could"
3143 " yield to weird entry node selection: we're missing both a"
3144 " sampled_idx and a confirmed_idx.");
3145 guard->sampled_idx = invalid_sampled_idx++;
3149 if (smartlist_len(extra) > 0) {
3154 guard->is_reachable = GUARD_REACHABLE_MAYBE;
3156 #define PB_FIELD(field) \
3158 if (pb_ ## field) { \
3160 double r = tor_parse_double(pb_ ## field, 0.0, 1e9, &ok, NULL); \
3162 log_warn(LD_CIRC, "Guard has invalid pb_%s %s", \
3163 #field, pb_ ## field); \
3165 guard->pb.field = r; \
3169 PB_FIELD(use_attempts);
3170 PB_FIELD(use_successes);
3171 PB_FIELD(circ_attempts);
3172 PB_FIELD(circ_successes);
3173 PB_FIELD(successful_circuits_closed);
3174 PB_FIELD(collapsed_circuits);
3175 PB_FIELD(unusable_circuits);
3189 entry_guard_free(guard);
3208 tor_free(pb_successful_circuits_closed);
3214 smartlist_free(extra);
3234 if (guard->is_persistent == 0)
3237 (*nextline)->key = tor_strdup(
"Guard");
3239 nextline = &(*nextline)->next;
3241 } SMARTLIST_FOREACH_END(guard);
3242 } SMARTLIST_FOREACH_END(gs);
3244 config_free_lines(state->
Guard);
3245 state->
Guard = lines;
3266 guard_selection_free(gs);
3270 } SMARTLIST_FOREACH_END(gs);
3273 for ( ; line != NULL; line = line->next) {
3275 if (guard == NULL) {
3280 if (!strcmp(guard->selection_name,
"legacy")) {
3282 entry_guard_free(guard);
3287 guard_selection_t *gs;
3292 guard->in_selection = gs;
3297 if (gs->next_sampled_idx <= guard->sampled_idx) {
3298 gs->next_sampled_idx = guard->sampled_idx + 1;
3302 entry_guard_free(guard);
3313 } SMARTLIST_FOREACH_END(gs);
3315 return n_errors ? -1 : 0;
3349 circuit_guard_state_t *
3352 circuit_guard_state_t *guard_state = NULL;
3353 entry_guard_t *guard = NULL;
3367 GUARD_CIRC_STATE_USABLE_ON_COMPLETION,
3379 entry_guard_handles_clear(e);
3420 if (BUG(gs->type != GS_TYPE_BRIDGE)) {
3426 if (! guard->is_filtered_guard)
3429 if (guard->is_reachable == GUARD_REACHABLE_NO)
3432 if (!use_maybe_reachable && guard->is_reachable == GUARD_REACHABLE_MAYBE)
3437 if (node && node->ri)
3439 } SMARTLIST_FOREACH_END(guard);
3450 const double EPSILON = 1.0e-9;
3455 if (node->pb.use_attempts >
EPSILON &&
3459 node->pb.path_bias_disabled = 1;
3461 "Path use bias is too high (%f/%f); disabling node %s",
3462 node->pb.circ_successes, node->pb.circ_attempts,
3473 const double EPSILON = 1.0e-9;
3478 if (node->pb.circ_attempts >
EPSILON &&
3482 node->pb.path_bias_disabled = 1;
3484 "Path bias is too high (%f/%f); disabling node %s",
3485 node->pb.circ_successes, node->pb.circ_attempts,
3504 if (msg && *msg == NULL) {
3505 *msg = tor_strdup(
"parsing error");
3514 #define SLOW_GUARD_STATE_FLUSH_TIME 600
3517 #define FAST_GUARD_STATE_FLUSH_TIME 30
3587 entry_guard_t *guard = entry_guard_handle_get(guard_state->guard);
3588 if (!guard || BUG(guard->in_selection == NULL)) {
3602 const char *status = NULL;
3605 char tbuf[ISO_TIME_LEN+1];
3613 if (e->confirmed_idx < 0) {
3614 status =
"never-connected";
3615 }
else if (! e->currently_listed) {
3616 when = e->unlisted_since_date;
3617 status =
"unusable";
3618 }
else if (! e->is_filtered_guard) {
3619 status =
"unusable";
3620 }
else if (e->is_reachable == GUARD_REACHABLE_NO) {
3621 when = e->failing_since;
3637 char *result = NULL;
3640 tor_asprintf(&result,
"%s %s %s\n", nbuf, status, tbuf);
3658 const char *question,
char **answer,
3659 const char **errmsg)
3668 if (!strcmp(question,
"entry-guards") ||
3669 !strcmp(question,
"helper-nodes")) {
3671 guards = gs->sampled_entry_guards;
3678 } SMARTLIST_FOREACH_END(e);
3705 uint32_t guardfraction_percentage)
3707 double guardfraction_fraction;
3711 guardfraction_fraction = guardfraction_percentage / 100.0;
3713 long guard_bw =
tor_lround(guardfraction_fraction * orig_bandwidth);
3716 guardfraction_bw->
guard_bw = (int) guard_bw;
3718 guardfraction_bw->
non_guard_bw = orig_bandwidth - (int) guard_bw;
3729 int mark_circuits = 0;
3738 return mark_circuits;
3746 circuit_guard_state_t **guard_state_out)
3749 const uint8_t *exit_id = NULL;
3750 entry_guard_restriction_t *rst = NULL;
3760 rst = guard_create_exit_restriction(exit_id);
3764 GUARD_USAGE_TRAFFIC,
3767 guard_state_out) < 0) {
3781 char *old_name = tor_strdup(gs->name);
3782 guard_selection_type_t old_type = gs->type;
3785 control_event_guard(entry->nickname, entry->identity,
"DROPPED");
3793 guard_selection_free(gs);
3814 circuit_guard_state_t **guard_state_out)
3817 entry_guard_restriction_t *rst = NULL;
3825 GUARD_USAGE_DIRGUARD,
3828 guard_state_out) < 0) {
3858 int num_present,
int num_usable)
3860 if (!gs->primary_guards_up_to_date)
3863 char *ret_str = NULL;
3864 int n_missing_descriptors = 0;
3865 int n_considered = 0;
3866 int num_primary_to_check;
3872 num_primary_to_check++;
3876 if (guard->is_reachable == GUARD_REACHABLE_NO)
3880 n_missing_descriptors++;
3881 if (n_considered >= num_primary_to_check)
3883 } SMARTLIST_FOREACH_END(guard);
3886 if (!n_missing_descriptors) {
3891 tor_asprintf(&ret_str,
"We're missing descriptors for %d/%d of our "
3892 "primary entry guards (total %sdescriptors: %d/%d). "
3893 "That's ok. We will try to fetch missing descriptors soon.",
3894 n_missing_descriptors, num_primary_to_check,
3895 using_mds?
"micro":
"", num_present, num_usable);
3904 int num_present,
int num_usable)
3909 num_present, num_usable);
3920 if (gs->sampled_entry_guards) {
3922 entry_guard_free(e));
3923 smartlist_free(gs->sampled_entry_guards);
3924 gs->sampled_entry_guards = NULL;
3927 smartlist_free(gs->confirmed_entry_guards);
3928 smartlist_free(gs->primary_entry_guards);
3943 guard_selection_free(gs);
3944 } SMARTLIST_FOREACH_END(gs);
int tor_addr_port_parse(int severity, const char *addrport, tor_addr_t *address_out, uint16_t *port_out, int default_port)
int tor_addr_port_eq(const tor_addr_port_t *a, const tor_addr_port_t *b)
#define fmt_and_decorate_addr(a)
const char * hex_str(const char *from, size_t fromlen)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
bridge_info_t * get_configured_bridge_by_exact_addr_port_digest(const tor_addr_t *addr, uint16_t port, const char *digest)
int node_is_a_configured_bridge(const node_t *node)
const tor_addr_port_t * bridge_get_addr_port(const bridge_info_t *bridge)
const uint8_t * bridge_get_rsa_id_digest(const bridge_info_t *bridge)
const smartlist_t * bridge_list_get(void)
Header file for circuitbuild.c.
Header file for channel.c.
double pathbias_get_extreme_use_rate(const or_options_t *options)
double pathbias_get_extreme_rate(const or_options_t *options)
double pathbias_get_use_success_count(entry_guard_t *guard)
int pathbias_get_dropguards(const or_options_t *options)
double pathbias_get_close_success_count(entry_guard_t *guard)
const uint8_t * build_state_get_exit_rsa_id(cpath_build_state_t *state)
circuit_guard_state_t * origin_circuit_get_guard_state(origin_circuit_t *circ)
Header file for circuitbuild.c.
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
void circuit_get_all_pending_on_channel(smartlist_t *out, channel_t *chan)
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
void circuit_build_times_free_timeouts(circuit_build_times_t *cbt)
circuit_build_times_t * get_circuit_build_times_mutable(void)
Header file for circuitstats.c.
int circuit_should_use_vanguards(uint8_t purpose)
Header file for circuituse.c.
const or_options_t * get_options(void)
Header file for config.c.
Header file for connection.c.
int control_event_guard(const char *nickname, const char *digest, const char *status)
Header file for control_events.c.
void * smartlist_choose(const smartlist_t *sl)
Common functions for using (pseudo-)random number generators.
time_t crypto_rand_time_range(time_t min, time_t max)
const char * node_describe(const node_t *node)
Header file for describe.c.
int tor_memeq(const void *a, const void *b, size_t sz)
#define tor_memneq(a, b, sz)
void digestset_add(digestset_t *set, const char *digest)
int digestset_probably_contains(const digestset_t *set, const char *digest)
digestset_t * digestset_new(int max_guess)
Types to handle sets of digests, based on bloom filters.
Header file for directory.c.
#define DIR_PURPOSE_FETCH_MICRODESC
void entry_guard_failed(circuit_guard_state_t **guard_state_p)
STATIC int get_n_primary_guards(void)
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
void entry_guard_learned_bridge_identity(const tor_addr_port_t *addrport, const uint8_t *rsa_id_digest)
STATIC void entry_guards_update_primary(guard_selection_t *gs)
static entry_guard_t * entry_guard_add_to_sample_impl(guard_selection_t *gs, const uint8_t *rsa_id_digest, const char *nickname, const tor_addr_port_t *bridge_addrport)
void entry_guard_chan_failed(channel_t *chan)
char * guard_selection_get_err_str_if_dir_info_missing(guard_selection_t *gs, int using_mds, int num_present, int num_usable)
static void entry_guards_update_guards_in_state(or_state_t *state)
static entry_guard_t * select_and_add_guard_item_for_sample(guard_selection_t *gs, smartlist_t *eligible_guards)
void entry_guards_changed(void)
const node_t * entry_guard_find_node(const entry_guard_t *guard)
static int guard_obeys_md_dirserver_restriction(const entry_guard_t *guard)
STATIC void entry_guards_note_guard_failure(guard_selection_t *gs, entry_guard_t *guard)
STATIC void guard_selection_free_(guard_selection_t *gs)
char * entry_guards_get_err_str_if_dir_info_missing(int using_mds, int num_present, int num_usable)
void remove_all_entry_guards(void)
static int reasonably_live_consensus_is_missing(const guard_selection_t *gs)
static void entry_guard_set_filtered_flags(const or_options_t *options, guard_selection_t *gs, entry_guard_t *guard)
STATIC double get_meaningful_restriction_threshold(void)
static entry_guard_t * get_sampled_guard_for_bridge(guard_selection_t *gs, const bridge_info_t *bridge)
STATIC entry_guard_t * entry_guards_expand_sample(guard_selection_t *gs)
STATIC guard_selection_type_t guard_selection_infer_type(guard_selection_type_t type, const char *name)
void entry_guard_cancel(circuit_guard_state_t **guard_state_p)
STATIC int get_nonprimary_guard_idle_timeout(void)
STATIC void mark_primary_guards_maybe_reachable(guard_selection_t *gs)
int entry_guards_upgrade_waiting_circuits(guard_selection_t *gs, const smartlist_t *all_circuits_in, smartlist_t *newly_complete_out)
static guard_selection_t * curr_guard_context
static void remove_guard_from_confirmed_and_primary_lists(guard_selection_t *gs, entry_guard_t *guard)
void remove_all_entry_guards_for_guard_selection(guard_selection_t *gs)
int num_bridges_usable(int use_maybe_reachable)
#define MIN_GUARDS_FOR_MD_RESTRICTION
static int guard_has_descriptor(const entry_guard_t *guard)
STATIC double get_extreme_restriction_threshold(void)
int entry_guards_update_all(guard_selection_t *gs)
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
const char * entry_guard_describe(const entry_guard_t *guard)
static entry_guard_t * entry_guard_add_bridge_to_sample(guard_selection_t *gs, const bridge_info_t *bridge)
STATIC int get_min_filtered_sample_size(void)
STATIC guard_selection_t * get_guard_selection_by_name(const char *name, guard_selection_type_t type, int create_if_absent)
static int guard_in_node_family(const entry_guard_t *guard, const node_t *node)
static size_t sampled_guards_update_consensus_presence(guard_selection_t *gs)
static int should_set_md_dirserver_restriction(void)
STATIC void entry_guard_free_(entry_guard_t *e)
STATIC void entry_guard_restriction_free_(entry_guard_restriction_t *rst)
STATIC entry_guard_t * entry_guard_add_to_sample(guard_selection_t *gs, const node_t *node)
int entry_list_is_constrained(const or_options_t *options)
STATIC int get_guard_confirmed_min_lifetime(void)
guard_usable_t entry_guard_succeeded(circuit_guard_state_t **guard_state_p)
STATIC entry_guard_restriction_t * guard_create_dirserver_md_restriction(void)
static size_t sampled_guards_prune_obsolete_entries(guard_selection_t *gs, const time_t remove_if_unlisted_since, const time_t maybe_remove_if_sampled_before, const time_t remove_if_confirmed_before)
STATIC int entry_guard_has_higher_priority(entry_guard_t *a, entry_guard_t *b)
void entry_guards_note_internet_connectivity(guard_selection_t *gs)
STATIC entry_guard_t * first_reachable_filtered_entry_guard(guard_selection_t *gs, const entry_guard_restriction_t *rst, unsigned flags)
STATIC void entry_guards_update_confirmed(guard_selection_t *gs)
STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs)
void entry_guards_update_state(or_state_t *state)
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)
static void pathbias_check_close_success_count(entry_guard_t *guard)
const char * entry_guard_get_rsa_id_digest(const entry_guard_t *guard)
int update_guard_selection_choice(const or_options_t *options)
STATIC entry_guard_t * get_sampled_guard_with_id(guard_selection_t *gs, const uint8_t *rsa_id)
static int compare_guards_by_sampled_idx(const void **a_, const void **b_)
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)
STATIC char * getinfo_helper_format_single_entry_guard(const entry_guard_t *e)
STATIC int get_remove_unlisted_guards_after_days(void)
const node_t * guards_choose_dirguard(uint8_t dir_purpose, circuit_guard_state_t **guard_state_out)
static void create_initial_guard_context(void)
STATIC int get_max_sample_size_absolute(void)
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_nonprimary_guard_connect_timeout(void)
static entry_guard_t * select_primary_guard_for_circuit(guard_selection_t *gs, guard_usage_t usage, const entry_guard_restriction_t *rst, unsigned *state_out)
static void parse_from_state_handle_time(entry_guard_t *guard, char *sampled_on, char *unlisted_since, char *confirmed_on)
entry_guard_t * entry_guard_get_by_id_digest_for_guard_selection(guard_selection_t *gs, const char *digest)
static entry_guard_t * select_filtered_guard_for_circuit(guard_selection_t *gs, guard_usage_t usage, const entry_guard_restriction_t *rst, unsigned *state_out)
int entry_guards_parse_state(or_state_t *state, int set, char **msg)
STATIC unsigned entry_guards_note_guard_success(guard_selection_t *gs, entry_guard_t *guard, unsigned old_state)
static int entry_guard_obeys_restriction(const entry_guard_t *guard, const entry_guard_restriction_t *rst)
int entry_guard_state_should_expire(circuit_guard_state_t *guard_state)
int entry_guard_could_succeed(const circuit_guard_state_t *guard_state)
static void pathbias_check_use_success_count(entry_guard_t *guard)
int guards_retry_optimistic(const or_options_t *options)
STATIC int entry_guard_is_listed(guard_selection_t *gs, const entry_guard_t *guard)
circuit_guard_state_t * get_guard_state_for_bridge_desc_fetch(const char *digest)
STATIC char * entry_guard_encode_for_state(entry_guard_t *guard, int dense_sampled_idx)
STATIC void entry_guard_consider_retry(entry_guard_t *guard)
static int entry_guard_passes_filter(const or_options_t *options, guard_selection_t *gs, entry_guard_t *guard)
const node_t * guards_choose_guard(cpath_build_state_t *state, uint8_t purpose, circuit_guard_state_t **guard_state_out)
static entry_guard_t * select_confirmed_guard_for_circuit(guard_selection_t *gs, guard_usage_t usage, const entry_guard_restriction_t *rst, unsigned *state_out)
#define SLOW_GUARD_STATE_FLUSH_TIME
STATIC double get_max_sample_threshold(void)
int should_apply_guardfraction(const networkstatus_t *ns)
void entry_guards_changed_for_guard_selection(guard_selection_t *gs)
static int bridge_passes_guard_filter(const or_options_t *options, const bridge_info_t *bridge)
static entry_guard_t * get_sampled_guard_by_bridge_addr(guard_selection_t *gs, const tor_addr_port_t *addrport)
static smartlist_t * guard_contexts
STATIC int num_reachable_filtered_guards(const guard_selection_t *gs, const entry_guard_restriction_t *rst)
STATIC circuit_guard_state_t * circuit_guard_state_new(entry_guard_t *guard, unsigned state, entry_guard_restriction_t *rst)
static int have_sampled_guard_with_id(guard_selection_t *gs, const uint8_t *rsa_id)
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 time_t get_remove_unlisted_guards_after_seconds(void)
STATIC int get_n_primary_guards_to_use(guard_usage_t usage)
static int get_retry_schedule(time_t failing_since, time_t now, int is_primary)
static int entry_guards_load_guards_from_state(or_state_t *state, int set)
#define FAST_GUARD_STATE_FLUSH_TIME
static int node_is_possible_guard(const node_t *node)
static smartlist_t * get_eligible_guards(const or_options_t *options, guard_selection_t *gs, int *n_guards_out)
STATIC void make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard)
static int circ_state_has_higher_priority(origin_circuit_t *a, const entry_guard_restriction_t *rst, origin_circuit_t *b)
int getinfo_helper_entry_guards(control_connection_t *conn, const char *question, char **answer, const char **errmsg)
STATIC int get_guard_lifetime(void)
guard_selection_t * get_guard_selection_info(void)
static void parse_from_state_set_vals(const char *s, smartlist_t *entries, smartlist_t *extra, strmap_t *vals)
static int get_max_sample_size(guard_selection_t *gs, int n_guards)
int guards_update_all(void)
STATIC void sampled_guards_update_from_consensus(guard_selection_t *gs)
static int entry_guards_dirty
static int node_passes_guard_filter(const or_options_t *options, const node_t *node)
static bridge_info_t * get_bridge_info_for_guard(const entry_guard_t *guard)
STATIC guard_selection_t * guard_selection_new(const char *name, guard_selection_type_t type)
STATIC entry_guard_t * entry_guard_parse_from_state(const char *s)
void entry_guards_free_all(void)
STATIC int get_internet_likely_down_interval(void)
Header file for circuitbuild.c.
const char * escaped(const char *s)
long tor_lround(double d)
Header file for mainloop.c.
int usable_consensus_flavor(void)
int microdesc_relay_is_outdated_dirserver(const char *relay_digest)
Header file for microdesc.c.
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Header file for networkstatus.c.
int is_legal_nickname(const char *s)
Header file for nickname.c.
const node_t * node_sl_choose_by_bandwidth(const smartlist_t *sl, bandwidth_weight_rule_t rule)
Header file for node_select.c.
Node information structure.
const smartlist_t * nodelist_get_list(void)
int router_addrs_in_same_network(const tor_addr_t *a1, const tor_addr_t *a2)
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
const char * node_get_nickname(const node_t *node)
int node_is_dir(const node_t *node)
const node_t * node_get_by_id(const char *identity_digest)
void node_get_addr(const node_t *node, tor_addr_t *addr_out)
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
int nodes_in_same_family(const node_t *node1, const node_t *node2)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define MAX_VERBOSE_NICKNAME_LEN
The or_state_t structure, which represents Tor's state file.
Origin circuit structure.
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
int reachable_addr_allows_addr(const tor_addr_t *addr, uint16_t port, firewall_connection_t fw_connection, int pref_only, int pref_ipv6)
int reachable_addr_allows_node(const node_t *node, firewall_connection_t fw_connection, int pref_only)
Header file for policies.c.
int tor_asprintf(char **strp, const char *fmt,...)
int tor_snprintf(char *str, size_t size, const char *format,...)
int router_digest_is_me(const char *digest)
Header file for router.c.
int routerset_contains_node(const routerset_t *set, const node_t *node)
int routerset_contains_bridge(const routerset_t *set, const bridge_info_t *bridge)
Header file for routerset.c.
int smartlist_ptrs_eq(const smartlist_t *s1, const smartlist_t *s2)
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
void smartlist_remove_keeporder(smartlist_t *sl, const void *element)
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
int smartlist_contains(const smartlist_t *sl, const void *element)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_clear(smartlist_t *sl)
void smartlist_remove(smartlist_t *sl, const void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
#define SMARTLIST_DEL_CURRENT(sl, var)
#define SMARTLIST_DEL_CURRENT_KEEPORDER(sl, var)
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
or_state_t * get_or_state(void)
void or_state_mark_dirty(or_state_t *state, time_t when)
char identity[DIGEST_LEN]
double successful_circuits_closed
char identity[DIGEST_LEN]
unsigned int is_possible_guard
struct routerset_t * EntryNodes
struct routerset_t * ExcludeNodes
struct config_line_t * Guard
struct circuit_guard_state_t * guard_state
#define MOCK_IMPL(rv, funcname, arglist)
void format_iso_time_nospace(char *buf, time_t t)
void format_iso_time(char *buf, time_t t)
void format_local_iso_time(char *buf, time_t t)
Headers for transports.c.
#define tor_assert_nonfatal_unreached()
#define FALLTHROUGH_UNLESS_ALL_BUGS_ARE_FATAL
int tor_digest_is_zero(const char *digest)