diff options
author | George Kadianakis <desnacked@riseup.net> | 2017-07-24 13:31:17 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-08 20:29:34 -0400 |
commit | cf58451a8ba03e869a805f973ef5b5f3f6d82b6b (patch) | |
tree | 3bf63e6ed1baf97b333e42aaa71a42e12e0cc8c3 /src/or/hs_common.c | |
parent | 2cd5f9a2fc2765539899b6e84ed4b1c9e02febad (diff) | |
download | tor-cf58451a8ba03e869a805f973ef5b5f3f6d82b6b.tar.gz tor-cf58451a8ba03e869a805f973ef5b5f3f6d82b6b.zip |
prop224: Refactor hs_get_time_period_num() to not use absolute time.
Instead use the SRV protocol duration to calculate the rotation offset
that was previously hardcoded to 12 hours.
Diffstat (limited to 'src/or/hs_common.c')
-rw-r--r-- | src/or/hs_common.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c index 0d81063cf7..0ae196d93e 100644 --- a/src/or/hs_common.c +++ b/src/or/hs_common.c @@ -196,13 +196,18 @@ uint64_t hs_get_time_period_num(time_t now) { uint64_t time_period_num; + + /* Start by calculating minutes since the epoch */ uint64_t time_period_length = get_time_period_length(); uint64_t minutes_since_epoch = now / 60; - /* Now subtract half a day to fit the prop224 time period schedule (see - * section [TIME-PERIODS]). */ - tor_assert(minutes_since_epoch > HS_TIME_PERIOD_ROTATION_OFFSET); - minutes_since_epoch -= HS_TIME_PERIOD_ROTATION_OFFSET; + /* Apply the rotation offset as specified by prop224 (section + * [TIME-PERIODS]), so that new time periods synchronize nicely with SRV + * publication */ + unsigned int time_period_rotation_offset = sr_state_get_phase_duration(); + time_period_rotation_offset /= 60; /* go from seconds to minutes */ + tor_assert(minutes_since_epoch > time_period_rotation_offset); + minutes_since_epoch -= time_period_rotation_offset; /* Calculate the time period */ time_period_num = minutes_since_epoch / time_period_length; |