mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-02-17 14:07:28 +08:00
improve sysinfo update
This commit is contained in:
Submodule libs/hbb_common updated: f9a10eaa1f...e7d210e03a
@@ -7,7 +7,8 @@ use std::{
|
||||
#[cfg(not(any(target_os = "ios")))]
|
||||
use crate::{ui_interface::get_builtin_option, Connection};
|
||||
use hbb_common::{
|
||||
config::{keys, Config, LocalConfig},
|
||||
config::{self, keys, Config, LocalConfig},
|
||||
log,
|
||||
tokio::{self, sync::broadcast, time::Instant},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -58,6 +59,7 @@ async fn start_hbbs_sync_async() {
|
||||
let mut last_sent: Option<Instant> = None;
|
||||
let mut info_uploaded: (bool, String, Option<Instant>, String) =
|
||||
(false, "".to_owned(), None, "".to_owned());
|
||||
let mut sysinfo_ver = "".to_owned();
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = interval.tick() => {
|
||||
@@ -67,7 +69,7 @@ async fn start_hbbs_sync_async() {
|
||||
*PRO.lock().unwrap() = false;
|
||||
continue;
|
||||
}
|
||||
if hbb_common::config::option2bool("stop-service", &Config::get_option("stop-service")) {
|
||||
if config::option2bool("stop-service", &Config::get_option("stop-service")) {
|
||||
continue;
|
||||
}
|
||||
let conns = Connection::alive_conns();
|
||||
@@ -103,11 +105,38 @@ async fn start_hbbs_sync_async() {
|
||||
if !device_group_name.is_empty() {
|
||||
v[keys::OPTION_PRESET_DEVICE_GROUP_NAME] = json!(device_group_name);
|
||||
}
|
||||
match crate::post_request(url.replace("heartbeat", "sysinfo"), v.to_string(), "").await {
|
||||
let v = v.to_string();
|
||||
use sha2::{Digest, Sha256};
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(url.as_bytes());
|
||||
hasher.update(&v.as_bytes());
|
||||
let res = hasher.finalize();
|
||||
let hash = hbb_common::base64::encode(&res[..]);
|
||||
let old_hash = config::Status::get("sysinfo_hash");
|
||||
let ver = config::Status::get("sysinfo_ver"); // sysinfo_ver is the version of sysinfo on server's side
|
||||
if hash == old_hash {
|
||||
let samever = match crate::post_request(url.replace("heartbeat", "sysinfo_ver"), "".to_owned(), "").await {
|
||||
Ok(x) => {
|
||||
sysinfo_ver = x.clone();
|
||||
x == ver
|
||||
}
|
||||
_ => {
|
||||
true // if failed to get sysinfo_ver, we assume it's the same version
|
||||
}
|
||||
};
|
||||
if samever {
|
||||
info_uploaded = (true, url.clone(), None, id.clone());
|
||||
log::info!("sysinfo not changed, skip upload");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
match crate::post_request(url.replace("heartbeat", "sysinfo"), v, "").await {
|
||||
Ok(x) => {
|
||||
if x == "SYSINFO_UPDATED" {
|
||||
info_uploaded = (true, url.clone(), None, id.clone());
|
||||
hbb_common::log::info!("sysinfo updated");
|
||||
log::info!("sysinfo updated");
|
||||
config::Status::set("sysinfo_hash", hash);
|
||||
config::Status::set("sysinfo_ver", sysinfo_ver.clone());
|
||||
*PRO.lock().unwrap() = true;
|
||||
} else if x == "ID_NOT_FOUND" {
|
||||
info_uploaded.2 = None; // next heartbeat will upload sysinfo again
|
||||
@@ -136,6 +165,11 @@ async fn start_hbbs_sync_async() {
|
||||
v["modified_at"] = json!(modified_at);
|
||||
if let Ok(s) = crate::post_request(url.clone(), v.to_string(), "").await {
|
||||
if let Ok(mut rsp) = serde_json::from_str::<HashMap::<&str, Value>>(&s) {
|
||||
if rsp.remove("sysinfo").is_some() {
|
||||
info_uploaded.0 = false;
|
||||
config::Status::set("sysinfo_hash", "".to_owned());
|
||||
log::info!("sysinfo required to forcely update");
|
||||
}
|
||||
if let Some(conns) = rsp.remove("disconnect") {
|
||||
if let Ok(conns) = serde_json::from_value::<Vec<i32>>(conns) {
|
||||
SENDER.lock().unwrap().send(conns).ok();
|
||||
@@ -150,6 +184,7 @@ async fn start_hbbs_sync_async() {
|
||||
}
|
||||
if let Some(strategy) = rsp.remove("strategy") {
|
||||
if let Ok(strategy) = serde_json::from_value::<StrategyOptions>(strategy) {
|
||||
log::info!("strategy updated");
|
||||
handle_config_options(strategy.config_options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user