Fixes and improvements

This commit is contained in:
imengying committed 2026-08-17 16:17:06 +08:00
1 parent 40ff956461
commit 97e4b3a5f1
23 files changed
+687 -375

No files matched your search

+36 -35
View File
@@ -37,9 +37,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
[[package]]
name = "cc"
version = "1.4.2"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d262e149917187838d5b42777c8253bcb64500067342904e7d429499a6f277e"
checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -205,9 +205,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "find-msvc-tools"
version = "0.1.10"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b73573e6edcd2af0cdf47bd6cb58f0b3839491263c314eaad1ccf24430e1de"
checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890"
[[package]]
name = "form_urlencoded"
@@ -286,9 +286,9 @@ dependencies = [
[[package]]
name = "icu_collections"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c"
checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513"
dependencies = [
"displaydoc",
"potential_utf",
@@ -300,9 +300,9 @@ dependencies = [
[[package]]
name = "icu_locale_core"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29"
checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb"
dependencies = [
"displaydoc",
"litemap",
@@ -313,9 +313,9 @@ dependencies = [
[[package]]
name = "icu_normalizer"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4"
checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f"
dependencies = [
"icu_collections",
"icu_normalizer_data",
@@ -327,16 +327,17 @@ dependencies = [
[[package]]
name = "icu_normalizer_data"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38"
checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0"
[[package]]
name = "icu_properties"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de"
checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148"
dependencies = [
"displaydoc",
"icu_collections",
"icu_locale_core",
"icu_properties_data",
@@ -347,15 +348,15 @@ dependencies = [
[[package]]
name = "icu_properties_data"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14"
checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa"
[[package]]
name = "icu_provider"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421"
checksum = "92a7ed671a6aad807a8651a2e1782a6598fda9ce5185dd8158549e95a91c6428"
dependencies = [
"displaydoc",
"icu_locale_core",
@@ -411,9 +412,9 @@ checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
[[package]]
name = "litemap"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0"
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
[[package]]
name = "litrs"
@@ -496,9 +497,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "potential_utf"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564"
checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
dependencies = [
"zerovec",
]
@@ -590,9 +591,9 @@ dependencies = [
[[package]]
name = "rustls-webpki"
version = "0.103.13"
version = "0.103.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e"
checksum = "0527518605e68109d875e248ea259b6758801cf165e4b2c2733ae3b51f12535a"
dependencies = [
"ring",
"rustls-pki-types",
@@ -793,9 +794,9 @@ dependencies = [
[[package]]
name = "tinystr"
version = "0.8.3"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d"
checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643"
dependencies = [
"displaydoc",
"zerovec",
@@ -1130,9 +1131,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "writeable"
version = "0.6.3"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
[[package]]
name = "yoke"
@@ -1186,9 +1187,9 @@ checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
[[package]]
name = "zerotrie"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf"
checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f"
dependencies = [
"displaydoc",
"yoke",
@@ -1197,9 +1198,9 @@ dependencies = [
[[package]]
name = "zerovec"
version = "0.11.6"
version = "0.11.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239"
checksum = "94b5c6b5976d66c1d703c4fd17d3f5e43c8cedaacf604961b171adc7130896d8"
dependencies = [
"yoke",
"zerofrom",
@@ -1208,13 +1209,13 @@ dependencies = [
[[package]]
name = "zerovec-derive"
version = "0.11.3"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555"
checksum = "47402523226a02bfe5230160dc3ccc089aa6f6f19e7fcbb4e6f824bbb1b4aa62"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
"syn 3.0.3",
]
[[package]]
+1 -1
View File
@@ -203,7 +203,7 @@ install_agent() {
if [ "$init_system" = "systemd" ]; then
printf '%s\n' \
'[Unit]' \
'Description=NodeFlare Rust Agent' \
'Description=nodeflare' \
'After=network-online.target' \
'Wants=network-online.target' \
'' \
+21 -29
View File
@@ -48,7 +48,7 @@ const LIVE_QUEUE_CAPACITY: usize = 720;
// the queue preserves the remaining samples for the next frame.
const LIVE_BATCH_CAPACITY: usize = 32;
// D1 persistence can take a few hundred milliseconds; allow the ACK to arrive
// before falling back to the configured interval.
// before continuing with the configured live interval.
const LIVE_ACK_READ_TIMEOUT: Duration = Duration::from_millis(1_000);
const CLOCK_CALIBRATION_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60);
const CLOCK_CALIBRATION_MIN_CHANGE_MS: i64 = 20_000;
@@ -229,19 +229,19 @@ type SharedClock = Arc<Mutex<ClockCalibration>>;
struct LiveSender {
pending: Arc<(Mutex<Vec<Report>>, Condvar)>,
report_interval: Arc<Mutex<Duration>>,
send_interval: Arc<Mutex<Duration>>,
}
impl LiveSender {
fn start(config: &RuntimeConfig, clock: SharedClock) -> Result<Self> {
let pending = Arc::new((Mutex::new(Vec::new()), Condvar::new()));
let report_interval = Arc::new(Mutex::new(Duration::from_secs(
config.report_interval.clamp(15, 3600),
let send_interval = Arc::new(Mutex::new(Duration::from_secs(
config.collect_interval.clamp(2, 60),
)));
let endpoint = live_endpoint(&config.endpoint)?;
let token = config.token.clone();
let sender_state = Arc::clone(&pending);
let sender_interval = Arc::clone(&report_interval);
let sender_interval = Arc::clone(&send_interval);
thread::Builder::new()
.name("nodeflare-live".to_string())
.spawn(move || {
@@ -249,7 +249,7 @@ impl LiveSender {
})?;
Ok(Self {
pending,
report_interval,
send_interval,
})
}
@@ -264,9 +264,9 @@ impl LiveSender {
}
}
fn set_report_interval(&self, seconds: u64) {
if let Ok(mut interval) = self.report_interval.lock() {
*interval = Duration::from_secs(seconds.clamp(15, 3600));
fn set_send_interval(&self, seconds: u64) {
if let Ok(mut interval) = self.send_interval.lock() {
*interval = Duration::from_secs(seconds.clamp(2, 60));
}
self.pending.1.notify_one();
}
@@ -1382,17 +1382,15 @@ struct LiveAck {
#[serde(rename = "nextD1WriteAfterMs")]
next_d1_write_after_ms: u64,
#[serde(rename = "nextWssReportAfterMs")]
next_wss_report_after_ms: Option<u64>,
next_wss_report_after_ms: u64,
}
fn ack_interval(ack: &LiveAck, fallback: Duration) -> Duration {
ack.next_wss_report_after_ms
.map(Duration::from_millis)
.map(|interval| interval.clamp(Duration::from_secs(2), Duration::from_secs(3600)))
.unwrap_or(fallback)
fn ack_interval(ack: &LiveAck) -> Duration {
Duration::from_millis(ack.next_wss_report_after_ms)
.clamp(Duration::from_secs(2), Duration::from_secs(60))
}
fn read_live_ack(socket: &mut LiveSocket, current_interval: Duration) -> Result<Option<Duration>> {
fn read_live_ack(socket: &mut LiveSocket) -> Result<Option<Duration>> {
match socket.read() {
Ok(Message::Text(text)) => {
let Ok(ack) = serde_json::from_str::<LiveAck>(text.as_ref()) else {
@@ -1402,7 +1400,7 @@ fn read_live_ack(socket: &mut LiveSocket, current_interval: Duration) -> Result<
return Ok(None);
}
let _ = (ack.persisted, ack.next_d1_write_after_ms);
Ok(Some(ack_interval(&ack, current_interval)))
Ok(Some(ack_interval(&ack)))
}
Ok(Message::Ping(payload)) => {
socket.send(Message::Pong(payload))?;
@@ -1453,7 +1451,7 @@ fn live_sender_loop(
let mut send_interval = configured_interval
.lock()
.map(|interval| *interval)
.unwrap_or(Duration::from_secs(60));
.unwrap_or(Duration::from_secs(5));
let mut next_send_at = Instant::now();
loop {
let (queue, ready) = &*pending;
@@ -1479,7 +1477,7 @@ fn live_sender_loop(
drop(queue);
if let Ok(interval) = configured_interval.lock() {
send_interval = (*interval).min(Duration::from_secs(3600));
send_interval = (*interval).clamp(Duration::from_secs(2), Duration::from_secs(60));
}
if socket.is_none() {
match connect_live(endpoint, token) {
@@ -1535,7 +1533,7 @@ fn live_sender_loop(
next_send_at = Instant::now() + send_interval;
let mut drop_socket = false;
if let Some(socket) = socket.as_mut() {
match read_live_ack(socket, send_interval) {
match read_live_ack(socket) {
Ok(Some(Duration::ZERO)) => drop_socket = true,
Ok(Some(interval)) => {
send_interval = interval;
@@ -1955,7 +1953,7 @@ fn run(options: &CliOptions, once: bool, print_only: bool) -> Result<()> {
next_latency.clear();
}
if let Some(live) = &live {
live.set_report_interval(config.report_interval);
live.set_send_interval(config.collect_interval);
}
}
if !once && config.auto_update && Instant::now() >= next_update_check {
@@ -2152,18 +2150,12 @@ mod tests {
r#"{"type":"ack","ts":100,"persisted":false,"nextD1WriteAfterMs":60000,"nextWssReportAfterMs":5000}"#,
)
.unwrap();
assert_eq!(
ack_interval(&ack, Duration::from_secs(60)),
Duration::from_secs(5)
);
assert_eq!(ack_interval(&ack), Duration::from_secs(5));
let slow: LiveAck = serde_json::from_str(
r#"{"type":"ack","ts":100,"persisted":true,"nextD1WriteAfterMs":60000,"nextWssReportAfterMs":1}"#,
)
.unwrap();
assert_eq!(
ack_interval(&slow, Duration::from_secs(60)),
Duration::from_secs(2)
);
assert_eq!(ack_interval(&slow), Duration::from_secs(2));
}
#[test]