fix sysinfo update when id change, and add debug info for pk change
This commit is contained in:
parent
9e7137ce09
commit
7fb2464d84
@ -867,6 +867,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
let mut config = Config::load_::<Config>("");
|
let mut config = Config::load_::<Config>("");
|
||||||
if config.key_pair.0.is_empty() {
|
if config.key_pair.0.is_empty() {
|
||||||
|
log::info!("Generated new keypair for id: {}", config.id);
|
||||||
let (pk, sk) = sign::gen_keypair();
|
let (pk, sk) = sign::gen_keypair();
|
||||||
let key_pair = (sk.0.to_vec(), pk.0.into());
|
let key_pair = (sk.0.to_vec(), pk.0.into());
|
||||||
config.key_pair = key_pair.clone();
|
config.key_pair = key_pair.clone();
|
||||||
|
@ -56,11 +56,13 @@ async fn start_hbbs_sync_async() {
|
|||||||
TIME_CONN,
|
TIME_CONN,
|
||||||
));
|
));
|
||||||
let mut last_sent: Option<Instant> = None;
|
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 {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = interval.tick() => {
|
_ = interval.tick() => {
|
||||||
let url = heartbeat_url();
|
let url = heartbeat_url();
|
||||||
|
let id = Config::get_id();
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
*PRO.lock().unwrap() = false;
|
*PRO.lock().unwrap() = false;
|
||||||
continue;
|
continue;
|
||||||
@ -69,19 +71,19 @@ async fn start_hbbs_sync_async() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let conns = Connection::alive_conns();
|
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;
|
info_uploaded.0 = false;
|
||||||
*PRO.lock().unwrap() = false;
|
*PRO.lock().unwrap() = false;
|
||||||
}
|
}
|
||||||
if !info_uploaded.0 && info_uploaded.2.map(|x| x.elapsed() >= UPLOAD_SYSINFO_TIMEOUT).unwrap_or(true){
|
if !info_uploaded.0 && info_uploaded.2.map(|x| x.elapsed() >= UPLOAD_SYSINFO_TIMEOUT).unwrap_or(true){
|
||||||
let mut v = crate::get_sysinfo();
|
let mut v = crate::get_sysinfo();
|
||||||
v["version"] = json!(crate::VERSION);
|
v["version"] = json!(crate::VERSION);
|
||||||
v["id"] = json!(Config::get_id());
|
v["id"] = json!(id);
|
||||||
v["uuid"] = json!(crate::encode64(hbb_common::get_uuid()));
|
v["uuid"] = json!(crate::encode64(hbb_common::get_uuid()));
|
||||||
match crate::post_request(url.replace("heartbeat", "sysinfo"), v.to_string(), "").await {
|
match crate::post_request(url.replace("heartbeat", "sysinfo"), v.to_string(), "").await {
|
||||||
Ok(x) => {
|
Ok(x) => {
|
||||||
if x == "SYSINFO_UPDATED" {
|
if x == "SYSINFO_UPDATED" {
|
||||||
info_uploaded = (true, url.clone(), None);
|
info_uploaded = (true, url.clone(), None, id.clone());
|
||||||
hbb_common::log::info!("sysinfo updated");
|
hbb_common::log::info!("sysinfo updated");
|
||||||
*PRO.lock().unwrap() = true;
|
*PRO.lock().unwrap() = true;
|
||||||
} else if x == "ID_NOT_FOUND" {
|
} else if x == "ID_NOT_FOUND" {
|
||||||
@ -100,7 +102,7 @@ async fn start_hbbs_sync_async() {
|
|||||||
}
|
}
|
||||||
last_sent = Some(Instant::now());
|
last_sent = Some(Instant::now());
|
||||||
let mut v = Value::default();
|
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["uuid"] = json!(crate::encode64(hbb_common::get_uuid()));
|
||||||
v["ver"] = json!(hbb_common::get_version_number(crate::VERSION));
|
v["ver"] = json!(hbb_common::get_version_number(crate::VERSION));
|
||||||
if !conns.is_empty() {
|
if !conns.is_empty() {
|
||||||
|
Loading…
Reference in New Issue
Block a user