Pārlūkot izejas kodu

Update dirvote_act() to return the time of its next action.

This is remarkably simple, given the macros in the last commit.
Nick Mathewson 6 gadi atpakaļ
vecāks
revīzija
9870497f9d
2 mainītis faili ar 18 papildinājumiem un 6 dzēšanām
  1. 15 4
      src/or/dirauth/dirvote.c
  2. 3 2
      src/or/dirauth/dirvote.h

+ 15 - 4
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
 }

+ 3 - 2
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