[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10114: if you're using relaybandwidthrate and relaybandwidthburst, (in tor/trunk: . src/or)



Author: arma
Date: 2007-05-04 05:20:13 -0400 (Fri, 04 May 2007)
New Revision: 10114

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/or/config.c
   tor/trunk/src/or/router.c
Log:
if you're using relaybandwidthrate and relaybandwidthburst, make
sure that's reflected in your router descriptor.


Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-05-04 09:14:40 UTC (rev 10113)
+++ tor/trunk/ChangeLog	2007-05-04 09:20:13 UTC (rev 10114)
@@ -6,10 +6,14 @@
       queue for each circuit.  This lets us use less slack memory, and
       will eventually let us be smarter about prioritizing different kinds
       of traffic.
-    - Allocate cells in memory pools better speed and memory efficiency,
-      especially on platforms where malloc() is inefficient.
+    - Use memory pools to allocate cells with better speed and memory
+      efficiency, especially on platforms where malloc() is inefficient.
     - Stop reading on edge connections when their corresponding circuit
       buffers are full; start again as the circuits empty out.
+    - New config options RelayBandwidthRate and RelayBandwidthBurst:
+      a separate set of token buckets for relayed traffic. Right now
+      relayed traffic is defined as answers to directory requests, and
+      OR connections that don't have any local circuits on them.
     - Make PreferTunneledDirConns and TunnelDirConns work even when
       we have no cached directory info. This means Tor clients can now
       do all of their connections protected by TLS.

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-05-04 09:14:40 UTC (rev 10113)
+++ tor/trunk/src/or/config.c	2007-05-04 09:20:13 UTC (rev 10114)
@@ -2275,6 +2275,24 @@
   return 0;
 }
 
+/** If <b>value</b> exceeds ROUTER_MAX_DECLARED_BANDWIDTH, write
+ * a complaint into *<b>msg</b> using string <b>desc</b>, and return -1.
+ * Else return 0.
+ */
+static int
+ensure_bandwidth_cap(uint64_t value, const char *desc, char **msg)
+{
+  int r;
+  char buf[1024];
+  if (value > ROUTER_MAX_DECLARED_BANDWIDTH) {
+    r = tor_snprintf(buf, sizeof(buf), "%s must be at most %d",
+                     desc, ROUTER_MAX_DECLARED_BANDWIDTH);
+    *msg = tor_strdup(r >= 0 ? buf : "internal error");
+    return -1;
+  }
+  return 0;
+}
+
 /** Lowest allowable value for RendPostPeriod; if this is too low, hidden
  * services can overload the directory system. */
 #define MIN_REND_POST_PERIOD (10*60)
@@ -2644,20 +2662,22 @@
   if (options->KeepalivePeriod < 1)
     REJECT("KeepalivePeriod option must be positive.");
 
-  if (options->BandwidthRate > ROUTER_MAX_DECLARED_BANDWIDTH) {
-    r = tor_snprintf(buf, sizeof(buf),
-                     "BandwidthRate must be at most %d",
-                     ROUTER_MAX_DECLARED_BANDWIDTH);
-    *msg = tor_strdup(r >= 0 ? buf : "internal error");
+  if (ensure_bandwidth_cap(options->BandwidthRate,
+                           "BandwidthRate", msg) < 0)
     return -1;
-  }
-  if (options->BandwidthBurst > ROUTER_MAX_DECLARED_BANDWIDTH) {
-    r = tor_snprintf(buf, sizeof(buf),
-                     "BandwidthBurst must be at most %d",
-                     ROUTER_MAX_DECLARED_BANDWIDTH);
-    *msg = tor_strdup(r >= 0 ? buf : "internal error");
+  if (ensure_bandwidth_cap(options->BandwidthBurst,
+                           "BandwidthBurst", msg) < 0)
     return -1;
-  }
+  if (ensure_bandwidth_cap(options->MaxAdvertisedBandwidth,
+                           "MaxAdvertisedBandwidth", msg) < 0)
+    return -1;
+  if (ensure_bandwidth_cap(options->RelayBandwidthRate,
+                           "RelayBandwidthRate", msg) < 0)
+    return -1;
+  if (ensure_bandwidth_cap(options->RelayBandwidthBurst,
+                           "RelayBandwidthBurst", msg) < 0)
+    return -1;
+
   if (server_mode(options)) {
     if (options->BandwidthRate < ROUTER_REQUIRED_MIN_BANDWIDTH*2) {
       r = tor_snprintf(buf, sizeof(buf),

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-05-04 09:14:40 UTC (rev 10113)
+++ tor/trunk/src/or/router.c	2007-05-04 09:20:13 UTC (rev 10114)
@@ -944,18 +944,23 @@
   }
   get_platform_str(platform, sizeof(platform));
   ri->platform = tor_strdup(platform);
+
+  /* compute ri->bandwidthrate as the min of various options */
   ri->bandwidthrate = (int)options->BandwidthRate;
+  if (ri->bandwidthrate > options->MaxAdvertisedBandwidth)
+    ri->bandwidthrate = (int)options->MaxAdvertisedBandwidth;
+  if (options->RelayBandwidthRate > 0 &&
+      ri->bandwidthrate > options->RelayBandwidthRate)
+    ri->bandwidthrate = (int)options->RelayBandwidthRate;
+
+  /* and compute ri->bandwidthburst similarly */
   ri->bandwidthburst = (int)options->BandwidthBurst;
+  if (options->RelayBandwidthBurst > 0 &&
+      ri->bandwidthburst > options->RelayBandwidthBurst)
+    ri->bandwidthburst = (int)options->RelayBandwidthBurst;
+
   ri->bandwidthcapacity = hibernating ? 0 : rep_hist_bandwidth_assess();
 
-  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);