[or-cvs] Compile cleanly on windows; prevent some insane bandwidth c...

Nick Mathewson nickm at seul.org
Mon Nov 22 22:24:13 UTC 2004


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv22327/src/or

Modified Files:
	config.c connection.c connection_or.c hibernate.c router.c 
Log Message:
Compile cleanly on windows; prevent some insane bandwidth cases (e.g., "BandwidthBurst 1000 TB" from occuring.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.263
retrieving revision 1.264
diff -u -d -r1.263 -r1.264
--- config.c	22 Nov 2004 21:56:51 -0000	1.263
+++ config.c	22 Nov 2004 22:24:10 -0000	1.264
@@ -1310,6 +1310,14 @@
     log(LOG_WARN,"BandwidthBurst must be more than twice BandwidthRate.");
     result = -1;
   }
+  if (options->BandwidthRate > INT_MAX) {
+    log(LOG_WARN,"BandwidthRate must be less than %d",INT_MAX);
+    result = -1;
+  }
+  if (options->BandwidthBurst > INT_MAX) {
+    log(LOG_WARN,"BandwidthBurst must be less than %d",INT_MAX);
+    result = -1;
+  }
 
   if (options->_MonthlyAccountingStart) {
     if (options->AccountingStart) {
@@ -2325,7 +2333,7 @@
     *ok = 0;
     return -1;
   }
-  return r;
+  return (int)r;
 }
 
 /*

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.294
retrieving revision 1.295
diff -u -d -r1.294 -r1.295
--- connection.c	21 Nov 2004 10:14:56 -0000	1.294
+++ connection.c	22 Nov 2004 22:24:10 -0000	1.295
@@ -723,8 +723,8 @@
  * and current_time to the current time. */
 void connection_bucket_init(void) {
   or_options_t *options = get_options();
-  global_read_bucket = options->BandwidthBurst; /* start it at max traffic */
-  global_write_bucket = options->BandwidthBurst; /* start it at max traffic */
+  global_read_bucket = (int)options->BandwidthBurst; /* start it at max traffic */
+  global_write_bucket = (int)options->BandwidthBurst; /* start it at max traffic */
 }
 
 /** A second has rolled over; increment buckets appropriately. */
@@ -736,11 +736,11 @@
 
   /* refill the global buckets */
   if(global_read_bucket < options->BandwidthBurst) {
-    global_read_bucket += options->BandwidthRate;
+    global_read_bucket += (int)options->BandwidthRate;
     log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
   }
   if(global_write_bucket < options->BandwidthBurst) {
-    global_write_bucket += options->BandwidthRate;
+    global_write_bucket += (int)options->BandwidthRate;
     log_fn(LOG_DEBUG,"global_write_bucket now %d.", global_write_bucket);
   }
 

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_or.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- connection_or.c	21 Nov 2004 10:14:57 -0000	1.143
+++ connection_or.c	22 Nov 2004 22:24:10 -0000	1.144
@@ -136,7 +136,7 @@
   conn->addr = addr;
   conn->port = port;
   /* This next part isn't really right, but it's good enough for now. */
-  conn->receiver_bucket = conn->bandwidth = options->BandwidthBurst;
+  conn->receiver_bucket = conn->bandwidth = (int)options->BandwidthBurst;
   memcpy(conn->identity_digest, id_digest, DIGEST_LEN);
   /* If we're an authoritative directory server, we may know a
    * nickname for this router. */

Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/hibernate.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- hibernate.c	22 Nov 2004 22:13:34 -0000	1.27
+++ hibernate.c	22 Nov 2004 22:24:10 -0000	1.28
@@ -336,8 +336,8 @@
 static void
 update_expected_bandwidth(void)
 {
-  uint64_t used;
-  uint32_t max_configured = (get_options()->BandwidthRate * 60);
+  uint64_t used, expected;
+  uint64_t max_configured = (get_options()->BandwidthRate * 60);
 
   if (n_seconds_active_in_interval < 1800) {
     /* If we haven't gotten enough data last interval, guess that
@@ -346,15 +346,17 @@
      * up until we send Max bytes.  Next interval, we'll choose
      * our starting time based on how much we sent this interval.
      */
-    expected_bandwidth_usage = max_configured;
+    expected = max_configured;
   } else {
     used = n_bytes_written_in_interval < n_bytes_read_in_interval ?
       n_bytes_read_in_interval : n_bytes_written_in_interval;
-    expected_bandwidth_usage = (uint32_t)
-      (used / (n_seconds_active_in_interval / 60));
-    if (expected_bandwidth_usage > max_configured)
-      expected_bandwidth_usage = max_configured;
+    expected = (used / (n_seconds_active_in_interval / 60));
+    if (expected > max_configured)
+      expected = max_configured;
   }
+  if (expected > UINT32_MAX)
+    expected = UINT32_MAX;
+  expected_bandwidth_usage = (uint32_t) expected;
 }
 
 /** Called at the start of a new accounting interval: reset our
@@ -440,7 +442,7 @@
   crypto_free_digest_env(d_env);
 
   if (expected_bandwidth_usage)
-    time_to_exhaust_bw =
+    time_to_exhaust_bw = (int)
       (get_options()->AccountingMax/expected_bandwidth_usage)*60;
   else
     time_to_exhaust_bw = 24*60*60;

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- router.c	22 Nov 2004 22:13:34 -0000	1.124
+++ router.c	22 Nov 2004 22:24:10 -0000	1.125
@@ -561,8 +561,8 @@
   }
   get_platform_str(platform, sizeof(platform));
   ri->platform = tor_strdup(platform);
-  ri->bandwidthrate = options->BandwidthRate;
-  ri->bandwidthburst = options->BandwidthBurst;
+  ri->bandwidthrate = (int)options->BandwidthRate;
+  ri->bandwidthburst = (int)options->BandwidthBurst;
   ri->bandwidthcapacity = router_get_bandwidth_capacity();
   router_add_exit_policy_from_config(ri);
   if(desc_routerinfo) /* inherit values */



More information about the tor-commits mailing list