[tor-commits] [tor/master] vote: Move dirvote_recalculate_timing() to voting_schedule.c

nickm at torproject.org nickm at torproject.org
Tue May 1 15:51:58 UTC 2018


commit 2d79d0155e3bdf42c2b8ff450d4d4bd85ee17c72
Author: David Goulet <dgoulet at torproject.org>
Date:   Tue May 1 11:25:25 2018 -0400

    vote: Move dirvote_recalculate_timing() to voting_schedule.c
    
    By doing so, it is renamed to voting_schedule_recalculate_timing(). This
    required a lot of changes to include voting_schedule.h everywhere that this
    function was used.
    
    This effectively now makes voting_schedule.{c|h} not include dirauth/dirvote.h
    for that symbol and thus no dependency on the dirauth module anymore.
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/or/config.c                |  3 ++-
 src/or/dirauth/dirvote.c       |  4 ++--
 src/or/dirauth/dirvote.h       |  1 -
 src/or/networkstatus.c         |  3 ++-
 src/or/voting_schedule.c       |  6 ++----
 src/or/voting_schedule.h       |  3 +++
 src/test/test_dir.c            |  3 ++-
 src/test/test_dir_handle_get.c |  7 ++++---
 src/test/test_hs_common.c      | 19 +++++++++++--------
 src/test/test_hs_service.c     |  7 ++++---
 src/test/test_shared_random.c  | 19 ++++++++++---------
 11 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 2b35138b6..a2b84991a 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -104,6 +104,7 @@
 #include "statefile.h"
 #include "transports.h"
 #include "ext_orport.h"
+#include "voting_schedule.h"
 #ifdef _WIN32
 #include <shlobj.h>
 #endif
@@ -2359,7 +2360,7 @@ options_act(const or_options_t *old_options)
   /* We may need to reschedule some directory stuff if our status changed. */
   if (old_options) {
     if (options_transition_affects_dirauth_timing(old_options, options)) {
-      dirvote_recalculate_timing(options, time(NULL));
+      voting_schedule_recalculate_timing(options, time(NULL));
       reschedule_dirvote(options);
     }
     if (!bool_eq(directory_fetches_dir_info_early(options),
diff --git a/src/or/dirauth/dirvote.c b/src/or/dirauth/dirvote.c
index b67b78cbb..6b7114b14 100644
--- a/src/or/dirauth/dirvote.c
+++ b/src/or/dirauth/dirvote.c
@@ -2768,7 +2768,7 @@ dirvote_act(const or_options_t *options, time_t now)
                "Mine is %s.",
                keys, hex_str(c->cache_info.identity_digest, DIGEST_LEN));
     tor_free(keys);
-    dirvote_recalculate_timing(options, now);
+    voting_schedule_recalculate_timing(options, now);
   }
 
 #define IF_TIME_FOR_NEXT_ACTION(when_field, done_field) \
@@ -2814,7 +2814,7 @@ dirvote_act(const or_options_t *options, time_t now)
                 networkstatus_get_latest_consensus_by_flavor(FLAV_NS));
     /* 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);
+    voting_schedule_recalculate_timing(options, now);
     return voting_schedule.voting_starts;
   } ENDIF
 
diff --git a/src/or/dirauth/dirvote.h b/src/or/dirauth/dirvote.h
index 729496292..228121268 100644
--- a/src/or/dirauth/dirvote.h
+++ b/src/or/dirauth/dirvote.h
@@ -178,7 +178,6 @@ dirvote_add_signatures(const char *detached_signatures_body, const char *source,
 
 #endif /* HAVE_MODULE_DIRAUTH */
 
-void dirvote_recalculate_timing(const or_options_t *options, time_t now);
 /* Item access */
 MOCK_DECL(const char*, dirvote_get_pending_consensus,
           (consensus_flavor_t flav));
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 99f149020..ac3e94e88 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -67,6 +67,7 @@
 #include "transports.h"
 #include "torcert.h"
 #include "channelpadding.h"
+#include "voting_schedule.h"
 
 #include "dirauth/dirvote.h"
 
