]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
New consensus method: clip the maximum votable unmeasured bw
authorNick Mathewson <nickm@torproject.org>
Wed, 16 May 2012 21:04:51 +0000 (17:04 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 5 Feb 2013 05:46:32 +0000 (00:46 -0500)
If we're deciding on a node's bandwidth based on "Bandwidth="
declarations, clip it to "20" or to the maxunmeasuredbw parameter,
if it's voted on.

This adds a new consensus method.

This is "part A" of bug 2286

src/or/dirvote.c
src/or/dirvote.h

index 43b9f5eb12e37fb48b8d3ad5f18dd67c24d192bf..08a9eb4c02907aa741985fa9d5dac8db1af6df6e 100644 (file)
@@ -1388,6 +1388,8 @@ networkstatus_compute_consensus(smartlist_t *votes,
   char *client_versions = NULL, *server_versions = NULL;
   smartlist_t *flags;
   const char *flavor_name;
+#define DEFAULT_MAX_UNMEASURED_BW 20
+  uint32_t max_unmeasured_bw = DEFAULT_MAX_UNMEASURED_BW;
   int64_t G=0, M=0, E=0, D=0, T=0; /* For bandwidth weights */
   const routerstatus_format_type_t rs_format =
     flavor == FLAV_NS ? NS_V3_CONSENSUS : NS_V3_CONSENSUS_MICRODESC;
@@ -1586,6 +1588,30 @@ networkstatus_compute_consensus(smartlist_t *votes,
     smartlist_free(dir_sources);
   }
 
+  if (consensus_method >= MIN_METHOD_TO_CLIP_UNMEASURED_BW) {
+    char *max_unmeasured_param = NULL;
+    if (params) {
+      if (strcmpstart(params, "maxunmeasuredbw=") == 0)
+        max_unmeasured_param = params;
+      else
+        max_unmeasured_param = strstr(params, " maxunmeasuredbw=");
+    }
+    if (max_unmeasured_param) {
+      int ok = 0;
+      char *eq = strchr(max_unmeasured_param, '=');
+      if (eq) {
+        max_unmeasured_bw = (uint32_t)
+          tor_parse_ulong(eq+1, 10, 1, UINT32_MAX, &ok, NULL);
+        if (!ok) {
+          log_warn(LD_DIR, "Bad element '%s' in max unmeasured bw param",
+                   escaped(max_unmeasured_param));
+          max_unmeasured_bw = DEFAULT_MAX_UNMEASURED_BW;
+        }
+      }
+    }
+  }
+
+
   /* Add the actual router entries. */
   {
     int *index; /* index[j] is the current index into votes[j]. */
@@ -1867,6 +1893,11 @@ networkstatus_compute_consensus(smartlist_t *votes,
       } else if (consensus_method >= 5 && num_bandwidths > 0) {
         rs_out.has_bandwidth = 1;
         rs_out.bandwidth = median_uint32(bandwidths, num_bandwidths);
+        if (consensus_method >= MIN_METHOD_TO_CLIP_UNMEASURED_BW) {
+          /* Cap non-measured bandwidths to 20k. */
+          if (rs_out.bandwidth > max_unmeasured_bw)
+            rs_out.bandwidth = max_unmeasured_bw;
+        }
       }
 
       /* Fix bug 2203: Do not count BadExit nodes as Exits for bw weights */
index f134454321af82f77e42f2bd2cd08d7c17c621fc..a7398743b06391bbecdf7029c98c95bd221e2c8a 100644 (file)
@@ -20,7 +20,7 @@
 #define MIN_VOTE_INTERVAL 300
 
 /** The highest consensus method that we currently support. */
-#define MAX_SUPPORTED_CONSENSUS_METHOD 16
+#define MAX_SUPPORTED_CONSENSUS_METHOD 17
 
 /** Lowest consensus method that contains a 'directory-footer' marker */
 #define MIN_METHOD_FOR_FOOTER 9
  * line */
 #define MIN_METHOD_FOR_NTOR_KEY 16
 
+/** Lowest consensus method that ensures that authorities output an
+ * Unmeasured=1 flag for unmeasured bandwidths */
+#define MIN_METHOD_TO_CLIP_UNMEASURED_BW 17
+
 void dirvote_free_all(void);
 
 /* vote manipulation */