rwhod: allow configuring packet send interval
Build and test / check (push) Successful in 1m7s
Build and test / build (push) Successful in 1m51s
Build and test / test (push) Successful in 2m2s
Build and test / docs (push) Successful in 4m7s

This commit is contained in:
2026-07-20 21:52:34 +09:00
parent c0c0e47c8a
commit ba0e8f214d
4 changed files with 34 additions and 2 deletions
+8
View File
@@ -61,6 +61,14 @@ in {
'';
};
send_interval_seconds = lib.mkOption {
type = lib.types.ints.unsigned;
default = 60;
description = ''
Interval between rwhod status packet broadcasts.
'';
};
ignoreUsers = lib.mkOption {
type = with lib.types; listOf (either str ints.unsigned);
default = [ ];
+19 -1
View File
@@ -105,6 +105,7 @@ async fn main() -> anyhow::Result<()> {
whod_status_store.clone(),
rwhod_ignore_list.clone(),
config.rwhod.interfaces.clone(),
config.rwhod.send_interval_seconds,
));
} else {
tracing::debug!("RWHOD server is disabled in configuration");
@@ -136,17 +137,34 @@ async fn ctrl_c_handler() -> anyhow::Result<()> {
.map_err(|e| anyhow::anyhow!("Failed to listen for Ctrl-C: {}", e))
}
/// Default interval, in seconds, between rwhod status packet broadcasts.
const DEFAULT_SEND_INTERVAL_SECONDS: u64 = 60;
async fn rwhod_server(
socket: UdpSocket,
whod_status_store: RwhodStatusStore,
ignore_list: Option<IgnoreList>,
allowed_interfaces: Option<HashSet<String>>,
send_interval_seconds: Option<u64>,
) -> anyhow::Result<()> {
let socket = Arc::new(socket);
let interfaces =
roowho2_lib::server::rwhod::determine_relevant_interfaces(allowed_interfaces.as_ref())?;
let sender_task = rwhod_packet_sender_task(socket.clone(), interfaces, ignore_list);
let send_interval_seconds = match send_interval_seconds {
Some(0) => {
tracing::warn!(
"rwhod.send_interval_seconds is set to 0, remapping to default value of {} seconds",
DEFAULT_SEND_INTERVAL_SECONDS
);
DEFAULT_SEND_INTERVAL_SECONDS
}
Some(seconds) => seconds,
None => DEFAULT_SEND_INTERVAL_SECONDS,
};
let send_interval = std::time::Duration::from_secs(send_interval_seconds);
let sender_task =
rwhod_packet_sender_task(socket.clone(), interfaces, ignore_list, send_interval);
let receiver_task = rwhod_packet_receiver_task(socket.clone(), whod_status_store);
tokio::select! {
+5
View File
@@ -43,6 +43,11 @@ pub struct RwhodConfig {
///
/// If left as `None`, the server will send on all relevant interfaces it can find.
pub interfaces: Option<HashSet<String>>,
/// Interval between rwhod status packet broadcasts.
///
/// If left as `None`, defaults to 60 seconds.
pub send_interval_seconds: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+2 -1
View File
@@ -114,8 +114,9 @@ pub async fn rwhod_packet_sender_task(
socket: Arc<UdpSocket>,
interfaces: Vec<RwhodSendTarget>,
ignore_list: Option<IgnoreList>,
send_interval: TokioDuration,
) -> anyhow::Result<()> {
let mut interval = interval(TokioDuration::from_secs(60));
let mut interval = interval(send_interval);
loop {
interval.tick().await;