diff --git a/src/or/directory.c b/src/or/directory.c index 5a1de4317a..54a55eca06 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -3288,6 +3288,45 @@ static const int server_consensus_dl_schedule[] = { static const int client_consensus_dl_schedule[] = { 0, 0, 60, 60*5, 60*10, 60*30, 60*60, 60*60, 60*60, 60*60*3, 60*60*6, 60*60*12 }; +/** Schedule for when clients should download bridge descriptors. */ +static const int bridge_dl_schedule[] = { + 60*60, 15*60, 15*60, 60*60 +}; + +/** Decide which download schedule we want to use, and then return a + * pointer to it along with a pointer to its length. Helper function for + * download_status_increment_failure() and download_status_reset(). */ +static void +find_dl_schedule_and_len(download_status_t *dls, int server, + const int **schedule, size_t *schedule_len) +{ + switch (dls->schedule) { + case DL_SCHED_GENERIC: + if (server) { + *schedule = server_dl_schedule; + *schedule_len = sizeof(server_dl_schedule)/sizeof(int); + } else { + *schedule = client_dl_schedule; + *schedule_len = sizeof(client_dl_schedule)/sizeof(int); + } + break; + case DL_SCHED_CONSENSUS: + if (server) { + *schedule = server_consensus_dl_schedule; + *schedule_len = sizeof(server_consensus_dl_schedule)/sizeof(int); + } else { + *schedule = client_consensus_dl_schedule; + *schedule_len = sizeof(client_consensus_dl_schedule)/sizeof(int); + } + break; + case DL_SCHED_BRIDGE: + *schedule = bridge_dl_schedule; + *schedule_len = sizeof(bridge_dl_schedule)/sizeof(int); + break; + default: + tor_assert(0); + } +} /** Called when an attempt to download dls has failed with HTTP status * status_code. Increment the failure count (if the code indicates a @@ -3306,28 +3345,7 @@ download_status_increment_failure(download_status_t *dls, int status_code, ++dls->n_download_failures; } - switch (dls->schedule) { - case DL_SCHED_GENERIC: - if (server) { - schedule = server_dl_schedule; - schedule_len = sizeof(server_dl_schedule)/sizeof(int); - } else { - schedule = client_dl_schedule; - schedule_len = sizeof(client_dl_schedule)/sizeof(int); - } - break; - case DL_SCHED_CONSENSUS: - if (server) { - schedule = server_consensus_dl_schedule; - schedule_len = sizeof(server_consensus_dl_schedule)/sizeof(int); - } else { - schedule = client_consensus_dl_schedule; - schedule_len = sizeof(client_consensus_dl_schedule)/sizeof(int); - } - break; - default: - tor_assert(0); - } + find_dl_schedule_and_len(dls, server, &schedule, &schedule_len); if (dls->n_download_failures < schedule_len) increment = schedule[dls->n_download_failures]; @@ -3357,12 +3375,24 @@ download_status_increment_failure(download_status_t *dls, int status_code, } /** Reset dls so that it will be considered downloadable - * immediately. */ + * immediately, and/or to show that we don't need it anymore. + * + * (We find the zeroth element of the download schedule, and set + * next_attempt_at to be the appropriate offset from 'now'. In most + * cases this means setting it to 'now', so the item will be immediately + * downloadable; in the case of bridge descriptors, the zeroth element + * is an hour from now.) */ void download_status_reset(download_status_t *dls) { + const int *schedule; + size_t schedule_len; + + find_dl_schedule_and_len(dls, get_options()->DirPort, + &schedule, &schedule_len); + dls->n_download_failures = 0; - dls->next_attempt_at = 0; + dls->next_attempt_at = time(NULL) + schedule[0]; } /** Called when one or more routerdesc (or extrainfo, if was_extrainfo) diff --git a/src/or/geoip.c b/src/or/geoip.c index 908cb307fb..3dbfab1869 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -451,7 +451,7 @@ round_to_next_multiple_of(unsigned number, unsigned divisor) /** Return a newly allocated comma-separated string containing entries for all * the countries from which we've seen enough clients connect. The entry * format is cc=num where num is the number of IPs we've seen connecting from - * that country, and cc is a lowercased country code. Returns NULL if we don't + * that country, and cc is a lowercased country code. Returns NULL if we don't * want to export geoip data yet. */ char * geoip_get_client_history(time_t now, geoip_client_action_t action) diff --git a/src/or/or.h b/src/or/or.h index e2f3a8c4c2..2d539e6b73 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1287,6 +1287,7 @@ typedef enum { typedef enum { DL_SCHED_GENERIC = 0, DL_SCHED_CONSENSUS = 1, + DL_SCHED_BRIDGE = 2, } download_schedule_t; /** Information about our plans for retrying downloads for a downloadable