]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Prevent hugely inflated observed bandwidth values
authorSebastian Hahn <sebastian@torproject.org>
Tue, 19 Apr 2011 14:00:41 +0000 (16:00 +0200)
committerNick Mathewson <nickm@torproject.org>
Tue, 19 Apr 2011 19:38:26 +0000 (15:38 -0400)
When reading the bw history from the state file, we'd add the 900-second
value as traffic that occured during one second. Fix that by adding the
average value to each second.

This bug was present since 0.2.0.5-alpha, but was hidden until
0.2.23-alpha when we started using the saved values.

changes/bug2704_part2 [new file with mode: 0644]
src/or/rephist.c

diff --git a/changes/bug2704_part2 b/changes/bug2704_part2
new file mode 100644 (file)
index 0000000..962c8b7
--- /dev/null
@@ -0,0 +1,5 @@
+  o Major bugfixes:
+    - Prevent relays that read their bandwidth history from their state file
+      from arbitrarily inflating that value. Fixes the second half of bug
+      2704, bugfix on tor-0.2.2.23-alpha.
+
index 6034bbcb2bad12d0cca4aef2cb364ffd62d840a2..fb091d5adf053c4f1f98fa625847ac33a2d23405 100644 (file)
@@ -1686,11 +1686,24 @@ rep_hist_load_bwhist_state_section(bw_array_t *b,
         }
 
         if (start < now) {
-          add_obs(b, start, v);
+          time_t cur_start = start;
+          time_t actual_interval_len = s_interval;
+          uint64_t cur_val = 0;
+          /* Calculate the average per second. This is the best we can do
+           * because our state file doesn't have per-second resolution. */
+          if (start + s_interval > now)
+            actual_interval_len = now - start;
+          cur_val = v / actual_interval_len;
+          /* This is potentially inefficient, but since we don't do it very
+           * often it should be ok. */
+          while (cur_start < start + actual_interval_len) {
+            add_obs(b, cur_start, cur_val);
+            ++cur_start;
+          }
           b->max_total = mv;
           /* This will result in some fairly choppy history if s_interval
-           * is notthe same as NUM_SECS_BW_SUM_INTERVAL. XXXX */
-          start += s_interval;
+           * is not the same as NUM_SECS_BW_SUM_INTERVAL. XXXX */
+          start += actual_interval_len;
         }
     } SMARTLIST_FOREACH_END(cp);
   }