From 529d74ec5d684daae48090943cefda57172664ef Mon Sep 17 00:00:00 2001 From: Jakob Schmid Date: Thu, 18 Jul 2024 13:32:50 +0200 Subject: [PATCH] randomize heartbeat send interval --- src-tauri/Cargo.lock | 1 + src-tauri/lib/codegen/Cargo.toml | 1 + src-tauri/lib/codegen/src/scheduler.rs | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9efae39..02f4a34 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -394,6 +394,7 @@ name = "canzero-codegen" version = "0.1.0" dependencies = [ "canzero-config", + "rand 0.8.5", ] [[package]] diff --git a/src-tauri/lib/codegen/Cargo.toml b/src-tauri/lib/codegen/Cargo.toml index 5f3c53f..7c1c210 100644 --- a/src-tauri/lib/codegen/Cargo.toml +++ b/src-tauri/lib/codegen/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] canzero-config = { path = "../config/" } +rand = "0.8.5" [dev-dependencies] canzero-yaml = { path = "../yaml/" } diff --git a/src-tauri/lib/codegen/src/scheduler.rs b/src-tauri/lib/codegen/src/scheduler.rs index 1af006c..e144645 100644 --- a/src-tauri/lib/codegen/src/scheduler.rs +++ b/src-tauri/lib/codegen/src/scheduler.rs @@ -1,4 +1,5 @@ use std::time::Duration; +use rand::Rng; use canzero_config::config; @@ -38,6 +39,8 @@ pub fn generate_scheduler( )); } + let heartbeat_interval = 100 + rand::thread_rng().gen_range(0..100); + let num_fragmentation_jobs = node_config .object_entries() .iter() @@ -302,7 +305,7 @@ static void schedule_get_resp_fragmentation_job(uint32_t *fragmentation_buffer, }} static job_t heartbeat_job; -static const uint32_t heartbeat_interval = 100; +static const uint32_t heartbeat_interval = {heartbeat_interval}; static void schedule_heartbeat_job() {{ {indent}heartbeat_job.climax = canzero_get_time(); {indent}heartbeat_job.tag = HEARTBEAT_JOB_TAG;