diff options
author | George Kadianakis <desnacked@riseup.net> | 2020-07-01 13:57:11 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2020-11-03 11:09:34 +0200 |
commit | 05880d238a95b09c08b600e546870d0870f856fd (patch) | |
tree | 4064b000b8b0574e84383ac2b1726ee509c9165f /src/feature/stats/rephist.c | |
parent | bd28551763bd008be5a6f676410d9b6b1d011bf6 (diff) | |
download | tor-05880d238a95b09c08b600e546870d0870f856fd.tar.gz tor-05880d238a95b09c08b600e546870d0870f856fd.zip |
Implement support for "unique v3 onions" stat.
Diffstat (limited to 'src/feature/stats/rephist.c')
-rw-r--r-- | src/feature/stats/rephist.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c index daf9db074c..5858f14245 100644 --- a/src/feature/stats/rephist.c +++ b/src/feature/stats/rephist.c @@ -1789,9 +1789,8 @@ rep_hist_seen_new_rp_cell(void) hs_v2_stats->rp_relay_cells_seen++; } -/** As HSDirs, we saw another hidden service with public key - * <b>pubkey</b>. Check whether we have counted it before, if not - * count it now! */ +/** As HSDirs, we saw another v2 onion with public key <b>pubkey</b>. Check + * whether we have counted it before, if not count it now! */ void rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey) { @@ -1908,6 +1907,31 @@ should_collect_v3_stats(void) return start_of_hs_v3_stats_interval <= approx_time(); } +/** We just received a new descriptor with <b>blinded_key</b>. See if we've + * seen this blinded key before, and if not add it to the stats. */ +void +rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key) +{ + /* Return early if we don't collect HSv3 stats, or if it's not yet the time + * to collect them. */ + if (!hs_v3_stats || !should_collect_v3_stats()) { + return; + } + + bool seen_before = !!digestmap_get(hs_v3_stats->v3_onions_seen_this_period, + (char*)blinded_key); + + log_info(LD_GENERAL, "Considering v3 descriptor with %s (%sseen before)", + safe_str(hex_str((char*)blinded_key, 32)), + seen_before ? "" : "not "); + + /* 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); + } +} + /* The number of cells that are supposed to be hidden from the adversary * by adding noise from the Laplace distribution. This value, divided by * EPSILON, is Laplace parameter b. It must be greather than 0. */ |