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

[or-cvs] Use correct logic to decide whether there are more director...



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv32328/src/or

Modified Files:
	directory.c main.c or.h rendclient.c routerlist.c 
Log Message:
Use correct logic to decide whether there are more directory servers to retry.

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.184
retrieving revision 1.185
diff -u -d -r1.184 -r1.185
--- directory.c	3 Jan 2005 20:07:07 -0000	1.184
+++ directory.c	3 Jan 2005 20:51:24 -0000	1.185
@@ -143,9 +143,12 @@
  * connection purpose 'purpose' requesting 'resource'.  The purpose
  * should be one of 'DIR_PURPOSE_FETCH_DIR',
  * 'DIR_PURPOSE_FETCH_RENDDESC', 'DIR_PURPOSE_FETCH_RUNNING_LIST.'
+ * If <b>retry_if_no_servers</b>, then if all the possible servers seem
+ * down, mark them up and try again.
  */
 void
-directory_get_from_dirserver(uint8_t purpose, const char *resource)
+directory_get_from_dirserver(uint8_t purpose, const char *resource,
+                             int retry_if_no_servers)
 {
   routerinfo_t *r = NULL;
   trusted_dir_server_t *ds = NULL;
@@ -155,30 +158,34 @@
       purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
     if (advertised_server_mode()) {
       /* only ask authdirservers, and don't ask myself */
-      ds = router_pick_trusteddirserver(1, fascistfirewall);
+      ds = router_pick_trusteddirserver(1, fascistfirewall,
+                                        retry_if_no_servers);
     } else {
       /* anybody with a non-zero dirport will do */
       r = router_pick_directory_server(1, fascistfirewall,
-                                purpose==DIR_PURPOSE_FETCH_RUNNING_LIST);
+                                purpose==DIR_PURPOSE_FETCH_RUNNING_LIST,
+                                       retry_if_no_servers);
       if (!r) {
         log_fn(LOG_INFO, "No router found for %s; falling back to dirserver list",
                purpose == DIR_PURPOSE_FETCH_RUNNING_LIST
                ? "status list" : "directory");
-        ds = router_pick_trusteddirserver(1, fascistfirewall);
+        ds = router_pick_trusteddirserver(1, fascistfirewall,
+                                          retry_if_no_servers);
       }
     }
   } else { // (purpose == DIR_PURPOSE_FETCH_RENDDESC)
     /* only ask authdirservers, any of them will do */
     /* Never use fascistfirewall; we're going via Tor. */
-    ds = router_pick_trusteddirserver(0, 0);
+    ds = router_pick_trusteddirserver(0, 0, retry_if_no_servers);
   }
 
   if (r)
     directory_initiate_command_router(r, purpose, resource, NULL, 0);
   else if (ds)
     directory_initiate_command_trusted_dir(ds, purpose, resource, NULL, 0);
-  else
+  else {
     log_fn(LOG_WARN,"No running dirservers known. Not trying. (purpose %d)", purpose);
+  }
 }
 
 /** Launch a new connection to the directory server <b>router</b> to upload or
@@ -222,16 +229,9 @@
   router_mark_as_down(conn->identity_digest); /* don't try him again */
   if (conn->purpose == DIR_PURPOSE_FETCH_DIR ||
       conn->purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
-    /* XXX This should possibly take into account that
-     * !advertised_server_mode() allows us to use more directory
-     * servers, and fascistfirewall allows us to use less.
-     */
-    if (!all_trusted_directory_servers_down()) {
-      log_fn(LOG_INFO,"Giving up on dirserver '%s'; trying another.", conn->address);
-      directory_get_from_dirserver(conn->purpose, NULL);
-    } else {
-      log_fn(LOG_INFO,"Giving up on dirserver '%s'; no more to try.", conn->address);
-    }
+    log_fn(LOG_INFO, "Giving up on directory server at '%s'; retrying");
+    directory_get_from_dirserver(conn->purpose, NULL,
+                                 0 /* don't retry_if_no_servers */);
   }
 }
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.411
retrieving revision 1.412
diff -u -d -r1.411 -r1.412
--- main.c	25 Dec 2004 06:43:40 -0000	1.411
+++ main.c	3 Jan 2005 20:51:24 -0000	1.412
@@ -605,7 +605,7 @@
       router_retry_connections();
     }
 
