commit 9870497f9df909c6a48a6f6c1e82171e99aa33a4 Author: Nick Mathewson nickm@torproject.org Date: Thu Apr 26 17:42:43 2018 -0400
Update dirvote_act() to return the time of its next action.
This is remarkably simple, given the macros in the last commit. --- src/or/dirauth/dirvote.c | 19 +++++++++++++++---- src/or/dirauth/dirvote.h | 5 +++-- 2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/or/dirauth/dirvote.c b/src/or/dirauth/dirvote.c index 90f8d2227..36f328d6c 100644 --- a/src/or/dirauth/dirvote.c +++ b/src/or/dirauth/dirvote.c @@ -2731,12 +2731,14 @@ get_detached_signatures_from_pending_consensuses(pending_consensus_t *pending,
/** * Entry point: Take whatever voting actions are pending as of <b>now</b>. + * + * Return the time at which the next action should be taken. */ -void +time_t dirvote_act(const or_options_t *options, time_t now) { if (!authdir_mode_v3(options)) - return; + return TIME_MAX; tor_assert_nonfatal(voting_schedule.voting_starts); /* If we haven't initialized this object through this codeflow, we need to * recalculate the timings to match our vote. The reason to do that is if we @@ -2754,8 +2756,13 @@ dirvote_act(const or_options_t *options, time_t now) }
#define IF_TIME_FOR_NEXT_ACTION(when_field, done_field) \ - if (voting_schedule.when_field < now && !voting_schedule.done_field) do { -#define ENDIF } while(0); + if (! voting_schedule.done_field) { \ + if (voting_schedule.when_field > now) { \ + return voting_schedule.when_field; \ + } else { +#define ENDIF \ + } \ + }
IF_TIME_FOR_NEXT_ACTION(voting_starts, have_voted) { log_notice(LD_DIR, "Time to vote."); @@ -2792,8 +2799,12 @@ dirvote_act(const or_options_t *options, time_t now) /* XXXX We will want to try again later if we haven't got enough * signatures yet. Implement this if it turns out to ever happen. */ dirvote_recalculate_timing(options, now); + return voting_schedule.voting_starts; } ENDIF
+ tor_assert_nonfatal_unreached(); + return now + 1; + #undef ENDIF #undef IF_TIME_FOR_NEXT_ACTION } diff --git a/src/or/dirauth/dirvote.h b/src/or/dirauth/dirvote.h index f69e872c8..729496292 100644 --- a/src/or/dirauth/dirvote.h +++ b/src/or/dirauth/dirvote.h @@ -96,7 +96,7 @@ */ #ifdef HAVE_MODULE_DIRAUTH
-void dirvote_act(const or_options_t *options, time_t now); +time_t dirvote_act(const or_options_t *options, time_t now); void dirvote_free_all(void);
void dirvote_parse_sr_commits(networkstatus_t *ns, smartlist_t *tokens); @@ -114,11 +114,12 @@ int dirvote_add_signatures(const char *detached_signatures_body,
#else /* HAVE_MODULE_DIRAUTH */
-static inline void +static inline time_t dirvote_act(const or_options_t *options, time_t now) { (void) options; (void) now; + return TIME_MAX; }
static inline void