Skip to content
Snippets Groups Projects
Commit 427cc8a4 authored by George Kadianakis's avatar George Kadianakis
Browse files

Move code from choose_random_entry_impl() to the new function.

This commit only _moves_ code.
parent e8c366e9
No related branches found
No related tags found
No related merge requests found
......@@ -1003,6 +1003,38 @@ populate_live_entry_guards(const smartlist_t *live_entry_guards,
int need_capacity,
int need_descriptor)
{
if (chosen_exit) {
nodelist_add_node_and_family(exit_family, chosen_exit);
}
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry) {
const char *msg;
node = entry_is_live(entry, need_uptime, need_capacity, 0,
need_descriptor, &msg);
if (!node)
continue; /* down, no point */
if (for_directory) {
if (!entry->is_dir_cache)
continue; /* We need a directory and didn't get one. */
}
if (node == chosen_exit)
continue; /* don't pick the same node for entry and exit */
if (smartlist_contains(exit_family, node))
continue; /* avoid relays that are family members of our exit */
if (dirinfo_type != NO_DIRINFO &&
!node_can_handle_dirinfo(node, dirinfo_type))
continue; /* this node won't be able to answer our dir questions */
smartlist_add(live_entry_guards, (void*)node);
if (!entry->made_contact) {
/* Always start with the first not-yet-contacted entry
* guard. Otherwise we might add several new ones, pick
* the second new one, and now we've expanded our entry
* guard list without needing to. */
goto choose_and_finish;
}
if (smartlist_len(live_entry_guards) >= num_needed)
goto choose_and_finish; /* we have enough */
} SMARTLIST_FOREACH_END(entry);
}
/** Helper for choose_random{entry,dirguard}. */
......@@ -1025,10 +1057,6 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
if (n_options_out)
*n_options_out = 0;
if (chosen_exit) {
nodelist_add_node_and_family(exit_family, chosen_exit);
}
if (!entry_guards)
entry_guards = smartlist_new();
......@@ -1041,34 +1069,6 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
retry:
smartlist_clear(live_entry_guards);
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry) {
const char *msg;
node = entry_is_live(entry, need_uptime, need_capacity, 0,
need_descriptor, &msg);
if (!node)
continue; /* down, no point */
if (for_directory) {
if (!entry->is_dir_cache)
continue; /* We need a directory and didn't get one. */
}
if (node == chosen_exit)
continue; /* don't pick the same node for entry and exit */
if (smartlist_contains(exit_family, node))
continue; /* avoid relays that are family members of our exit */
if (dirinfo_type != NO_DIRINFO &&
!node_can_handle_dirinfo(node, dirinfo_type))
continue; /* this node won't be able to answer our dir questions */
smartlist_add(live_entry_guards, (void*)node);
if (!entry->made_contact) {
/* Always start with the first not-yet-contacted entry
* guard. Otherwise we might add several new ones, pick
* the second new one, and now we've expanded our entry
* guard list without needing to. */
goto choose_and_finish;
}
if (smartlist_len(live_entry_guards) >= num_needed)
goto choose_and_finish; /* we have enough */
} SMARTLIST_FOREACH_END(entry);
if (entry_list_is_constrained(options)) {
/* If we prefer the entry nodes we've got, and we have at least
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment