[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r10970: patches on r10968: compare advertised capacity, not bandwidt (tor/trunk/src/or)
Author: arma
Date: 2007-07-29 01:56:30 -0400 (Sun, 29 Jul 2007)
New Revision: 10970
Modified:
tor/trunk/src/or/dirserv.c
Log:
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.
Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c 2007-07-29 05:32:03 UTC (rev 10969)
+++ tor/trunk/src/or/dirserv.c 2007-07-29 05:56:30 UTC (rev 10970)
@@ -1728,6 +1728,7 @@
{
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 @@
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 @@
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 */