allow set machine uid with command line (#1009)

This commit is contained in:
Sijie.Sun
2025-06-18 11:02:29 +08:00
committed by GitHub
parent 34ba0bc95b
commit 8c2f96d1aa
4 changed files with 32 additions and 4 deletions

View File

@@ -8,6 +8,8 @@ use time::util::refresh_tz;
use tokio::{task::JoinSet, time::timeout};
use tracing::Instrument;
use crate::{set_global_var, use_global_var};
pub mod compressor;
pub mod config;
pub mod constants;
@@ -87,7 +89,17 @@ pub fn join_joinset_background<T: Debug + Send + Sync + 'static>(
);
}
pub fn set_default_machine_id(mid: Option<String>) {
set_global_var!(MACHINE_UID, mid);
}
pub fn get_machine_id() -> uuid::Uuid {
if let Some(default_mid) = use_global_var!(MACHINE_UID) {
let mut b = [0u8; 16];
crate::tunnel::generate_digest_from_str("", &default_mid, &mut b);
return uuid::Uuid::from_bytes(b);
}
// a path same as the binary
let machine_id_file = std::env::current_exe()
.map(|x| x.with_file_name("et_machine_id"))