From e923e440eac4f81e5cc91e86d6dd6cf2ad590743 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Sat, 23 Mar 2024 21:00:19 +0100 Subject: [PATCH 1/2] added who poll interval as server config --- book/src/configuration/servers.md | 4 ++++ data/src/client.rs | 11 +++++------ data/src/config/server.rs | 31 ++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/book/src/configuration/servers.md b/book/src/configuration/servers.md index 1beb3c90e..77b67b87f 100644 --- a/book/src/configuration/servers.md +++ b/book/src/configuration/servers.md @@ -33,6 +33,10 @@ channels = ["#halloy"] | `dangerously_accept_invalid_certs` | On `true`, all certificate validations are skipped. Defaults to `false`. | `false` | | `root_cert_path` | The path to the root TLS certificate for this server in PEM format. | `""` | | `on_connect` | Commands which are executed once connected. Example. `["/msg NickServ IDENTIFY foo bar"]`. | `[]` | +| `who_poll_interval` | WHO poll interval (in seconds) for servers without away-notify. | `180`[^1] | +| `who_retry_interval` | WHO retry interval (in seconds) for servers without away-notify. | `10`[^1] | + +[^1]: Limited between `5` and `3600` seconds. ## `[servers.sasl]` Section diff --git a/data/src/client.rs b/data/src/client.rs index a8d23f104..3e863d142 100644 --- a/data/src/client.rs +++ b/data/src/client.rs @@ -11,8 +11,6 @@ use crate::time::Posix; use crate::user::{Nick, NickRef}; use crate::{config, message, mode, Buffer, Server, User}; -const WHO_POLL_INTERVAL: Duration = Duration::from_secs(60); -const WHO_RETRY_INTERVAL: Duration = Duration::from_secs(10); const HIGHLIGHT_BLACKOUT_INTERVAL: Duration = Duration::from_secs(5); #[derive(Debug, Clone, Copy)] @@ -758,11 +756,12 @@ impl Client { let request = match state.last_who { Some(WhoStatus::Done(last)) if !self.supports_away_notify => { - (now.duration_since(last) >= WHO_POLL_INTERVAL).then_some(Request::Poll) - } - Some(WhoStatus::Requested(requested)) => { - (now.duration_since(requested) >= WHO_RETRY_INTERVAL).then_some(Request::Retry) + (now.duration_since(last) >= self.config.who_poll_interval) + .then_some(Request::Poll) } + Some(WhoStatus::Requested(requested)) => (now.duration_since(requested) + >= self.config.who_retry_interval) + .then_some(Request::Retry), _ => None, }; diff --git a/data/src/config/server.rs b/data/src/config/server.rs index 9c03f9e79..74284433e 100644 --- a/data/src/config/server.rs +++ b/data/src/config/server.rs @@ -1,8 +1,9 @@ use std::collections::HashMap; use std::path::PathBuf; +use std::time::Duration; use irc::connection; -use serde::Deserialize; +use serde::{Deserialize, Deserializer}; #[derive(Debug, Clone, Default, Deserialize)] pub struct Server { @@ -65,6 +66,18 @@ pub struct Server { /// Commands which are executed once connected. #[serde(default)] pub on_connect: Vec, + /// WHO poll interval for servers without away-notify. + #[serde( + default = "default_who_poll_interval", + deserialize_with = "deserialize_duration_from_u64" + )] + pub who_poll_interval: Duration, + /// WHO retry interval for servers without away-notify. + #[serde( + default = "default_who_retry_interval", + deserialize_with = "deserialize_duration_from_u64" + )] + pub who_retry_interval: Duration, } impl Server { @@ -141,6 +154,14 @@ impl Sasl { } } +fn deserialize_duration_from_u64<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let seconds: u64 = Deserialize::deserialize(deserializer)?; + Ok(Duration::from_secs(seconds.clamp(5, 3600))) +} + fn default_use_tls() -> bool { true } @@ -164,3 +185,11 @@ fn default_reconnect_delay() -> u64 { fn default_ghost_sequence() -> Vec { vec!["GHOST".into()] } + +fn default_who_poll_interval() -> Duration { + Duration::from_secs(180) +} + +fn default_who_retry_interval() -> Duration { + Duration::from_secs(10) +} From e35d758eda2f92fa1452bfa383f377c4dda78cd1 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Sun, 24 Mar 2024 16:24:04 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cce33fb87..202c476b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +Added: + +- Configuration to adjust WHO polling for servers without away-notify (see [server configuration](https://halloy.squidowl.org/configuration/servers.html)) + Fixed: - Accept '@' in usernames to support bouncers that use the user@identifier/network convention