aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-18 16:44:03 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commit2cd5f9a2fc2765539899b6e84ed4b1c9e02febad (patch)
tree9c0e51b065538d6dff2d977856f917b62f67b0c4 /src/or
parent0b22b7fce3f1ce97a85f4022533b206f847b7307 (diff)
downloadtor-2cd5f9a2fc2765539899b6e84ed4b1c9e02febad.tar.gz
tor-2cd5f9a2fc2765539899b6e84ed4b1c9e02febad.zip
prop224: Compute start time of next time period.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/hs_common.c16
-rw-r--r--src/or/hs_common.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 01bd204e11..0d81063cf7 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -23,6 +23,7 @@
#include "rendservice.h"
#include "router.h"
#include "shared_random.h"
+#include "shared_random_state.h"
/* Ed25519 Basepoint value. Taken from section 5 of
* https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03 */
@@ -216,6 +217,21 @@ hs_get_next_time_period_num(time_t now)
return hs_get_time_period_num(now) + 1;
}
+/* Return the start time of the upcoming time period based on <b>now</b>. */
+time_t
+hs_get_start_time_of_next_time_period(time_t now)
+{
+ uint64_t time_period_length = get_time_period_length();
+
+ /* Get start time of next time period */
+ uint64_t next_time_period_num = hs_get_next_time_period_num(now);
+ uint64_t start_of_next_tp_in_mins = next_time_period_num *time_period_length;
+
+ /* Apply rotation offset as specified by prop224 section [TIME-PERIODS] */
+ unsigned int time_period_rotation_offset = sr_state_get_phase_duration();
+ return start_of_next_tp_in_mins * 60 + time_period_rotation_offset;
+}
+
/* Create a new rend_data_t for a specific given <b>version</b>.
* Return a pointer to the newly allocated data structure. */
static rend_data_t *
diff --git a/src/or/hs_common.h b/src/or/hs_common.h
index cbf1ac113d..519485d576 100644
--- a/src/or/hs_common.h
+++ b/src/or/hs_common.h
@@ -195,6 +195,7 @@ void hs_get_subcredential(const ed25519_public_key_t *identity_pk,
uint64_t hs_get_time_period_num(time_t now);
uint64_t hs_get_next_time_period_num(time_t now);
+time_t hs_get_start_time_of_next_time_period(time_t now);
link_specifier_t *hs_link_specifier_dup(const link_specifier_t *lspec);