[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Tweak #6752 patch based on comments by nickm.



commit b0d4ca4990d50f45a4e0e2805ff471f7408c3007
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri May 24 09:48:15 2013 +0200

    Tweak #6752 patch based on comments by nickm.
---
 src/common/container.c |    4 +-
 src/or/config.c        |  142 +++++++++++++-----------------------------------
 src/or/confparse.c     |    4 +-
 src/or/directory.c     |   14 +++--
 4 files changed, 50 insertions(+), 114 deletions(-)

diff --git a/src/common/container.c b/src/common/container.c
index 03c65b7..476dc82 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -243,8 +243,8 @@ smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2)
   return 1;
 }
 
-/** Return true iff the two lists contain the same ints in the same order,
- * or if they are both NULL. */
+/** Return true iff the two lists contain the same int pointer values in
+ * the same order, or if they are both NULL. */
 int
 smartlist_ints_eq(const smartlist_t *sl1, const smartlist_t *sl2)
 {
diff --git a/src/or/config.c b/src/or/config.c
index 5809937..d85ba4c 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2315,8 +2315,9 @@ compute_publishserverdescriptor(or_options_t *options)
  * */
 #define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT (10)
 
-/** Return 0 if every setting in <b>options</b> is reasonable, and a
- * permissible transition from <b>old_options</b>. Else return -1.
+/** Return 0 if every setting in <b>options</b> is reasonable, does not
+ * differ from <b>default_options</b> unless in testing Tor networks, and
+ * is a permissible transition from <b>old_options</b>. Else return -1.
  * Should have no side effects, except for normalizing the contents of
  * <b>options</b>.
  *
@@ -3211,33 +3212,43 @@ options_validate(or_options_t *old_options, or_options_t *options,
              "ignore you.");
   }
 
-  if (default_options->TestingV3AuthInitialVotingInterval !=
-              options->TestingV3AuthInitialVotingInterval &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingV3AuthInitialVotingInterval may only be changed in testing "
-           "Tor networks!");
-  } else if (options->TestingV3AuthInitialVotingInterval < MIN_VOTE_INTERVAL) {
+#define CHECK_DEFAULT(arg) \
+  STMT_BEGIN if (default_options->arg != options->arg && \
+      !options->TestingTorNetwork && \
+      !options->UsingTestNetworkDefaults_) { \
+    REJECT("Testing* options may only be changed in testing Tor " \
+           "networks!"); \
+  } STMT_END
+  CHECK_DEFAULT(TestingV3AuthInitialVotingInterval);
+  CHECK_DEFAULT(TestingV3AuthInitialVoteDelay);
+  CHECK_DEFAULT(TestingV3AuthInitialDistDelay);
+  CHECK_DEFAULT(TestingAuthDirTimeToLearnReachability);
+  CHECK_DEFAULT(TestingEstimatedDescriptorPropagationTime);
+  CHECK_DEFAULT(TestingServerDownloadSchedule);
+  CHECK_DEFAULT(TestingClientDownloadSchedule);
+  CHECK_DEFAULT(TestingServerConsensusDownloadSchedule);
+  CHECK_DEFAULT(TestingClientConsensusDownloadSchedule);
+  CHECK_DEFAULT(TestingBridgeDownloadSchedule);
+  CHECK_DEFAULT(TestingClientMaxIntervalWithoutRequest);
+  CHECK_DEFAULT(TestingDirConnectionMaxStall);
+  CHECK_DEFAULT(TestingConsensusMaxDownloadTries);
+  CHECK_DEFAULT(TestingDescriptorMaxDownloadTries);
+  CHECK_DEFAULT(TestingMicrodescMaxDownloadTries);
+  CHECK_DEFAULT(TestingCertMaxDownloadTries);
+#undef CHECK_DEFAULT
+
+  if (options->TestingV3AuthInitialVotingInterval < MIN_VOTE_INTERVAL) {
     REJECT("TestingV3AuthInitialVotingInterval is insanely low.");
   } else if (((30*60) % options->TestingV3AuthInitialVotingInterval) != 0) {
     REJECT("TestingV3AuthInitialVotingInterval does not divide evenly into "
            "30 minutes.");
   }
 
-  if (default_options->TestingV3AuthInitialVoteDelay !=
-              options->TestingV3AuthInitialVoteDelay &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingV3AuthInitialVoteDelay may only be changed in testing "
-           "Tor networks!");
-  } else if (options->TestingV3AuthInitialVoteDelay < MIN_VOTE_SECONDS) {
+  if (options->TestingV3AuthInitialVoteDelay < MIN_VOTE_SECONDS) {
     REJECT("TestingV3AuthInitialVoteDelay is way too low.");
   }
 
-  if (default_options->TestingV3AuthInitialDistDelay !=
-              options->TestingV3AuthInitialDistDelay &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingV3AuthInitialDistDelay may only be changed in testing "
-           "Tor networks!");
-  } else if (options->TestingV3AuthInitialDistDelay < MIN_DIST_SECONDS) {
+  if (options->TestingV3AuthInitialDistDelay < MIN_DIST_SECONDS) {
     REJECT("TestingV3AuthInitialDistDelay is way too low.");
   }
 
@@ -3248,124 +3259,49 @@ options_validate(or_options_t *old_options, or_options_t *options,
            "must be less than half TestingV3AuthInitialVotingInterval");
   }
 
-  if (default_options->TestingAuthDirTimeToLearnReachability !=
-              options->TestingAuthDirTimeToLearnReachability &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingAuthDirTimeToLearnReachability may only be changed in "
-           "testing Tor networks!");
-  } else if (options->TestingAuthDirTimeToLearnReachability < 0) {
+  if (options->TestingAuthDirTimeToLearnReachability < 0) {
     REJECT("TestingAuthDirTimeToLearnReachability must be non-negative.");
   } else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) {
     COMPLAIN("TestingAuthDirTimeToLearnReachability is insanely high.");
   }
 
-  if (default_options->TestingEstimatedDescriptorPropagationTime !=
-              options->TestingEstimatedDescriptorPropagationTime &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingEstimatedDescriptorPropagationTime may only be changed in "
-           "testing Tor networks!");
-  } else if (options->TestingEstimatedDescriptorPropagationTime < 0) {
+  if (options->TestingEstimatedDescriptorPropagationTime < 0) {
     REJECT("TestingEstimatedDescriptorPropagationTime must be non-negative.");
   } else if (options->TestingEstimatedDescriptorPropagationTime > 60*60) {
     COMPLAIN("TestingEstimatedDescriptorPropagationTime is insanely high.");
   }
 
-  if (!smartlist_ints_eq(options->TestingServerDownloadSchedule,
-                 default_options->TestingServerDownloadSchedule) &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingServerDownloadSchedule may only be changed in testing "
-           "Tor networks!");
-  }
-
-  if (!smartlist_ints_eq(options->TestingClientDownloadSchedule,
-                 default_options->TestingClientDownloadSchedule) &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingClientDownloadSchedule may only be changed in testing "
-           "Tor networks!");
-  }
-
-  if (!smartlist_ints_eq(options->TestingServerConsensusDownloadSchedule,
-                 default_options->TestingServerConsensusDownloadSchedule) &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingServerConsensusDownloadSchedule may only be changed "
-           "in testing Tor networks!");
-  }
-
-  if (!smartlist_ints_eq(options->TestingClientConsensusDownloadSchedule,
-                 default_options->TestingClientConsensusDownloadSchedule) &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingClientConsensusDownloadSchedule may only be changed "
-           "in testing Tor networks!");
-  }
-
-  if (!smartlist_ints_eq(options->TestingBridgeDownloadSchedule,
-                 default_options->TestingBridgeDownloadSchedule) &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingBridgeDownloadSchedule may only be changed in testing "
-           "Tor networks!");
-  }
-
-  if (default_options->TestingClientMaxIntervalWithoutRequest !=
-              options->TestingClientMaxIntervalWithoutRequest &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingClientMaxIntervalWithoutRequest may only be changed "
-           "in testing Tor networks!");
-  } else if (options->TestingClientMaxIntervalWithoutRequest < 1) {
+  if (options->TestingClientMaxIntervalWithoutRequest < 1) {
     REJECT("TestingClientMaxIntervalWithoutRequest is way too low.");
   } else if (options->TestingClientMaxIntervalWithoutRequest > 3600) {
     COMPLAIN("TestingClientMaxIntervalWithoutRequest is insanely high.");
   }
 
-  if (default_options->TestingDirConnectionMaxStall !=
-              options->TestingDirConnectionMaxStall &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingDirConnectionMaxStall may only be changed in testing "
-           "Tor networks!");
-  } else if (options->TestingDirConnectionMaxStall < 5) {
+  if (options->TestingDirConnectionMaxStall < 5) {
     REJECT("TestingDirConnectionMaxStall is way too low.");
   } else if (options->TestingDirConnectionMaxStall > 3600) {
     COMPLAIN("TestingDirConnectionMaxStall is insanely high.");
   }
 
-  if (default_options->TestingConsensusMaxDownloadTries !=
-              options->TestingConsensusMaxDownloadTries &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingConsensusMaxDownloadTries may only be changed in "
-           "testing Tor networks!");
-  } else if (options->TestingConsensusMaxDownloadTries < 2) {
+  if (options->TestingConsensusMaxDownloadTries < 2) {
     REJECT("TestingConsensusMaxDownloadTries must be greater than 1.");
   } else if (options->TestingConsensusMaxDownloadTries > 800) {
     COMPLAIN("TestingConsensusMaxDownloadTries is insanely high.");
   }
 
-  if (default_options->TestingDescriptorMaxDownloadTries !=
-              options->TestingDescriptorMaxDownloadTries &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingDescriptorMaxDownloadTries may only be changed in "
-           "testing Tor networks!");
-  } else if (options->TestingDescriptorMaxDownloadTries < 2) {
+  if (options->TestingDescriptorMaxDownloadTries < 2) {
     REJECT("TestingDescriptorMaxDownloadTries must be greater than 1.");
   } else if (options->TestingDescriptorMaxDownloadTries > 800) {
     COMPLAIN("TestingDescriptorMaxDownloadTries is insanely high.");
   }
 
-  if (default_options->TestingMicrodescMaxDownloadTries !=
-              options->TestingMicrodescMaxDownloadTries &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingMicrodescMaxDownloadTries may only be changed in "
-           "testing Tor networks!");
-  } else if (options->TestingMicrodescMaxDownloadTries < 2) {
+  if (options->TestingMicrodescMaxDownloadTries < 2) {
     REJECT("TestingMicrodescMaxDownloadTries must be greater than 1.");
   } else if (options->TestingMicrodescMaxDownloadTries > 800) {
     COMPLAIN("TestingMicrodescMaxDownloadTries is insanely high.");
   }
 
-  if (default_options->TestingCertMaxDownloadTries !=
-              options->TestingCertMaxDownloadTries &&
-      !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
-    REJECT("TestingCertMaxDownloadTries may only be changed in testing "
-           "Tor networks!");
-  } else if (options->TestingCertMaxDownloadTries < 2) {
+  if (options->TestingCertMaxDownloadTries < 2) {
     REJECT("TestingCertMaxDownloadTries must be greater than 1.");
   } else if (options->TestingCertMaxDownloadTries > 800) {
     COMPLAIN("TestingCertMaxDownloadTries is insanely high.");
diff --git a/src/or/confparse.c b/src/or/confparse.c
index 8607f58..eb0362f 100644
--- a/src/or/confparse.c
+++ b/src/or/confparse.c
@@ -588,7 +588,6 @@ config_get_assigned_option(const config_format_t *fmt, const void *options,
   const void *value;
   config_line_t *result;
   smartlist_t *csv_str;
-  char *s;
   tor_assert(options && key);
 
   CONFIG_CHECK(fmt, options);
@@ -676,8 +675,7 @@ config_get_assigned_option(const config_format_t *fmt, const void *options,
         csv_str = smartlist_new();
         SMARTLIST_FOREACH_BEGIN(*(smartlist_t**)value, int *, i)
           {
-            tor_asprintf(&s, "%d", *i);
-            smartlist_add(csv_str, s);
+            smartlist_add_asprintf(csv_str, "%d", *i);
           }
         SMARTLIST_FOREACH_END(i);
         result->value = smartlist_join_strings(csv_str, ",", 0, NULL);
diff --git a/src/or/directory.c b/src/or/directory.c
index caf8a55..88d6717 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -3723,10 +3723,12 @@ dir_networkstatus_download_failed(smartlist_t *failed, int status_code)
   } SMARTLIST_FOREACH_END(fp);
 }
 
-/** Decide which download schedule we want to use, and then return a
- * pointer to it along with a pointer to its length. Helper function for
- * download_status_increment_failure() and download_status_reset(). */
-static smartlist_t *
+/** Decide which download schedule we want to use based on descriptor type
+ * in <b>dls</b> and whether we are acting as directory <b>server</b>, and
+ * then return a list of int pointers defining download delays in seconds.
+ * Helper function for download_status_increment_failure() and
+ * download_status_reset(). */
+static const smartlist_t *
 find_dl_schedule_and_len(download_status_t *dls, int server)
 {
   switch (dls->schedule) {
@@ -3755,7 +3757,7 @@ time_t
 download_status_increment_failure(download_status_t *dls, int status_code,
                                   const char *item, int server, time_t now)
 {
-  smartlist_t *schedule;
+  const smartlist_t *schedule;
   int increment;
   tor_assert(dls);
   if (status_code != 503 || server) {
@@ -3803,7 +3805,7 @@ download_status_increment_failure(download_status_t *dls, int status_code,
 void
 download_status_reset(download_status_t *dls)
 {
-  smartlist_t *schedule = find_dl_schedule_and_len(
+  const smartlist_t *schedule = find_dl_schedule_and_len(
                           dls, get_options()->DirPort_set);
 
   dls->n_download_failures = 0;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits