[or-cvs] r9677: Clamp declarable bandwidth at INT32_MAX, not INT_MAX. (in tor/trunk: . src/common src/or)

nickm at seul.org nickm at seul.org
Wed Feb 28 16:56:24 UTC 2007


Author: nickm
Date: 2007-02-28 11:56:07 -0500 (Wed, 28 Feb 2007)
New Revision: 9677

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/common/torint.h
   tor/trunk/src/or/config.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/router.c
Log:
 r11981 at catbus:  nickm | 2007-02-28 11:55:27 -0500
 Clamp declarable bandwidth at INT32_MAX, not INT_MAX.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r11981] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-02-28 16:22:42 UTC (rev 9676)
+++ tor/trunk/ChangeLog	2007-02-28 16:56:07 UTC (rev 9677)
@@ -10,6 +10,8 @@
   o Minor bugfixes (other):
     - Fix an assert that could trigger if a controller quickly set then
       cleared EntryNodes.  (Bug found by Udo van den Heuvel.)
+    - On architectures where sizeof(int)>4, still clamp declarable bandwidth
+      to INT32_MAX.
 
 
 Changes in version 0.1.2.8-beta - 2007-02-26

Modified: tor/trunk/src/common/torint.h
===================================================================
--- tor/trunk/src/common/torint.h	2007-02-28 16:22:42 UTC (rev 9676)
+++ tor/trunk/src/common/torint.h	2007-02-28 16:56:07 UTC (rev 9677)
@@ -120,7 +120,10 @@
 #ifndef UINT32_MAX
 #define UINT32_MAX 0xffffffffu
 #endif
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffffu
 #endif
+#endif
 
 #if (SIZEOF_LONG == 4)
 #ifndef HAVE_INT32_T

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-02-28 16:22:42 UTC (rev 9676)
+++ tor/trunk/src/or/config.c	2007-02-28 16:56:07 UTC (rev 9677)
@@ -2635,15 +2635,15 @@
   if (options->KeepalivePeriod < 1)
     REJECT("KeepalivePeriod option must be positive.");
 
-  if (options->BandwidthRate > INT_MAX) {
+  if (options->BandwidthRate > ROUTER_MAX_DECLARED_BANDWIDTH) {
     r = tor_snprintf(buf, sizeof(buf),
-                     "BandwidthRate must be less than %d",INT_MAX);
+                     "BandwidthRate must be less than %d",INT32_MAX);
     *msg = tor_strdup(r >= 0 ? buf : "internal error");
     return -1;
   }
-  if (options->BandwidthBurst > INT_MAX) {
+  if (options->BandwidthBurst > ROUTER_MAX_DECLARED_BANDWIDTH) {
     r = tor_snprintf(buf, sizeof(buf),
-                     "BandwidthBurst must be less than %d",INT_MAX);
+                     "BandwidthBurst must be less than %d",INT32_MAX);
     *msg = tor_strdup(r >= 0 ? buf : "internal error");
     return -1;
   }

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-02-28 16:22:42 UTC (rev 9676)
+++ tor/trunk/src/or/or.h	2007-02-28 16:56:07 UTC (rev 9677)
@@ -2903,6 +2903,7 @@
                                              uint16_t port);
 
 #define ROUTER_REQUIRED_MIN_BANDWIDTH 10000
+#define ROUTER_MAX_DECLARED_BANDWIDTH INT32_MAX
 int router_is_unreliable(routerinfo_t *router, int need_uptime,
                          int need_capacity, int need_guard);
 uint32_t router_get_advertised_bandwidth(routerinfo_t *router);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-02-28 16:22:42 UTC (rev 9676)
+++ tor/trunk/src/or/router.c	2007-02-28 16:56:07 UTC (rev 9677)
@@ -877,8 +877,13 @@
   ri->bandwidthburst = (int)options->BandwidthBurst;
   ri->bandwidthcapacity = hibernating ? 0 : rep_hist_bandwidth_assess();
 
-  if (options->BandwidthRate > options->MaxAdvertisedBandwidth)
-    ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
+  if (options->BandwidthRate > options->MaxAdvertisedBandwidth) {
+    if (options->MaxAdvertisedBandwidth > ROUTER_MAX_DECLARED_BANDWIDTH) {
+      ri->bandwidthrate = ROUTER_MAX_DECLARED_BANDWIDTH;
+    } else {
+      ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
+    }
+  }
 
   policies_parse_exit_policy(options->ExitPolicy, &ri->exit_policy,
                              options->ExitPolicyRejectPrivate);



More information about the tor-commits mailing list