aboutsummaryrefslogtreecommitdiff
path: root/src/or/networkstatus.c
diff options
context:
space:
mode:
authorrubiate <cb@viennan.net>2016-11-10 10:16:18 +1300
committerrubiate <cb@viennan.net>2016-11-10 10:16:18 +1300
commitd46c1b49a459f1249ef358b3751ef656d9e19038 (patch)
tree8063c1ba91b486fd9aeb6f35d71c2591e5e422a3 /src/or/networkstatus.c
parent0fed324c2c3862b1911a1add352f45c9a21f7a47 (diff)
downloadtor-d46c1b49a459f1249ef358b3751ef656d9e19038.tar.gz
tor-d46c1b49a459f1249ef358b3751ef656d9e19038.zip
Do not serve a consensus if it is too old
Closes ticket 20511.
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r--src/or/networkstatus.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index ed888fb53e..fde0b18a5a 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1342,6 +1342,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. */
@@ -1350,12 +1368,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;