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

[or-cvs] r15343: Add instrumentation to the 0.1.2.x branch (disabled by defau (in tor/branches/tor-0_1_2-patches: . src/or)



Author: nickm
Date: 2008-06-17 23:26:13 -0400 (Tue, 17 Jun 2008)
New Revision: 15343

Modified:
   tor/branches/tor-0_1_2-patches/ChangeLog
   tor/branches/tor-0_1_2-patches/src/or/routerlist.c
Log:
Add instrumentation to the 0.1.2.x branch (disabled by default) to dump the weights of various directory servers when we update our local networkstatus opinions.  To turn this on, define DUMP_DIR_WEIGHTS in routerlist.c.  This has to be in 0.1.2.x, since the code to pick 0.1.2.x directories is pretty different in more recent releases.

Modified: tor/branches/tor-0_1_2-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_2-patches/ChangeLog	2008-06-18 00:22:29 UTC (rev 15342)
+++ tor/branches/tor-0_1_2-patches/ChangeLog	2008-06-18 03:26:13 UTC (rev 15343)
@@ -31,7 +31,13 @@
       preemptively build circuits to handle expected directory requests.
       Fixes bug 660.
 
+  o Minor testing features:
+    - Add disabled-by-default code to log the relative probability of routing
+      a v2 directory request through all known routers.  This is quite handy
+      for estimating what fraction of the total v2-directory-protocol-using
+      network a directory server has seen.
 
+
 Changes in version 0.1.2.19 - 2008-01-17
   Tor 0.1.2.19 fixes a huge memory leak on exit relays, makes the default
   exit policy a little bit more conservative so it's safer to run an

Modified: tor/branches/tor-0_1_2-patches/src/or/routerlist.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/routerlist.c	2008-06-18 00:22:29 UTC (rev 15342)
+++ tor/branches/tor-0_1_2-patches/src/or/routerlist.c	2008-06-18 03:26:13 UTC (rev 15343)
@@ -17,6 +17,8 @@
 
 // #define DEBUG_ROUTERLIST
 
+// #define DUMP_DIR_WEIGHTS
+
 /****************************************************************************/
 
 /* static function prototypes */
@@ -101,6 +103,10 @@
  * listed by the authorities  */
 static int have_warned_about_new_version = 0;
 
+#ifdef DUMP_DIR_WEIGHTS
+static int log_dir_weights = 0;
+#endif
+
 /** Return the number of v2 directory authorities */
 static INLINE int
 get_n_v2_authorities(void)
@@ -577,20 +583,56 @@
   });
 
   if (smartlist_len(tunnel)) {
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights)
+      log_notice(LD_DIR, "Picking from tunnel-supporting dirs");
+#endif
     result = routerstatus_sl_choose_by_bandwidth(tunnel);
   } else if (smartlist_len(overloaded_tunnel)) {
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights)
+      log_notice(LD_DIR, "Picking from overloaded tunnel-supporting dirs");
+#endif
     result = routerstatus_sl_choose_by_bandwidth(overloaded_tunnel);
   } else if (smartlist_len(trusted_tunnel)) {
     /* FFFF We don't distinguish between trusteds and overloaded trusteds
      * yet. Maybe one day we should. */
     /* FFFF We also don't load balance over authorities yet. I think this
      * is a feature, but it could easily be a bug. -RD */
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights) {
+      int n = smartlist_len(trusted_tunnel);
+      double d = n ? 100.0/n : 0.0;
+      log_notice(LD_DIR, "Picking from trusted tunnel-supporting dirs.");
+      SMARTLIST_FOREACH(trusted_tunnel, routerstatus_t *, rs,
+         log_notice(LD_DIR, "  [%05.2lf] %s %s", d,
+                    hex_str(rs->identity_digest, DIGEST_LEN), rs->nickname));
+    }
+#endif
     result = smartlist_choose(trusted_tunnel);
   } else if (smartlist_len(direct)) {
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights)
+      log_notice(LD_DIR, "Picking from direct dir connections");
+#endif
     result = routerstatus_sl_choose_by_bandwidth(direct);
   } else if (smartlist_len(overloaded_direct)) {
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights)
+      log_notice(LD_DIR, "Picking from overloaded direct dir connections");
+#endif
     result = routerstatus_sl_choose_by_bandwidth(overloaded_direct);
   } else {
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights) {
+      int n = smartlist_len(trusted_tunnel);
+      double d = n ? 100.0/n : 0.0;
+      log_notice(LD_DIR, "Picking from trusted direct dir connections");
+      SMARTLIST_FOREACH(trusted_tunnel, routerstatus_t *, rs,
+         log_notice(LD_DIR, "  [%05.2lf] %s %s", d,
+                    hex_str(rs->identity_digest, DIGEST_LEN), rs->nickname));
+    }
+#endif
     result = smartlist_choose(trusted_direct);
   }
   smartlist_free(direct);
@@ -1160,6 +1202,7 @@
   /* Last, count through sl until we get to the element we picked */
   tmp = 0;
   for (i=0; i < smartlist_len(sl); i++) {
+    uint64_t this_bw;
     if (statuses) {
       status = smartlist_get(sl, i);
       is_exit = status->is_exit;
@@ -1172,17 +1215,32 @@
 
     /* Weights can be 0 if not counting guards/exits */
     if (is_exit && is_guard)
-      tmp += ((uint64_t)(bandwidths[i] * exit_weight * guard_weight));
+      this_bw = ((uint64_t)(bandwidths[i] * exit_weight * guard_weight));
     else if (is_guard)
-      tmp += ((uint64_t)(bandwidths[i] * guard_weight));
+      this_bw = ((uint64_t)(bandwidths[i] * guard_weight));
     else if (is_exit)
-      tmp += ((uint64_t)(bandwidths[i] * exit_weight));
+      this_bw = ((uint64_t)(bandwidths[i] * exit_weight));
     else
-      tmp += bandwidths[i];
+      this_bw = bandwidths[i];
+    tmp += this_bw;
 
+#ifdef DUMP_DIR_WEIGHTS
+    if (log_dir_weights && statuses) {
+      routerstatus_t *rs = smartlist_get(sl, i);
+      double pct = 100.0 * (U64_TO_DBL(this_bw)/U64_TO_DBL(total_bw));
+      log_notice(LD_DIR, "  [%05.2lf] %s %s", pct,
+                 hex_str(rs->identity_digest, DIGEST_LEN), rs->nickname);
+    } else
+#endif
+
     if (tmp >= rand_bw)
       break;
   }
+#ifdef DUMP_DIR_WEIGHTS
+  if (log_dir_weights)
+    return NULL;
+#endif
+
   if (i == smartlist_len(sl)) {
     /* This is possible due to round-off error. */
     --i;
@@ -3557,6 +3615,16 @@
   }
 }
 
+#ifdef DUMP_DIR_WEIGHTS
+static void
+dump_dir_weights(void)
+{
+  log_dir_weights = 1;
+  router_pick_directory_server_impl(0, 0, 0, 1);
+  log_dir_weights = 0;
+}
+#endif
+
 /** Helper for routerstatus_list_update_from_networkstatus: remember how many
  * authorities recommend a given descriptor digest. */
 typedef struct {
@@ -3867,6 +3935,10 @@
 
   control_event_networkstatus_changed(changed_list);
   smartlist_free(changed_list);
+
+#ifdef DUMP_DIR_WEIGHTS
+  dump_dir_weights();
+#endif
 }
 
 /** Given a list <b>routers</b> of routerinfo_t *, update each routers's