Merge remote-tracking branch 'origin/maint-0.2.2'

This commit is contained in:
Nick Mathewson 2011-04-19 15:39:04 -04:00
commit 7c83d4043d
3 changed files with 27 additions and 4 deletions

5
changes/bug2704_part1 Normal file
View File

@ -0,0 +1,5 @@
o Minor bugfixes:
- Fix an issue causing calculation of Tor's average bandwidth as saved
in the state file to be 10 times smaller than it should be. Fixes the
first part of bug 2704, bugfix on tor-0.2.2.23-alpha.

5
changes/bug2704_part2 Normal file
View File

@ -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.

View File

@ -1678,7 +1678,7 @@ rep_hist_load_bwhist_state_section(bw_array_t *b,
mv *= NUM_SECS_ROLLING_MEASURE; mv *= NUM_SECS_ROLLING_MEASURE;
} else { } else {
/* No maxima known; guess average rate to be conservative. */ /* No maxima known; guess average rate to be conservative. */
mv = v / s_interval; mv = (v / s_interval) * NUM_SECS_ROLLING_MEASURE;
} }
if (!ok) { if (!ok) {
retval = -1; retval = -1;
@ -1691,11 +1691,24 @@ rep_hist_load_bwhist_state_section(bw_array_t *b,
} }
if (start < now) { 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; b->max_total = mv;
/* This will result in some fairly choppy history if s_interval /* This will result in some fairly choppy history if s_interval
* is notthe same as NUM_SECS_BW_SUM_INTERVAL. XXXX */ * is not the same as NUM_SECS_BW_SUM_INTERVAL. XXXX */
start += s_interval; start += actual_interval_len;
} }
} SMARTLIST_FOREACH_END(cp); } SMARTLIST_FOREACH_END(cp);
} }