浏览代码

replace former relaunches of directory downloads with reset of failure count and relaunch of status downloads. Fix memory leak in trusted_dir_server_t. Reset "last download attempted" time when resetting failure counts.

svn:r5195
Nick Mathewson 20 年之前
父节点
当前提交
370e4abdc9
共有 4 个文件被更改,包括 64 次插入25 次删除
  1. 4 0
      src/or/circuituse.c
  2. 9 6
      src/or/main.c
  3. 2 2
      src/or/or.h
  4. 49 17
      src/or/routerlist.c

+ 4 - 0
src/or/circuituse.c

@@ -870,6 +870,10 @@ circuit_get_open_circ_or_launch(connection_t *conn,
   if (!has_fetched_directory) {
   if (!has_fetched_directory) {
     if (!connection_get_by_type(CONN_TYPE_DIR)) {
     if (!connection_get_by_type(CONN_TYPE_DIR)) {
       log(LOG_NOTICE,"Application request when we're believed to be offline. Optimistically trying again.");
       log(LOG_NOTICE,"Application request when we're believed to be offline. Optimistically trying again.");
+      router_reset_status_download_failures();
+      router_reset_descriptor_download_failures();
+      update_networkstatus_downloads(time(NULL));
+
       /* XXXX011 NM This should be a generic "retry all directory fetches". */
       /* XXXX011 NM This should be a generic "retry all directory fetches". */
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1); /*XXXX011NM*/
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1); /*XXXX011NM*/
     }
     }

+ 9 - 6
src/or/main.c

@@ -752,10 +752,7 @@ run_scheduled_events(time_t now)
     /* Also, once per minute, check whether we want to download any
     /* Also, once per minute, check whether we want to download any
      * networkstatus documents.
      * networkstatus documents.
      */
      */
-    if (server_mode(options) && options->DirPort)
-      update_networkstatus_cache_downloads(now);
-    else
-      update_networkstatus_client_downloads(now);
+    update_networkstatus_downloads(now);
   }
   }
 
 
   /** 3a. Every second, we examine pending circuits and prune the
   /** 3a. Every second, we examine pending circuits and prune the
@@ -946,8 +943,14 @@ do_hup(void)
       log_fn(LOG_NOTICE, "Error reloading fingerprints. Continuing with old list.");
       log_fn(LOG_NOTICE, "Error reloading fingerprints. Continuing with old list.");
     }
     }
   }
   }
-  /* XXXX011 NM This should be a generic "retry all directory fetches". */
-  directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1); /*XXXX011NM*/
+  /* retry appropriate downloads */
+  router_reset_status_download_failures();
+  router_reset_descriptor_download_failures();
+  update_networkstatus_downloads(time(NULL));
+
+  /* We'll retry routerstatus downloads in about 10 seconds; no need to
+   * force a retry there. */
+
   if (server_mode(options)) {
   if (server_mode(options)) {
     const char *descriptor;
     const char *descriptor;
     /* Restart cpuworker and dnsworker processes, so they get up-to-date
     /* Restart cpuworker and dnsworker processes, so they get up-to-date

+ 2 - 2
src/or/or.h

@@ -2146,8 +2146,7 @@ void add_trusted_dir_server(const char *nickname,
 void clear_trusted_dir_servers(void);
 void clear_trusted_dir_servers(void);
 networkstatus_t *networkstatus_get_by_digest(const char *digest);
 networkstatus_t *networkstatus_get_by_digest(const char *digest);
 local_routerstatus_t *router_get_combined_status_by_digest(const char *digest);
 local_routerstatus_t *router_get_combined_status_by_digest(const char *digest);
-void update_networkstatus_cache_downloads(time_t now);
-void update_networkstatus_client_downloads(time_t now);
+void update_networkstatus_downloads(time_t now);
 void update_router_descriptor_downloads(time_t now);
 void update_router_descriptor_downloads(time_t now);
 void routers_update_all_from_networkstatus(void);
 void routers_update_all_from_networkstatus(void);
 void routers_update_status_from_networkstatus(smartlist_t *routers,
 void routers_update_status_from_networkstatus(smartlist_t *routers,
@@ -2156,6 +2155,7 @@ smartlist_t *router_list_superseded(void);
 int router_have_minimum_dir_info(void);
 int router_have_minimum_dir_info(void);
 void networkstatus_list_update_recent(time_t now);
 void networkstatus_list_update_recent(time_t now);
 void router_reset_descriptor_download_failures(void);
 void router_reset_descriptor_download_failures(void);
+void router_reset_status_download_failures(void);
 
 
 /********************************* routerparse.c ************************/
 /********************************* routerparse.c ************************/
 
 

+ 49 - 17
src/or/routerlist.c

@@ -31,6 +31,9 @@ static int router_nickname_is_in_list(routerinfo_t *router, const char *list);
 static int router_nickname_matches(routerinfo_t *router, const char *nickname);
 static int router_nickname_matches(routerinfo_t *router, const char *nickname);
 static void routerstatus_list_update_from_networkstatus(time_t now);
 static void routerstatus_list_update_from_networkstatus(time_t now);
 static void local_routerstatus_free(local_routerstatus_t *rs);
 static void local_routerstatus_free(local_routerstatus_t *rs);
+static void trusted_dir_server_free(trusted_dir_server_t *ds);
+static void update_networkstatus_cache_downloads(time_t now);
+static void update_networkstatus_client_downloads(time_t now);
 
 
 /****************************************************************************/
 /****************************************************************************/
 
 
@@ -63,6 +66,11 @@ static smartlist_t *warned_nicknames = NULL;
  * and that are still conflicted. */
  * and that are still conflicted. */
 static smartlist_t *warned_conflicts = NULL;
 static smartlist_t *warned_conflicts = NULL;
 
 
+/* DOCDOC */
+static time_t last_routerdesc_download_attempted = 0;
+/* DOCDOC */
+static time_t last_networkstatus_download_attempted = 0;
+
 /*DOCDOC*/
 /*DOCDOC*/
 static int have_warned_about_unverified_status = 0;
 static int have_warned_about_unverified_status = 0;
 static int have_warned_about_old_version = 0;
 static int have_warned_about_old_version = 0;
@@ -482,6 +490,15 @@ mark_all_trusteddirservers_up(void)
       dir->n_networkstatus_failures = 0;
       dir->n_networkstatus_failures = 0;
     });
     });
   }
   }
