diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-20 08:05:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-20 08:05:07 -0400 |
commit | 11a76b903b283ee39ab0dbf9d926d4c4b60b7a92 (patch) | |
tree | 94e6e66939beb2560b0901762bfd8c37f0e738cb /src/or/nodelist.c | |
parent | 334edc22d1bd05cbadb1ccc132d099e8a282bff4 (diff) | |
parent | 7b9cd5cca54d0077c0f8c163a58b055c85bf067f (diff) | |
download | tor-11a76b903b283ee39ab0dbf9d926d4c4b60b7a92.tar.gz tor-11a76b903b283ee39ab0dbf9d926d4c4b60b7a92.zip |
Merge branch 'maint-0.3.4'
Diffstat (limited to 'src/or/nodelist.c')
-rw-r--r-- | src/or/nodelist.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/or/nodelist.c b/src/or/nodelist.c index 5e575e9a83..060f5d908f 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -121,6 +121,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 @@ -638,6 +643,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; + } } /** Return 1 iff <b>node</b> has Exit flag and no BadExit flag. @@ -871,6 +882,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.) */ |