[or-cvs] r11133: Backport r10939 and r10956: correct handling for weighted ex (in tor/branches/tor-0_1_2-patches: . doc src/or)
nickm at seul.org
nickm at seul.org
Thu Aug 16 16:41:39 UTC 2007
Author: nickm
Date: 2007-08-16 12:41:38 -0400 (Thu, 16 Aug 2007)
New Revision: 11133
Modified:
tor/branches/tor-0_1_2-patches/
tor/branches/tor-0_1_2-patches/ChangeLog
tor/branches/tor-0_1_2-patches/doc/TODO.012
tor/branches/tor-0_1_2-patches/src/or/routerlist.c
Log:
r14589 at catbus: nickm | 2007-08-16 12:16:06 -0400
Backport r10939 and r10956: correct handling for weighted exit selection. I'm not backporting the bitfield code, so this is marginally slower than the version in trunk.
Property changes on: tor/branches/tor-0_1_2-patches
___________________________________________________________________
svk:merge ticket from /tor/012 [r14589] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/branches/tor-0_1_2-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_2-patches/ChangeLog 2007-08-16 16:41:36 UTC (rev 11132)
+++ tor/branches/tor-0_1_2-patches/ChangeLog 2007-08-16 16:41:38 UTC (rev 11133)
@@ -8,8 +8,17 @@
now its only effect is to change our buffer sizes from nice
powers of two (which platform mallocs tend to like) to values
slightly over powers of two (which make some platform mallocs sad).
+ - If exit bandwidth ever exceeds one third of total bandwidth, then
+ use the correct formula to weight exit nodes when choosing paths.
+ (Based on patch from Mike Perry.)
+ o Minor bugfixes (misc):
+ - Choose perfectly fairly among routers when choosing by bandwidth and
+ weighting by fraction of bandwidth provided by exits. Previously,
+ we would choose with only approximate fairness, and correct ourselves
+ if we ran off the end of the list.
+
Changes in version 0.1.2.16 - 2007-08-01
o Major security fixes:
- Close immediately after missing authentication on control port;
Modified: tor/branches/tor-0_1_2-patches/doc/TODO.012
===================================================================
--- tor/branches/tor-0_1_2-patches/doc/TODO.012 2007-08-16 16:41:36 UTC (rev 11132)
+++ tor/branches/tor-0_1_2-patches/doc/TODO.012 2007-08-16 16:41:38 UTC (rev 11133)
@@ -1,6 +1,6 @@
Backport items for 0.1.2:
- - r10939: Choose with complete fairness when exits are weighted.
- - r10956: fix the math for exit bandwidth weighting
+ o r10939: Choose with complete fairness when exits are weighted.
+ o r10956: fix the math for exit bandwidth weighting
o r10994: Disable SENTINELS checking in order to use less RAM in
buffer allocation.
- r11117: cookie auth more usable
Modified: tor/branches/tor-0_1_2-patches/src/or/routerlist.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/routerlist.c 2007-08-16 16:41:36 UTC (rev 11132)
+++ tor/branches/tor-0_1_2-patches/src/or/routerlist.c 2007-08-16 16:41:38 UTC (rev 11133)
@@ -961,6 +961,7 @@
uint64_t rand_bw, tmp;
double exit_weight;
int n_unknown = 0;
+ int include_exits = 1;
/* First count the total bandwidth weight, and make a list
* of each value. <0 means "unknown; no routerinfo." We use the
@@ -1043,19 +1044,35 @@
/* If we're choosing an exit node, exit bandwidth counts fully. */
exit_weight = 1.0;
total_bw = total_exit_bw + total_nonexit_bw;
- } else if (total_exit_bw < total_nonexit_bw / 2) {
- /* If we're choosing a relay and exits are greatly outnumbered, ignore
- * them. */
- exit_weight = 0.0;
- total_bw = total_nonexit_bw;
} else {
- /* If we're choosing a relay and exits aren't outnumbered use the formula
- * from path-spec. */
- uint64_t leftover = (total_exit_bw - total_nonexit_bw / 2);
- exit_weight = U64_TO_DBL(leftover) /
- U64_TO_DBL(leftover + total_nonexit_bw);
- total_bw = total_nonexit_bw +
- DBL_TO_U64(exit_weight * U64_TO_DBL(total_exit_bw));
+ double all_bw = U64_TO_DBL(total_exit_bw+total_nonexit_bw);
+ double exit_bw = U64_TO_DBL(total_exit_bw);
+ /*
+ * For detailed derivation of this formula, see
+ * http://archives.seul.org/or/dev/Jul-2007/msg00056.html
+ */
+ exit_weight = 1.0 - all_bw/(3.0*exit_bw);
+ if (exit_weight <= 0.0) {
+ include_exits = 0;
+ exit_weight = 0.0;
+ total_bw = total_nonexit_bw;
+ } else {
+ include_exits = 1;
+ total_bw = 0;
+ for (i=0; i < smartlist_len(sl); i++) {
+ if (statuses) {
+ status = smartlist_get(sl, i);
+ is_exit = status->is_exit;
+ } else {
+ router = smartlist_get(sl, i);
+ is_exit = router->is_exit;
+ }
+ if (is_exit)
+ total_bw += ((uint64_t)(bandwidths[i] * exit_weight));
+ else
+ total_bw += bandwidths[i];
+ }
+ }
}
/*
log_debug(LD_CIRC, "Total bw = "U64_FORMAT", total exit bw = "U64_FORMAT
More information about the tor-commits
mailing list