diff --git a/src/or/bridges.c b/src/or/bridges.c index 73510cf10c..508c77fc9e 100644 --- a/src/or/bridges.c +++ b/src/or/bridges.c @@ -52,7 +52,6 @@ typedef struct { } bridge_info_t; static void bridge_free(bridge_info_t *bridge); -static int num_bridges_usable(void); /** A list of configured bridges. Whenever we actually get a descriptor * for one, we add it as an entry guard. Note that the order of bridges @@ -719,7 +718,7 @@ learned_bridge_descriptor(routerinfo_t *ri, int from_cache) fmt_and_decorate_addr(&bridge->addr), (int) bridge->port); } - add_an_entry_guard(get_guard_selection_info(), node, 1, 1, 0, 0); + add_bridge_as_entry_guard(get_guard_selection_info(), node); log_notice(LD_DIR, "new bridge descriptor '%s' (%s): %s", ri->nickname, from_cache ? "cached" : "fresh", router_describe(ri)); @@ -747,19 +746,6 @@ any_bridge_descriptors_known(void) return choose_random_entry(NULL) != NULL; } -/** Return the number of bridges that have descriptors that are marked with - * purpose 'bridge' and are running. - */ -static int -num_bridges_usable(void) -{ - int n_options = 0; - tor_assert(get_options()->UseBridges); - (void) choose_random_entry_impl(get_guard_selection_info(), - NULL, 0, 0, &n_options); - return n_options; -} - /** Return a smartlist containing all bridge identity digests */ MOCK_IMPL(smartlist_t *, list_bridge_identities, (void)) diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c index 886e6533b7..95b3c5aaaa 100644 --- a/src/or/entrynodes.c +++ b/src/or/entrynodes.c @@ -893,6 +893,16 @@ add_an_entry_guard(guard_selection_t *gs, return node; } +/** Entry point for bridges.c to add a bridge as guard. + * + * XXXX prop271 refactor.*/ +void +add_bridge_as_entry_guard(guard_selection_t *gs, + const node_t *chosen) +{ + add_an_entry_guard(gs, chosen, 1, 1, 0, 0); +} + /** Choose how many entry guards or directory guards we'll use. If * for_directory is true, we return how many directory guards to * use; else we return how many entry guards to use. */ @@ -1490,6 +1500,19 @@ choose_random_dirguard(dirinfo_type_t type) NULL, 1, type, NULL); } +/** Return the number of bridges that have descriptors that are marked with + * purpose 'bridge' and are running. + */ +int +num_bridges_usable(void) +{ + int n_options = 0; + tor_assert(get_options()->UseBridges); + (void) choose_random_entry_impl(get_guard_selection_info(), + NULL, 0, 0, &n_options); + return n_options; +} + /** Filter all_entry_guards for usable entry guards and put them * in live_entry_guards. We filter based on whether the node is * currently alive, and on whether it satisfies the restrictions diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h index 8407945e4c..f07f843ae7 100644 --- a/src/or/entrynodes.h +++ b/src/or/entrynodes.h @@ -154,6 +154,11 @@ const char *entry_guard_get_rsa_id_digest(const entry_guard_t *guard); const char *entry_guard_describe(const entry_guard_t *guard); guard_pathbias_t *entry_guard_get_pathbias_state(entry_guard_t *guard); +/* Used by bridges.c only. */ +void add_bridge_as_entry_guard(guard_selection_t *gs, + const node_t *chosen); +int num_bridges_usable(void); + #ifdef ENTRYNODES_PRIVATE STATIC time_t randomize_time(time_t now, time_t max_backdate); STATIC void entry_guard_add_to_sample(guard_selection_t *gs,