@@ -2014,7 +2015,7 @@ networkstatus_set_current_consensus(const char *consensus,
      * the first thing we need to do is recalculate the voting schedule static
      * object so we can use the timings in there needed by some subsystems
      * such as hidden service and shared random. */
-    dirvote_recalculate_timing(options, now);
+    voting_schedule_recalculate_timing(options, now);
     reschedule_dirvote(options);
 
     nodelist_set_consensus(c);
diff --git a/src/or/voting_schedule.c b/src/or/voting_schedule.c
index 88415993c..b7676d5e7 100644
--- a/src/or/voting_schedule.c
+++ b/src/or/voting_schedule.c
@@ -15,8 +15,6 @@
 #include "config.h"
 #include "networkstatus.h"
 
-#include "dirauth/dirvote.h"
-
 /* =====
  * Vote scheduling
  * ===== */
@@ -143,7 +141,7 @@ voting_schedule_get_next_valid_after_time(void)
    * voting schedule can lead to bugs. */
   if (tor_mem_is_zero((const char *) &voting_schedule,
                       sizeof(voting_schedule))) {
-    dirvote_recalculate_timing(get_options(), time(NULL));
+    voting_schedule_recalculate_timing(get_options(), time(NULL));
     voting_schedule.created_on_demand = 1;
   }
   return voting_schedule.interval_starts;
@@ -153,7 +151,7 @@ voting_schedule_get_next_valid_after_time(void)
  * doing. All type of tor do that because HS subsystem needs the timing as
  * well to function properly. */
 void
-dirvote_recalculate_timing(const or_options_t *options, time_t now)
+voting_schedule_recalculate_timing(const or_options_t *options, time_t now)
 {
   voting_schedule_t *new_voting_schedule;
 
diff --git a/src/or/voting_schedule.h b/src/or/voting_schedule.h
index cd45914db..4f9d58403 100644
--- a/src/or/voting_schedule.h
+++ b/src/or/voting_schedule.h
@@ -49,6 +49,9 @@ typedef struct {
 
 extern voting_schedule_t voting_schedule;
 
+void voting_schedule_recalculate_timing(const or_options_t *options,
+                                        time_t now);
+
 time_t voting_schedule_get_start_of_next_interval(time_t now,
                                                   int interval,
                                                   int offset);
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 84fdb96e4..492753029 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -41,6 +41,7 @@
 #include "torcert.h"
 #include "relay.h"
 #include "log_test_helpers.h"
+#include "voting_schedule.h"
 
 #define NS_MODULE dir
 
@@ -2379,7 +2380,7 @@ test_a_networkstatus(
   sign_skey_2 = crypto_pk_new();
   sign_skey_3 = crypto_pk_new();
   sign_skey_leg1 = pk_generate(4);
-  dirvote_recalculate_timing(get_options(), now);
+  voting_schedule_recalculate_timing(get_options(), now);
   sr_state_init(0, 0);
 
   tt_assert(!crypto_pk_read_private_key_from_string(sign_skey_1,
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index 1bff249df..688d26bdc 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -32,6 +32,7 @@
 #include "dirserv.h"
 #include "dirauth/dirvote.h"
 #include "log_test_helpers.h"
+#include "voting_schedule.h"
 
 #ifdef _WIN32
 /* For mkdir() */
@@ -2056,7 +2057,7 @@ test_dir_handle_get_status_vote_d(void* data)
   mock_options->TestingV3AuthInitialDistDelay = 1;
 
   time_t now = 1441223455 -1;
-  dirvote_recalculate_timing(mock_options, now);
+  voting_schedule_recalculate_timing(mock_options, now);
 
   const char *msg_out = NULL;
   int status_out = 0;
@@ -2402,7 +2403,7 @@ test_dir_handle_get_status_vote_next_authority(void* data)
   mock_options->TestingV3AuthInitialDistDelay = 1;
 
   time_t now = 1441223455 -1;
-  dirvote_recalculate_timing(mock_options, now);
+  voting_schedule_recalculate_timing(mock_options, now);
 
   struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
                                                  &status_out);
@@ -2481,7 +2482,7 @@ test_dir_handle_get_status_vote_current_authority(void* data)
   mock_options->TestingV3AuthInitialDistDelay = 1;
 
   time_t now = 1441223455;
-  dirvote_recalculate_timing(mock_options, now-1);
+  voting_schedule_recalculate_timing(mock_options, now-1);
 
   struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
                                                  &status_out);
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index 43a2c5e80..dcca5713e 100644
--- a/src/test/test_hs_common.c
+++ b/src/test/test_hs_common.c
@@ -30,6 +30,7 @@
 #include "circuitlist.h"
 #include "dirauth/shared_random.h"
 #include "util.h"
+#include "voting_schedule.h"
 
 /** Test the validation of HS v3 addresses */
 static void
@@ -812,7 +813,7 @@ test_time_between_tp_and_srv(void *arg)
   tt_int_op(ret, OP_EQ, 0);
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 01:00:00 UTC", &ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), ns.valid_after);
   ret = hs_in_period_between_tp_and_srv(&ns, 0);
   tt_int_op(ret, OP_EQ, 0);
 
@@ -820,7 +821,7 @@ test_time_between_tp_and_srv(void *arg)
   tt_int_op(ret, OP_EQ, 0);
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 12:00:00 UTC", &ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), ns.valid_after);
   ret = hs_in_period_between_tp_and_srv(&ns, 0);
   tt_int_op(ret, OP_EQ, 0);
 
@@ -828,7 +829,7 @@ test_time_between_tp_and_srv(void *arg)
   tt_int_op(ret, OP_EQ, 0);
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", &ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), ns.valid_after);
   ret = hs_in_period_between_tp_and_srv(&ns, 0);
   tt_int_op(ret, OP_EQ, 1);
 
@@ -836,7 +837,7 @@ test_time_between_tp_and_srv(void *arg)
   tt_int_op(ret, OP_EQ, 0);
   ret = parse_rfc1123_time("Sat, 27 Oct 1985 00:00:00 UTC", &ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), ns.valid_after);
   ret = hs_in_period_between_tp_and_srv(&ns, 0);
   tt_int_op(ret, OP_EQ, 1);
 
@@ -844,7 +845,7 @@ test_time_between_tp_and_srv(void *arg)
   tt_int_op(ret, OP_EQ, 0);
   ret = parse_rfc1123_time("Sat, 27 Oct 1985 01:00:00 UTC", &ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), ns.valid_after);
   ret = hs_in_period_between_tp_and_srv(&ns, 0);
   tt_int_op(ret, OP_EQ, 0);
 
@@ -1331,7 +1332,8 @@ run_reachability_scenario(const reachability_cfg_t *cfg, int num_scenario)
                       &mock_service_ns->valid_until);
   set_consensus_times(cfg->service_valid_until,
                       &mock_service_ns->fresh_until);
-  dirvote_recalculate_timing(get_options(), mock_service_ns->valid_after);
+  voting_schedule_recalculate_timing(get_options(),
+                                     mock_service_ns->valid_after);
   /* Set client consensus time. */
   set_consensus_times(cfg->client_valid_after,
                       &mock_client_ns->valid_after);
@@ -1339,7 +1341,8 @@ run_reachability_scenario(const reachability_cfg_t *cfg, int num_scenario)
                       &mock_client_ns->valid_until);
   set_consensus_times(cfg->client_valid_until,
                       &mock_client_ns->fresh_until);
