diff options
-rw-r--r-- | src/or/dirserv.c | 16 | ||||
-rw-r--r-- | src/or/or.h | 1 | ||||
-rw-r--r-- | src/or/routerlist.c | 13 |
3 files changed, 20 insertions, 10 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 7cdfa15776..258ec21ecb 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -592,13 +592,12 @@ dirserver_getinfo_unregistered(const char *question) 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(routerinfo_t *router, { 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 void **b) } /** 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(routerlist_t *rl) 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 diff --git a/src/or/or.h b/src/or/or.h index 9253b3c48a..1e97bdf9ed 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2312,6 +2312,7 @@ routerinfo_t *router_find_exact_exit_enclave(const char *address, #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, diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 7c8887d028..5e3c3b37cf 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -752,6 +752,16 @@ routerlist_sl_remove_unreliable_routers(smartlist_t *sl, int need_uptime, } } +/** 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(smartlist_t *sl) 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; |