Browse Source

Add support for offsetting the voting interval in order to bootstrap faster.

A new option TestingV3AuthVotingStartOffset is added which offsets the
starting time of the voting interval. This is possible only when
TestingTorNetwork is set.

This patch makes run_scheduled_events() check for new consensus
downloads every second when TestingTorNetwork, instead of every
minute. This should be fine, see #8532 for reasoning.

This patch also brings MIN_VOTE_SECONDS and MIN_DIST_SECONDS down from
20 to 2 seconds, unconditionally. This makes sanity checking of
misconfiguration slightly less sane.

Addresses #8532.
Linus Nordberg 11 years ago
parent
commit
4d54b9774d
8 changed files with 55 additions and 14 deletions
  1. 4 0
      changes/bug8532
  2. 4 0
      doc/tor.1.txt
  3. 10 0
      src/or/config.c
  4. 2 1
      src/or/dirserv.c
  5. 14 7
      src/or/dirvote.c
  6. 5 3
      src/or/dirvote.h
  7. 12 3
      src/or/main.c
  8. 4 0
      src/or/or.h

+ 4 - 0
changes/bug8532

@@ -0,0 +1,4 @@
+  o Minor features
+    - Add support for offsetting the voting interval in order to
+      bootstrap a network faster by adding configuration option
+      TestingV3AuthVotingStartOffset. Addresses #8532.

+ 4 - 0
doc/tor.1.txt

@@ -2032,6 +2032,10 @@ The following options are used for running a testing Tor network.
     the first consensus has been created. Changing this requires that
     the first consensus has been created. Changing this requires that
     **TestingTorNetwork** is set. (Default: 5 minutes)
     **TestingTorNetwork** is set. (Default: 5 minutes)
 
 
+**TestingV3AuthVotingStartOffset** __N__ **seconds**|**minutes**|**hours**::
+    Directory authorities offset voting start time by this much.
+    Changing this requires that **TestingTorNetwork** is set. (Default: 0)
+
 **TestingAuthDirTimeToLearnReachability** __N__ **minutes**|**hours**::
 **TestingAuthDirTimeToLearnReachability** __N__ **minutes**|**hours**::
     After starting as an authority, do not make claims about whether routers
     After starting as an authority, do not make claims about whether routers
     are Running until this much time has passed. Changing this requires
     are Running until this much time has passed. Changing this requires

+ 10 - 0
src/or/config.c

@@ -413,6 +413,7 @@ static config_var_t option_vars_[] = {
   V(TestingV3AuthInitialVotingInterval, INTERVAL, "30 minutes"),
   V(TestingV3AuthInitialVotingInterval, INTERVAL, "30 minutes"),
   V(TestingV3AuthInitialVoteDelay, INTERVAL, "5 minutes"),
   V(TestingV3AuthInitialVoteDelay, INTERVAL, "5 minutes"),
   V(TestingV3AuthInitialDistDelay, INTERVAL, "5 minutes"),
   V(TestingV3AuthInitialDistDelay, INTERVAL, "5 minutes"),
+  V(TestingV3AuthVotingStartOffset, INTERVAL, "0"),
   V(V3AuthVotingInterval,        INTERVAL, "1 hour"),
   V(V3AuthVotingInterval,        INTERVAL, "1 hour"),
   V(V3AuthVoteDelay,             INTERVAL, "5 minutes"),
   V(V3AuthVoteDelay,             INTERVAL, "5 minutes"),
   V(V3AuthDistDelay,             INTERVAL, "5 minutes"),
   V(V3AuthDistDelay,             INTERVAL, "5 minutes"),
@@ -475,6 +476,7 @@ static const config_var_t testing_tor_network_defaults[] = {
   V(TestingV3AuthInitialVotingInterval, INTERVAL, "5 minutes"),
   V(TestingV3AuthInitialVotingInterval, INTERVAL, "5 minutes"),
   V(TestingV3AuthInitialVoteDelay, INTERVAL, "20 seconds"),
   V(TestingV3AuthInitialVoteDelay, INTERVAL, "20 seconds"),
   V(TestingV3AuthInitialDistDelay, INTERVAL, "20 seconds"),
   V(TestingV3AuthInitialDistDelay, INTERVAL, "20 seconds"),
+  V(TestingV3AuthVotingStartOffset, INTERVAL, "0"),
   V(TestingAuthDirTimeToLearnReachability, INTERVAL, "0 minutes"),
   V(TestingAuthDirTimeToLearnReachability, INTERVAL, "0 minutes"),
   V(TestingEstimatedDescriptorPropagationTime, INTERVAL, "0 minutes"),
   V(TestingEstimatedDescriptorPropagationTime, INTERVAL, "0 minutes"),
   V(MinUptimeHidServDirectoryV2, INTERVAL, "0 minutes"),
   V(MinUptimeHidServDirectoryV2, INTERVAL, "0 minutes"),
@@ -3224,6 +3226,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
   CHECK_DEFAULT(TestingV3AuthInitialVotingInterval);
   CHECK_DEFAULT(TestingV3AuthInitialVotingInterval);
   CHECK_DEFAULT(TestingV3AuthInitialVoteDelay);
   CHECK_DEFAULT(TestingV3AuthInitialVoteDelay);
   CHECK_DEFAULT(TestingV3AuthInitialDistDelay);
   CHECK_DEFAULT(TestingV3AuthInitialDistDelay);
+  CHECK_DEFAULT(TestingV3AuthVotingStartOffset);
   CHECK_DEFAULT(TestingAuthDirTimeToLearnReachability);
   CHECK_DEFAULT(TestingAuthDirTimeToLearnReachability);
   CHECK_DEFAULT(TestingEstimatedDescriptorPropagationTime);
   CHECK_DEFAULT(TestingEstimatedDescriptorPropagationTime);
   CHECK_DEFAULT(TestingServerDownloadSchedule);
   CHECK_DEFAULT(TestingServerDownloadSchedule);
@@ -3261,6 +3264,13 @@ options_validate(or_options_t *old_options, or_options_t *options,
            "must be less than half TestingV3AuthInitialVotingInterval");
            "must be less than half TestingV3AuthInitialVotingInterval");
   }
   }
 
 
