mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 07:43:01 +08:00
Merge pull request #1104 from Heap-Hop/master
fix: android build & CONFIG deadlock
This commit is contained in:
commit
06a4eaed10
@ -596,6 +596,18 @@ impl Config {
|
||||
config.store();
|
||||
}
|
||||
|
||||
// * Manually make sure no gen_keypair more than once
|
||||
// for uuid, avoid deadlock
|
||||
pub fn get_key_pair_without_lock() -> (Vec<u8>, Vec<u8>) {
|
||||
let mut config = Config::load_::<Config>("");
|
||||
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.clone()
|
||||
}
|
||||
|
||||
pub fn get_key_pair() -> (Vec<u8>, Vec<u8>) {
|
||||
// lock here to make sure no gen_keypair more than once
|
||||
let mut config = CONFIG.write().unwrap();
|
||||
|
@ -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<u8> = gen_uuid();
|
||||
}
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
pub type Stream = quic::Connection;
|
||||
#[cfg(not(feature = "quic"))]
|
||||
@ -202,13 +206,24 @@ pub fn get_modified_time(path: &std::path::Path) -> SystemTime {
|
||||
.unwrap_or(UNIX_EPOCH)
|
||||
}
|
||||
|
||||
pub fn get_uuid() -> Vec<u8> {
|
||||
fn gen_uuid() -> Vec<u8> {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if let Ok(id) = machine_uid::get() {
|
||||
return id.into();
|
||||
}
|
||||
id.into()
|
||||
} else {
|
||||
Config::get_key_pair().1
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
Config::get_key_pair_without_lock().1
|
||||
}
|
||||
|
||||
pub fn init_uuid() {
|
||||
let _ = *UUID;
|
||||
}
|
||||
|
||||
pub fn get_uuid() -> Vec<u8> {
|
||||
UUID.to_owned()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
@ -1212,15 +1212,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 {
|
||||
|
@ -3,7 +3,7 @@ use crate::mobile::connection_manager::{self, get_clients_length, get_clients_st
|
||||
use crate::mobile::{self, Session};
|
||||
use crate::common::{make_fd_to_json};
|
||||
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer};
|
||||
use hbb_common::ResultType;
|
||||
use hbb_common::{ResultType, init_uuid};
|
||||
use hbb_common::{
|
||||
config::{self, Config, LocalConfig, PeerConfig, ONLINE},
|
||||
fs, log,
|
||||
@ -16,7 +16,6 @@ use std::{
|
||||
};
|
||||
|
||||
fn initialize(app_dir: &str) {
|
||||
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
android_logger::init_once(
|
||||
@ -30,6 +29,8 @@ fn initialize(app_dir: &str) {
|
||||
use hbb_common::env_logger::*;
|
||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "debug"));
|
||||
}
|
||||
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
|
||||
init_uuid();
|
||||
crate::common::test_rendezvous_server();
|
||||
crate::common::test_nat_type();
|
||||
#[cfg(target_os = "android")]
|
||||
@ -118,7 +119,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 +164,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 +459,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" => {
|
||||
|
@ -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()
|
||||
});
|
||||
|
@ -644,7 +644,7 @@ pub fn handle_one_frame_encoded(
|
||||
})?;
|
||||
let mut send_conn_ids: HashSet<i32> = Default::default();
|
||||
let vp9_frame = EncodedVideoFrame {
|
||||
data: frame.to_vec(),
|
||||
data: frame.to_vec().into(),
|
||||
key: true,
|
||||
pts: ms,
|
||||
..Default::default()
|
||||
|
Loading…
Reference in New Issue
Block a user