[or-cvs] r15083: report partial bootstrapping progress as we fetch descriptor (tor/trunk/src/or)

arma at seul.org arma at seul.org
Mon Jun 9 06:33:29 UTC 2008


Author: arma
Date: 2008-06-09 02:33:29 -0400 (Mon, 09 Jun 2008)
New Revision: 15083

Modified:
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/relay.c
   tor/trunk/src/or/routerlist.c
Log:
report partial bootstrapping progress as we fetch descriptors


Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2008-06-09 06:16:58 UTC (rev 15082)
+++ tor/trunk/src/or/directory.c	2008-06-09 06:33:29 UTC (rev 15083)
@@ -1304,6 +1304,8 @@
 
   router_load_routers_from_string(body, NULL, SAVED_NOWHERE, which,
                                   descriptor_digests, buf);
+  control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_DESCRIPTORS,
+                          count_loading_descriptors_progress());
 }
 
 /** We are a client, and we've finished reading the server's

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-06-09 06:16:58 UTC (rev 15082)
+++ tor/trunk/src/or/or.h	2008-06-09 06:33:29 UTC (rev 15083)
@@ -4047,6 +4047,7 @@
 int router_have_minimum_dir_info(void);
 void router_dir_info_changed(void);
 const char *get_dir_info_status_string(void);
+int count_loading_descriptors_progress(void);
 void router_reset_descriptor_download_failures(void);
 int router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2);
 int routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei,

Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c	2008-06-09 06:16:58 UTC (rev 15082)
+++ tor/trunk/src/or/relay.c	2008-06-09 06:33:29 UTC (rev 15083)
@@ -949,7 +949,8 @@
           control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_STATUS, 0);
           break;
         case DIR_PURPOSE_FETCH_SERVERDESC:
-          control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_DESCRIPTORS, 0);
+          control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_DESCRIPTORS,
+                                  count_loading_descriptors_progress());
           break;
       }
     }

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2008-06-09 06:16:58 UTC (rev 15082)
+++ tor/trunk/src/or/routerlist.c	2008-06-09 06:33:29 UTC (rev 15083)
@@ -4168,6 +4168,52 @@
   return dir_info_status;
 }
 
+static void
+count_usable_descriptors(int *num_present, int *num_usable,
+                         const networkstatus_t *consensus,
+                         or_options_t *options, time_t now)
+{
+  *num_present = 0, *num_usable=0;
+
+  SMARTLIST_FOREACH(consensus->routerstatus_list, routerstatus_t *, rs,
+     {
+       if (client_would_use_router(rs, now, options)) {
+         ++*num_usable; /* the consensus says we want it. */
+         if (router_get_by_descriptor_digest(rs->descriptor_digest)) {
+           /* we have the descriptor listed in the consensus. */
+           ++*num_present;
+         }
+       }
+     });
+
+  log_debug(LD_DIR, "%d usable, %d present.", *num_usable, *num_present);
+}
+
+int
+count_loading_descriptors_progress(void)
+{
+  int num_present = 0, num_usable=0;
+  time_t now = time(NULL);
+  const networkstatus_t *consensus =
+    networkstatus_get_reasonably_live_consensus(now);
+  double fraction;
+
+  if (!consensus)
+    return 0; /* can't count descriptors if we have no list of them */
+
+  count_usable_descriptors(&num_present, &num_usable,
+                           consensus, get_options(), now);
+
+  if (num_usable == 0)
+    return 0; /* don't div by 0 */
+  fraction = num_present / (num_usable/4.);
+  if (fraction > 1.0)
+    return 0; /* it's not the number of descriptors holding us back */
+  return BOOTSTRAP_STATUS_LOADING_DESCRIPTORS +
+           fraction*(BOOTSTRAP_STATUS_CONN_OR-1 -
+                     BOOTSTRAP_STATUS_LOADING_DESCRIPTORS);
+}
+
 /** Change the value of have_min_dir_info, setting it true iff we have enough
  * network and router information to build circuits.  Clear the value of
  * need_to_update_have_min_dir_info. */
@@ -4200,19 +4246,8 @@
     goto done;
   }
 
-  SMARTLIST_FOREACH(consensus->routerstatus_list, routerstatus_t *, rs,
-     {
-       if (client_would_use_router(rs, now, options)) {
-         ++num_usable; /* the consensus says we want it. */
-         if (router_get_by_descriptor_digest(rs->descriptor_digest)) {
-           /* we have the descriptor listed in the consensus. */
-           ++num_present;
-         }
-       }
-     });
+  count_usable_descriptors(&num_present, &num_usable, consensus, options, now);
 
-  log_debug(LD_DIR, "%d usable, %d present.", num_usable, num_present);
-
   if (num_present < num_usable/4) {
     tor_snprintf(dir_info_status, sizeof(dir_info_status),
             "We have only %d/%d usable descriptors.", num_present, num_usable);



More information about the tor-commits mailing list