diff options
author | Roger Dingledine <arma@torproject.org> | 2007-07-29 05:56:30 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2007-07-29 05:56:30 +0000 |
commit | a68e6e23c98ddbfe318e1aad615de6af2b4c1e45 (patch) | |
tree | fb6f7997d7c698850fa7258561cd78ac53fdb8d9 | |
parent | 9031bbd4d86b4222af8e487a2f8204c334e410a5 (diff) | |
download | tor-a68e6e23c98ddbfe318e1aad615de6af2b4c1e45.tar tor-a68e6e23c98ddbfe318e1aad615de6af2b4c1e45.tar.gz |
patches on r10968: compare advertised capacity, not bandwidthrate;
and make the sorting order deterministic to avoid flapping.
also note that we could take the "is_auth" checks out of the
sorting entirely.
svn:r10970
-rw-r--r-- | src/or/dirserv.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index bf818d01e..d596f8923 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1728,6 +1728,7 @@ _compare_routerinfo_by_ip_and_bw(const void **a, const void **b) { routerinfo_t *first = *(routerinfo_t **)a, *second = *(routerinfo_t **)b; int first_is_auth, second_is_auth; + uint32_t bw_first, bw_second; /* we return -1 if first should appear before second... that is, * if first is a better router. */ @@ -1736,6 +1737,8 @@ _compare_routerinfo_by_ip_and_bw(const void **a, const void **b) else if (first->addr > second->addr) return 1; + /* XXX020 k n lg n memcmps could show up bigtime in profiling. If + * they do, I suggest we just give authorities a free pass. -RD */ first_is_auth = router_digest_is_trusted_dir(first->cache_info.identity_digest); second_is_auth = @@ -1751,12 +1754,17 @@ _compare_routerinfo_by_ip_and_bw(const void **a, const void **b) else if (!first->is_running && second->is_running) return 1; - else if (first->bandwidthrate > second->bandwidthrate) - return -1; - else if (first->bandwidthrate < second->bandwidthrate) + bw_first = router_get_advertised_bandwidth(first); + bw_second = router_get_advertised_bandwidth(second); + + if (bw_first > bw_second) + return -1; + else if (bw_first < bw_second) return 1; - else - return 0; + + /* They're equal! Compare by identity digest, so there's a + * deterministic order and we avoid flapping. */ + return _compare_routerinfo_by_id_digest(a, b); } /** DOCDOC takes list of routerinfo */ |