diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-10-24 19:53:08 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-10-24 19:53:08 +0000 |
commit | 9767415dca97280fabd457f18998426a53c7c9b2 (patch) | |
tree | 8ea0ddf8485ca409694644457526e51993bcd704 /src | |
parent | 02e7a83f91f7a051f3f493906e227aba1eb8a70a (diff) | |
download | tor-9767415dca97280fabd457f18998426a53c7c9b2.tar.gz tor-9767415dca97280fabd457f18998426a53c7c9b2.zip |
r16111@catbus: nickm | 2007-10-24 15:03:57 -0400
Allow multiple download schedules to exist. At the moment, we use one for consensus, and the other one for everything else.
svn:r12158
Diffstat (limited to 'src')
-rw-r--r-- | src/or/directory.c | 70 | ||||
-rw-r--r-- | src/or/networkstatus.c | 2 | ||||
-rw-r--r-- | src/or/or.h | 7 |
3 files changed, 57 insertions, 22 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 4e30c177f9..ac9e1c9285 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -2725,6 +2725,19 @@ dir_networkstatus_download_failed(smartlist_t *failed, int status_code) }); } +static const int server_dl_schedule[] = { + 0, 0, 0, 60, 60, 60*2, 60*5, 60*15, INT_MAX +}; +static const int client_dl_schedule[] = { + 0, 0, 60, 60*5, 60*10, INT_MAX +}; +static const int server_consensus_dl_schedule[] = { + 0, 0, 60, 60*5, 60*10, 60*30, 60*30, 60*30, 60*30, 60*30, 60*60, 60*60*2 +}; +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 +}; + /** Called when an attempt to download <b>dls</b> has failed with HTTP status * <b>status_code</b>. Increment the failure count (if the code indicates a * real failure) and set <b>dls<b>->next_attempt_at to an appropriate time in @@ -2733,31 +2746,46 @@ time_t download_status_increment_failure(download_status_t *dls, int status_code, const char *item, int server, time_t now) { + const int *schedule; + int schedule_len; + int increment; tor_assert(dls); if (status_code != 503 || server) ++dls->n_download_failures; - if (server) { - switch (dls->n_download_failures) { - case 0: dls->next_attempt_at = 0; break; - case 1: dls->next_attempt_at = 0; break; - case 2: dls->next_attempt_at = 0; break; - case 3: dls->next_attempt_at = now+60; break; - case 4: dls->next_attempt_at = now+60; break; - case 5: dls->next_attempt_at = now+60*2; break; - case 6: dls->next_attempt_at = now+60*5; break; - case 7: dls->next_attempt_at = now+60*15; break; - default: dls->next_attempt_at = TIME_MAX; break; - } - } else { - switch (dls->n_download_failures) { - case 0: dls->next_attempt_at = 0; break; - case 1: dls->next_attempt_at = 0; break; - case 2: dls->next_attempt_at = now+60; break; - case 3: dls->next_attempt_at = now+60*5; break; - case 4: dls->next_attempt_at = now+60*10; break; - default: dls->next_attempt_at = TIME_MAX; break; - } + + 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); } + + if (dls->n_download_failures < schedule_len) + increment = schedule[dls->n_download_failures]; + else + increment = schedule[schedule_len-1]; + + if (increment < INT_MAX) + dls->next_attempt_at = now+increment; + else + dls->next_attempt_at = TIME_MAX; + if (item) { if (dls->next_attempt_at == 0) log_debug(LD_DIR, "%s failed %d time(s); I'll try again immediately.", diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index d3f8ef8c6b..338028b216 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -49,7 +49,7 @@ static time_t last_networkstatus_download_attempted = 0; * before the current consensus becomes invalid. */ static time_t time_to_download_next_consensus = 0; /** Download status for the current consensus networkstatus. */ -static download_status_t consensus_dl_status = { 0, 0}; +static download_status_t consensus_dl_status = { 0, 0, DL_SCHED_CONSENSUS }; /** True iff we have logged a warning about this OR not being valid or * not being named. */ diff --git a/src/or/or.h b/src/or/or.h index fa5cd6acb0..57f657dcf9 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1067,6 +1067,12 @@ typedef enum { SAVED_IN_JOURNAL } saved_location_t; +/** DOCDOC */ +typedef enum { + DL_SCHED_GENERIC = 0, + DL_SCHED_CONSENSUS = 1, +} download_schedule_t; + /** Information about our plans for retrying downloads for a downloadable * object. */ typedef struct download_status_t { @@ -1074,6 +1080,7 @@ typedef struct download_status_t { * again? */ uint8_t n_download_failures; /**< Number of failures trying to download the * most recent descriptor. */ + download_schedule_t schedule : 1; } download_status_t; /** Information need to cache an onion router's descriptor. */ |