Loading src/feature/stats/rephist.c +15 −16 Original line number Diff line number Diff line Loading @@ -1712,20 +1712,11 @@ rep_hist_log_circuit_handshake_stats(time_t now) * not collecting hidden service statistics. */ static time_t start_of_hs_v2_stats_interval; /** Carries the various hidden service statistics, and any other * information needed. */ 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_v2_stats_t; /** Our statistics structure singleton. */ /** Our v2 statistics structure singleton. */ static hs_v2_stats_t *hs_v2_stats = NULL; /** HSv2 stats */ /** Allocate, initialize and return an hs_v2_stats_t structure. */ static hs_v2_stats_t * hs_v2_stats_new(void) Loading Loading @@ -1771,7 +1762,7 @@ rep_hist_reset_hs_v2_stats(time_t now) hs_v2_stats = hs_v2_stats_new(); } hs_v2_stats->rp_relay_cells_seen = 0; hs_v2_stats->rp_v2_relay_cells_seen = 0; digestmap_free(hs_v2_stats->v2_onions_seen_this_period, NULL); hs_v2_stats->v2_onions_seen_this_period = digestmap_new(); Loading Loading @@ -1861,7 +1852,7 @@ rep_hist_format_hs_v2_stats(time_t now) int64_t obfuscated_onions_seen; uint64_t rounded_cells_seen = round_uint64_to_next_multiple_of(hs_v2_stats->rp_relay_cells_seen, = round_uint64_to_next_multiple_of(hs_v2_stats->rp_v2_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, Loading @@ -1886,8 +1877,7 @@ rep_hist_format_hs_v2_stats(time_t now) 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, (obfuscated_onions_seen), ONIONS_SEEN_DELTA_F, ONIONS_SEEN_EPSILON, ONIONS_SEEN_BIN_SIZE); return hs_v2_stats_string; Loading Loading @@ -2155,3 +2145,12 @@ rep_hist_free_all(void) tor_assert_nonfatal(rephist_total_alloc == 0); tor_assert_nonfatal_once(rephist_total_num == 0); } #ifdef TOR_UNIT_TESTS /* only exists for unit tests: get HSv2 stats object */ const hs_v2_stats_t * rep_hist_get_hs_v2_stats(void) { return hs_v2_stats; } src/feature/stats/rephist.h +38 −2 Original line number Diff line number Diff line Loading @@ -64,11 +64,10 @@ 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_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); void rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey); void rep_hist_free_all(void); Loading @@ -83,6 +82,38 @@ extern int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1]; extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1]; #endif #ifdef REPHIST_PRIVATE /** Carries the various hidden service statistics, and any other * information needed. */ typedef struct hs_v2_stats_t { /** How many v2 relay cells have we seen as rendezvous points? */ uint64_t rp_v2_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_v2_stats_t; /** Structure that contains the various statistics we keep about v3 * services. * * Because of the time period logic of v3 services, v3 statistics are more * sensitive to time than v2 stats. For this reason, we collect v3 * statistics strictly from 12:00UTC to 12:00UTC as dictated by * 'start_of_hs_v3_stats_interval'. **/ typedef struct hs_v3_stats_t { /** How many v3 relay cells have we seen as a rendezvous point? */ uint64_t rp_v3_relay_cells_seen; /* The number of unique v3 onion descriptors (actually, unique v3 blind keys) * we've seen during the measurement period */ digestmap_t *v3_onions_seen_this_period; } hs_v3_stats_t; STATIC char *rep_hist_format_hs_v2_stats(time_t now, bool is_v3); #endif /* defined(REPHIST_PRIVATE) */ /** * Represents the type of a cell for padding accounting */ Loading @@ -108,4 +139,9 @@ void rep_hist_reset_padding_counts(void); void rep_hist_prep_published_padding_counts(time_t now); void rep_hist_padding_count_timers(uint64_t num_timers); #ifdef TOR_UNIT_TESTS typedef struct hs_v2_stats_t hs_v2_stats_t; const hs_v2_stats_t *rep_hist_get_hs_v2_stats(void); #endif #endif /* !defined(TOR_REPHIST_H) */ Loading
src/feature/stats/rephist.c +15 −16 Original line number Diff line number Diff line Loading @@ -1712,20 +1712,11 @@ rep_hist_log_circuit_handshake_stats(time_t now) * not collecting hidden service statistics. */ static time_t start_of_hs_v2_stats_interval; /** Carries the various hidden service statistics, and any other * information needed. */ 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_v2_stats_t; /** Our statistics structure singleton. */ /** Our v2 statistics structure singleton. */ static hs_v2_stats_t *hs_v2_stats = NULL; /** HSv2 stats */ /** Allocate, initialize and return an hs_v2_stats_t structure. */ static hs_v2_stats_t * hs_v2_stats_new(void) Loading Loading @@ -1771,7 +1762,7 @@ rep_hist_reset_hs_v2_stats(time_t now) hs_v2_stats = hs_v2_stats_new(); } hs_v2_stats->rp_relay_cells_seen = 0; hs_v2_stats->rp_v2_relay_cells_seen = 0; digestmap_free(hs_v2_stats->v2_onions_seen_this_period, NULL); hs_v2_stats->v2_onions_seen_this_period = digestmap_new(); Loading Loading @@ -1861,7 +1852,7 @@ rep_hist_format_hs_v2_stats(time_t now) int64_t obfuscated_onions_seen; uint64_t rounded_cells_seen = round_uint64_to_next_multiple_of(hs_v2_stats->rp_relay_cells_seen, = round_uint64_to_next_multiple_of(hs_v2_stats->rp_v2_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, Loading @@ -1886,8 +1877,7 @@ rep_hist_format_hs_v2_stats(time_t now) 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, (obfuscated_onions_seen), ONIONS_SEEN_DELTA_F, ONIONS_SEEN_EPSILON, ONIONS_SEEN_BIN_SIZE); return hs_v2_stats_string; Loading Loading @@ -2155,3 +2145,12 @@ rep_hist_free_all(void) tor_assert_nonfatal(rephist_total_alloc == 0); tor_assert_nonfatal_once(rephist_total_num == 0); } #ifdef TOR_UNIT_TESTS /* only exists for unit tests: get HSv2 stats object */ const hs_v2_stats_t * rep_hist_get_hs_v2_stats(void) { return hs_v2_stats; }
src/feature/stats/rephist.h +38 −2 Original line number Diff line number Diff line Loading @@ -64,11 +64,10 @@ 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_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); void rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey); void rep_hist_free_all(void); Loading @@ -83,6 +82,38 @@ extern int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1]; extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1]; #endif #ifdef REPHIST_PRIVATE /** Carries the various hidden service statistics, and any other * information needed. */ typedef struct hs_v2_stats_t { /** How many v2 relay cells have we seen as rendezvous points? */ uint64_t rp_v2_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_v2_stats_t; /** Structure that contains the various statistics we keep about v3 * services. * * Because of the time period logic of v3 services, v3 statistics are more * sensitive to time than v2 stats. For this reason, we collect v3 * statistics strictly from 12:00UTC to 12:00UTC as dictated by * 'start_of_hs_v3_stats_interval'. **/ typedef struct hs_v3_stats_t { /** How many v3 relay cells have we seen as a rendezvous point? */ uint64_t rp_v3_relay_cells_seen; /* The number of unique v3 onion descriptors (actually, unique v3 blind keys) * we've seen during the measurement period */ digestmap_t *v3_onions_seen_this_period; } hs_v3_stats_t; STATIC char *rep_hist_format_hs_v2_stats(time_t now, bool is_v3); #endif /* defined(REPHIST_PRIVATE) */ /** * Represents the type of a cell for padding accounting */ Loading @@ -108,4 +139,9 @@ void rep_hist_reset_padding_counts(void); void rep_hist_prep_published_padding_counts(time_t now); void rep_hist_padding_count_timers(uint64_t num_timers); #ifdef TOR_UNIT_TESTS typedef struct hs_v2_stats_t hs_v2_stats_t; const hs_v2_stats_t *rep_hist_get_hs_v2_stats(void); #endif #endif /* !defined(TOR_REPHIST_H) */