[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r12158: Allow multiple download schedules to exist. At the moment, w (in tor/trunk: . src/or)



Author: nickm
Date: 2007-10-24 15:53:08 -0400 (Wed, 24 Oct 2007)
New Revision: 12158

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/networkstatus.c
   tor/trunk/src/or/or.h
Log:
 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.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r16111] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-10-24 18:42:16 UTC (rev 12157)
+++ tor/trunk/ChangeLog	2007-10-24 19:53:08 UTC (rev 12158)
@@ -90,6 +90,8 @@
       after one fails: don't wait 60 seconds to notice.
     - When fetching a consensus as a cache, wait until a newer consensus
       should exist before trying to replace the current one.
+    - Use a more forgiving schedule for retrying failed consensus downloads
+      than for other types.
 
   o Minor bugfixes (other directory issues):
     - Correct the implementation of "download votes by digest." Bugfix on

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-10-24 18:42:16 UTC (rev 12157)
+++ tor/trunk/src/or/directory.c	2007-10-24 19:53:08 UTC (rev 12158)
@@ -2725,6 +2725,19 @@
   });
 }
 
+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 @@
 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.",

Modified: tor/trunk/src/or/networkstatus.c
===================================================================
--- tor/trunk/src/or/networkstatus.c	2007-10-24 18:42:16 UTC (rev 12157)
+++ tor/trunk/src/or/networkstatus.c	2007-10-24 19:53:08 UTC (rev 12158)
@@ -49,7 +49,7 @@
  * 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. */

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-10-24 18:42:16 UTC (rev 12157)
+++ tor/trunk/src/or/or.h	2007-10-24 19:53:08 UTC (rev 12158)
@@ -1067,6 +1067,12 @@
   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 @@
                            * 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. */