[tor-commits] [tor/master] Make room for v3: s/hs_stats/hs_v2_stats/

dgoulet at torproject.org dgoulet at torproject.org
Tue Nov 17 15:49:48 UTC 2020


commit 1de7843658e00baa2271048fb3e3e436639e70c4
Author: George Kadianakis <desnacked at riseup.net>
Date:   Mon Oct 26 18:19:25 2020 +0200

    Make room for v3: s/hs_stats/hs_v2_stats/
---
 src/core/mainloop/mainloop.c |  2 +-
 src/feature/stats/rephist.c  | 98 ++++++++++++++++++++++----------------------
 src/feature/stats/rephist.h  |  8 ++--
 3 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index c75039b378..4b4ac5c4a7 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -1937,7 +1937,7 @@ write_stats_file_callback(time_t now, const or_options_t *options)
       next_time_to_write_stats_files = next_write;
   }
   if (options->HiddenServiceStatistics) {
-    time_t next_write = rep_hist_hs_stats_write(now);
+    time_t next_write = rep_hist_hs_v2_stats_write(now);
     if (next_write && next_write < next_time_to_write_stats_files)
       next_time_to_write_stats_files = next_write;
   }
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c
index b66eed80ef..739ead195f 100644
--- a/src/feature/stats/rephist.c
+++ b/src/feature/stats/rephist.c
@@ -1710,92 +1710,92 @@ rep_hist_log_circuit_handshake_stats(time_t now)
 
 /** Start of the current hidden service stats interval or 0 if we're
  * not collecting hidden service statistics. */
-static time_t start_of_hs_stats_interval;
+static time_t start_of_hs_v2_stats_interval;
 
 /** Carries the various hidden service statistics, and any other
  *  information needed. */
-typedef struct hs_stats_t {
+typedef struct hs_v2_stats_t {
   /** How many relay cells have we seen as rendezvous points? */
   uint64_t rp_relay_cells_seen;
 
   /** Set of unique public key digests we've seen this stat period
    * (could also be implemented as sorted smartlist). */
   digestmap_t *v2_onions_seen_this_period;
-} hs_stats_t;
+} hs_v2_stats_t;
 
 /** Our statistics structure singleton. */
-static hs_stats_t *hs_stats = NULL;
+static hs_v2_stats_t *hs_v2_stats = NULL;
 
-/** Allocate, initialize and return an hs_stats_t structure. */
-static hs_stats_t *
-hs_stats_new(void)
+/** Allocate, initialize and return an hs_v2_stats_t structure. */
+static hs_v2_stats_t *
+hs_v2_stats_new(void)
 {
-  hs_stats_t *new_hs_stats = tor_malloc_zero(sizeof(hs_stats_t));
-  new_hs_stats->v2_onions_seen_this_period = digestmap_new();
+  hs_v2_stats_t *new_hs_v2_stats = tor_malloc_zero(sizeof(hs_v2_stats_t));
+  new_hs_v2_stats->v2_onions_seen_this_period = digestmap_new();
 
-  return new_hs_stats;
+  return new_hs_v2_stats;
 }
 
-#define hs_stats_free(val) \
-  FREE_AND_NULL(hs_stats_t, hs_stats_free_, (val))
+#define hs_v2_stats_free(val) \
+  FREE_AND_NULL(hs_v2_stats_t, hs_v2_stats_free_, (val))
 
-/** Free an hs_stats_t structure. */
+/** Free an hs_v2_stats_t structure. */
 static void
