Compare commits

..

2 Commits

Author SHA1 Message Date
Hocuri
0df7cc2612 test: Adapt test_stats_key_creation_timestamp() 2026-05-05 23:10:36 +02:00
Hocuri
24876f92aa feat: Reduce resolution of key_create_timestamps in the statistics
Right now, I'm reducing the resolution to 4 weeks (i.e. the timestamp is
rounded to the next multiple of 4 weeks); we could change this.
2026-05-05 23:01:12 +02:00
3 changed files with 23 additions and 6 deletions

9
Cargo.lock generated
View File

@@ -3941,14 +3941,15 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "openssl"
version = "0.10.79"
version = "0.10.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf0b434746ee2832f4f0baf10137e1cabb18cbe6912c69e2e33263c45250f542"
checksum = "f38c4372413cdaaf3cc79dd92d29d7d9f5ab09b51b10dded508fb90bb70b9222"
dependencies = [
"bitflags 2.11.0",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
"openssl-macros",
"openssl-sys",
]
@@ -3981,9 +3982,9 @@ dependencies = [
[[package]]
name = "openssl-sys"
version = "0.9.115"
version = "0.9.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781"
checksum = "13ce1245cd07fcc4cfdb438f7507b0c7e4f3849a69fd84d52374c66d83741bb6"
dependencies = [
"cc",
"libc",

View File

@@ -29,6 +29,7 @@ const STATISTICS_BOT_VCARD: &str = include_str!("../assets/statistics-bot.vcf");
const SENDING_INTERVAL_SECONDS: i64 = 3600 * 24 * 7; // 1 week
// const SENDING_INTERVAL_SECONDS: i64 = 60; // 1 minute (for testing)
const MESSAGE_STATS_UPDATE_INTERVAL_SECONDS: i64 = 4 * 60; // 4 minutes (less than the lowest ephemeral messages timeout)
const KEY_CREATE_TIMESTAMP_RESOLUTION: u32 = 3600 * 24 * 7 * 4; // 4 weeks
#[derive(Serialize)]
struct Statistics {
@@ -348,7 +349,13 @@ async fn get_stats(context: &Context) -> Result<String> {
let key_create_timestamps: Vec<u32> = load_self_public_keyring(context)
.await?
.iter()
.map(|k| k.created_at().as_secs())
.map(|k| {
k.created_at()
.as_secs()
.div_ceil(KEY_CREATE_TIMESTAMP_RESOLUTION)
.checked_mul(KEY_CREATE_TIMESTAMP_RESOLUTION)
.unwrap_or(0)
})
.collect();
let sending_enabled_timestamps =

View File

@@ -486,6 +486,15 @@ async fn test_stats_key_creation_timestamp() -> Result<()> {
// Alice uses a pregenerated key. It was created at this timestamp:
const ALICE_KEY_CREATION_TIME: u128 = 1582855645;
// The key creation time's resolution is reduced in order to prevent deanonymization:
const CENSORED_KEY_CREATION_TIME: u128 = 1584576000;
assert!(CENSORED_KEY_CREATION_TIME.is_multiple_of(KEY_CREATE_TIMESTAMP_RESOLUTION as u128));
assert!(CENSORED_KEY_CREATION_TIME > ALICE_KEY_CREATION_TIME);
assert!(
CENSORED_KEY_CREATION_TIME - ALICE_KEY_CREATION_TIME
< KEY_CREATE_TIMESTAMP_RESOLUTION as u128
);
let alice = &TestContext::new_alice().await;
alice.set_config_bool(Config::StatsSending, true).await?;
@@ -495,7 +504,7 @@ async fn test_stats_key_creation_timestamp() -> Result<()> {
assert_eq!(
key_create_timestamps,
&vec![Value::Number(
Number::from_u128(ALICE_KEY_CREATION_TIME).unwrap()
Number::from_u128(CENSORED_KEY_CREATION_TIME).unwrap()
)]
);