[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-dev] 3 Re: [PATCH] entrynodes.c: Improve readability (issue 9971)



Am 2014-06-28 23:57, schrieb Martin Kepplinger:
> Maybe we can do away with issue 9971 and improve readability:
> https://trac.torproject.org/projects/tor/ticket/9971
> 
NEEDS REVIEW.

From 9e7f10abc9012e6820102b96c30c54a7d8ab8600 Mon Sep 17 00:00:00 2001
From: Martin Kepplinger <martink@xxxxxxxxx>
Date: Sat, 28 Jun 2014 23:18:44 +0200
Subject: [PATCH] remove prepend argument of add_an_entry_guard()

  node_t *chosen        is a node to add
  prepend               is set if the guard should become first in the list

  there are 2 users of add_an_entry_guard() that pass it a chosen node. One is
  a bridge (prepend) and the other one is a user-defined node (!prepend), so:

  Given the fact that the list is not supposed to be long and the two 'users'
  are somewhat similar, prepend the node if explicitly given.
---
 src/or/entrynodes.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 957217a..e119db2 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -351,7 +351,7 @@ control_event_guard_deferred(void)
  * already in our entry_guards list, put it at the *beginning*.
  * Else, put the one we pick at the end of the list. */
 static const node_t *
-add_an_entry_guard(const node_t *chosen, int reset_status, int prepend,
+add_an_entry_guard(const node_t *chosen, int reset_status,
                    int for_discovery, int for_directory)
 {
   const node_t *node;
@@ -424,7 +424,7 @@ add_an_entry_guard(const node_t *chosen, int reset_status, int prepend,
     entry->made_contact = 1;
 
   ((node_t*)node)->using_as_guard = 1;
-  if (prepend)
+  if (chosen)
     smartlist_insert(entry_guards, 0, entry);
   else
     smartlist_add(entry_guards, entry);
@@ -456,7 +456,7 @@ pick_entry_guards(const or_options_t *options, int for_directory)
   tor_assert(entry_guards);
 
   while (num_live_entry_guards(for_directory) < num_needed) {
-    if (!add_an_entry_guard(NULL, 0, 0, 0, for_directory))
+    if (!add_an_entry_guard(NULL, 0, 0, for_directory))
       break;
     changed = 1;
   }
@@ -908,7 +908,7 @@ entry_guards_set_from_config(const or_options_t *options)
 
   /* Next, the rest of EntryNodes */
   SMARTLIST_FOREACH_BEGIN(entry_nodes, const node_t *, node) {
-    add_an_entry_guard(node, 0, 0, 1, 0);
+    add_an_entry_guard(node, 0, 1, 0);
     if (smartlist_len(entry_guards) > options->NumEntryGuards * 10)
       break;
   } SMARTLIST_FOREACH_END(node);
@@ -1095,7 +1095,7 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
       /* XXX if guard doesn't imply fast and stable, then we need
        * to tell add_an_entry_guard below what we want, or it might
        * be a long time til we get it. -RD */
-      node = add_an_entry_guard(NULL, 0, 0, 1, for_directory);
+      node = add_an_entry_guard(NULL, 0, 1, for_directory);
       if (node) {
         entry_guards_changed();
         /* XXX we start over here in case the new node we added shares
@@ -2187,7 +2187,7 @@ learned_bridge_descriptor(routerinfo_t *ri, int from_cache)
       node = node_get_mutable_by_id(ri->cache_info.identity_digest);
       tor_assert(node);
       rewrite_node_address_for_bridge(bridge, node);
-      add_an_entry_guard(node, 1, 1, 0, 0);
+      add_an_entry_guard(node, 1, 0, 0);
 
       log_notice(LD_DIR, "new bridge descriptor '%s' (%s): %s", ri->nickname,
                  from_cache ? "cached" : "fresh", router_describe(ri));
-- 
1.7.10.4

_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev