rwhod: allow configuring packet send interval
This commit is contained in:
@@ -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
@@ -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! {
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user