-hs_stats_free_(hs_stats_t *victim_hs_stats)
+hs_v2_stats_free_(hs_v2_stats_t *victim_hs_v2_stats)
 {
-  if (!victim_hs_stats) {
+  if (!victim_hs_v2_stats) {
     return;
   }
 
-  digestmap_free(victim_hs_stats->v2_onions_seen_this_period, NULL);
-  tor_free(victim_hs_stats);
+  digestmap_free(victim_hs_v2_stats->v2_onions_seen_this_period, NULL);
+  tor_free(victim_hs_v2_stats);
 }
 
 /** Initialize hidden service statistics. */
 void
-rep_hist_hs_stats_init(time_t now)
+rep_hist_hs_v2_stats_init(time_t now)
 {
-  if (!hs_stats) {
-    hs_stats = hs_stats_new();
+  if (!hs_v2_stats) {
+    hs_v2_stats = hs_v2_stats_new();
   }
 
-  start_of_hs_stats_interval = now;
+  start_of_hs_v2_stats_interval = now;
 }
 
 /** Clear history of hidden service statistics and set the measurement
  * interval start to <b>now</b>. */
 static void
-rep_hist_reset_hs_stats(time_t now)
+rep_hist_reset_hs_v2_stats(time_t now)
 {
-  if (!hs_stats) {
-    hs_stats = hs_stats_new();
+  if (!hs_v2_stats) {
+    hs_v2_stats = hs_v2_stats_new();
   }
 
-  hs_stats->rp_relay_cells_seen = 0;
+  hs_v2_stats->rp_relay_cells_seen = 0;
 
-  digestmap_free(hs_stats->v2_onions_seen_this_period, NULL);
-  hs_stats->v2_onions_seen_this_period = digestmap_new();
+  digestmap_free(hs_v2_stats->v2_onions_seen_this_period, NULL);
+  hs_v2_stats->v2_onions_seen_this_period = digestmap_new();
 
-  start_of_hs_stats_interval = now;
+  start_of_hs_v2_stats_interval = now;
 }
 
 /** Stop collecting hidden service stats in a way that we can re-start
  * doing so in rep_hist_buffer_stats_init(). */
 void
-rep_hist_hs_stats_term(void)
+rep_hist_hs_v2_stats_term(void)
 {
-  rep_hist_reset_hs_stats(0);
+  rep_hist_reset_hs_v2_stats(0);
 }
 
 /** We saw a new HS relay cell, Count it! */
 void
 rep_hist_seen_new_rp_cell(void)
 {
-  if (!hs_stats) {
+  if (!hs_v2_stats) {
     return; // We're not collecting stats
   }
 
-  hs_stats->rp_relay_cells_seen++;
+  hs_v2_stats->rp_relay_cells_seen++;
 }
 
 /** As HSDirs, we saw another hidden service with public key
@@ -1806,7 +1806,7 @@ rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey)
 {
   char pubkey_hash[DIGEST_LEN];
 
-  if (!hs_stats) {
+  if (!hs_v2_stats) {
     return; // We're not collecting stats
   }
 
@@ -1820,9 +1820,9 @@ rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey)
 
   /* Check if this is the first time we've seen this hidden
      service. If it is, count it as new. */
-  if (!digestmap_get(hs_stats->v2_onions_seen_this_period,
+  if (!digestmap_get(hs_v2_stats->v2_onions_seen_this_period,
                      pubkey_hash)) {
-    digestmap_set(hs_stats->v2_onions_seen_this_period,
+    digestmap_set(hs_v2_stats->v2_onions_seen_this_period,
                   pubkey_hash, (void*)(uintptr_t)1);
   }
 }
@@ -1853,15 +1853,15 @@ rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey)
 /** Allocate and return a string containing hidden service stats that
  *  are meant to be placed in the extra-info descriptor. */
 static char *
-rep_hist_format_hs_stats(time_t now)
+rep_hist_format_hs_v2_stats(time_t now)
 {
   char t[ISO_TIME_LEN+1];
-  char *hs_stats_string;
+  char *hs_v2_stats_string;
   int64_t obfuscated_cells_seen;
   int64_t obfuscated_onions_seen;
 
   uint64_t rounded_cells_seen
-    = round_uint64_to_next_multiple_of(hs_stats->rp_relay_cells_seen,
+    = round_uint64_to_next_multiple_of(hs_v2_stats->rp_relay_cells_seen,
                                        REND_CELLS_BIN_SIZE);
   rounded_cells_seen = MIN(rounded_cells_seen, INT64_MAX);
   obfuscated_cells_seen = add_laplace_noise((int64_t)rounded_cells_seen,
@@ -1870,7 +1870,7 @@ rep_hist_format_hs_stats(time_t now)
 
   uint64_t rounded_onions_seen =
     round_uint64_to_next_multiple_of((size_t)digestmap_size(
-                                        hs_stats->v2_onions_seen_this_period),
+                                        hs_v2_stats->v2_onions_seen_this_period),
                                      ONIONS_SEEN_BIN_SIZE);
   rounded_onions_seen = MIN(rounded_onions_seen, INT64_MAX);
   obfuscated_onions_seen = add_laplace_noise((int64_t)rounded_onions_seen,
@@ -1878,19 +1878,19 @@ rep_hist_format_hs_stats(time_t now)
                            ONIONS_SEEN_EPSILON);
 
   format_iso_time(t, now);
-  tor_asprintf(&hs_stats_string, "hidserv-stats-end %s (%d s)\n"
+  tor_asprintf(&hs_v2_stats_string, "hidserv-stats-end %s (%d s)\n"
                "hidserv-rend-relayed-cells %"PRId64" delta_f=%d "
                                            "epsilon=%.2f bin_size=%d\n"
                "hidserv-dir-onions-seen %"PRId64" delta_f=%d "
                                         "epsilon=%.2f bin_size=%d\n",
-               t, (unsigned) (now - start_of_hs_stats_interval),
+               t, (unsigned) (now - start_of_hs_v2_stats_interval),
                (obfuscated_cells_seen), REND_CELLS_DELTA_F,
                REND_CELLS_EPSILON, REND_CELLS_BIN_SIZE,
                (obfuscated_onions_seen),
                ONIONS_SEEN_DELTA_F,
                ONIONS_SEEN_EPSILON, ONIONS_SEEN_BIN_SIZE);
 
-  return hs_stats_string;
+  return hs_v2_stats_string;
 }
 
 /** If 24 hours have passed since the beginning of the current HS
@@ -1899,23 +1899,23 @@ rep_hist_format_hs_stats(time_t now)
  * when we would next want to write buffer stats or 0 if we never want to
  * write. */
 time_t
-rep_hist_hs_stats_write(time_t now)
+rep_hist_hs_v2_stats_write(time_t now)
 {
   char *str = NULL;
 
-  if (!start_of_hs_stats_interval) {
+  if (!start_of_hs_v2_stats_interval) {
     return 0; /* Not initialized. */
   }
 
-  if (start_of_hs_stats_interval + WRITE_STATS_INTERVAL > now) {
+  if (start_of_hs_v2_stats_interval + WRITE_STATS_INTERVAL > now) {
     goto done; /* Not ready to write */
   }
 
   /* Generate history string. */
-  str = rep_hist_format_hs_stats(now);
+  str = rep_hist_format_hs_v2_stats(now);
 
   /* Reset HS history. */
-  rep_hist_reset_hs_stats(now);
+  rep_hist_reset_hs_v2_stats(now);
 
   /* Try to write to disk. */
   if (!check_or_create_data_subdir("stats")) {
@@ -1925,7 +1925,7 @@ rep_hist_hs_stats_write(time_t now)
 
  done:
   tor_free(str);
-  return start_of_hs_stats_interval + WRITE_STATS_INTERVAL;
+  return start_of_hs_v2_stats_interval + WRITE_STATS_INTERVAL;
 }
 
 static uint64_t link_proto_count[MAX_LINK_PROTO+1][2];
@@ -2134,7 +2134,7 @@ rep_hist_log_link_protocol_counts(void)
 void
 rep_hist_free_all(void)
 {
-  hs_stats_free(hs_stats);
+  hs_v2_stats_free(hs_v2_stats);
   digestmap_free(history_map, free_or_history);
 
   tor_free(exit_bytes_read);
diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h
index c9ebc5c328..abcb70249f 100644
--- a/src/feature/stats/rephist.h
+++ b/src/feature/stats/rephist.h
@@ -63,10 +63,10 @@ void rep_hist_log_circuit_handshake_stats(time_t now);
 MOCK_DECL(int, rep_hist_get_circuit_handshake_requested, (uint16_t type));
 MOCK_DECL(int, rep_hist_get_circuit_handshake_assigned, (uint16_t type));
 
-void rep_hist_hs_stats_init(time_t now);
-void rep_hist_hs_stats_term(void);
-time_t rep_hist_hs_stats_write(time_t now);
-char *rep_hist_get_hs_stats_string(void);
+void rep_hist_hs_v2_stats_init(time_t now);
+void rep_hist_hs_v2_stats_term(void);
+time_t rep_hist_hs_v2_stats_write(time_t now);
+char *rep_hist_get_hs_v2_stats_string(void);
 void rep_hist_seen_new_rp_cell(void);
 void rep_hist_stored_maybe_new_hs(const crypto_pk_t *pubkey);
 





More information about the tor-commits mailing list