Browse Source

prop224: Don't use nodes as HSDirs if they don't have an HSDir index.

George Kadianakis 6 years ago
parent
commit
e42c55626a
2 changed files with 30 additions and 4 deletions
  1. 27 1
      src/or/hs_common.c
  2. 3 3
      src/or/nodelist.c

+ 27 - 1
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);

+ 3 - 3
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;
   }