rwhod: put max cap on status update storage

Without a max cap, someone could potentially flood our memory by posting
tons and tons of spoofed status updates.
This commit is contained in:
2026-07-20 23:41:05 +09:00
parent 2b89f6c755
commit 4373eec6b5
6 changed files with 196 additions and 7 deletions
+19 -2
View File
@@ -15,10 +15,15 @@ use tracing_subscriber::layer::SubscriberExt;
use roowho2_lib::server::{
config::{DEFAULT_CONFIG_PATH, LogLevel},
ignore_list::IgnoreList,
rwhod::{RwhodStatusStore, rwhod_packet_receiver_task, rwhod_packet_sender_task},
rwhod::{
RwhodStatusRegistry, RwhodStatusStore, rwhod_packet_receiver_task, rwhod_packet_sender_task,
},
varlink_api::varlink_client_server_task,
};
/// Default maximum number of distinct hosts to keep rwhod status records for at the same time.
const DEFAULT_MAX_STATUS_ENTRIES: usize = 4096;
#[derive(Parser)]
#[command(
author = "Programvareverkstedet <projects@pvv.ntnu.no>",
@@ -75,7 +80,19 @@ async fn main() -> anyhow::Result<()> {
let mut join_set = tokio::task::JoinSet::new();
let whod_status_store = Arc::new(RwLock::new(HashMap::new()));
let max_status_entries = match config.rwhod.max_status_entries {
Some(0) => {
tracing::warn!(
"rwhod.max_status_entries is set to 0, remapping to default value of {}",
DEFAULT_MAX_STATUS_ENTRIES
);
DEFAULT_MAX_STATUS_ENTRIES
}
Some(max_status_entries) => max_status_entries,
None => DEFAULT_MAX_STATUS_ENTRIES,
};
let whod_status_store: RwhodStatusStore =
Arc::new(RwLock::new(RwhodStatusRegistry::new(max_status_entries)));
let client_server_token = CancellationToken::new();
let client_server_token_ = client_server_token.clone();