summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-24 13:30:04 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commit0b22b7fce3f1ce97a85f4022533b206f847b7307 (patch)
tree44eff9cd6443b39b27380a719c2d7e615ba46e0f /src/or
parent2af254096f68f0cefadb5cb06b010d19edd2e6e1 (diff)
downloadtor-0b22b7fce3f1ce97a85f4022533b206f847b7307.tar.gz
tor-0b22b7fce3f1ce97a85f4022533b206f847b7307.zip
SR: Calculate current SRV phase/run duration.
This is also needed to make the HS desc overlap mode function independent of absolute hours.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/shared_random_state.c16
-rw-r--r--src/or/shared_random_state.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
index 1fc1440d0d..7f8094dafd 100644
--- a/src/or/shared_random_state.c
+++ b/src/or/shared_random_state.c
@@ -176,6 +176,22 @@ sr_state_get_start_time_of_current_protocol_run(time_t now)
return beginning_of_current_round - time_elapsed_since_start_of_run;
}
+/** Return the time (in seconds) it takes to complete a full SR protocol phase
+ * (e.g. the commit phase). */
+unsigned int
+sr_state_get_phase_duration(void)
+{
+ return SHARED_RANDOM_N_ROUNDS * get_voting_interval();
+}
+
+/** Return the time (in seconds) it takes to complete a full SR protocol run */
+unsigned int
+sr_state_get_protocol_run_duration(void)
+{
+ int total_protocol_rounds = SHARED_RANDOM_N_ROUNDS * SHARED_RANDOM_N_PHASES;
+ return total_protocol_rounds * get_voting_interval();
+}
+
/* Return the time we should expire the state file created at <b>now</b>.
* We expire the state file in the beginning of the next protocol run. */
STATIC time_t
diff --git a/src/or/shared_random_state.h b/src/or/shared_random_state.h
index ae1c5ac219..03dd5eb37e 100644
--- a/src/or/shared_random_state.h
+++ b/src/or/shared_random_state.h
@@ -122,6 +122,8 @@ void sr_state_save(void);
void sr_state_free(void);
time_t sr_state_get_start_time_of_current_protocol_run(time_t now);
+unsigned int sr_state_get_phase_duration(void);
+unsigned int sr_state_get_protocol_run_duration(void);
#ifdef SHARED_RANDOM_STATE_PRIVATE