aboutsummaryrefslogtreecommitdiff
path: root/src/feature/hs_common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-07-17 16:19:32 -0400
committerNick Mathewson <nickm@torproject.org>2018-07-17 16:19:32 -0400
commite2b744ce38edb8901cff3288634c4ebb5b4568b9 (patch)
tree9af8bf64a8ed5412ea7b55bd08f3e390867ce770 /src/feature/hs_common
parent12afdcc15a8429bcc50d9287321849b6fa924c2f (diff)
parent14b507e5207ce7e581c5fc773921f8cf65d08247 (diff)
downloadtor-e2b744ce38edb8901cff3288634c4ebb5b4568b9.tar.gz
tor-e2b744ce38edb8901cff3288634c4ebb5b4568b9.zip
Merge branch 'bug25552_ope_squashed'
Diffstat (limited to 'src/feature/hs_common')
-rw-r--r--src/feature/hs_common/shared_random_client.c36
-rw-r--r--src/feature/hs_common/shared_random_client.h3
2 files changed, 30 insertions, 9 deletions
diff --git a/src/feature/hs_common/shared_random_client.c b/src/feature/hs_common/shared_random_client.c
index 329f053d3b..ff98a719db 100644
--- a/src/feature/hs_common/shared_random_client.c
+++ b/src/feature/hs_common/shared_random_client.c
@@ -222,24 +222,44 @@ sr_parse_srv(const smartlist_t *args)
return srv;
}
-/** Return the start time of the current SR protocol run. For example, if the
- * time is 23/06/2017 23:47:08 and a full SR protocol run is 24 hours, this
- * function should return 23/06/2017 00:00:00. */
+/** Return the start time of the current SR protocol run using the times from
+ * the current consensus. For example, if the latest consensus valid-after is
+ * 23/06/2017 23:00:00 and a full SR protocol run is 24 hours, this function
+ * returns 23/06/2017 00:00:00. */
time_t
-sr_state_get_start_time_of_current_protocol_run(time_t now)
+sr_state_get_start_time_of_current_protocol_run(void)
{
int total_rounds = SHARED_RANDOM_N_ROUNDS * SHARED_RANDOM_N_PHASES;
int voting_interval = get_voting_interval();
/* Find the time the current round started. */
- time_t beginning_of_current_round = get_start_time_of_current_round();
+ time_t beginning_of_curr_round = get_start_time_of_current_round();
/* Get current SR protocol round */
- int current_round = (now / voting_interval) % total_rounds;
+ int curr_round_slot;
+ curr_round_slot = (beginning_of_curr_round / voting_interval) % total_rounds;
/* Get start time by subtracting the time elapsed from the beginning of the
protocol run */
- time_t time_elapsed_since_start_of_run = current_round * voting_interval;
- return beginning_of_current_round - time_elapsed_since_start_of_run;
+ time_t time_elapsed_since_start_of_run = curr_round_slot * voting_interval;
+
+ log_debug(LD_GENERAL, "Current SRV proto run: Start of current round: %u. "
+ "Time elapsed: %u (%d)", (unsigned) beginning_of_curr_round,
+ (unsigned) time_elapsed_since_start_of_run, voting_interval);
+
+ return beginning_of_curr_round - time_elapsed_since_start_of_run;
+}
+
+/** Return the start time of the previous SR protocol run. See
+ * sr_state_get_start_time_of_current_protocol_run() for more details. */
+time_t
+sr_state_get_start_time_of_previous_protocol_run(void)
+{
+ time_t start_time_of_current_run =
+ sr_state_get_start_time_of_current_protocol_run();
+
+ /* We get the start time of previous protocol run, by getting the start time
+ * of current run and the subtracting a full protocol run from that. */
+ return start_time_of_current_run - sr_state_get_protocol_run_duration();
}
/** Return the time (in seconds) it takes to complete a full SR protocol phase
diff --git a/src/feature/hs_common/shared_random_client.h b/src/feature/hs_common/shared_random_client.h
index 497a015c18..0e26f530a4 100644
--- a/src/feature/hs_common/shared_random_client.h
+++ b/src/feature/hs_common/shared_random_client.h
@@ -34,7 +34,8 @@ sr_srv_t *sr_parse_srv(const smartlist_t *args);
/* Number of phase we have in a protocol. */
#define SHARED_RANDOM_N_PHASES 2
-time_t sr_state_get_start_time_of_current_protocol_run(time_t now);
+time_t sr_state_get_start_time_of_current_protocol_run(void);
+time_t sr_state_get_start_time_of_previous_protocol_run(void);
unsigned int sr_state_get_phase_duration(void);
unsigned int sr_state_get_protocol_run_duration(void);
time_t get_start_time_of_current_round(void);