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

[tor-commits] [tor/master] Merge remote-tracking branch 'public/format_doubles'



commit b4bd4964eba5b0dae811a5c28c664b8f78a0672c
Merge: 981e896 0bec9f3
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Jun 5 10:30:50 2012 -0400

    Merge remote-tracking branch 'public/format_doubles'
    
    Conflicts:
    	src/or/geoip.c

 changes/bug3894_fmt_doubles |    4 ++++
 src/or/dirserv.c            |    2 +-
 src/or/geoip.c              |    4 ++--
 src/or/rephist.c            |    6 +++---
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --cc src/or/geoip.c
index 68a1942,8fb4c98..5d64888
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@@ -1023,117 -1006,61 +1023,117 @@@ geoip_format_dirreq_stats(time_t now
                                 ns_v3_responses[i], RESPONSE_GRANULARITY);
    }
  #undef RESPONSE_GRANULARITY
 -  if (fprintf(out, "dirreq-v3-resp ok=%u,not-enough-sigs=%u,unavailable=%u,"
 -                   "not-found=%u,not-modified=%u,busy=%u\n",
 -                   ns_v3_responses[GEOIP_SUCCESS],
 -                   ns_v3_responses[GEOIP_REJECT_NOT_ENOUGH_SIGS],
 -                   ns_v3_responses[GEOIP_REJECT_UNAVAILABLE],
 -                   ns_v3_responses[GEOIP_REJECT_NOT_FOUND],
 -                   ns_v3_responses[GEOIP_REJECT_NOT_MODIFIED],
 -                   ns_v3_responses[GEOIP_REJECT_BUSY]) < 0)
 -    goto done;
 -  if (fprintf(out, "dirreq-v2-resp ok=%u,unavailable=%u,"
 -                   "not-found=%u,not-modified=%u,busy=%u\n",
 -                   ns_v2_responses[GEOIP_SUCCESS],
 -                   ns_v2_responses[GEOIP_REJECT_UNAVAILABLE],
 -                   ns_v2_responses[GEOIP_REJECT_NOT_FOUND],
 -                   ns_v2_responses[GEOIP_REJECT_NOT_MODIFIED],
 -                   ns_v2_responses[GEOIP_REJECT_BUSY]) < 0)
 -    goto done;
 -  memset(ns_v2_responses, 0, sizeof(ns_v2_responses));
 -  memset(ns_v3_responses, 0, sizeof(ns_v3_responses));
 +
    if (!geoip_get_mean_shares(now, &v2_share, &v3_share)) {
-     tor_asprintf(&v2_share_string, "dirreq-v2-share %0.2lf%%\n",
 -    if (fprintf(out, "dirreq-v2-share %0.2f%%\n", v2_share*100) < 0)
 -      goto done;
 -    if (fprintf(out, "dirreq-v3-share %0.2f%%\n", v3_share*100) < 0)
 -      goto done;
++    tor_asprintf(&v2_share_string, "dirreq-v2-share %0.2f%%\n",
 +                 v2_share*100);
-     tor_asprintf(&v3_share_string, "dirreq-v3-share %0.2lf%%\n",
++    tor_asprintf(&v3_share_string, "dirreq-v3-share %0.2f%%\n",
 +                 v3_share*100);
    }
  
 -  data_v2 = geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS_V2,
 -                                       DIRREQ_DIRECT);
 -  data_v3 = geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS,
 -                                       DIRREQ_DIRECT);
 -  if (fprintf(out, "dirreq-v3-direct-dl %s\ndirreq-v2-direct-dl %s\n",
 -              data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0)
 -    goto done;
 -  tor_free(data_v2);
 -  tor_free(data_v3);
 -  data_v2 = geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS_V2,
 -                                       DIRREQ_TUNNELED);
 -  data_v3 = geoip_get_dirreq_history(GEOIP_CLIENT_NETWORKSTATUS,
 -                                       DIRREQ_TUNNELED);
 -  if (fprintf(out, "dirreq-v3-tunneled-dl %s\ndirreq-v2-tunneled-dl %s\n",
 -              data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0)
 -    goto done;
 +  v2_direct_dl_string = geoip_get_dirreq_history(
 +                        GEOIP_CLIENT_NETWORKSTATUS_V2, DIRREQ_DIRECT);
 +  v3_direct_dl_string = geoip_get_dirreq_history(
 +                        GEOIP_CLIENT_NETWORKSTATUS, DIRREQ_DIRECT);
 +
 +  v2_tunneled_dl_string = geoip_get_dirreq_history(
 +                          GEOIP_CLIENT_NETWORKSTATUS_V2, DIRREQ_TUNNELED);
 +  v3_tunneled_dl_string = geoip_get_dirreq_history(
 +                          GEOIP_CLIENT_NETWORKSTATUS, DIRREQ_TUNNELED);
 +
 +  /* Put everything together into a single string. */
 +  tor_asprintf(&result, "dirreq-stats-end %s (%d s)\n"
 +              "dirreq-v3-ips %s\n"
 +              "dirreq-v2-ips %s\n"
 +              "dirreq-v3-reqs %s\n"
 +              "dirreq-v2-reqs %s\n"
 +              "dirreq-v3-resp ok=%u,not-enough-sigs=%u,unavailable=%u,"
 +                   "not-found=%u,not-modified=%u,busy=%u\n"
 +              "dirreq-v2-resp ok=%u,unavailable=%u,"
 +                   "not-found=%u,not-modified=%u,busy=%u\n"
 +              "%s"
 +              "%s"
 +              "dirreq-v3-direct-dl %s\n"
 +              "dirreq-v2-direct-dl %s\n"
 +              "dirreq-v3-tunneled-dl %s\n"
 +              "dirreq-v2-tunneled-dl %s\n",
 +              t,
 +              (unsigned) (now - start_of_dirreq_stats_interval),
 +              v3_ips_string ? v3_ips_string : "",
 +              v2_ips_string ? v2_ips_string : "",
 +              v3_reqs_string ? v3_reqs_string : "",
 +              v2_reqs_string ? v2_reqs_string : "",
 +              ns_v3_responses[GEOIP_SUCCESS],
 +              ns_v3_responses[GEOIP_REJECT_NOT_ENOUGH_SIGS],
 +              ns_v3_responses[GEOIP_REJECT_UNAVAILABLE],
 +              ns_v3_responses[GEOIP_REJECT_NOT_FOUND],
 +              ns_v3_responses[GEOIP_REJECT_NOT_MODIFIED],
 +              ns_v3_responses[GEOIP_REJECT_BUSY],
 +              ns_v2_responses[GEOIP_SUCCESS],
 +              ns_v2_responses[GEOIP_REJECT_UNAVAILABLE],
 +              ns_v2_responses[GEOIP_REJECT_NOT_FOUND],
 +              ns_v2_responses[GEOIP_REJECT_NOT_MODIFIED],
 +              ns_v2_responses[GEOIP_REJECT_BUSY],
 +              v2_share_string ? v2_share_string : "",
 +              v3_share_string ? v3_share_string : "",
 +              v3_direct_dl_string ? v3_direct_dl_string : "",
 +              v2_direct_dl_string ? v2_direct_dl_string : "",
 +              v3_tunneled_dl_string ? v3_tunneled_dl_string : "",
 +              v2_tunneled_dl_string ? v2_tunneled_dl_string : "");
 +
 +  /* Free partial strings. */
 +  tor_free(v3_ips_string);
 +  tor_free(v2_ips_string);
 +  tor_free(v3_reqs_string);
 +  tor_free(v2_reqs_string);
 +  tor_free(v2_share_string);
 +  tor_free(v3_share_string);
 +  tor_free(v3_direct_dl_string);
 +  tor_free(v2_direct_dl_string);
 +  tor_free(v3_tunneled_dl_string);
 +  tor_free(v2_tunneled_dl_string);
  
 -  finish_writing_to_file(open_file);
 -  open_file = NULL;
 +  return result;
 +}
  
 -  start_of_dirreq_stats_interval = now;
 +/** If 24 hours have passed since the beginning of the current dirreq
 + * stats period, write dirreq stats to $DATADIR/stats/dirreq-stats
 + * (possibly overwriting an existing file) and reset counters.  Return
 + * when we would next want to write dirreq stats or 0 if we never want to
 + * write. */
 +time_t
 +geoip_dirreq_stats_write(time_t now)
 +{
 +  char *statsdir = NULL, *filename = NULL, *str = NULL;
 +
 +  if (!start_of_dirreq_stats_interval)
 +    return 0; /* Not initialized. */
 +  if (start_of_dirreq_stats_interval + WRITE_STATS_INTERVAL > now)
 +    goto done; /* Not ready to write. */
 +
 +  /* Discard all items in the client history that are too old. */
 +  geoip_remove_old_clients(start_of_dirreq_stats_interval);
 +
 +  /* Generate history string .*/
 +  str = geoip_format_dirreq_stats(now);
 +
 +  /* Write dirreq-stats string to disk. */
 +  statsdir = get_datadir_fname("stats");
 +  if (check_private_dir(statsdir, CPD_CREATE, get_options()->User) < 0) {
 +    log_warn(LD_HIST, "Unable to create stats/ directory!");
 +    goto done;
 +  }
 +  filename = get_datadir_fname2("stats", "dirreq-stats");
 +  if (write_str_to_file(filename, str, 0) < 0)
 +    log_warn(LD_HIST, "Unable to write dirreq statistics to disk!");
 +
 +  /* Reset measurement interval start. */
 +  geoip_reset_dirreq_stats(now);
  
   done:
 -  if (open_file)
 -    abort_writing_to_file(open_file);
 -  tor_free(filename);
    tor_free(statsdir);
 -  tor_free(data_v2);
 -  tor_free(data_v3);
 +  tor_free(filename);
 +  tor_free(str);
    return start_of_dirreq_stats_interval + WRITE_STATS_INTERVAL;
  }
  



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits