diff options
author | Sebastian Hahn <sebastian@torproject.org> | 2011-04-19 16:00:41 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-04-19 15:38:26 -0400 |
commit | 3f7f96d9e7aa2254d62d63530c37ee96d4b3abc8 (patch) | |
tree | 0d5b08fb80b253f24db6bcfede7ef5cd70931dcb /src/or/rephist.c | |
parent | 13c3884ff60aa0e58464f379f988683f1c30438a (diff) | |
download | tor-3f7f96d9e7aa2254d62d63530c37ee96d4b3abc8.tar.gz tor-3f7f96d9e7aa2254d62d63530c37ee96d4b3abc8.zip |
Prevent hugely inflated observed bandwidth values
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.
Diffstat (limited to 'src/or/rephist.c')
-rw-r--r-- | src/or/rephist.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/or/rephist.c b/src/or/rephist.c index 6034bbcb2b..fb091d5adf 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -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); } |