[tor-commits] [tor/master] Move code from choose_random_entry_impl() to the new function.

nickm at torproject.org nickm at torproject.org
Wed Jul 16 13:34:43 UTC 2014


commit 427cc8a4520e6ea93608957fd2aabe6364c678de
Author: George Kadianakis <desnacked at riseup.net>
Date:   Mon Jun 9 18:04:39 2014 +0100

    Move code from choose_random_entry_impl() to the new function.
    
    This commit only _moves_ code.
---
 src/or/entrynodes.c |   64 +++++++++++++++++++++++++--------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 8208af3..1b0979b 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -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





More information about the tor-commits mailing list