Skip to content

Commit 5b025e0

Browse files
chore: add default system time accuracy check on startup
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 2c602e9 commit 5b025e0

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎Cargo.lock‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ r2d2 = { version = "0.8", default-features = false }
9595
refinery = { version = "0.9", default-features = false }
9696
refinery-core = { version = "0.9", default-features = false }
9797
rusqlite = { version = "0.40", features = ["bundled", "chrono", "modern_sqlite"] }
98+
rsntp = { version = "4.1.2", default-features = false, features = ["async"] }
9899

99100
[dev-dependencies]
100101
axum-test = { version = "21" }

‎src/app/mod.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ impl Liwan {
117117
}
118118

119119
pub fn run_background_tasks(&self) {
120+
if !self.config.disable_ntp_check {
121+
tokio::task::spawn(async {
122+
if let Ok(result) = rsntp::AsyncSntpClient::new().synchronize("pool.ntp.org").await {
123+
let offset_seconds = result.clock_offset().as_secs_f64();
124+
if offset_seconds.abs() >= 5.0 * 60.0 {
125+
tracing::warn!(
126+
offset_seconds,
127+
"System clock is not synchronized; analytics timestamps may be inaccurate"
128+
);
129+
}
130+
}
131+
});
132+
}
120133
#[cfg(feature = "geoip")]
121134
tokio::task::spawn(core::keep_updated(self.geoip.clone()));
122135
}

‎src/config.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub struct Config {
2323
// don't load favicons from the duckduckgo api
2424
pub disable_favicons: bool,
2525

26+
#[serde(default)]
27+
pub disable_ntp_check: bool,
28+
2629
#[serde(default = "default_data_dir")]
2730
pub data_dir: String,
2831

@@ -56,6 +59,7 @@ impl Default for Config {
5659
duckdb: Default::default(),
5760
limits: Default::default(),
5861
disable_favicons: false,
62+
disable_ntp_check: false,
5963
listen: None,
6064
port: None,
6165
trusted_headers: default_trusted_headers(),

0 commit comments

Comments
 (0)