[or-cvs] When deciding whether a router is Fast or Guard-worthy, con...

arma at seul.org arma at seul.org
Tue Mar 28 12:02:00 UTC 2006


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

Modified Files:
	dirserv.c or.h routerlist.c 
Log Message:
When deciding whether a router is Fast or Guard-worthy, consider
his advertised BandwidthRate and not just the BandwidthCapacity.

This is a bug in 0.1.0.x as well, but let's not bother backporting.


Index: dirserv.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.316
retrieving revision 1.317
diff -u -p -d -r1.316 -r1.317
--- dirserv.c	27 Mar 2006 02:25:34 -0000	1.316
+++ dirserv.c	28 Mar 2006 12:01:58 -0000	1.317
@@ -592,13 +592,12 @@ dirserver_getinfo_unregistered(const cha
   answerlist = smartlist_create();
   SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ent, {
     r = dirserv_router_get_status(ent, NULL);
-    if (ent->bandwidthcapacity >= (size_t)min_bw &&
-        ent->bandwidthrate >= (size_t)min_bw &&
+    if (router_get_advertised_bandwidth(ent) >= (size_t)min_bw &&
         r != FP_NAMED) {
       /* then log this one */
       tor_snprintf(buf, sizeof(buf),
                    "%s: BW %d on '%s'.",
-                   ent->nickname, ent->bandwidthcapacity,
+                   ent->nickname, router_get_advertised_bandwidth(ent),
                    ent->platform ? ent->platform : "");
       smartlist_add(answerlist, tor_strdup(buf));
     }
@@ -1189,7 +1188,8 @@ dirserv_thinks_router_is_unreliable(rout
 {
   if (need_uptime && router->uptime < stable_uptime)
     return 1;
-  if (need_capacity && router->bandwidthcapacity < fast_bandwidth)
+  if (need_capacity &&
+      router_get_advertised_bandwidth(router) < fast_bandwidth)
     return 1;
   return 0;
 }
@@ -1204,8 +1204,8 @@ _compare_uint32(const void **a, const vo
 }
 
 /** Look through the routerlist, and assign the median uptime
- * of running valid servers to stable_uptime, and the median bandwidth
- * capacity to fast_bandwidth. */
+ * of running valid servers to stable_uptime, and the relative bandwidth
+ * capacities to fast_bandwidth and guard_bandwidth. */
 static void
 dirserv_compute_performance_thresholds(routerlist_t *rl)
 {
@@ -1220,7 +1220,7 @@ dirserv_compute_performance_thresholds(r
       uint32_t *bw = tor_malloc(sizeof(uint32_t));
       *up = (uint32_t) ri->uptime;
       smartlist_add(uptimes, up);
-      *bw = (uint32_t) ri->bandwidthcapacity;
+      *bw = router_get_advertised_bandwidth(ri);
       smartlist_add(bandwidths, bw);
     }
   });
@@ -1360,7 +1360,7 @@ generate_v2_networkstatus(void)
       int f_named = naming && ri->is_named;
       int f_valid = ri->is_valid;
       int f_guard = f_fast && f_stable &&
-                    ri->bandwidthcapacity > guard_bandwidth &&
+                    router_get_advertised_bandwidth(ri) > guard_bandwidth &&
                     (!tor_version_as_new_as(ri->platform,"0.1.1.10-alpha") ||
                      tor_version_as_new_as(ri->platform,"0.1.1.16-rc-cvs"));
       /* 0.1.1.9-alpha is the first version to support fetch by descriptor

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.816
retrieving revision 1.817
diff -u -p -d -r1.816 -r1.817
--- or.h	27 Mar 2006 02:25:34 -0000	1.816
+++ or.h	28 Mar 2006 12:01:58 -0000	1.817
@@ -2312,6 +2312,7 @@ routerinfo_t *router_find_exact_exit_enc
 #define ROUTER_REQUIRED_MIN_BANDWIDTH 10000
 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);
 routerinfo_t *routerlist_sl_choose_by_bandwidth(smartlist_t *sl);
 routerinfo_t *router_choose_random_node(const char *preferred,
                                         const char *excluded,

Index: routerlist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.474
retrieving revision 1.475
diff -u -p -d -r1.474 -r1.475
--- routerlist.c	27 Mar 2006 17:29:53 -0000	1.474
+++ routerlist.c	28 Mar 2006 12:01:58 -0000	1.475
@@ -752,6 +752,16 @@ routerlist_sl_remove_unreliable_routers(
   }
 }
 
+/** Return the smaller of the router's configured BandwidthRate
+ * and its advertised capacity. */
+uint32_t
+router_get_advertised_bandwidth(routerinfo_t *router)
+{
+  if (router->bandwidthcapacity < router->bandwidthrate)
+    return router->bandwidthcapacity;
+  return router->bandwidthrate;
+}
+
 #define MAX_BELIEVABLE_BANDWIDTH 1500000 /* 1.5 MB/sec */
 
 /** Choose a random element of router list <b>sl</b>, weighted by
@@ -771,8 +781,7 @@ routerlist_sl_choose_by_bandwidth(smartl
   bandwidths = smartlist_create();
   for (i = 0; i < smartlist_len(sl); ++i) {
     router = smartlist_get(sl, i);
-    this_bw = (router->bandwidthcapacity < router->bandwidthrate) ?
-               router->bandwidthcapacity : router->bandwidthrate;
+    this_bw = router_get_advertised_bandwidth(router);
     /* if they claim something huge, don't believe it */
     if (this_bw > MAX_BELIEVABLE_BANDWIDTH)
       this_bw = MAX_BELIEVABLE_BANDWIDTH;



More information about the tor-commits mailing list