if (options->UseBridges && type != BRIDGE_DIRINFO) {
/* We want to ask a running bridge for which we have a descriptor.
*
- * When we ask choose_random_entry() for a bridge, we specify that
- * we're going to be using it for a dir fetch: if any of our bridges
- * can handle microdescriptor questions, we'll get one of the ones
- * that can.
+ * When we ask choose_random_entry() for a bridge, we specify what
+ * sort of dir fetch we'll be doing, so it won't return a bridge
+ * that can't answer our question.
*/
/* XXX024 Not all bridges handle conditional consensus downloading,
* so, for now, never assume the server supports that. -PP */
- const node_t *node = choose_random_entry(NULL, 1);
+ const node_t *node = choose_random_entry(NULL, type);
if (node && node->ri) {
/* every bridge has a routerinfo. */
tor_addr_t addr;
static void bridge_free(bridge_info_t *bridge);
static const node_t *choose_random_entry_impl(cpath_build_state_t *state,
int for_directory,
- dirinfo_type_t dirtype,
- int prefer_microdescs);
+ dirinfo_type_t dirtype);
/** Return the list of entry guards, creating it if necessary. */
const smartlist_t *
return 0;
}
+/** Return true iff <b>node</b> is able to answer directory questions
+ * of type <b>dirinfo</b>. */
+static int
+node_can_handle_dirinfo(const node_t *node, dirinfo_type_t dirinfo)
+{
+ if ((dirinfo & MICRODESC_DIRINFO) &&
+ !node_understands_microdescriptors(node))
+ return 0;
+ return 1;
+}
+
/** Pick a live (up and listed) entry guard from entry_guards. If
* <b>state</b> is non-NULL, this is for a specific circuit --
* make sure not to pick this circuit's exit or any node in the
* exit's family. If <b>state</b> is NULL, we're looking for a random
- * guard (likely a bridge).
- *
- * If the prefer_microdescs flag is set, we are looking for a bridge to
- * use for directory fetching and pick a bridge that supports microdescriptors
- * if we know any that do so.
- */
+ * guard (likely a bridge). If <b>dirinfo</b> is not NO_DIRINFO, then
+ * only select from nodes that know how to answer directory questions
+ * of that type. */
const node_t *
-choose_random_entry(cpath_build_state_t *state, int prefer_microdescs)
+choose_random_entry(cpath_build_state_t *state, dirinfo_type_t dirinfo)
{
- return choose_random_entry_impl(state, 0, 0, prefer_microdescs);
+ return choose_random_entry_impl(state, 0, dirinfo);
}
/** Pick a live (up and listed) directory guard from entry_guards for
const node_t *
choose_random_dirguard(dirinfo_type_t type)
{
- return choose_random_entry_impl(NULL, 1, type, 0);
+ return choose_random_entry_impl(NULL, 1, type);
}
/** Helper for choose_random{entry,dirguard}. */
static const node_t *
choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
- dirinfo_type_t dirinfo_type, int prefer_microdescs)
+ dirinfo_type_t dirinfo_type)
{
const or_options_t *options = get_options();
smartlist_t *live_entry_guards = smartlist_new();
continue; /* don't pick the same node for entry and exit */
if (consider_exit_family && smartlist_contains(exit_family, node))
continue; /* avoid relays that are family members of our exit */
- if (prefer_microdescs &&
- we_use_microdescriptors_for_circuits(options) &&
- !node_understands_microdescriptors(node))
+ if (dirinfo_type != NO_DIRINFO &&
+ !node_can_handle_dirinfo(node, dirinfo_type))
continue; /* this node won't be able to answer our dir questions */
#if 0 /* since EntryNodes is always strict now, this clause is moot */
if (options->EntryNodes &&
any_bridge_descriptors_known(void)
{
tor_assert(get_options()->UseBridges);
- return choose_random_entry(NULL, 0)!=NULL ? 1 : 0;
+ return choose_random_entry(NULL, NO_DIRINFO)!=NULL ? 1 : 0;
}
/** Return 1 if there are any directory conns fetching bridge descriptors