diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 3b8b3e57d..3767b1b83 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -584,6 +584,17 @@ impl Config { config.store(); } + pub fn get_sk_uuid() -> Vec { + // for uuid, avoid deadlock + let mut config = Config::load_::(""); + if config.key_pair.0.is_empty() { + let (pk, sk) = sign::gen_keypair(); + config.key_pair = (sk.0.to_vec(), pk.0.into()); + Config::store_(&config, ""); + } + config.key_pair.1 + } + pub fn get_key_pair() -> (Vec, Vec) { // lock here to make sure no gen_keypair more than once let mut config = CONFIG.write().unwrap(); diff --git a/libs/hbb_common/src/lib.rs b/libs/hbb_common/src/lib.rs index a5443db0f..3ae95c83e 100644 --- a/libs/hbb_common/src/lib.rs +++ b/libs/hbb_common/src/lib.rs @@ -39,6 +39,10 @@ pub use tokio_socks::IntoTargetAddr; pub use tokio_socks::TargetAddr; pub mod password_security; +lazy_static::lazy_static!{ + static ref UUID: Vec = gen_uuid(); +} + #[cfg(feature = "quic")] pub type Stream = quic::Connection; #[cfg(not(feature = "quic"))] @@ -202,12 +206,16 @@ pub fn get_modified_time(path: &std::path::Path) -> SystemTime { .unwrap_or(UNIX_EPOCH) } -pub fn get_uuid() -> Vec { +fn gen_uuid() -> Vec { #[cfg(not(any(target_os = "android", target_os = "ios")))] if let Ok(id) = machine_uid::get() { return id.into(); } - Config::get_key_pair().1 + Config::get_sk_uuid() +} + +pub fn get_uuid() -> Vec { + UUID.to_owned() } #[cfg(test)] diff --git a/src/ipc.rs b/src/ipc.rs index 6d2dd102f..2324f691c 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -87,6 +87,7 @@ pub enum FS { }, } +#[cfg(not(any(target_os = "android", target_os = "ios")))] #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(tag = "t", content = "c")] pub enum DataKeyboard { @@ -103,6 +104,7 @@ pub enum DataKeyboardResponse { GetKeyState(bool), } +#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))] #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(tag = "t", content = "c")] pub enum DataMouse { @@ -171,8 +173,11 @@ pub enum Data { ClipboardFileEnabled(bool), PrivacyModeState((i32, PrivacyModeState)), TestRendezvousServer, + #[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))] Keyboard(DataKeyboard), + #[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))] KeyboardResponse(DataKeyboardResponse), + #[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))] Mouse(DataMouse), Control(DataControl), Empty, diff --git a/src/mobile.rs b/src/mobile.rs index d3adaaa79..6e96f17c6 100644 --- a/src/mobile.rs +++ b/src/mobile.rs @@ -478,8 +478,8 @@ impl Interface for Session { } } - async fn handle_hash(&mut self, hash: Hash, peer: &mut Stream) { - handle_hash(self.lc.clone(), hash, self, peer).await; + async fn handle_hash(&mut self, pass: &str, hash: Hash, peer: &mut Stream) { + handle_hash(self.lc.clone(), pass, hash, self, peer).await; } async fn handle_login_from_ui(&mut self, password: String, remember: bool, peer: &mut Stream) { @@ -611,7 +611,7 @@ impl Connection { } } Some(message::Union::Hash(hash)) => { - self.session.handle_hash(hash, peer).await; + self.session.handle_hash("", hash, peer).await; } Some(message::Union::LoginResponse(lr)) => match lr.union { Some(login_response::Union::Error(err)) => { @@ -629,7 +629,7 @@ impl Connection { let content = if cb.compress { decompress(&cb.content) } else { - cb.content + cb.content.into() }; if let Ok(content) = String::from_utf8(content) { self.session @@ -1213,15 +1213,13 @@ pub mod connection_manager { Some(Data::Login { id, is_file_transfer, - port_forward, peer_id, name, authorized, keyboard, clipboard, audio, - file, - file_transfer_enabled, + .. }) => { current_id = id; let mut client = Client { diff --git a/src/mobile_ffi.rs b/src/mobile_ffi.rs index 6a0b71a5e..34eb9bdb8 100644 --- a/src/mobile_ffi.rs +++ b/src/mobile_ffi.rs @@ -118,7 +118,7 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co res = Config::get_id(); } "server_password" => { - res = Config::get_password(); + todo!() } "connect_statue" => { res = ONLINE @@ -163,7 +163,7 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co } } "uuid" => { - res = base64::encode(crate::get_uuid()); + res = base64::encode(hbb_common::get_uuid()); } _ => { log::error!("Unknown name of get_by_name: {}", name); @@ -458,11 +458,7 @@ unsafe extern "C" fn set_by_name(name: *const c_char, value: *const c_char) { } // Server Side "update_password" => { - if value.is_empty() { - Config::set_password(&Config::get_auto_password()); - } else { - Config::set_password(value); - } + todo!() } #[cfg(target_os = "android")] "chat_server_mode" => { diff --git a/src/server/audio_service.rs b/src/server/audio_service.rs index 02db0bffd..addc06644 100644 --- a/src/server/audio_service.rs +++ b/src/server/audio_service.rs @@ -347,7 +347,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) { Ok(data) => { let mut msg_out = Message::new(); msg_out.set_audio_frame(AudioFrame { - data, + data: data.into(), timestamp: crate::common::get_time(), ..Default::default() }); diff --git a/src/server/video_service.rs b/src/server/video_service.rs index afe5c5627..b84bebd22 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -646,7 +646,7 @@ pub fn handle_one_frame_encoded( })?; let mut send_conn_ids: HashSet = Default::default(); let vp9_frame = EncodedVideoFrame { - data: frame.to_vec(), + data: frame.to_vec().into(), key: true, pts: ms, ..Default::default()