From 7fb2464d84b621767a357f03c3d33498c00da882 Mon Sep 17 00:00:00 2001 From: hzhou Date: Mon, 1 Apr 2024 16:20:36 +0800 Subject: [PATCH] fix sysinfo update when id change, and add debug info for pk change --- libs/hbb_common/src/config.rs | 1 + src/hbbs_http/sync.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 5af811047..5446b7a01 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -867,6 +867,7 @@ impl Config { } let mut config = Config::load_::(""); if config.key_pair.0.is_empty() { + log::info!("Generated new keypair for id: {}", config.id); let (pk, sk) = sign::gen_keypair(); let key_pair = (sk.0.to_vec(), pk.0.into()); config.key_pair = key_pair.clone(); diff --git a/src/hbbs_http/sync.rs b/src/hbbs_http/sync.rs index 2a33b3114..8cf925434 100644 --- a/src/hbbs_http/sync.rs +++ b/src/hbbs_http/sync.rs @@ -56,11 +56,13 @@ async fn start_hbbs_sync_async() { TIME_CONN, )); let mut last_sent: Option = None; - let mut info_uploaded: (bool, String, Option) = (false, "".to_owned(), None); + let mut info_uploaded: (bool, String, Option, String) = + (false, "".to_owned(), None, "".to_owned()); loop { tokio::select! { _ = interval.tick() => { let url = heartbeat_url(); + let id = Config::get_id(); if url.is_empty() { *PRO.lock().unwrap() = false; continue; @@ -69,19 +71,19 @@ async fn start_hbbs_sync_async() { continue; } let conns = Connection::alive_conns(); - if info_uploaded.0 && url != info_uploaded.1 { + if info_uploaded.0 && (url != info_uploaded.1 || id != info_uploaded.3){ info_uploaded.0 = false; *PRO.lock().unwrap() = false; } if !info_uploaded.0 && info_uploaded.2.map(|x| x.elapsed() >= UPLOAD_SYSINFO_TIMEOUT).unwrap_or(true){ let mut v = crate::get_sysinfo(); v["version"] = json!(crate::VERSION); - v["id"] = json!(Config::get_id()); + v["id"] = json!(id); v["uuid"] = json!(crate::encode64(hbb_common::get_uuid())); match crate::post_request(url.replace("heartbeat", "sysinfo"), v.to_string(), "").await { Ok(x) => { if x == "SYSINFO_UPDATED" { - info_uploaded = (true, url.clone(), None); + info_uploaded = (true, url.clone(), None, id.clone()); hbb_common::log::info!("sysinfo updated"); *PRO.lock().unwrap() = true; } else if x == "ID_NOT_FOUND" { @@ -100,7 +102,7 @@ async fn start_hbbs_sync_async() { } last_sent = Some(Instant::now()); let mut v = Value::default(); - v["id"] = json!(Config::get_id()); + v["id"] = json!(id); v["uuid"] = json!(crate::encode64(hbb_common::get_uuid())); v["ver"] = json!(hbb_common::get_version_number(crate::VERSION)); if !conns.is_empty() {