[or-cvs] make the numbers in read-history and write-history into uin...

arma at seul.org arma at seul.org
Fri Sep 23 08:30:00 UTC 2005


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	rephist.c router.c 
Log Message:
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.


Index: rephist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- rephist.c	13 Aug 2005 00:22:07 -0000	1.63
+++ rephist.c	23 Sep 2005 08:29:58 -0000	1.64
@@ -399,7 +399,7 @@
   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 @@
   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,15 +590,16 @@
   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,
-            NUM_SECS_BW_SUM_INTERVAL);
+    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);
 
     if (b->num_maxes_set <= b->next_max_idx)
@@ -612,9 +613,11 @@
     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));

Index: router.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.208
retrieving revision 1.209
diff -u -d -r1.208 -r1.209
--- router.c	16 Sep 2005 06:15:34 -0000	1.208
+++ router.c	23 Sep 2005 08:29:58 -0000	1.209
@@ -775,7 +775,7 @@
   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);



More information about the tor-commits mailing list