[or-cvs] r17798: {tor} partial move to letting bridge descriptor fetches use our ne (tor/trunk/src/or)

arma at seul.org arma at seul.org
Sat Dec 27 07:30:47 UTC 2008


Author: arma
Date: 2008-12-27 02:30:47 -0500 (Sat, 27 Dec 2008)
New Revision: 17798

Modified:
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/geoip.c
   tor/trunk/src/or/or.h
Log:
partial move to letting bridge descriptor fetches use our new (well,
new from their perspective) directory download schedule abstraction.

not done yet, but i'd better get this out of my sandbox before nick
does another sweeping change. :)


Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2008-12-27 07:28:47 UTC (rev 17797)
+++ tor/trunk/src/or/directory.c	2008-12-27 07:30:47 UTC (rev 17798)
@@ -3288,7 +3288,46 @@
 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 <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
@@ -3306,28 +3345,7 @@
       ++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 @@
 }
 
 /** Reset <b>dls</b> 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 <b>was_extrainfo</b>)

Modified: tor/trunk/src/or/geoip.c
===================================================================
--- tor/trunk/src/or/geoip.c	2008-12-27 07:28:47 UTC (rev 17797)
+++ tor/trunk/src/or/geoip.c	2008-12-27 07:30:47 UTC (rev 17798)
@@ -451,7 +451,7 @@
 /** 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)

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-12-27 07:28:47 UTC (rev 17797)
+++ tor/trunk/src/or/or.h	2008-12-27 07:30:47 UTC (rev 17798)
@@ -1287,6 +1287,7 @@
 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



More information about the tor-commits mailing list