summaryrefslogtreecommitdiff
path: root/src/or/rephist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-10-10 15:07:19 +0000
committerNick Mathewson <nickm@torproject.org>2007-10-10 15:07:19 +0000
commit9ed39643fad313679d9acaf99df2c4b24476da89 (patch)
treedc32ff1ac1f869eb5427583f5f188318b1b088e3 /src/or/rephist.c
parentcb0dbbcfa593439bee29ff3b125301d58051a095 (diff)
downloadtor-9ed39643fad313679d9acaf99df2c4b24476da89.tar.gz
tor-9ed39643fad313679d9acaf99df2c4b24476da89.zip
r15626@catbus: nickm | 2007-10-10 11:02:32 -0400
Resolve bug 516: Never report our bandwidth-history as over RelayBandwidthRate*NUM_SECS_BW_SUM_INTERVAL. svn:r11833
Diffstat (limited to 'src/or/rephist.c')
-rw-r--r--src/or/rephist.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/or/rephist.c b/src/or/rephist.c
index f039d45e1a..cb983b79f3 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -1014,6 +1014,8 @@ rep_hist_fill_bandwidth_history(char *buf, size_t len, bw_array_t *b)
{
char *cp = buf;
int i, n;
+ or_options_t *options = get_options();
+ uint64_t cutoff;
if (b->num_maxes_set <= b->next_max_idx) {
/* We haven't been through the circular array yet; time starts at i=0.*/
@@ -1024,6 +1026,15 @@ rep_hist_fill_bandwidth_history(char *buf, size_t len, bw_array_t *b)
i = b->next_max_idx;
}
+ if (options->RelayBandwidthRate) {
+ /* We don't want to report that we used more bandwidth than the max we're
+ * willing to relay; otherwise everybody will know how much traffic
+ * we used ourself. */
+ cutoff = options->RelayBandwidthRate * NUM_SECS_BW_SUM_INTERVAL;
+ } else {
+ cutoff = UINT64_MAX;
+ }
+
for (n=0; n<b->num_maxes_set; ++n,++i) {
uint64_t total;
if (i >= NUM_TOTALS)
@@ -1031,6 +1042,9 @@ rep_hist_fill_bandwidth_history(char *buf, size_t len, bw_array_t *b)
tor_assert(i < NUM_TOTALS);
/* Round the bandwidth used down to the nearest 1k. */
total = b->totals[i] & ~0x3ff;
+ if (total > cutoff)
+ total = cutoff;
+
if (n==(b->num_maxes_set-1))
tor_snprintf(cp, len-(cp-buf), U64_FORMAT, U64_PRINTF_ARG(total));
else