diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-01-09 23:39:07 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-01-09 23:39:07 +0000 |
commit | 56c55c343e6d4f89ed1274263ef8c6dfbb45d53b (patch) | |
tree | fac56a66616bdbef6d8381f7a8d34857b3356410 | |
parent | bec9b705cc1c01b866a73a8ec34052b207e31ac4 (diff) | |
download | tor-56c55c343e6d4f89ed1274263ef8c6dfbb45d53b.tar.gz tor-56c55c343e6d4f89ed1274263ef8c6dfbb45d53b.zip |
When picking a random directory, prefer non-authorities if any are known.
svn:r5761
-rw-r--r-- | src/or/routerlist.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index d79d8931a7..3dbd0f5f6c 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -316,6 +316,7 @@ router_get_trusted_dir_servers(smartlist_t **outp) * reload the routerlist and try one last time. If for_runningrouters is * true, then only pick a dirserver that can answer runningrouters queries * (that is, a trusted dirserver, or one running 0.0.9rc5-cvs or later). + * Don't pick an authority if any non-authority is viable. * Other args are as in router_pick_directory_server_impl(). */ routerstatus_t * @@ -400,7 +401,7 @@ router_pick_trusteddirserver(int need_v1_authority, } /** Pick a random running verified directory server/mirror from our - * routerlist. + * routerlist. Don't pick an authority if any non-authorities are viable. * If <b>fascistfirewall</b>, * make sure the router we pick is allowed by our firewall options. * If <b>requireother</b>, it cannot be us. If <b>for_v2_directory</b>, @@ -413,15 +414,18 @@ router_pick_directory_server_impl(int requireother, int fascistfirewall, { routerstatus_t *result; smartlist_t *sl; + smartlist_t *trusted; if (!routerstatus_list) return NULL; /* Find all the running dirservers we know about. */ sl = smartlist_create(); + trusted = smartlist_create(); SMARTLIST_FOREACH(routerstatus_list, local_routerstatus_t *, _local_status, { routerstatus_t *status = &(_local_status->status); + int is_trusted; if (!status->is_running || !status->dir_port || !status->is_valid) continue; if (requireother && router_digest_is_me(status->identity_digest)) @@ -430,15 +434,18 @@ router_pick_directory_server_impl(int requireother, int fascistfirewall, if (!fascist_firewall_allows_address(status->addr, status->dir_port)) continue; } - if (for_v2_directory && - !(status->is_v2_dir || - router_digest_is_trusted_dir(status->identity_digest))) + is_trusted = router_digest_is_trusted_dir(status->identity_digest); + if (for_v2_directory && !(status->is_v2_dir || is_trusted)) continue; - smartlist_add(sl, status); + smartlist_add(is_trusted ? trusted : sl, status); }); - result = smartlist_choose(sl); + if (smartlist_len(sl)) + result = smartlist_choose(sl); + else + result = smartlist_choose(trusted); smartlist_free(sl); + smartlist_free(trusted); return result; } |