[or-cvs] Clean fake_status a bit. Switch from has_fetched_directory...

Nick Mathewson nickm at seul.org
Thu Dec 15 20:44:17 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv22611/src/or

Modified Files:
	circuituse.c directory.c main.c or.h routerlist.c 
Log Message:
Clean fake_status a bit.  Switch from has_fetched_directory to have_minimum_dir_info, and make the latter function smarter.

Index: circuituse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuituse.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- circuituse.c	14 Dec 2005 20:40:40 -0000	1.104
+++ circuituse.c	15 Dec 2005 20:44:15 -0000	1.105
@@ -19,7 +19,6 @@
 /********* START VARIABLES **********/
 
 extern circuit_t *global_circuitlist; /* from circuitlist.c */
-extern int has_fetched_directory; /* from main.c */
 
 /********* END VARIABLES ************/
 
@@ -423,7 +422,7 @@
   connection_ap_attach_pending();
 
   /* make sure any hidden services have enough intro points */
-  if (has_fetched_directory)
+  if (router_have_minimum_dir_info())
     rend_services_introduce();
 
   if (time_to_new_circuit < now) {
@@ -769,8 +768,9 @@
 {
   circuit_t *circ;
 
-  if (!has_fetched_directory) {
-    debug(LD_CIRC,"Haven't fetched directory yet; canceling circuit launch.");
+  if (!router_have_minimum_dir_info()) {
+    debug(LD_CIRC,"Haven't fetched enough directory info yet; canceling "
+          "circuit launch.");
     return NULL;
   }
 
@@ -899,7 +899,7 @@
     return 1; /* we're happy */
   }
 
-  if (!has_fetched_directory) {
+  if (!router_have_minimum_dir_info()) {
     if (!connection_get_by_type(CONN_TYPE_DIR)) {
       notice(LD_APP|LD_DIR,"Application request when we're believed to be "
              "offline. Optimistically trying directory fetches again.");
@@ -910,7 +910,7 @@
       /* XXXX011 NM This should be a generic "retry all directory fetches". */
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
     }
-    /* the stream will be dealt with when has_fetched_directory becomes
+    /* the stream will be dealt with when router_have_minimum_dir_info becomes
      * 1, or when all directory attempts fail and directory_all_unreachable()
      * kills it.
      */

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.326
retrieving revision 1.327
diff -u -d -r1.326 -r1.327
--- directory.c	14 Dec 2005 22:00:58 -0000	1.326
+++ directory.c	15 Dec 2005 20:44:15 -0000	1.327
@@ -212,7 +212,9 @@
       /* anybody with a non-zero dirport will do. Disregard firewalls. */
       rs = router_pick_directory_server(1, 0, need_v2_support,
                                         retry_if_no_servers);
-      /* XXXX If no rs, fall back to trusted dir servers? -NM */
+      /* If we have any hope of building an indirect conn, we know some router
+       * decriptors.  If (rs==NULL), we can't build circuits anyway, so
+       * there's no point in falling back to the authorities in this case.  */
     }
   }
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.601
retrieving revision 1.602
diff -u -d -r1.601 -r1.602
--- main.c	14 Dec 2005 20:40:40 -0000	1.601
+++ main.c	15 Dec 2005 20:44:15 -0000	1.602
@@ -57,11 +57,6 @@
 
 static int nfds=0; /**< Number of connections currently active. */
 
-/** We set this to 1 when we've fetched a dir, to know whether to complain
- * yet about unrecognized nicknames in entrynodes, exitnodes, etc.
- * Also, we don't try building circuits unless this is 1. */
-int has_fetched_directory=0;
-
 /** We set this to 1 when we've opened a circuit, so we can print a log
  * entry to inform the user that Tor is working. */
 int has_completed_circuit=0;
@@ -513,9 +508,7 @@
 directory_all_unreachable(time_t now)
 {
   connection_t *conn;
-  /* XXXX011 NM Update this to reflect new directories? */
 
-  has_fetched_directory=0;
   stats_n_seconds_working=0; /* reset it */
 
   while ((conn = connection_get_by_type_state(CONN_TYPE_AP,
@@ -574,13 +567,6 @@
     return;
   }
 
-  if (!has_fetched_directory) {
-    log(LOG_NOTICE, LD_DIR, "We have enough directory information to "
-        "build circuits.");
-  }
-
-  has_fetched_directory=1;
-
   if (server_mode(options) &&
       !we_are_hibernating()) { /* connect to the appropriate routers */
     if (!authdir_mode(options))
@@ -704,6 +690,7 @@
   static time_t time_to_add_entropy = 0;
   or_options_t *options = get_options();
   int i;
+  int have_dir_info;
 
   /** 0. See if we've been asked to shut down and our timeout has
    * expired; or if our bandwidth limits are exhausted and we
@@ -861,7 +848,8 @@
    *    that became dirty more than MaxCircuitDirtiness seconds ago,
    *    and we make a new circ if there are no clean circuits.
    */
-  if (has_fetched_directory && !we_are_hibernating())
+  have_dir_info = router_have_minimum_dir_info();
+  if (have_dir_info && !we_are_hibernating())
     circuit_build_needed_circs(now);
 
   /** 5. We do housekeeping for each connection... */
@@ -883,7 +871,7 @@
   circuit_close_all_marked();
 
   /** 7. And upload service descriptors if necessary. */
-  if (has_fetched_directory && !we_are_hibernating())
+  if (have_dir_info && !we_are_hibernating())
     rend_consider_services_upload(now);
 
   /** 8. and blow away any connections that need to die. have to do this now,

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.757
retrieving revision 1.758
diff -u -d -r1.757 -r1.758
--- or.h	14 Dec 2005 22:00:58 -0000	1.757
+++ or.h	15 Dec 2005 20:44:15 -0000	1.758
@@ -2195,7 +2195,10 @@
   int n_networkstatus_failures; /**< How many times have we asked for this
                                  * server's network-status unsuccessfully? */
   routerstatus_t fake_status; /**< Used when we need to pass this trusted
-                               * dir_server_t as a routerstatus_t. */
+                               * dir_server_t to directory_initiate_command_*
+                               * as a routerstatus_t.  Not updated by the
+                               * router-status management code!
+                               **/
 } trusted_dir_server_t;
 
 int router_reload_router_list(void);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.393
retrieving revision 1.394
diff -u -d -r1.393 -r1.394
--- routerlist.c	15 Dec 2005 09:53:00 -0000	1.393
+++ routerlist.c	15 Dec 2005 20:44:15 -0000	1.394
@@ -46,8 +46,6 @@
 /** Global list of all of the routers that we know about. */
 static routerlist_t *routerlist = NULL;
 
-extern int has_fetched_directory; /* from main.c */
-
 /** Global list of all of the current network_status documents that we know
  * about.  This list is kept sorted by published_on. */
 static smartlist_t *networkstatus_list = NULL;
@@ -497,8 +495,12 @@
   if (trusted_dir_servers) {
     SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, dir,
     {
+      local_routerstatus_t *rs;
       dir->is_running = 1;
       dir->n_networkstatus_failures = 0;
+      rs = router_get_combined_status_by_digest(dir->digest);
+      if (rs)
+        rs->status.is_running = 1;
     });
   }
   last_networkstatus_download_attempted = 0;
@@ -573,6 +575,7 @@
 {
   routerinfo_t *router;
   smartlist_t *nickname_list;
+  int have_dir_info = router_have_minimum_dir_info();
 
   if (!list)
     return; /* nothing to do */
@@ -607,7 +610,7 @@
       }
     } else {
       if (!warned) {
-        log_fn(has_fetched_directory ? LOG_WARN : LOG_INFO, LD_CONFIG,
+        log_fn(have_dir_info ? LOG_WARN : LOG_INFO, LD_CONFIG,
                "Nickname list includes '%s' which isn't a known router.",nick);
         smartlist_add(warned_nicknames, tor_strdup(nick));
       }
@@ -2559,10 +2562,6 @@
   strlcpy(ent->fake_status.nickname, nickname,
           sizeof(ent->fake_status.nickname));
   ent->fake_status.dir_port = ent->dir_port;
-  ent->fake_status.is_running = 1;
-  ent->fake_status.is_named = 1;
-  ent->fake_status.is_valid = 1;
-  ent->fake_status.is_v2_dir = 1;
 
   smartlist_add(trusted_dir_servers, ent);
 }
@@ -3308,19 +3307,43 @@
 /** Return true iff we have enough networkstatus and router information to
  * start building circuits.  Right now, this means "at least 2 networkstatus
  * documents, and at least 1/4 of expected routers." */
-//XXX should consider whether we have enough exiting nodes here.
-//and also consider if they're too "old"?
 int
 router_have_minimum_dir_info(void)
 {
-  int tot = 0, avg;
-  if (!networkstatus_list || smartlist_len(networkstatus_list)<2 ||
-      !routerlist)
-    return 0;
+  int tot = 0, any_running = 0;
+  int n_ns, res, avg;
+  static int have_enough = 0;
+  if (!networkstatus_list || !routerlist) {
+    res = 0;
+    goto done;
+  }
+  n_ns = smartlist_len(networkstatus_list);
+  if (n_ns<2) {
+    res = 0;
+    goto done;
+  }
   SMARTLIST_FOREACH(networkstatus_list, networkstatus_t *, ns,
                     tot += smartlist_len(ns->entries));
-  avg = tot / smartlist_len(networkstatus_list);
-  return smartlist_len(routerlist->routers) > (avg/4);
+  avg = tot / n_ns;
+  SMARTLIST_FOREACH(routerstatus_list, local_routerstatus_t *, rs,
+     {
+       if (rs->status.is_running) {
+         any_running = 1;
+         break;
+       }
+     });
+  res = smartlist_len(routerlist->routers) > (avg/4) && any_running;
+ done:
+  if (res && !have_enough) {
+    log(LOG_NOTICE, LD_DIR,
+        "We now have enough directory information to build circuits.");
+  }
+  if (!res && !have_enough) {
+    log(LOG_NOTICE, LD_DIR, "Our directory information is no longer up-to-date "
+        "enough to build circuits.");
+  }
+  have_enough = res;
+  return res;
 }
 
 /** Reset the descriptor download failure count on all routers, so that we



More information about the tor-commits mailing list