]> git.ipfire.org Git - thirdparty/tor.git/commit
Change smartlist_choose_node_by_bandwidth to avoid double
authorNick Mathewson <nickm@torproject.org>
Thu, 9 Aug 2012 16:21:37 +0000 (12:21 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 9 Aug 2012 16:21:37 +0000 (12:21 -0400)
commite106812a778f53760c819ab20a214ac3222b3b15
tree38d5ff9ade183c3cfa93a2dd75ecf9a935a6d12c
parent91b52a259a271df7ceeea6d8bf7adbd4d7e15a6c
Change smartlist_choose_node_by_bandwidth to avoid double

This should make our preferred solution to #6538 easier to
implement, avoid a bunch of potential nastiness with excessive
int-vs-double math, and generally make the code there a little less
scary.

"But wait!" you say.  "Is it really safe to do this? Won't the
results come out differently?"

Yes, but not much.  We now round every weighted bandwidth to the
nearest byte before computing on it.  This will make every node that
had a fractional part of its weighted bandwidth before either
slighty more likely or slightly less likely.  Further, the rand_bw
value was only ever set with integer precision, so it can't
accurately sample routers with tiny fractional bandwidth values
anyway.  Finally, doing repeated double-vs-uint64 comparisons is
just plain sad; it will involve an implicit cast to double, which is
never a fun thing.
changes/bug6538 [new file with mode: 0644]
configure.in
src/common/util.c
src/common/util.h
src/or/routerlist.c