+  last_networkstatus_download_attempted = 0;
+}
+
+/** Reset all internal variables used to count failed downloads of network
+ * status objects. */
+void
+router_reset_status_download_failures(void)
+{
+  mark_all_trusteddirservers_up();
 }
 }
 
 
 /** Return 0 if \\exists an authoritative dirserver that's currently
 /** Return 0 if \\exists an authoritative dirserver that's currently
@@ -1078,7 +1095,7 @@ routerlist_free_all(void)
   }
   }
   if (trusted_dir_servers) {
   if (trusted_dir_servers) {
     SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
     SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
-                      { tor_free(ds->address); tor_free(ds); });
+                      trusted_dir_server_free(ds));
     smartlist_free(trusted_dir_servers);
     smartlist_free(trusted_dir_servers);
     trusted_dir_servers = NULL;
     trusted_dir_servers = NULL;
   }
   }
@@ -1679,20 +1696,19 @@ router_get_combined_status_by_digest(const char *digest)
  * asking each trusted directory for its network-status.  For caches, this means
  * asking each trusted directory for its network-status.  For caches, this means
  * asking a random authority for all network-statuses.
  * asking a random authority for all network-statuses.
  */
  */
-void
+static void
 update_networkstatus_cache_downloads(time_t now)
 update_networkstatus_cache_downloads(time_t now)
 {
 {
-  static time_t last_downloaded = 0;
   int authority = authdir_mode(get_options());
   int authority = authdir_mode(get_options());
   int interval =
   int interval =
     authority ? AUTHORITY_NS_CACHE_INTERVAL : NONAUTHORITY_NS_CACHE_INTERVAL;
     authority ? AUTHORITY_NS_CACHE_INTERVAL : NONAUTHORITY_NS_CACHE_INTERVAL;
 
 
-  if (last_downloaded + interval >= now)
+  if (last_networkstatus_download_attempted + interval >= now)
     return;
     return;
   if (!trusted_dir_servers)
   if (!trusted_dir_servers)
     return;
     return;
 
 
-  last_downloaded = now;
+  last_networkstatus_download_attempted = now;
 
 
   if (authority) {
   if (authority) {
     /* An authority launches a separate connection for everybody. */
     /* An authority launches a separate connection for everybody. */
@@ -1734,7 +1750,7 @@ update_networkstatus_cache_downloads(time_t now)
  * by launching a new directory fetch for enough network-status documents "as
  * by launching a new directory fetch for enough network-status documents "as
  * necessary".  See function comments for implementation details.
  * necessary".  See function comments for implementation details.
  */
  */
-void
+static void
 update_networkstatus_client_downloads(time_t now)
 update_networkstatus_client_downloads(time_t now)
 {
 {
   int n_live = 0, needed = 0, n_running_dirservers, n_dirservers, i;
   int n_live = 0, needed = 0, n_running_dirservers, n_dirservers, i;
@@ -1829,6 +1845,17 @@ update_networkstatus_client_downloads(time_t now)
   tor_free(resource);
   tor_free(resource);
 }
 }
 
 
+/*DOCDOC*/
+void
+update_networkstatus_downloads(time_t now)
+{
+  or_options_t *options = get_options();
+  if (server_mode(options) && options->DirPort)
+      update_networkstatus_cache_downloads(time(NULL));
+    else
+      update_networkstatus_client_downloads(time(NULL));
+}
+
 /** Decide whether a given addr:port is definitely accepted,
 /** Decide whether a given addr:port is definitely accepted,
  * definitely rejected, probably accepted, or probably rejected by a
  * definitely rejected, probably accepted, or probably rejected by a
  * given policy.  If <b>addr</b> is 0, we don't know the IP of the
  * given policy.  If <b>addr</b> is 0, we don't know the IP of the
@@ -2069,18 +2096,23 @@ add_trusted_dir_server(const char *nickname, const char *address,
   smartlist_add(trusted_dir_servers, ent);
   smartlist_add(trusted_dir_servers, ent);
 }
 }
 
 
+/** Free storage held in <b>ds</b> */
+void
+trusted_dir_server_free(trusted_dir_server_t *ds)
+{
+  tor_free(ds->nickname);
+  tor_free(ds->description);
+  tor_free(ds->address);
+  tor_free(ds);
+}
+
 /** Remove all members from the list of trusted dir servers. */
 /** Remove all members from the list of trusted dir servers. */
 void
 void
 clear_trusted_dir_servers(void)
 clear_trusted_dir_servers(void)
 {
 {
   if (trusted_dir_servers) {
   if (trusted_dir_servers) {
     SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ent,
     SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ent,
-      {
-        tor_free(ent->nickname);
-        tor_free(ent->description);
-        tor_free(ent->address);
-        tor_free(ent);
-      });
+                      trusted_dir_server_free(ent));
     smartlist_clear(trusted_dir_servers);
     smartlist_clear(trusted_dir_servers);
   } else {
   } else {
     trusted_dir_servers = smartlist_create();
     trusted_dir_servers = smartlist_create();
@@ -2655,13 +2687,12 @@ update_router_descriptor_downloads(time_t now)
   int get_all = 0;
   int get_all = 0;
   int dirserv = server_mode(get_options()) && get_options()->DirPort;
   int dirserv = server_mode(get_options()) && get_options()->DirPort;
   int should_delay, n_downloadable;
   int should_delay, n_downloadable;
-  static time_t last_download_attempted = 0;
   if (!networkstatus_list || smartlist_len(networkstatus_list)<2)
   if (!networkstatus_list || smartlist_len(networkstatus_list)<2)
     get_all = 1;
     get_all = 1;
 
 
   if (get_all) {
   if (get_all) {
     log_fn(LOG_NOTICE, "Launching request for all routers");
     log_fn(LOG_NOTICE, "Launching request for all routers");
-    last_download_attempted = now;
+    last_routerdesc_download_attempted = now;
     directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,"all.z",1);
     directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,"all.z",1);
     return;
     return;
   }
   }
@@ -2673,10 +2704,10 @@ update_router_descriptor_downloads(time_t now)
   else if (n_downloadable == 0)
   else if (n_downloadable == 0)
     should_delay = 1;
     should_delay = 1;
   else if (dirserv)
   else if (dirserv)
-    should_delay = (last_download_attempted +
+    should_delay = (last_routerdesc_download_attempted +
                     MAX_SERVER_INTERVAL_WITHOUT_REQUEST) < now;
                     MAX_SERVER_INTERVAL_WITHOUT_REQUEST) < now;
   else
   else
-    should_delay = (last_download_attempted +
+    should_delay = (last_routerdesc_download_attempted +
                     MAX_CLIENT_INTERVAL_WITHOUT_REQUEST) < now;
                     MAX_CLIENT_INTERVAL_WITHOUT_REQUEST) < now;
 
 
   if (! should_delay) {
   if (! should_delay) {
@@ -2707,7 +2738,7 @@ update_router_descriptor_downloads(time_t now)
       memcpy(cp-1, ".z", 3);
       memcpy(cp-1, ".z", 3);
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,resource,1);
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,resource,1);
     }
     }
-    last_download_attempted = now;
+    last_routerdesc_download_attempted = now;
     tor_free(resource);
     tor_free(resource);
   }
   }
   SMARTLIST_FOREACH(downloadable, char *, c, tor_free(c));
   SMARTLIST_FOREACH(downloadable, char *, c, tor_free(c));
@@ -2743,5 +2774,6 @@ router_reset_descriptor_download_failures(void)
     rs->n_download_failures = 0;
     rs->n_download_failures = 0;
     rs->next_attempt_at = 0;
     rs->next_attempt_at = 0;
   });
   });
+  last_routerdesc_download_attempted = 0;
 }
 }