[tor-commits] [tor/master] entrynodes: Be specific about how many primary descriptors we miss.

nickm at torproject.org nickm at torproject.org
Tue Oct 3 13:07:00 UTC 2017


commit c9729853a5ccfc15d206c43be8e15aea93ae19ee
Author: George Kadianakis <desnacked at riseup.net>
Date:   Mon Oct 2 20:43:22 2017 +0300

    entrynodes: Be specific about how many primary descriptors we miss.
---
 src/or/entrynodes.c        | 29 ++++++++++++++++++++---------
 src/or/entrynodes.h        |  5 ++---
 src/or/nodelist.c          | 13 ++++++++-----
 src/test/test_entrynodes.c | 19 +++++++++++++++++++
 4 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 129b98333..1e96fc7f5 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -3440,15 +3440,16 @@ guards_retry_optimistic(const or_options_t *options)
 }
 
 /**
- * Return true iff we know enough directory information to construct
- * circuits through all of the primary guards we'd currently use.
- */
-int
-guard_selection_have_enough_dir_info_to_build_circuits(guard_selection_t *gs)
+ * Check if we are missing any crucial dirinfo for the guard subsystem to
+ * work. Return NULL if everything went well, otherwise return a newly
+ * allocated string with an informative error message. */
+char *
+guard_selection_get_dir_info_status_str(guard_selection_t *gs)
 {
   if (!gs->primary_guards_up_to_date)
     entry_guards_update_primary(gs);
 
+  char *ret_str = NULL;
   int n_missing_descriptors = 0;
   int n_considered = 0;
   int num_primary_to_check;
@@ -3470,15 +3471,25 @@ guard_selection_have_enough_dir_info_to_build_circuits(guard_selection_t *gs)
       break;
   } SMARTLIST_FOREACH_END(guard);
 
-  return n_missing_descriptors == 0;
+  /* If we are not missing any descriptors, return NULL. */
+  if (!n_missing_descriptors) {
+    return NULL;
+  }
+
+  /* otherwise return a helpful error string */
+  tor_asprintf(&ret_str, "We're missing descriptors for %d/%d of our "
+               "primary entry guards",
+               n_missing_descriptors, num_primary_to_check);
+
+  return ret_str;
 }
 
 /** As guard_selection_have_enough_dir_info_to_build_circuits, but uses
  * the default guard selection. */
-int
-entry_guards_have_enough_dir_info_to_build_circuits(void)
+char *
+entry_guards_get_dir_info_status_str(void)
 {
-  return guard_selection_have_enough_dir_info_to_build_circuits(
+  return guard_selection_get_dir_info_status_str(
                                         get_guard_selection_info());
 }
 
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index f74ccd97f..d049a88cd 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -572,9 +572,8 @@ int getinfo_helper_entry_guards(control_connection_t *conn,
 int entries_known_but_down(const or_options_t *options);
 void entries_retry_all(const or_options_t *options);
 
-int guard_selection_have_enough_dir_info_to_build_circuits(
-                                                    guard_selection_t *gs);
-int entry_guards_have_enough_dir_info_to_build_circuits(void);
+char *entry_guards_get_dir_info_status_str(void);
+char *guard_selection_get_dir_info_status_str(guard_selection_t *gs);
 
 void entry_guards_free_all(void);
 
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index df735a9d2..93dd43f3c 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -2300,11 +2300,14 @@ update_router_have_minimum_dir_info(void)
 
   using_md = consensus->flavor == FLAV_MICRODESC;
 
-  if (! entry_guards_have_enough_dir_info_to_build_circuits()) {
-    strlcpy(dir_info_status, "We're missing descriptors for some of our "
-            "primary entry guards", sizeof(dir_info_status));
-    res = 0;
-    goto done;
+  { /* Check entry guard dirinfo status */
+    char *guard_error = entry_guards_get_dir_info_status_str();
+    if (guard_error) {
+      strlcpy(dir_info_status, guard_error, sizeof(dir_info_status));
+      tor_free(guard_error);
+      res = 0;
+      goto done;
+    }
   }
 
   /* Check fraction of available paths */
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 1e008c3a2..36e457bdf 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -1639,6 +1639,25 @@ test_entry_guard_manage_primary(void *arg)
     tt_ptr_op(g, OP_EQ, smartlist_get(prev_guards, g_sl_idx));
   });
 
+  /* Do some dirinfo checks */
+  {
+    /* Check that we have all required dirinfo for the primaries (that's done in
+     * big_fake_network_setup()) */
+    char *dir_info_str = guard_selection_get_dir_info_status_str(gs);
+    tt_assert(!dir_info_str);
+
+    /* Now artificially remove the first primary's descriptor and re-check */
+    entry_guard_t *first_primary;
+    first_primary = smartlist_get(gs->primary_entry_guards, 0);
+    /* Change the first primary's identity digest so that the mocked functions
+     * can't find its descriptor */
+    memset(first_primary->identity, 9, sizeof(first_primary->identity));
+    dir_info_str = guard_selection_get_dir_info_status_str(gs);
+    tt_str_op(dir_info_str, OP_EQ,
+              "We're missing descriptors for 1/2 of our primary entry guards");
+    tor_free(dir_info_str);
+  }
+
  done:
   guard_selection_free(gs);
   smartlist_free(prev_guards);





More information about the tor-commits mailing list