diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-12-12 09:20:56 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-12-12 09:20:56 -0500 |
commit | 1ad96ed9cda1573cfd9f0a388ac28bfeaf3b62aa (patch) | |
tree | ca9fe6491eb2c8c7494c0c5481437059632e0e90 /src/or/networkstatus.c | |
parent | 9025991a8d16b28e0b1ed875aab76630f9aa1715 (diff) | |
parent | d46c1b49a459f1249ef358b3751ef656d9e19038 (diff) | |
download | tor-1ad96ed9cda1573cfd9f0a388ac28bfeaf3b62aa.tar.gz tor-1ad96ed9cda1573cfd9f0a388ac28bfeaf3b62aa.zip |
Merge remote-tracking branch 'rubiate/ticket20511'
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r-- | src/or/networkstatus.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index bfb36413ce..fa548305f9 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1377,6 +1377,24 @@ networkstatus_get_live_consensus,(time_t now)) return NULL; } +/** Determine if <b>consensus</b> is valid or expired recently enough that + * we can still use it. + * + * Return 1 if the consensus is reasonably live, or 0 if it is too old. + */ +int +networkstatus_consensus_reasonably_live(networkstatus_t *consensus, time_t now) +{ +#define REASONABLY_LIVE_TIME (24*60*60) + if (BUG(!consensus)) + return 0; + + if (now <= consensus->valid_until + REASONABLY_LIVE_TIME) + return 1; + + return 0; +} + /* XXXX remove this in favor of get_live_consensus. But actually, * leave something like it for bridge users, who need to not totally * lose if they spend a while fetching a new consensus. */ @@ -1385,12 +1403,11 @@ networkstatus_get_live_consensus,(time_t now)) networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor) { -#define REASONABLY_LIVE_TIME (24*60*60) networkstatus_t *consensus = networkstatus_get_latest_consensus_by_flavor(flavor); if (consensus && consensus->valid_after <= now && - now <= consensus->valid_until+REASONABLY_LIVE_TIME) + networkstatus_consensus_reasonably_live(consensus, now)) return consensus; else return NULL; |