diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-20 08:05:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-20 08:05:07 -0400 |
commit | 11a76b903b283ee39ab0dbf9d926d4c4b60b7a92 (patch) | |
tree | 94e6e66939beb2560b0901762bfd8c37f0e738cb /src/or/voting_schedule.c | |
parent | 334edc22d1bd05cbadb1ccc132d099e8a282bff4 (diff) | |
parent | 7b9cd5cca54d0077c0f8c163a58b055c85bf067f (diff) | |
download | tor-11a76b903b283ee39ab0dbf9d926d4c4b60b7a92.tar.gz tor-11a76b903b283ee39ab0dbf9d926d4c4b60b7a92.zip |
Merge branch 'maint-0.3.4'
Diffstat (limited to 'src/or/voting_schedule.c')
-rw-r--r-- | src/or/voting_schedule.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/or/voting_schedule.c b/src/or/voting_schedule.c index 983cabbbf3..9d2ebd0385 100644 --- a/src/or/voting_schedule.c +++ b/src/or/voting_schedule.c @@ -85,6 +85,10 @@ get_voting_schedule(const or_options_t *options, time_t now, int severity) interval = (int)( consensus->fresh_until - consensus->valid_after ); vote_delay = consensus->vote_seconds; dist_delay = consensus->dist_seconds; + + /* Note down the consensus valid after, so that we detect outdated voting + * schedules in case of skewed clocks etc. */ + new_voting_schedule->live_consensus_valid_after = consensus->valid_after; } else { interval = options->TestingV3AuthInitialVotingInterval; vote_delay = options->TestingV3AuthInitialVoteDelay; @@ -140,14 +144,34 @@ voting_schedule_t voting_schedule; time_t voting_schedule_get_next_valid_after_time(void) { + time_t now = approx_time(); + bool need_to_recalculate_voting_schedule = false; + /* This is a safe guard in order to make sure that the voting schedule * static object is at least initialized. Using this function with a zeroed * voting schedule can lead to bugs. */ if (tor_mem_is_zero((const char *) &voting_schedule, sizeof(voting_schedule))) { - voting_schedule_recalculate_timing(get_options(), time(NULL)); + need_to_recalculate_voting_schedule = true; + goto done; /* no need for next check if we have to recalculate anyway */ + } + + /* Also make sure we are not using an outdated voting schedule. If we have a + * newer consensus, make sure we recalculate the voting schedule. */ + const networkstatus_t *ns = networkstatus_get_live_consensus(now); + if (ns && ns->valid_after != voting_schedule.live_consensus_valid_after) { + log_info(LD_DIR, "Voting schedule is outdated: recalculating (%d/%d)", + (int) ns->valid_after, + (int) voting_schedule.live_consensus_valid_after); + need_to_recalculate_voting_schedule = true; + } + + done: + if (need_to_recalculate_voting_schedule) { + voting_schedule_recalculate_timing(get_options(), now); voting_schedule.created_on_demand = 1; } + return voting_schedule.interval_starts; } |