aboutsummaryrefslogtreecommitdiff
path: root/src/feature/hs_common
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2018-08-17 15:10:20 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2018-08-22 18:09:47 +0300
commit5febea0d54ea986ab66dc62905a686cc23abbcb6 (patch)
treed8ab754ed033a0dbf3ed8c286215f90118653ac8 /src/feature/hs_common
parent075fcb599c095d18ba554084b910619a6971cc44 (diff)
downloadtor-5febea0d54ea986ab66dc62905a686cc23abbcb6.tar.gz
tor-5febea0d54ea986ab66dc62905a686cc23abbcb6.zip
Fix revision counter bugs caused by bad SRV start time computation.
Bug description: For each descriptor, its revision counter is the OPE ciphertext of the number of seconds since the start time of its SRV value. This bug caused us to confuse the SRV start time in the middle of the lifetime of a descriptor in some edge-cases, which caused descriptor rejects. Bug cause: The bug occurs when we fetch a 23:00 consensus after midnight (e.g. at 00:08 when not all dirauths have fetched the latest 00:00 consensus). In that case, the voting schedule (which was used for SRV start time calculation) would return a valid-after past-midnight, whereas our consensus would be pre-midnight, and that would confuse the SRV start time computation which is used by HS revision counters (because we would reset the start time of SRV, without rotating descriptors). Bug fix: We now use our local consensus time to calculate the SRV start time, instead of the voting schedule. The voting schedule does not work as originally envisioned in this case, because it was created for voting by dirauths and not for scheduling stuff on clients.
Diffstat (limited to 'src/feature/hs_common')
-rw-r--r--src/feature/hs_common/shared_random_client.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/feature/hs_common/shared_random_client.c b/src/feature/hs_common/shared_random_client.c
index ff98a719db..a13404a329 100644
--- a/src/feature/hs_common/shared_random_client.c
+++ b/src/feature/hs_common/shared_random_client.c
@@ -51,9 +51,13 @@ get_voting_interval(void)
return interval;
}
-/* Given the time <b>now</b>, return the start time of the current round of
+/* Given the current consensus, return the start time of the current round of
* the SR protocol. For example, if it's 23:47:08, the current round thus
- * started at 23:47:00 for a voting interval of 10 seconds. */
+ * started at 23:47:00 for a voting interval of 10 seconds.
+ *
+ * This function uses the consensus voting schedule to derive its results,
+ * instead of the actual consensus we are currently using, so it should be used
+ * for voting purposes. */
time_t
get_start_time_of_current_round(void)
{
@@ -231,8 +235,17 @@ 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_curr_round = get_start_time_of_current_round();
+ time_t beginning_of_curr_round;
+
+ /* This function is not used for voting purposes, so if we have a live
+ consensus, use its valid-after as the beginning of the current round,
+ otherwise resort to the voting schedule which should always exist. */
+ networkstatus_t *ns = networkstatus_get_live_consensus(approx_time());
+ if (ns) {
+ beginning_of_curr_round = ns->valid_after;
+ } else {
+ beginning_of_curr_round = get_start_time_of_current_round();
+ }
/* Get current SR protocol round */
int curr_round_slot;