summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2018-06-14 15:25:43 +0300
committerNick Mathewson <nickm@torproject.org>2018-07-17 15:57:46 -0400
commitdeec6913c5a30a568fd761c707867e2001646237 (patch)
tree740c8def89ec291cdf640a58f5d3d736c3d46364 /src
parent34a5eb5904896cfbfb8c2729fe3b029fab6deb39 (diff)
downloadtor-deec6913c5a30a568fd761c707867e2001646237.tar.gz
tor-deec6913c5a30a568fd761c707867e2001646237.zip
Introduce useful SRV funcs (start time of prev protocol run)
Diffstat (limited to 'src')
-rw-r--r--src/or/shared_random_client.c13
-rw-r--r--src/or/shared_random_client.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/or/shared_random_client.c b/src/or/shared_random_client.c
index f0b13a171e..d787b6b2ec 100644
--- a/src/or/shared_random_client.c
+++ b/src/or/shared_random_client.c
@@ -243,6 +243,19 @@ 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 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(time_t now)
+{
+ time_t start_time_of_current_run =
+ sr_state_get_start_time_of_current_protocol_run(now);
+
+ /* 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
* (e.g. the commit phase). */
unsigned int
diff --git a/src/or/shared_random_client.h b/src/or/shared_random_client.h
index 079829496c..35ebb1bd57 100644
--- a/src/or/shared_random_client.h
+++ b/src/or/shared_random_client.h
@@ -35,6 +35,7 @@ sr_srv_t *sr_parse_srv(const smartlist_t *args);
#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_previous_protocol_run(time_t now);
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);