-    directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL);
+    directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
     time_to_fetch_directory = now + options->DirFetchPeriod;
     if (time_to_fetch_running_routers < now + options->StatusFetchPeriod) {
       time_to_fetch_running_routers = now + options->StatusFetchPeriod;
@@ -617,7 +617,7 @@
 
   if (time_to_fetch_running_routers < now) {
     if (!authdir_mode(options)) {
-      directory_get_from_dirserver(DIR_PURPOSE_FETCH_RUNNING_LIST, NULL);
+      directory_get_from_dirserver(DIR_PURPOSE_FETCH_RUNNING_LIST, NULL, 1);
     }
     time_to_fetch_running_routers = now + options->StatusFetchPeriod;
   }
@@ -779,7 +779,7 @@
     }
   }
   /* Fetch a new directory. Even authdirservers do this. */
-  directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL);
+  directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
   if (server_mode(options)) {
     /* Restart cpuworker and dnsworker processes, so they get up-to-date
      * configuration options. */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.513
retrieving revision 1.514
diff -u -d -r1.513 -r1.514
--- or.h	3 Jan 2005 20:07:07 -0000	1.513
+++ or.h	3 Jan 2005 20:51:24 -0000	1.514
@@ -1313,12 +1313,13 @@
 int dir_policy_permits_address(uint32_t addr);
 void directory_post_to_dirservers(uint8_t purpose, const char *payload,
                                   size_t payload_len);
-void directory_get_from_dirserver(uint8_t purpose, const char *resource);
+void directory_get_from_dirserver(uint8_t purpose, const char *resource,
+                                  int retry_if_no_servers);
 int connection_dir_reached_eof(connection_t *conn);
 int connection_dir_process_inbuf(connection_t *conn);
 int connection_dir_finished_flushing(connection_t *conn);
 int connection_dir_finished_connecting(connection_t *conn);
-int connection_dir_failed(connection_t *conn);
+int connection_dir_connect_failed(connection_t *conn);
 void parse_dir_policy(void);
 
 /********************************* dirserv.c ***************************/
@@ -1571,8 +1572,13 @@
 
 int router_reload_router_list(void);
 void router_get_trusted_dir_servers(smartlist_t **outp);
-routerinfo_t *router_pick_directory_server(int requireothers, int fascistfirewall, int for_running_routers);
-trusted_dir_server_t *router_pick_trusteddirserver(int requireothers, int fascistfirewall);
+routerinfo_t *router_pick_directory_server(int requireothers,
+                                           int fascistfirewall,
+                                           int for_running_routers,
+                                           int retry_if_no_servers);
+trusted_dir_server_t *router_pick_trusteddirserver(int requireothers,
+                                                   int fascistfirewall,
+                                                   int retry_if_no_servers);
 int all_trusted_directory_servers_down(void);
 struct smartlist_t;
 void routerlist_add_family(struct smartlist_t *sl, routerinfo_t *router);

Index: rendclient.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendclient.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- rendclient.c	7 Dec 2004 19:42:45 -0000	1.71
+++ rendclient.c	3 Jan 2005 20:51:24 -0000	1.72
@@ -250,7 +250,7 @@
     log_fn(LOG_INFO,"Would fetch a new renddesc here (for %s), but one is already in progress.", query);
   } else {
     /* not one already; initiate a dir rend desc lookup */
-    directory_get_from_dirserver(DIR_PURPOSE_FETCH_RENDDESC, query);
+    directory_get_from_dirserver(DIR_PURPOSE_FETCH_RENDDESC, query, 1);
   }
 }
 

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -d -r1.202 -r1.203
--- routerlist.c	3 Jan 2005 17:53:20 -0000	1.202
+++ routerlist.c	3 Jan 2005 20:51:24 -0000	1.203
@@ -95,7 +95,8 @@
  */
 routerinfo_t *router_pick_directory_server(int requireothers,
                                            int fascistfirewall,
-                                           int for_runningrouters) {
+                                           int for_runningrouters,
+                                           int retry_if_no_servers) {
   routerinfo_t *choice;
 
   if (!routerlist)
@@ -103,7 +104,7 @@
 
   choice = router_pick_directory_server_impl(requireothers, fascistfirewall,
                                              for_runningrouters);
-  if (choice)
+  if (choice || !retry_if_no_servers)
     return choice;
 
   log_fn(LOG_INFO,"No reachable router entries for dirservers. Trying them all again.");
@@ -128,11 +129,12 @@
 }
 
 trusted_dir_server_t *router_pick_trusteddirserver(int requireothers,
-                                                   int fascistfirewall) {
+                                                   int fascistfirewall,
+                                                   int retry_if_no_servers) {
   trusted_dir_server_t *choice;
 
   choice = router_pick_trusteddirserver_impl(requireothers, fascistfirewall);
-  if (choice)
+  if (choice || !retry_if_no_servers)
     return choice;
 
   log_fn(LOG_INFO,"No trusted dirservers are reachable. Trying them all again.");