diff options
author | George Kadianakis <desnacked@riseup.net> | 2017-08-04 12:21:14 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-08 20:29:34 -0400 |
commit | b89d2fa1db2379bffd2e2b4c851c3facc57b6ed8 (patch) | |
tree | 6f4769adc1ddfd5d4c82958eba03ce5575bd113c /src/or/networkstatus.c | |
parent | 440eaa9b22573cdb0d38bf5c13200cc1077a453f (diff) | |
download | tor-b89d2fa1db2379bffd2e2b4c851c3facc57b6ed8.tar.gz tor-b89d2fa1db2379bffd2e2b4c851c3facc57b6ed8.zip |
Don't set HSDir index if we don't have a live consensus.
We also had to alter the SRV functions to take a consensus as optional
input, since we might be setting our HSDir index using a consensus that
is currently being processed and won't be returned by the
networkstatus_get_live_consensus() function.
This change has two results:
a) It makes sure we are using a fresh consensus with the right SRV value
when we are calculating the HSDir hash ring.
b) It ensures that we will not use the sr_get_current/previous()
functions when we don't have a consensus which would have falsely
triggered the disaster SRV logic.
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r-- | src/or/networkstatus.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index aff36b4c0b..82ceb8a9eb 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1393,14 +1393,21 @@ networkstatus_get_latest_consensus_by_flavor,(consensus_flavor_t f)) MOCK_IMPL(networkstatus_t *, networkstatus_get_live_consensus,(time_t now)) { - if (networkstatus_get_latest_consensus() && - networkstatus_get_latest_consensus()->valid_after <= now && - now <= networkstatus_get_latest_consensus()->valid_until) - return networkstatus_get_latest_consensus(); + networkstatus_t *ns = networkstatus_get_latest_consensus(); + if (ns && networkstatus_is_live(ns, now)) + return ns; else return NULL; } +/** Given a consensus in <b>ns</b>, validate that it's currently live and + * unexpired. */ +int +networkstatus_is_live(const networkstatus_t *ns, time_t now) +{ + return (ns->valid_after <= now && now <= ns->valid_until); +} + /** Determine if <b>consensus</b> is valid or expired recently enough that * we can still use it. * |