Browse Source

r16129@tombo: nickm | 2008-06-10 14:28:06 -0400
More geoip tweaks. Include in the file a rough estimator of our total share.


svn:r15099

Nick Mathewson 16 years ago
parent
commit
b87a7760e0
4 changed files with 74 additions and 2 deletions
  1. 3 2
      ChangeLog
  2. 7 0
      src/or/geoip.c
  3. 2 0
      src/or/or.h
  4. 62 0
      src/or/routerlist.c

+ 3 - 2
ChangeLog

@@ -107,8 +107,9 @@ Changes in version 0.2.1.1-alpha - 2008-??-??
     - 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.

+ 7 - 0
src/or/geoip.c

@@ -528,6 +528,7 @@ dump_geoip_stats(void)
   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 @@ dump_geoip_stats(void)
               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;

+ 2 - 0
src/or/or.h

@@ -3967,6 +3967,8 @@ routerstatus_t *router_pick_directory_server(authority_type_t type, int flags);
 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);

+ 62 - 0
src/or/routerlist.c

@@ -80,6 +80,11 @@ static smartlist_t *warned_nicknames = NULL;
  * 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 @@ router_pick_directory_server(authority_type_t type, int flags)
   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 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
         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 "