commit e42c55626abf7447a154f5271e3bc35743340a21
Author: George Kadianakis <desnac...@riseup.net>
Date:   Wed Aug 2 16:50:15 2017 +0300

    prop224: Don't use nodes as HSDirs if they don't have an HSDir index.
---
 src/or/hs_common.c | 28 +++++++++++++++++++++++++++-
 src/or/nodelist.c  |  6 +++---
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index f63adf51b..d68c446fd 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -1121,6 +1121,30 @@ hs_get_hsdir_spread_store(void)
                                  HS_DEFAULT_HSDIR_SPREAD_STORE, 1, 128);
 }
 
+/** <b>node</b> is an HSDir so make sure that we have assigned an hsdir index.
+ *  Return 0 if everything is as expected, else return -1. */
+static int
+node_has_hsdir_index(const node_t *node)
+{
+  tor_assert(node_supports_v3_hsdir(node));
+
+  /* A node can't have an HSDir index without a descriptor since we need desc
+   * to get its ed25519 key */
+  if (!node_has_descriptor(node)) {
+    return 0;
+  }
+
+  /* At this point, since the node has a desc, this node must also have an
+   * hsdir index. If not, something went wrong, so BUG out. */
+  if (BUG(node->hsdir_index == NULL) ||
+      BUG(tor_mem_is_zero((const char*)node->hsdir_index->current,
+                          DIGEST256_LEN))) {
+    return 0;
+  }
+
+  return 1;
+}
+
 /* For a given blinded key and time period number, get the responsible HSDir
  * and put their routerstatus_t object in the responsible_dirs list. If
  * is_next_period is true, the next hsdir_index of the node_t is used. If
@@ -1162,7 +1186,9 @@ hs_get_responsible_hsdirs(const ed25519_public_key_t 
*blinded_pk,
       node_t *n = node_get_mutable_by_id(rs->identity_digest);
       tor_assert(n);
       if (node_supports_v3_hsdir(n) && rs->is_hs_dir) {
-        if (BUG(n->hsdir_index == NULL)) {
+        if (!node_has_hsdir_index(n)) {
+          log_info(LD_GENERAL, "Node %s was found without hsdir index.",
+                   node_describe(n));
           continue;
         }
         smartlist_add(sorted_nodes, n);
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 1666fffb7..c5a5979f3 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -189,9 +189,9 @@ node_set_hsdir_index(node_t *node, const networkstatus_t 
*ns)
 
   node_identity_pk = node_get_ed25519_id(node);
   if (node_identity_pk == NULL) {
-    log_warn(LD_BUG, "ed25519 identity public key not found when "
-                     "trying to build the hsdir indexes for node %s",
-             node_describe(node));
+    log_debug(LD_GENERAL, "ed25519 identity public key not found when "
+              "trying to build the hsdir indexes for node %s",
+              node_describe(node));
     goto done;
   }
 



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

Reply via email to