+  if (options->TestingV3AuthVotingStartOffset >
+      MIN(options->TestingV3AuthInitialVotingInterval,
+          options->V3AuthVotingInterval)) {
+    REJECT("TestingV3AuthVotingStartOffset is higher than the voting "
+           "interval.");
+  }
+
   if (options->TestingAuthDirTimeToLearnReachability < 0) {
   if (options->TestingAuthDirTimeToLearnReachability < 0) {
     REJECT("TestingAuthDirTimeToLearnReachability must be non-negative.");
     REJECT("TestingAuthDirTimeToLearnReachability must be non-negative.");
   } else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) {
   } else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) {

+ 2 - 1
src/or/dirserv.c

@@ -3093,7 +3093,8 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
     else
     else
       last_consensus_interval = options->TestingV3AuthInitialVotingInterval;
       last_consensus_interval = options->TestingV3AuthInitialVotingInterval;
     v3_out->valid_after =
     v3_out->valid_after =
-      dirvote_get_start_of_next_interval(now, (int)last_consensus_interval);
+      dirvote_get_start_of_next_interval(now, (int)last_consensus_interval,
+                                      options->TestingV3AuthVotingStartOffset);
     format_iso_time(tbuf, v3_out->valid_after);
     format_iso_time(tbuf, v3_out->valid_after);
     log_notice(LD_DIR,"Choosing valid-after time in vote as %s: "
     log_notice(LD_DIR,"Choosing valid-after time in vote as %s: "
                "consensus_set=%d, last_interval=%d",
                "consensus_set=%d, last_interval=%d",

+ 14 - 7
src/or/dirvote.c

@@ -2523,12 +2523,13 @@ dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out)
   timing_out->dist_delay = options->V3AuthDistDelay;
   timing_out->dist_delay = options->V3AuthDistDelay;
 }
 }
 
 
-/** Return the start of the next interval of size <b>interval</b> (in seconds)
- * after <b>now</b>.  Midnight always starts a fresh interval, and if the last
- * interval of a day would be truncated to less than half its size, it is
- * rolled into the previous interval. */
+/** Return the start of the next interval of size <b>interval</b> (in
+ * seconds) after <b>now</b>, plus <b>offset</b>. Midnight always
+ * starts a fresh interval, and if the last interval of a day would be
+ * truncated to less than half its size, it is rolled into the
+ * previous interval. */
 time_t
 time_t
-dirvote_get_start_of_next_interval(time_t now, int interval)
+dirvote_get_start_of_next_interval(time_t now, int interval, int offset)
 {
 {
   struct tm tm;
   struct tm tm;
   time_t midnight_today=0;
   time_t midnight_today=0;
@@ -2556,6 +2557,10 @@ dirvote_get_start_of_next_interval(time_t now, int interval)
   if (next + interval/2 > midnight_tomorrow)
   if (next + interval/2 > midnight_tomorrow)
     next = midnight_tomorrow;
     next = midnight_tomorrow;
 
 
+  next += offset;
+  if (next - interval > now)
+    next -= interval;
+
   return next;
   return next;
 }
 }
 
 
