make the numbers in read-history and write-history into uint64s,

so they don't overflow and publish negatives in the descriptor.
fixes bug 193.


svn:r5119
This commit is contained in:
Roger Dingledine 2005-09-23 08:29:58 +00:00
parent 12e10aeaf2
commit 03d0f62da0
2 changed files with 11 additions and 8 deletions

View File

@ -399,7 +399,7 @@ typedef struct bw_array_t {
int total_obs; /**< Total for all members of obs except obs[cur_obs_idx] */
int max_total; /**< Largest value that total_obs has taken on in the current
* period. */
int total_in_period; /**< Total bytes transferred in the current period. */
uint64_t total_in_period; /**< Total bytes transferred in the current period. */
/** When does the next period begin? */
time_t next_period;
@ -414,7 +414,7 @@ typedef struct bw_array_t {
int maxima[NUM_TOTALS];
/** Circular array of the total bandwidth usage for the last NUM_TOTALS
* periods */
int totals[NUM_TOTALS];
uint64_t totals[NUM_TOTALS];
} bw_array_t;
/** Shift the current period of b forward by one.
@ -590,14 +590,15 @@ rep_hist_get_bandwidth_lines(void)
size_t len;
/* opt (read|write)-history yyyy-mm-dd HH:MM:SS (n s) n,n,n,n,n... */
len = (60+12*NUM_TOTALS)*2;
len = (60+20*NUM_TOTALS)*2;
buf = tor_malloc_zero(len);
cp = buf;
for (r=0;r<2;++r) {
b = r?read_array:write_array;
tor_assert(b);
format_iso_time(t, b->next_period-NUM_SECS_BW_SUM_INTERVAL);
tor_snprintf(cp, len-(cp-buf), "opt %s %s (%d s) ", r?"read-history ":"write-history", t,
tor_snprintf(cp, len-(cp-buf), "opt %s %s (%d s) ",
r ? "read-history " : "write-history", t,
NUM_SECS_BW_SUM_INTERVAL);
cp += strlen(cp);
@ -612,9 +613,11 @@ rep_hist_get_bandwidth_lines(void)
for (n=0; n<b->num_maxes_set; ++n,++i) {
while (i >= NUM_TOTALS) i -= NUM_TOTALS;
if (n==(b->num_maxes_set-1))
tor_snprintf(cp, len-(cp-buf), "%d", b->totals[i]);
tor_snprintf(cp, len-(cp-buf), U64_FORMAT,
U64_PRINTF_ARG(b->totals[i]));
else
tor_snprintf(cp, len-(cp-buf), "%d,", b->totals[i]);
tor_snprintf(cp, len-(cp-buf), U64_FORMAT",",
U64_PRINTF_ARG(b->totals[i]));
cp += strlen(cp);
}
strlcat(cp, "\n", len-(cp-buf));

View File

@ -775,7 +775,7 @@ router_rebuild_descriptor(int force)
ri->signed_descriptor = tor_malloc(8192);
if (router_dump_router_to_string(ri->signed_descriptor, 8192,
ri, get_identity_key())<0) {
log_fn(LOG_WARN, "Couldn't dump router to string.");
log_fn(LOG_WARN, "Couldn't allocate string for descriptor.");
return -1;
}
ri->signed_descriptor_len = strlen(ri->signed_descriptor);