When picking a random directory, prefer non-authorities if any are known.

svn:r5761
This commit is contained in:
Nick Mathewson 2006-01-09 23:39:07 +00:00
parent bec9b705cc
commit 56c55c343e

View File

@ -316,6 +316,7 @@ router_get_trusted_dir_servers(smartlist_t **outp)
* reload the routerlist and try one last time. If for_runningrouters is * reload the routerlist and try one last time. If for_runningrouters is
* true, then only pick a dirserver that can answer runningrouters queries * 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). * (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(). * Other args are as in router_pick_directory_server_impl().
*/ */
routerstatus_t * routerstatus_t *
@ -400,7 +401,7 @@ router_pick_trusteddirserver(int need_v1_authority,
} }
/** Pick a random running verified directory server/mirror from our /** 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>, * If <b>fascistfirewall</b>,
* make sure the router we pick is allowed by our firewall options. * 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>, * 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; routerstatus_t *result;
smartlist_t *sl; smartlist_t *sl;
smartlist_t *trusted;
if (!routerstatus_list) if (!routerstatus_list)
return NULL; return NULL;
/* Find all the running dirservers we know about. */ /* Find all the running dirservers we know about. */
sl = smartlist_create(); sl = smartlist_create();
trusted = smartlist_create();
SMARTLIST_FOREACH(routerstatus_list, local_routerstatus_t *, _local_status, SMARTLIST_FOREACH(routerstatus_list, local_routerstatus_t *, _local_status,
{ {
routerstatus_t *status = &(_local_status->status); routerstatus_t *status = &(_local_status->status);
int is_trusted;
if (!status->is_running || !status->dir_port || !status->is_valid) if (!status->is_running || !status->dir_port || !status->is_valid)
continue; continue;
if (requireother && router_digest_is_me(status->identity_digest)) 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)) if (!fascist_firewall_allows_address(status->addr, status->dir_port))
continue; continue;
} }
if (for_v2_directory && is_trusted = router_digest_is_trusted_dir(status->identity_digest);
!(status->is_v2_dir || if (for_v2_directory && !(status->is_v2_dir || is_trusted))
router_digest_is_trusted_dir(status->identity_digest)))
continue; 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(sl);
smartlist_free(trusted);
return result; return result;
} }