@@ -2619,8 +2624,10 @@ dirvote_recalculate_timing(const or_options_t *options, time_t now)
     vote_delay = dist_delay = interval / 4;
     vote_delay = dist_delay = interval / 4;
 
 
   start = voting_schedule.interval_starts =
   start = voting_schedule.interval_starts =
-    dirvote_get_start_of_next_interval(now,interval);
-  end = dirvote_get_start_of_next_interval(start+1, interval);
+    dirvote_get_start_of_next_interval(now,interval,
+                                      options->TestingV3AuthVotingStartOffset);
+  end = dirvote_get_start_of_next_interval(start+1, interval,
+                                      options->TestingV3AuthVotingStartOffset);
 
 
   tor_assert(end > start);
   tor_assert(end > start);
 
 

+ 5 - 3
src/or/dirvote.h

@@ -13,9 +13,9 @@
 #define TOR_DIRVOTE_H
 #define TOR_DIRVOTE_H
 
 
 /** Lowest allowable value for VoteSeconds. */
 /** Lowest allowable value for VoteSeconds. */
-#define MIN_VOTE_SECONDS 20
+#define MIN_VOTE_SECONDS 2
 /** Lowest allowable value for DistSeconds. */
 /** Lowest allowable value for DistSeconds. */
-#define MIN_DIST_SECONDS 20
+#define MIN_DIST_SECONDS 2
 /** Smallest allowable voting interval. */
 /** Smallest allowable voting interval. */
 #define MIN_VOTE_INTERVAL 300
 #define MIN_VOTE_INTERVAL 300
 
 
@@ -86,7 +86,9 @@ authority_cert_t *authority_cert_dup(authority_cert_t *cert);
 
 
 /* vote scheduling */
 /* vote scheduling */
 void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
 void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
-time_t dirvote_get_start_of_next_interval(time_t now, int interval);
+time_t dirvote_get_start_of_next_interval(time_t now,
+                                          int interval,
+                                          int offset);
 void dirvote_recalculate_timing(const or_options_t *options, time_t now);
 void dirvote_recalculate_timing(const or_options_t *options, time_t now);
 void dirvote_act(const or_options_t *options, time_t now);
 void dirvote_act(const or_options_t *options, time_t now);
 
 

+ 12 - 3
src/or/main.c

@@ -1153,6 +1153,7 @@ run_scheduled_events(time_t now)
   static time_t time_to_check_v3_certificate = 0;
   static time_t time_to_check_v3_certificate = 0;
   static time_t time_to_check_listeners = 0;
   static time_t time_to_check_listeners = 0;
   static time_t time_to_check_descriptor = 0;
   static time_t time_to_check_descriptor = 0;
+  static time_t time_to_download_networkstatus = 0;
   static time_t time_to_shrink_memory = 0;
   static time_t time_to_shrink_memory = 0;
   static time_t time_to_try_getting_descriptors = 0;
   static time_t time_to_try_getting_descriptors = 0;
   static time_t time_to_reset_descriptor_failures = 0;
   static time_t time_to_reset_descriptor_failures = 0;
@@ -1442,10 +1443,18 @@ run_scheduled_events(time_t now)
     networkstatus_v2_list_clean(now);
     networkstatus_v2_list_clean(now);
     /* Remove dead routers. */
     /* Remove dead routers. */
     routerlist_remove_old_routers();
     routerlist_remove_old_routers();
+  }
 
 
-    /* Also, once per minute, check whether we want to download any
-     * networkstatus documents.
-     */
+  /* 2c. Every minute (or every second if TestingTorNetwork), check
+   * whether we want to download any networkstatus documents. */
+
+/* How often do we check whether we should download network status
+ * documents? */
+#define CHECK_NETWORKSTATUS_DOWNLOAD_INTERVAL (60)
+
+  if (time_to_download_networkstatus < now && !options->DisableNetwork) {
+    time_to_download_networkstatus = now +
+      options->TestingTorNetwork ? 1 : CHECK_NETWORKSTATUS_DOWNLOAD_INTERVAL;
     update_networkstatus_downloads(now);
     update_networkstatus_downloads(now);
   }
   }
 
 

+ 4 - 0
src/or/or.h

@@ -3897,6 +3897,10 @@ typedef struct {
    * signatures.  Only altered on testing networks.*/
    * signatures.  Only altered on testing networks.*/
   int TestingV3AuthInitialDistDelay;
   int TestingV3AuthInitialDistDelay;
 
 
+  /** Offset in seconds added to the starting time for consensus
+      voting. Only altered on testing networks. */
+  int TestingV3AuthVotingStartOffset;
+
   /** If an authority has been around for less than this amount of time, it
   /** If an authority has been around for less than this amount of time, it
    * does not believe its reachability information is accurate.  Only
    * does not believe its reachability information is accurate.  Only
    * altered on testing networks. */
    * altered on testing networks. */