[tor-commits] [tor/master] Switch v3_onions_seen_this_period to digest256map_t.
dgoulet at torproject.org
dgoulet at torproject.org
Tue Nov 17 15:49:48 UTC 2020
commit 9a98d1da30a25b1f263859cae21a3c0863d8c91d
Author: George Kadianakis <desnacked at riseup.net>
Date: Tue Nov 3 17:34:46 2020 +0200
Switch v3_onions_seen_this_period to digest256map_t.
---
src/feature/stats/rephist.c | 19 ++++++++++---------
src/feature/stats/rephist.h | 2 +-
src/test/test_stats.c | 15 ++++++++++-----
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c
index 37250108d1..7b4bc97bda 100644
--- a/src/feature/stats/rephist.c
+++ b/src/feature/stats/rephist.c
@@ -1828,7 +1828,7 @@ static hs_v3_stats_t *
hs_v3_stats_new(void)
{
hs_v3_stats_t *new_hs_v3_stats = tor_malloc_zero(sizeof(hs_v3_stats_t));
- new_hs_v3_stats->v3_onions_seen_this_period = digestmap_new();
+ new_hs_v3_stats->v3_onions_seen_this_period = digest256map_new();
return new_hs_v3_stats;
}
@@ -1844,7 +1844,7 @@ hs_v3_stats_free_(hs_v3_stats_t *victim_hs_v3_stats)
return;
}
- digestmap_free(victim_hs_v3_stats->v3_onions_seen_this_period, NULL);
+ digest256map_free(victim_hs_v3_stats->v3_onions_seen_this_period, NULL);
tor_free(victim_hs_v3_stats);
}
@@ -1857,8 +1857,8 @@ rep_hist_reset_hs_v3_stats(time_t now)
hs_v3_stats = hs_v3_stats_new();
}
- digestmap_free(hs_v3_stats->v3_onions_seen_this_period, NULL);
- hs_v3_stats->v3_onions_seen_this_period = digestmap_new();
+ digest256map_free(hs_v3_stats->v3_onions_seen_this_period, NULL);
+ hs_v3_stats->v3_onions_seen_this_period = digest256map_new();
hs_v3_stats->rp_v3_relay_cells_seen = 0;
@@ -1888,8 +1888,9 @@ rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key)
return;
}
- bool seen_before = !!digestmap_get(hs_v3_stats->v3_onions_seen_this_period,
- (char*)blinded_key);
+ bool seen_before =
+ !!digest256map_get(hs_v3_stats->v3_onions_seen_this_period,
+ blinded_key);
log_info(LD_GENERAL, "Considering v3 descriptor with %s (%sseen before)",
safe_str(hex_str((char*)blinded_key, 32)),
@@ -1897,8 +1898,8 @@ rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key)
/* Count it if we haven't seen it before. */
if (!seen_before) {
- digestmap_set(hs_v3_stats->v3_onions_seen_this_period,
- (char*)blinded_key, (void*)(uintptr_t)1);
+ digest256map_set(hs_v3_stats->v3_onions_seen_this_period,
+ blinded_key, (void*)(uintptr_t)1);
}
}
@@ -1985,7 +1986,7 @@ rep_hist_format_hs_stats(time_t now, bool is_v3)
uint64_t rp_cells_seen = is_v3 ?
hs_v3_stats->rp_v3_relay_cells_seen : hs_v2_stats->rp_v2_relay_cells_seen;
size_t onions_seen = is_v3 ?
- digestmap_size(hs_v3_stats->v3_onions_seen_this_period) :
+ digest256map_size(hs_v3_stats->v3_onions_seen_this_period) :
digestmap_size(hs_v2_stats->v2_onions_seen_this_period);
time_t start_of_hs_stats_interval = is_v3 ?
start_of_hs_v3_stats_interval : start_of_hs_v2_stats_interval;
diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h
index a2caa4fc15..de27b16ae0 100644
--- a/src/feature/stats/rephist.h
+++ b/src/feature/stats/rephist.h
@@ -113,7 +113,7 @@ typedef struct hs_v3_stats_t {
/* 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;
+ digest256map_t *v3_onions_seen_this_period;
} hs_v3_stats_t;
MOCK_DECL(STATIC bool, should_collect_v3_stats,(void));
diff --git a/src/test/test_stats.c b/src/test/test_stats.c
index dc02c9e784..64d89cf1e9 100644
--- a/src/test/test_stats.c
+++ b/src/test/test_stats.c
@@ -528,7 +528,8 @@ test_rephist_v3_onions(void *arg)
/* HS stats should be zero here */
hs_v3_stats = rep_hist_get_hs_v3_stats();
- tt_int_op(digestmap_size(hs_v3_stats->v3_onions_seen_this_period), OP_EQ, 0);
+ tt_int_op(digest256map_size(hs_v3_stats->v3_onions_seen_this_period),
+ OP_EQ, 0);
/* Generate a valid descriptor */
ret = ed25519_keypair_generate(&signing_kp1, 0);
@@ -542,7 +543,8 @@ test_rephist_v3_onions(void *arg)
ret = hs_cache_store_as_dir(desc1_str);
tt_int_op(ret, OP_EQ, 0);
hs_v3_stats = rep_hist_get_hs_v3_stats();
- tt_int_op(digestmap_size(hs_v3_stats->v3_onions_seen_this_period), OP_EQ, 1);
+ tt_int_op(digest256map_size(hs_v3_stats->v3_onions_seen_this_period),
+ OP_EQ, 1);
/* cleanup */
hs_descriptor_free(desc1);
@@ -560,7 +562,8 @@ test_rephist_v3_onions(void *arg)
ret = hs_cache_store_as_dir(desc1_str);
tt_int_op(ret, OP_EQ, 0);
hs_v3_stats = rep_hist_get_hs_v3_stats();
- tt_int_op(digestmap_size(hs_v3_stats->v3_onions_seen_this_period), OP_EQ, 2);
+ tt_int_op(digest256map_size(hs_v3_stats->v3_onions_seen_this_period),
+ OP_EQ, 2);
/* Check that storing the same descriptor twice does not work */
ret = hs_cache_store_as_dir(desc1_str);
@@ -580,7 +583,8 @@ test_rephist_v3_onions(void *arg)
/* Store descriptor and check that stats are updated */
ret = hs_cache_store_as_dir(desc1_str);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(digestmap_size(hs_v3_stats->v3_onions_seen_this_period), OP_EQ, 2);
+ tt_int_op(digest256map_size(hs_v3_stats->v3_onions_seen_this_period),
+ OP_EQ, 2);
/* cleanup */
hs_descriptor_free(desc1);
@@ -600,7 +604,8 @@ test_rephist_v3_onions(void *arg)
/* Store descriptor and check that stats are updated */
ret = hs_cache_store_as_dir(desc1_str);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(digestmap_size(hs_v3_stats->v3_onions_seen_this_period), OP_EQ, 3);
+ tt_int_op(digest256map_size(hs_v3_stats->v3_onions_seen_this_period),
+ OP_EQ, 3);
/* cleanup */
hs_descriptor_free(desc1);
More information about the tor-commits
mailing list