mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
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
This commit is contained in:
parent
9031bbd4d8
commit
a68e6e23c9
@ -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;
|
routerinfo_t *first = *(routerinfo_t **)a, *second = *(routerinfo_t **)b;
|
||||||
int first_is_auth, second_is_auth;
|
int first_is_auth, second_is_auth;
|
||||||
|
uint32_t bw_first, bw_second;
|
||||||
|
|
||||||
/* we return -1 if first should appear before second... that is,
|
/* we return -1 if first should appear before second... that is,
|
||||||
* if first is a better router. */
|
* 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)
|
else if (first->addr > second->addr)
|
||||||
return 1;
|
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 =
|
first_is_auth =
|
||||||
router_digest_is_trusted_dir(first->cache_info.identity_digest);
|
router_digest_is_trusted_dir(first->cache_info.identity_digest);
|
||||||
second_is_auth =
|
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)
|
else if (!first->is_running && second->is_running)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
else if (first->bandwidthrate > second->bandwidthrate)
|
bw_first = router_get_advertised_bandwidth(first);
|
||||||
return -1;
|
bw_second = router_get_advertised_bandwidth(second);
|
||||||
else if (first->bandwidthrate < second->bandwidthrate)
|
|
||||||
|
if (bw_first > bw_second)
|
||||||
|
return -1;
|
||||||
|
else if (bw_first < bw_second)
|
||||||
return 1;
|
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 */
|
/** DOCDOC takes list of routerinfo */
|
||||||
|
Loading…
Reference in New Issue
Block a user