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

[tor-dev] 1 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
> 


From 8de701e860d2e68d6b05767824efdf6e91de77fa Mon Sep 17 00:00:00 2001
From: Martin Kepplinger <martink@xxxxxxxxx>
Date: Sat, 28 Jun 2014 21:44:16 +0200
Subject: [PATCH] rename entry_guard_t's made_contact to used_so_save_if_down

rename the bit made_contact in entry_guard_t to used_so_save_if_down
to make the process more readable.

in part, this addresses ticket 9971
---
addresses https://trac.torproject.org/projects/tor/ticket/9971
it's a bit clunky and long but readable. what do you think?

 src/or/entrynodes.c |   30 +++++++++++++++---------------
 src/or/entrynodes.h |    2 +-
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 957217a..f9c518f 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -293,13 +293,13 @@ log_entry_guards(int severity)
         smartlist_add_asprintf(elements, "%s [%s] (up %s)",
                      e->nickname,
                      hex_str(e->identity, DIGEST_LEN),
-                     e->made_contact ? "made-contact" : "never-contacted");
+                     e->used_so_save_if_down ? "was-in-use" : "never-used");
       else
         smartlist_add_asprintf(elements, "%s [%s] (%s, %s)",
                      e->nickname,
                      hex_str(e->identity, DIGEST_LEN),
                      msg,
-                     e->made_contact ? "made-contact" : "never-contacted");
+                     e->used_so_save_if_down ? "was-in-use" : "never-used");
     }
   SMARTLIST_FOREACH_END(e);
 
@@ -416,12 +416,12 @@ add_an_entry_guard(const node_t *chosen, int reset_status, int prepend,
    * down so we need another one (for_discovery is 1), or because we
    * decided we need more variety in our guard list (for_discovery is 0)?
    *
-   * Currently we hack this behavior into place by setting "made_contact"
-   * for guards of the latter variety, so we'll be willing to use any of
-   * them right off the bat.
+   * Currently we hack this behavior into place by setting
+   * "used_so_save_if_down" for guards of the latter variety, so we'll
+   * be willing to use any of them right off the bat.
    */
   if (!for_discovery)
-    entry->made_contact = 1;
+    entry->used_so_save_if_down = 1;
 
   ((node_t*)node)->using_as_guard = 1;
   if (prepend)
@@ -733,12 +733,12 @@ entry_guard_register_connect_status(const char *digest, int succeeded,
       control_event_guard(entry->nickname, entry->identity, "UP");
       changed = 1;
     }
-    if (!entry->made_contact) {
-      entry->made_contact = 1;
+    if (!entry->used_so_save_if_down) {
+      entry->used_so_save_if_down = 1;
       first_contact = changed = 1;
     }
   } else { /* ! succeeded */
-    if (!entry->made_contact) {
+    if (!entry->used_so_save_if_down) {
       /* We've never connected to this one. */
       log_info(LD_CIRC,
                "Connection to never-contacted entry guard '%s' (%s) failed. "
@@ -781,7 +781,7 @@ entry_guard_register_connect_status(const char *digest, int succeeded,
     SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
         if (e == entry)
           break;
-        if (e->made_contact) {
+        if (e->used_so_save_if_down) {
           const char *msg;
           const node_t *r = entry_is_live(e, 0, 1, 1, 0, &msg);
           if (r && e->unreachable_since) {
@@ -1066,7 +1066,7 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
       }
 #endif
       smartlist_add(live_entry_guards, (void*)node);
-      if (!entry->made_contact) {
+      if (!entry->used_so_save_if_down) {
         /* 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
@@ -1170,7 +1170,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
       smartlist_t *args = smartlist_new();
       node = tor_malloc_zero(sizeof(entry_guard_t));
       /* all entry guards on disk have been contacted */
-      node->made_contact = 1;
+      node->used_so_save_if_down = 1;
       smartlist_add(new_entry_guards, node);
       smartlist_split_string(args, line->value, " ",
                              SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@@ -1450,7 +1450,7 @@ entry_guards_update_state(or_state_t *state)
     entry_guards = smartlist_new();
   SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
       char dbuf[HEX_DIGEST_LEN+1];
-      if (!e->made_contact)
+      if (!e->used_so_save_if_down)
         continue; /* don't write this one to disk */
       *next = line = tor_malloc_zero(sizeof(config_line_t));
       line->key = tor_strdup("EntryGuard");
@@ -1543,7 +1543,7 @@ getinfo_helper_entry_guards(control_connection_t *conn,
         time_t when = 0;
         const node_t *node;
 
-        if (!e->made_contact) {
+        if (!e->used_so_save_if_down) {
           status = "never-connected";
         } else if (e->bad_since) {
           when = e->bad_since;
@@ -2191,7 +2191,7 @@ learned_bridge_descriptor(routerinfo_t *ri, int from_cache)
 
       log_notice(LD_DIR, "new bridge descriptor '%s' (%s): %s", ri->nickname,
                  from_cache ? "cached" : "fresh", router_describe(ri));
-      /* set entry->made_contact so if it goes down we don't drop it from
+      /* set entry->used_so_save_if_down so if it goes down we don't drop it from
        * our entry node list */
       entry_guard_register_connect_status(ri->cache_info.identity_digest,
                                           1, 0, now);
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index e229f3b..7ce00ad 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -27,7 +27,7 @@ typedef struct entry_guard_t {
                           * "0" if we don't know. */
   char *chosen_by_version; /**< What tor version added this guard? NULL
                             * if we don't know. */
-  unsigned int made_contact : 1; /**< 0 if we have never connected to this
+  unsigned int used_so_save_if_down : 1; /**< 0 if we have never connected to this
                                   * router, 1 if we have. */
   unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
                                * in spite of having it marked as unreachable?*/
-- 
1.7.10.4

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