aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2011-04-16 16:01:36 +0200
committerSebastian Hahn <sebastian@torproject.org>2011-04-19 14:51:40 +0200
commitc1927d7d5f5dff5b8d7da5bd4e7a743eb06bcbb3 (patch)
tree9f98c833a3e901c999301767805d515524aed840 /src/or
parent4cbbb92e7fc7c9c4d374b35211c216a5419e3da2 (diff)
downloadtor-c1927d7d5f5dff5b8d7da5bd4e7a743eb06bcbb3.tar
tor-c1927d7d5f5dff5b8d7da5bd4e7a743eb06bcbb3.tar.gz
Don't report empty bw-history lines in extrainfo
Some tor relays would report lines like these in their extrainfo documents: dirreq-write-history 2011-03-14 16:46:44 (900 s) This was confusing to some people who look at the stats. It would happen whenever a relay first starts up, or when a relay has dirport disabled. Change this so that lines without actual bw entries are omitted. Implements ticket 2497.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/rephist.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 9b7eefecf..b55797ac9 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -1524,10 +1524,15 @@ rep_hist_get_bandwidth_lines(void)
size_t len;
/* opt [dirreq-](read|write)-history yyyy-mm-dd HH:MM:SS (n s) n,n,n... */
- len = (67+21*NUM_TOTALS)*4;
+/* The n,n,n part above. Largest representation of a uint64_t is 20 chars
+ * long, plus the comma. */
+#define MAX_HIST_VALUE_LEN 21*NUM_TOTALS
+ len = (67+MAX_HIST_VALUE_LEN)*4;
buf = tor_malloc_zero(len);
cp = buf;
for (r=0;r<4;++r) {
+ char tmp[MAX_HIST_VALUE_LEN];
+ size_t slen;
switch (r) {
case 0:
b = write_array;
@@ -1547,11 +1552,16 @@ rep_hist_get_bandwidth_lines(void)
break;
}
tor_assert(b);
+ slen = rep_hist_fill_bandwidth_history(tmp, MAX_HIST_VALUE_LEN, b);
+ /* If we don't have anything to write, skip to the next entry. */
+ if (slen == 0)
+ continue;
format_iso_time(t, b->next_period-NUM_SECS_BW_SUM_INTERVAL);
tor_snprintf(cp, len-(cp-buf), "%s %s (%d s) ",
desc, t, NUM_SECS_BW_SUM_INTERVAL);
cp += strlen(cp);
- cp += rep_hist_fill_bandwidth_history(cp, len-(cp-buf), b);
+ strlcat(cp, tmp, len-(cp-buf));
+ cp += slen;
strlcat(cp, "\n", len-(cp-buf));
++cp;
}