-  dirvote_recalculate_timing(get_options(), mock_client_ns->valid_after);
+  voting_schedule_recalculate_timing(get_options(),
+                                     mock_client_ns->valid_after);
 
   /* New time period checks for this scenario. */
   tt_int_op(hs_in_period_between_tp_and_srv(mock_service_ns, 0), OP_EQ,
@@ -1563,7 +1566,7 @@ helper_set_consensus_and_system_time(networkstatus_t *ns, int position)
   } else {
     tt_assert(0);
   }
-  dirvote_recalculate_timing(get_options(), ns->valid_after);
+  voting_schedule_recalculate_timing(get_options(), ns->valid_after);
 
   /* Set system time: pretend to be just 2 minutes before consensus expiry */
   real_time = ns->valid_until - 120;
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index fc8e016b5..d2198c621 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -52,6 +52,7 @@
 #include "rendservice.h"
 #include "statefile.h"
 #include "dirauth/shared_random_state.h"
+#include "voting_schedule.h"
 
 /* Trunnel */
 #include "hs/cell_establish_intro.h"
@@ -1057,7 +1058,7 @@ test_rotate_descriptors(void *arg)
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
                            &mock_ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), mock_ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
 
   /* Create a service with a default descriptor and state. It's added to the
    * global map. */
@@ -1095,7 +1096,7 @@ test_rotate_descriptors(void *arg)
   ret = parse_rfc1123_time("Sat, 27 Oct 1985 02:00:00 UTC",
                            &mock_ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), mock_ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
 
   /* Note down what to expect for the next rotation time which is 01:00 + 23h
    * meaning 00:00:00. */
