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 | |
parent | bd28551763bd008be5a6f676410d9b6b1d011bf6 (diff) | |
download | tor-05880d238a95b09c08b600e546870d0870f856fd.tar.gz tor-05880d238a95b09c08b600e546870d0870f856fd.zip |
Implement support for "unique v3 onions" stat.
Diffstat (limited to 'src')
-rw-r--r-- | src/feature/hs/hs_cache.c | 5 | ||||
-rw-r--r-- | src/feature/stats/rephist.c | 30 | ||||
-rw-r--r-- | src/feature/stats/rephist.h | 1 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/feature/hs/hs_cache.c b/src/feature/hs/hs_cache.c index 0688d7765d..b57f133362 100644 --- a/src/feature/hs/hs_cache.c +++ b/src/feature/hs/hs_cache.c @@ -175,7 +175,10 @@ cache_store_v3_as_dir(hs_cache_dir_descriptor_t *desc) * old HS protocol cache subsystem for which we are tied with. */ rend_cache_increment_allocation(cache_get_dir_entry_size(desc)); - /* XXX: Update HS statistics. We should have specific stats for v3. */ + /* Update HSv3 statistics */ + if (get_options()->HiddenServiceStatistics) { + rep_hist_hsdir_stored_maybe_new_v3_onion(desc->key); + } return 0; 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. */ diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h index e6c1509498..5873594781 100644 --- a/src/feature/stats/rephist.h +++ b/src/feature/stats/rephist.h @@ -71,6 +71,7 @@ void rep_hist_hsdir_stored_maybe_new_v2_onion(const crypto_pk_t *pubkey); time_t rep_hist_hs_v3_stats_write(time_t now); char *rep_hist_get_hs_v3_stats_string(void); +void rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key); void rep_hist_free_all(void); |