diff options
author | George Kadianakis <desnacked@riseup.net> | 2018-06-13 13:28:39 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-20 08:01:02 -0400 |
commit | b7b7dab00d321d2c3e2a2d52e76d9e1190836420 (patch) | |
tree | 9c4aca2936ef8263942f1d8aea2b238145214250 /src | |
parent | a686464420801c5aa58bde1babbf96d3b8520b00 (diff) | |
download | tor-b7b7dab00d321d2c3e2a2d52e76d9e1190836420.tar.gz tor-b7b7dab00d321d2c3e2a2d52e76d9e1190836420.zip |
Recreate nodelist before use if it's outdated.
We currently only do the check when we are about to use the HSDir indices.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/hs_common.c | 3 | ||||
-rw-r--r-- | src/or/nodelist.c | 30 | ||||
-rw-r--r-- | src/or/nodelist.h | 1 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c index 6f51e1d131..5354055bb0 100644 --- a/src/or/hs_common.c +++ b/src/or/hs_common.c @@ -1340,6 +1340,9 @@ hs_get_responsible_hsdirs(const ed25519_public_key_t *blinded_pk, goto done; } + /* Ensure the nodelist is fresh, since it contains the HSDir indices. */ + nodelist_ensure_freshness(c); + /* Add every node_t that support HSDir v3 for which we do have a valid * hsdir_index already computed for them for this consensus. */ { diff --git a/src/or/nodelist.c b/src/or/nodelist.c index bc9a79940b..ce1830083f 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -113,6 +113,11 @@ typedef struct nodelist_t { /* Set of addresses that belong to nodes we believe in. */ address_set_t *node_addrs; + + /* The valid-after time of the last live consensus that initialized the + * nodelist. We use this to detect outdated nodelists that need to be + * rebuilt using a newer consensus. */ + time_t live_consensus_valid_after; } nodelist_t; static inline unsigned int @@ -630,6 +635,12 @@ nodelist_set_consensus(networkstatus_t *ns) } } SMARTLIST_FOREACH_END(node); } + + /* If the consensus is live, note down the consensus valid-after that formed + * the nodelist. */ + if (networkstatus_is_live(ns, approx_time())) { + the_nodelist->live_consensus_valid_after = ns->valid_after; + } } /** Helper: return true iff a node has a usable amount of information*/ @@ -854,6 +865,25 @@ nodelist_assert_ok(void) digestmap_free(dm, NULL); } +/** Ensure that the nodelist has been created with the most recent consensus. + * If that's not the case, make it so. */ +void +nodelist_ensure_freshness(networkstatus_t *ns) +{ + tor_assert(ns); + + /* We don't even have a nodelist: this is a NOP. */ + if (!the_nodelist) { + return; + } + + if (the_nodelist->live_consensus_valid_after != ns->valid_after) { + log_info(LD_GENERAL, "Nodelist was not fresh: rebuilding. (%d / %d)", + (int) the_nodelist->live_consensus_valid_after, + (int) ns->valid_after); + nodelist_set_consensus(ns); + } +} /** Return a list of a node_t * for every node we know about. The caller * MUST NOT modify the list. (You can set and clear flags in the nodes if * you must, but you must not add or remove nodes.) */ diff --git a/src/or/nodelist.h b/src/or/nodelist.h index 1ffba2e8df..dbe9ad18ff 100644 --- a/src/or/nodelist.h +++ b/src/or/nodelist.h @@ -29,6 +29,7 @@ const node_t *node_get_by_hex_id(const char *identity_digest, node_t *nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out); node_t *nodelist_add_microdesc(microdesc_t *md); void nodelist_set_consensus(networkstatus_t *ns); +void nodelist_ensure_freshness(networkstatus_t *ns); int nodelist_probably_contains_address(const tor_addr_t *addr); void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md); |