@@ -1157,7 +1158,7 @@ test_build_update_descriptors(void *arg)
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 04:00:00 UTC",
                            &mock_ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
-  dirvote_recalculate_timing(get_options(), mock_ns.valid_after);
+  voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
 
   /* Create a service without a current descriptor to trigger a build. */
   service = helper_create_service();
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 95a7ff28f..1c16524b6 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -19,6 +19,7 @@
 #include "shared_random_common.h"
 #include "networkstatus.h"
 #include "log_test_helpers.h"
+#include "voting_schedule.h"
 
 static authority_cert_t *mock_cert;
 
@@ -171,7 +172,7 @@ test_get_state_valid_until_time(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:01 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     valid_until_time = get_state_valid_until_time(current_time);
 
     /* Compare it with the correct result */
@@ -183,7 +184,7 @@ test_get_state_valid_until_time(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 19:22:00 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     valid_until_time = get_state_valid_until_time(current_time);
 
     format_iso_time(tbuf, valid_until_time);
@@ -194,7 +195,7 @@ test_get_state_valid_until_time(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 23:59:00 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     valid_until_time = get_state_valid_until_time(current_time);
 
     format_iso_time(tbuf, valid_until_time);
@@ -205,7 +206,7 @@ test_get_state_valid_until_time(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     valid_until_time = get_state_valid_until_time(current_time);
 
     format_iso_time(tbuf, valid_until_time);
@@ -243,7 +244,7 @@ test_get_start_time_of_current_run(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:01 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     run_start_time =
       sr_state_get_start_time_of_current_protocol_run(current_time);
 
@@ -256,7 +257,7 @@ test_get_start_time_of_current_run(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 23:59:59 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     run_start_time =
       sr_state_get_start_time_of_current_protocol_run(current_time);
 
@@ -269,7 +270,7 @@ test_get_start_time_of_current_run(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     run_start_time =
       sr_state_get_start_time_of_current_protocol_run(current_time);
 
@@ -292,7 +293,7 @@ test_get_start_time_of_current_run(void *arg)
     retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:15:32 UTC",
                                 &current_time);
     tt_int_op(retval, OP_EQ, 0);
-    dirvote_recalculate_timing(get_options(), current_time);
+    voting_schedule_recalculate_timing(get_options(), current_time);
     run_start_time =
       sr_state_get_start_time_of_current_protocol_run(current_time);
 
@@ -325,7 +326,7 @@ test_get_start_time_functions(void *arg)
   tt_int_op(retval, OP_EQ, 0);
   time_t now = mock_consensus.valid_after;
 
-  dirvote_recalculate_timing(get_options(), now);
+  voting_schedule_recalculate_timing(get_options(), now);
   time_t start_time_of_protocol_run =
     sr_state_get_start_time_of_current_protocol_run(now);
   tt_assert(start_time_of_protocol_run);





More information about the tor-commits mailing list