mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
Make directory download code slightly less likely to segfault or assert.
svn:r4929
This commit is contained in:
parent
022f23249f
commit
3a99927859
@ -170,6 +170,8 @@ directory_get_from_dirserver(uint8_t purpose, const char *resource,
|
|||||||
int priv = purpose_is_private(purpose);
|
int priv = purpose_is_private(purpose);
|
||||||
int need_v1_support = purpose == DIR_PURPOSE_FETCH_DIR ||
|
int need_v1_support = purpose == DIR_PURPOSE_FETCH_DIR ||
|
||||||
purpose == DIR_PURPOSE_FETCH_RUNNING_LIST;
|
purpose == DIR_PURPOSE_FETCH_RUNNING_LIST;
|
||||||
|
int need_v2_support = purpose == DIR_PURPOSE_FETCH_NETWORKSTATUS ||
|
||||||
|
purpose == DIR_PURPOSE_FETCH_SERVERDESC;
|
||||||
|
|
||||||
if (directconn) {
|
if (directconn) {
|
||||||
if (fetch_fresh_first && purpose == DIR_PURPOSE_FETCH_NETWORKSTATUS &&
|
if (fetch_fresh_first && purpose == DIR_PURPOSE_FETCH_NETWORKSTATUS &&
|
||||||
@ -186,7 +188,7 @@ directory_get_from_dirserver(uint8_t purpose, const char *resource,
|
|||||||
}
|
}
|
||||||
if (!ds) {
|
if (!ds) {
|
||||||
/* anybody with a non-zero dirport will do */
|
/* anybody with a non-zero dirport will do */
|
||||||
r = router_pick_directory_server(1, fascistfirewall, 0,
|
r = router_pick_directory_server(1, fascistfirewall, need_v2_support,
|
||||||
retry_if_no_servers);
|
retry_if_no_servers);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
const char *which;
|
const char *which;
|
||||||
|
@ -1294,12 +1294,14 @@ update_networkstatus_downloads(void)
|
|||||||
* publication time. We want to download a new *one* if the most recent
|
* publication time. We want to download a new *one* if the most recent
|
||||||
* one's publication time is under ABOUT_HALF_AN_HOUR.
|
* one's publication time is under ABOUT_HALF_AN_HOUR.
|
||||||
*/
|
*/
|
||||||
|
if (!trusted_dir_servers || !smartlist_len(trusted_dir_servers))
|
||||||
tor_assert(trusted_dir_servers);
|
return;
|
||||||
n_dirservers = smartlist_len(trusted_dir_servers);
|
n_dirservers = smartlist_len(trusted_dir_servers);
|
||||||
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
|
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
|
||||||
{
|
{
|
||||||
networkstatus_t *ns = networkstatus_get_by_digest(ds->digest);
|
networkstatus_t *ns = networkstatus_get_by_digest(ds->digest);
|
||||||
|
if (!ns)
|
||||||
|
continue;
|
||||||
if (ns->published_on > now-ABOUT_TWO_DAYS)
|
if (ns->published_on > now-ABOUT_TWO_DAYS)
|
||||||
++n_live;
|
++n_live;
|
||||||
if (!most_recent || ns->received_on > most_recent_received) {
|
if (!most_recent || ns->received_on > most_recent_received) {
|
||||||
@ -1330,7 +1332,7 @@ update_networkstatus_downloads(void)
|
|||||||
for (i = most_recent_idx+1; needed; ++i) {
|
for (i = most_recent_idx+1; needed; ++i) {
|
||||||
char resource[HEX_DIGEST_LEN+1];
|
char resource[HEX_DIGEST_LEN+1];
|
||||||
trusted_dir_server_t *ds;
|
trusted_dir_server_t *ds;
|
||||||
if (i > n_dirservers)
|
if (i >= n_dirservers)
|
||||||
i = 0;
|
i = 0;
|
||||||
ds = smartlist_get(trusted_dir_servers, i);
|
ds = smartlist_get(trusted_dir_servers, i);
|
||||||
base16_encode(resource, sizeof(resource), ds->digest, DIGEST_LEN);
|
base16_encode(resource, sizeof(resource), ds->digest, DIGEST_LEN);
|
||||||
|
Loading…
Reference in New Issue
Block a user