Fix our check for the "first" bridge descriptor.

This is meant to be a better bug 9229 fix -- or at least, one more
in tune with the intent of the original code, which calls
router_retry_directory_downloads() only on the first bridge descriptor.
This commit is contained in:
Nick Mathewson 2014-03-10 15:11:21 -04:00
parent b8ceb464e5
commit 7aa2192048
2 changed files with 33 additions and 8 deletions

5
changes/bug9229_025 Normal file
View File

@ -0,0 +1,5 @@
o Minor bugfixes:
- Avoid 60-second delays in the bootstrapping process when Tor
is launching for a second time while using bridges. Fixes bug 9229;
bugfix on 0.2.0.3-alpha.

View File

@ -70,7 +70,9 @@ static int entry_guards_dirty = 0;
static void bridge_free(bridge_info_t *bridge); static void bridge_free(bridge_info_t *bridge);
static const node_t *choose_random_entry_impl(cpath_build_state_t *state, static const node_t *choose_random_entry_impl(cpath_build_state_t *state,
int for_directory, int for_directory,
dirinfo_type_t dirtype); dirinfo_type_t dirtype,
int *n_options_out);
static int num_bridges_usable(void);
/** Return the list of entry guards, creating it if necessary. */ /** Return the list of entry guards, creating it if necessary. */
const smartlist_t * const smartlist_t *
@ -982,7 +984,7 @@ node_can_handle_dirinfo(const node_t *node, dirinfo_type_t dirinfo)
const node_t * const node_t *
choose_random_entry(cpath_build_state_t *state) choose_random_entry(cpath_build_state_t *state)
{ {
return choose_random_entry_impl(state, 0, 0); return choose_random_entry_impl(state, 0, 0, NULL);
} }
/** Pick a live (up and listed) directory guard from entry_guards for /** Pick a live (up and listed) directory guard from entry_guards for
@ -990,13 +992,13 @@ choose_random_entry(cpath_build_state_t *state)
const node_t * const node_t *
choose_random_dirguard(dirinfo_type_t type) choose_random_dirguard(dirinfo_type_t type)
{ {
return choose_random_entry_impl(NULL, 1, type); return choose_random_entry_impl(NULL, 1, type, NULL);
} }
/** Helper for choose_random{entry,dirguard}. */ /** Helper for choose_random{entry,dirguard}. */
static const node_t * static const node_t *
choose_random_entry_impl(cpath_build_state_t *state, int for_directory, choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
dirinfo_type_t dirinfo_type) dirinfo_type_t dirinfo_type, int *n_options_out)
{ {
const or_options_t *options = get_options(); const or_options_t *options = get_options();
smartlist_t *live_entry_guards = smartlist_new(); smartlist_t *live_entry_guards = smartlist_new();
@ -1010,6 +1012,9 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
int need_descriptor = !for_directory; int need_descriptor = !for_directory;
const int num_needed = decide_num_guards(options, for_directory); const int num_needed = decide_num_guards(options, for_directory);
if (n_options_out)
n_options_out = 0;
if (chosen_exit) { if (chosen_exit) {
nodelist_add_node_and_family(exit_family, chosen_exit); nodelist_add_node_and_family(exit_family, chosen_exit);
consider_exit_family = 1; consider_exit_family = 1;
@ -1136,6 +1141,8 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
* *double*-weight our guard selection. */ * *double*-weight our guard selection. */
node = smartlist_choose(live_entry_guards); node = smartlist_choose(live_entry_guards);
} }
if (n_options_out)
*n_options_out = smartlist_len(live_entry_guards);
smartlist_free(live_entry_guards); smartlist_free(live_entry_guards);
smartlist_free(exit_family); smartlist_free(exit_family);
return node; return node;
@ -2166,7 +2173,7 @@ learned_bridge_descriptor(routerinfo_t *ri, int from_cache)
tor_assert(ri); tor_assert(ri);
tor_assert(ri->purpose == ROUTER_PURPOSE_BRIDGE); tor_assert(ri->purpose == ROUTER_PURPOSE_BRIDGE);
if (get_options()->UseBridges) { if (get_options()->UseBridges) {
int first = !any_bridge_descriptors_known(); int first = num_bridges_usable() <= 1;
bridge_info_t *bridge = get_configured_bridge_by_routerinfo(ri); bridge_info_t *bridge = get_configured_bridge_by_routerinfo(ri);
time_t now = time(NULL); time_t now = time(NULL);
router_set_status(ri->cache_info.identity_digest, 1); router_set_status(ri->cache_info.identity_digest, 1);
@ -2188,14 +2195,15 @@ learned_bridge_descriptor(routerinfo_t *ri, int from_cache)
* our entry node list */ * our entry node list */
entry_guard_register_connect_status(ri->cache_info.identity_digest, entry_guard_register_connect_status(ri->cache_info.identity_digest,
1, 0, now); 1, 0, now);
if (first) if (first) {
routerlist_retry_directory_downloads(now); routerlist_retry_directory_downloads(now);
}
} }
} }
} }
/** Return 1 if any of our entry guards have descriptors that /** Return the number of bridges that have descriptors that
* are marked with purpose 'bridge' and are running. Else return 0. * are marked with purpose 'bridge' and are running.
* *
* We use this function to decide if we're ready to start building * We use this function to decide if we're ready to start building
* circuits through our bridges, or if we need to wait until the * circuits through our bridges, or if we need to wait until the
@ -2207,6 +2215,18 @@ any_bridge_descriptors_known(void)
return choose_random_entry(NULL) != NULL; 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(NULL, 0, 0, &n_options);
return n_options == 1;
}
/** Return 1 if there are any directory conns fetching bridge descriptors /** Return 1 if there are any directory conns fetching bridge descriptors
* that aren't marked for close. We use this to guess if we should tell * that aren't marked for close. We use this to guess if we should tell
* the controller that we have a problem. */ * the controller that we have a problem. */