summaryrefslogtreecommitdiff
path: root/src/or/hs_common.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-08-02 16:50:15 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commite42c55626abf7447a154f5271e3bc35743340a21 (patch)
treea07a6912da184ed42f65a6e8ad5c6f1f2204281a /src/or/hs_common.c
parent74981d1f133f0ecb1050715af4ee5d409fcebd41 (diff)
downloadtor-e42c55626abf7447a154f5271e3bc35743340a21.tar.gz
tor-e42c55626abf7447a154f5271e3bc35743340a21.zip
prop224: Don't use nodes as HSDirs if they don't have an HSDir index.
Diffstat (limited to 'src/or/hs_common.c')
-rw-r--r--src/or/hs_common.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index f63adf51bd..d68c446fd0 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);