aboutsummaryrefslogtreecommitdiff
path: root/src/or/hs_common.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2017-09-01 16:18:50 -0400
committerGeorge Kadianakis <desnacked@riseup.net>2017-09-07 18:16:07 +0300
commit72c7f81459e087e2a0485361eb34db1023d12155 (patch)
treed8f01ee1d12860ac5cff8f90fcaa93df7359265f /src/or/hs_common.c
parentf117da3ea006fbdda3f5e921d5f8da2ae3d3bdfd (diff)
downloadtor-72c7f81459e087e2a0485361eb34db1023d12155.tar.gz
tor-72c7f81459e087e2a0485361eb34db1023d12155.zip
prop224: When computing hsdir index and time period, use valid_after time
Use the valid_after time from the consensus to get the time period number else we might get out of sync with the overlap period that uses valid_after. Make it an optional feature since some functions require passing a specific time (like hs_get_start_time_of_next_time_period()). Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/hs_common.c')
-rw-r--r--src/or/hs_common.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 5ea44b97e7..36f94507e7 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -211,15 +211,26 @@ get_time_period_length(void)
return (uint64_t) time_period_length;
}
-/** Get the HS time period number at time <b>now</b> */
+/** Get the HS time period number at time <b>now</b>. If <b>now</b> is not set,
+ * we try to get the time ourselves. */
uint64_t
hs_get_time_period_num(time_t now)
{
uint64_t time_period_num;
+ time_t current_time;
+
+ /* If no time is specified, set current time based on consensus time, and
+ * only fall back to system time if that fails. */
+ if (now != 0) {
+ current_time = now;
+ } else {
+ networkstatus_t *ns = networkstatus_get_live_consensus(approx_time());
+ current_time = ns ? ns->valid_after : approx_time();
+ }
/* Start by calculating minutes since the epoch */
uint64_t time_period_length = get_time_period_length();
- uint64_t minutes_since_epoch = now / 60;
+ uint64_t minutes_since_epoch = current_time / 60;
/* Apply the rotation offset as specified by prop224 (section
* [TIME-PERIODS]), so that new time periods synchronize nicely with SRV