[or-cvs] r15099: More geoip tweaks. Include in the file a rough estimator of (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Tue Jun 10 18:28:11 UTC 2008


Author: nickm
Date: 2008-06-10 14:28:10 -0400 (Tue, 10 Jun 2008)
New Revision: 15099

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/geoip.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/routerlist.c
Log:
 r16129 at tombo:  nickm | 2008-06-10 14:28:06 -0400
 More geoip tweaks.  Include in the file a rough estimator of our total share.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r16129] on 49666b30-7950-49c5-bedf-9dc8f3168102

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-06-10 18:16:33 UTC (rev 15098)
+++ tor/trunk/ChangeLog	2008-06-10 18:28:10 UTC (rev 15099)
@@ -107,8 +107,9 @@
     - Allow comments in geoip file.
     - New configure/torrc options (--enable-geoip-stats,
       DirRecordUsageByCountry) to record how many IPs we've served directory
-      info to in each country code, and how many status documents total
-      we've sent to each country code.
+      info to in each country code, how many status documents total
+      we've sent to each country code, and what share of the total
+      directory requests we should expect to see.
     - Never use OpenSSL compression: it wastes RAM and CPU trying to
       compress cells, which are basically all encrypted, compressed, or
       both.

Modified: tor/trunk/src/or/geoip.c
===================================================================
--- tor/trunk/src/or/geoip.c	2008-06-10 18:16:33 UTC (rev 15098)
+++ tor/trunk/src/or/geoip.c	2008-06-10 18:28:10 UTC (rev 15099)
@@ -528,6 +528,7 @@
   char *data_v2 = NULL, *data_v3 = NULL;
   char since[ISO_TIME_LEN+1], written[ISO_TIME_LEN+1];
   open_file_t *open_file = NULL;
+  double v2_share = 0.0, v3_share = 0.0;
   FILE *out;
 
   data_v2 = geoip_get_client_history(now, GEOIP_CLIENT_NETWORKSTATUS_V2);
@@ -554,6 +555,12 @@
               since,
               data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0)
     goto done;
+  if (!router_get_my_share_of_directory_requests(&v2_share, &v3_share)) {
+    if (fprintf(out, "v2-ns-share %0.2lf%%\n", v2_share*100) < 0)
+      goto done;
+    if (fprintf(out, "v3-ns-share %0.2lf%%\n", v3_share*100) < 0)
+      goto done;
+  }
 
   finish_writing_to_file(open_file);
   open_file = NULL;

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-06-10 18:16:33 UTC (rev 15098)
+++ tor/trunk/src/or/or.h	2008-06-10 18:28:10 UTC (rev 15099)
@@ -3967,6 +3967,8 @@
 trusted_dir_server_t *router_get_trusteddirserver_by_digest(const char *d);
 trusted_dir_server_t *trusteddirserver_get_by_v3_auth_digest(const char *d);
 routerstatus_t *router_pick_trusteddirserver(authority_type_t type, int flags);
+int router_get_my_share_of_directory_requests(double *v2_share_out,
+                                              double *v3_share_out);
 void router_reset_status_download_failures(void);
 void routerlist_add_family(smartlist_t *sl, routerinfo_t *router);
 int routers_in_same_family(routerinfo_t *r1, routerinfo_t *r2);

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2008-06-10 18:16:33 UTC (rev 15098)
+++ tor/trunk/src/or/routerlist.c	2008-06-10 18:28:10 UTC (rev 15099)
@@ -80,6 +80,11 @@
  * download is low. */
 static time_t last_routerdesc_download_attempted = 0;
 
+/* DOCDOC This is a massive massive kludge XXXX021 */
+static uint64_t sl_last_total_weighted_bw = 0;
+static double sl_last_guard_weight = 0.0;
+static double sl_last_exit_weight = 0.0;
+
 /** Return the number of directory authorities whose type matches some bit set
  * in <b>type</b>  */
 int
@@ -862,6 +867,57 @@
   return choice;
 }
 
+/** DOCDOC */
+int
+router_get_my_share_of_directory_requests(double *v2_share_out,
+                                          double *v3_share_out)
+{
+  routerinfo_t *me = router_get_my_routerinfo();
+  routerinfo_t *me_published;
+  routerstatus_t *rs;
+  const int pds_flags = PDS_ALLOW_SELF|PDS_IGNORE_FASCISTFIREWALL;
+  uint32_t bw;
+  *v2_share_out = *v3_share_out = 0.0;
+  if (!me)
+    return -1;
+  me_published = router_get_by_digest(me->cache_info.identity_digest);
+  rs = router_get_consensus_status_by_id(me->cache_info.identity_digest);
+  if (!rs || !me_published)
+    return -1;
+  bw = me_published->bandwidthcapacity;
+  if (!rs->is_running)
+    return 0;
+
+  /* Calling for side effect */
+  if (rs->is_v2_dir) {
+    sl_last_total_weighted_bw = 0;
+    router_pick_directory_server(V2_AUTHORITY, pds_flags);
+    if (sl_last_total_weighted_bw != 0) {
+      double share = (double)bw;
+      if (rs->is_exit)
+        share *= sl_last_exit_weight;
+      if (rs->is_possible_guard)
+        share *= sl_last_guard_weight;
+      *v2_share_out = share / U64_TO_DBL(sl_last_total_weighted_bw);
+    }
+  }
+
+  if (rs->version_supports_v3_dir) {
+    sl_last_total_weighted_bw = 0;
+    router_pick_directory_server(V3_AUTHORITY, pds_flags);
+    if (sl_last_total_weighted_bw != 0) {
+      double share = (double)bw;
+      if (rs->is_exit)
+        share *= sl_last_exit_weight;
+      if (rs->is_possible_guard)
+        share *= sl_last_guard_weight;
+      *v2_share_out = share / U64_TO_DBL(sl_last_total_weighted_bw);
+    }
+  }
+
+  return 0;
+}
+
 /** Return the trusted_dir_server_t for the directory authority whose identity
  * key hashes to <b>digest</b>, or NULL if no such authority is known.
  */
@@ -1577,6 +1633,12 @@
         total_bw += bandwidths[i];
     }
   }
+
+  /* XXXX021 this is a kludge to expose these values. */
+  sl_last_total_weighted_bw = total_bw;
+  sl_last_guard_weight = guard_weight;
+  sl_last_exit_weight = exit_weight;
+
   log_debug(LD_CIRC, "Total weighted bw = "U64_FORMAT
             ", exit bw = "U64_FORMAT
             ", nonexit bw = "U64_FORMAT", exit weight = %lf "



More information about the tor-commits mailing list