From 45c51e32385d6f3c3eaefcab4927a50d1968d437 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 30 Sep 2010 06:10:25 +0200 Subject: [PATCH 1/4] Fix check-spaces --- src/common/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/util.c b/src/common/util.c index b4f3052e19..dafe12071f 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2877,3 +2877,4 @@ load_windows_system_library(const TCHAR *library_name) return LoadLibrary(path); } #endif + From 73def430e3ad3be0c9fe9accd4ebfc7a35e572b2 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 30 Sep 2010 06:10:56 +0200 Subject: [PATCH 2/4] Use an upper and lower bound for bridge weights When picking bridges (or other nodes without a consensus entry (and thus no bandwidth weights)) we shouldn't just trust the node's descriptor. So far we believed anything between 0 and 10MB/s, where 0 would mean that a node doesn't get any use from use unless it is our only one, and 10MB/s would be a quite siginficant weight. To make this situation better, we now believe weights in the range from 20kB/s to 100kB/s. This should allow new bridges to get use more quickly, and means that it will be harder for bridges to see almost all our traffic. --- src/or/routerlist.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index a6ca03cde3..ee8c45d0a4 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1572,6 +1572,29 @@ router_get_advertised_bandwidth_capped(routerinfo_t *router) return result; } +/** When weighting bridges, enforce these values as lower and upper + * bound for believable bandwidth, because there is no way for us + * to verify a bridge's bandwidth currently. */ +#define BRIDGE_MIN_BELIEVABLE_BANDWIDTH 20000 /* 20 kB/sec */ +#define BRIDGE_MAX_BELIEVABLE_BANDWIDTH 100000 /* 100 kB/sec */ + +/** Return the smaller of the router's configured BandwidthRate + * and its advertised capacity, making sure to stay within the + * interval between bridge-min-believe-bw and + * bridge-max-believe-bw. */ +static uint32_t +bridge_get_advertised_bandwidth_bounded(routerinfo_t *router) +{ + uint32_t result = router->bandwidthcapacity; + if (result > router->bandwidthrate) + result = router->bandwidthrate; + if (result > BRIDGE_MAX_BELIEVABLE_BANDWIDTH) + result = BRIDGE_MAX_BELIEVABLE_BANDWIDTH; + else if (result < BRIDGE_MIN_BELIEVABLE_BANDWIDTH) + result = BRIDGE_MIN_BELIEVABLE_BANDWIDTH; + return result; +} + /** Return bw*1000, unless bw*1000 would overflow, in which case return * INT32_MAX. */ static INLINE int32_t @@ -1726,7 +1749,7 @@ smartlist_choose_by_bandwidth_weights(smartlist_t *sl, if (rs && rs->has_bandwidth) { this_bw = kb_to_bytes(rs->bandwidth); } else { /* bridge or other descriptor not in our consensus */ - this_bw = router_get_advertised_bandwidth_capped(router); + this_bw = bridge_get_advertised_bandwidth_bounded(router); have_unknown = 1; } if (router_digest_is_me(router->cache_info.identity_digest)) @@ -1897,7 +1920,7 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule, flags |= is_exit ? 2 : 0; flags |= is_guard ? 4 : 0; } else /* bridge or other descriptor not in our consensus */ - this_bw = router_get_advertised_bandwidth_capped(router); + this_bw = bridge_get_advertised_bandwidth_bounded(router); } if (is_exit) bitarray_set(exit_bits, i); From 0702429cf778f4eba4440a1b0356924e4574e923 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 30 Sep 2010 06:11:51 +0200 Subject: [PATCH 3/4] Note an XXX about potential overflow --- src/or/routerlist.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/or/routerlist.c b/src/or/routerlist.c index ee8c45d0a4..e52165ed84 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1928,6 +1928,8 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule, bitarray_set(guard_bits, i); if (is_known) { bandwidths[i] = (int32_t) this_bw; // safe since MAX_BELIEVABLE= 0); if (is_guard) total_guard_bw += this_bw; From 5a19df1d94d8552a06dfc8fca9228dd36ed994e8 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 30 Sep 2010 06:16:41 +0200 Subject: [PATCH 4/4] Add a changes file for the bug1912 fix --- changes/bug1912 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 changes/bug1912 diff --git a/changes/bug1912 b/changes/bug1912 new file mode 100644 index 0000000000..5a7af756d1 --- /dev/null +++ b/changes/bug1912 @@ -0,0 +1,9 @@ + o Major bugfixes: + - When weighting bridges, we used to trust the bandwidths they provided + in their descriptor, only capping them at 10MB/s. This turned out to be + problematic for two reasons: Bridges could claim to handle a lot more + traffic then they actually would, thus making more clients pick them and + have a pretty effective DoS attack. The other issue is that new bridges + that might not have a good estimate for their bw capacity yet would not + get used at all unless no other bridges are available to a client. + This fixes bug 1912; bugfix on 0.2.2.7-alpha.