fix sysinfo update when id change, and add debug info for pk change

This commit is contained in:
hzhou 2024-04-01 16:20:36 +08:00
parent 9e7137ce09
commit 7fb2464d84
2 changed files with 8 additions and 5 deletions

View File

@ -867,6 +867,7 @@ impl Config {
}
let mut config = Config::load_::<Config>("");
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();

View File

@ -56,11 +56,13 @@ async fn start_hbbs_sync_async() {
TIME_CONN,
));
let mut last_sent: Option<Instant> = None;
let mut info_uploaded: (bool, String, Option<Instant>) = (false, "".to_owned(), None);
let mut info_uploaded: (bool, String, Option<Instant>, 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() {