fix: android build & CONFIG deadlock
This commit is contained in:
parent
6bbfe13028
commit
da2906c95f
@ -584,6 +584,17 @@ impl Config {
|
|||||||
config.store();
|
config.store();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_sk_uuid() -> Vec<u8> {
|
||||||
|
// for uuid, avoid deadlock
|
||||||
|
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.1
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_key_pair() -> (Vec<u8>, Vec<u8>) {
|
pub fn get_key_pair() -> (Vec<u8>, Vec<u8>) {
|
||||||
// lock here to make sure no gen_keypair more than once
|
// lock here to make sure no gen_keypair more than once
|
||||||
let mut config = CONFIG.write().unwrap();
|
let mut config = CONFIG.write().unwrap();
|
||||||
|
@ -39,6 +39,10 @@ pub use tokio_socks::IntoTargetAddr;
|
|||||||
pub use tokio_socks::TargetAddr;
|
pub use tokio_socks::TargetAddr;
|
||||||
pub mod password_security;
|
pub mod password_security;
|
||||||
|
|
||||||
|
lazy_static::lazy_static!{
|
||||||
|
static ref UUID: Vec<u8> = gen_uuid();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "quic")]
|
#[cfg(feature = "quic")]
|
||||||
pub type Stream = quic::Connection;
|
pub type Stream = quic::Connection;
|
||||||
#[cfg(not(feature = "quic"))]
|
#[cfg(not(feature = "quic"))]
|
||||||
@ -202,12 +206,16 @@ pub fn get_modified_time(path: &std::path::Path) -> SystemTime {
|
|||||||
.unwrap_or(UNIX_EPOCH)
|
.unwrap_or(UNIX_EPOCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_uuid() -> Vec<u8> {
|
fn gen_uuid() -> Vec<u8> {
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
if let Ok(id) = machine_uid::get() {
|
if let Ok(id) = machine_uid::get() {
|
||||||
return id.into();
|
return id.into();
|
||||||
}
|
}
|
||||||
Config::get_key_pair().1
|
Config::get_sk_uuid()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_uuid() -> Vec<u8> {
|
||||||
|
UUID.to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -87,6 +87,7 @@ pub enum FS {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(tag = "t", content = "c")]
|
#[serde(tag = "t", content = "c")]
|
||||||
pub enum DataKeyboard {
|
pub enum DataKeyboard {
|
||||||
@ -103,6 +104,7 @@ pub enum DataKeyboardResponse {
|
|||||||
GetKeyState(bool),
|
GetKeyState(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(tag = "t", content = "c")]
|
#[serde(tag = "t", content = "c")]
|
||||||
pub enum DataMouse {
|
pub enum DataMouse {
|
||||||
@ -171,8 +173,11 @@ pub enum Data {
|
|||||||
ClipboardFileEnabled(bool),
|
ClipboardFileEnabled(bool),
|
||||||
PrivacyModeState((i32, PrivacyModeState)),
|
PrivacyModeState((i32, PrivacyModeState)),
|
||||||
TestRendezvousServer,
|
TestRendezvousServer,
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||||
Keyboard(DataKeyboard),
|
Keyboard(DataKeyboard),
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||||
KeyboardResponse(DataKeyboardResponse),
|
KeyboardResponse(DataKeyboardResponse),
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||||
Mouse(DataMouse),
|
Mouse(DataMouse),
|
||||||
Control(DataControl),
|
Control(DataControl),
|
||||||
Empty,
|
Empty,
|
||||||
|
@ -478,8 +478,8 @@ impl Interface for Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_hash(&mut self, hash: Hash, peer: &mut Stream) {
|
async fn handle_hash(&mut self, pass: &str, hash: Hash, peer: &mut Stream) {
|
||||||
handle_hash(self.lc.clone(), hash, self, peer).await;
|
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) {
|
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)) => {
|
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(message::Union::LoginResponse(lr)) => match lr.union {
|
||||||
Some(login_response::Union::Error(err)) => {
|
Some(login_response::Union::Error(err)) => {
|
||||||
@ -629,7 +629,7 @@ impl Connection {
|
|||||||
let content = if cb.compress {
|
let content = if cb.compress {
|
||||||
decompress(&cb.content)
|
decompress(&cb.content)
|
||||||
} else {
|
} else {
|
||||||
cb.content
|
cb.content.into()
|
||||||
};
|
};
|
||||||
if let Ok(content) = String::from_utf8(content) {
|
if let Ok(content) = String::from_utf8(content) {
|
||||||
self.session
|
self.session
|
||||||
@ -1213,15 +1213,13 @@ pub mod connection_manager {
|
|||||||
Some(Data::Login {
|
Some(Data::Login {
|
||||||
id,
|
id,
|
||||||
is_file_transfer,
|
is_file_transfer,
|
||||||
port_forward,
|
|
||||||
peer_id,
|
peer_id,
|
||||||
name,
|
name,
|
||||||
authorized,
|
authorized,
|
||||||
keyboard,
|
keyboard,
|
||||||
clipboard,
|
clipboard,
|
||||||
audio,
|
audio,
|
||||||
file,
|
..
|
||||||
file_transfer_enabled,
|
|
||||||
}) => {
|
}) => {
|
||||||
current_id = id;
|
current_id = id;
|
||||||
let mut client = Client {
|
let mut client = Client {
|
||||||
|
@ -118,7 +118,7 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
|
|||||||
res = Config::get_id();
|
res = Config::get_id();
|
||||||
}
|
}
|
||||||
"server_password" => {
|
"server_password" => {
|
||||||
res = Config::get_password();
|
todo!()
|
||||||
}
|
}
|
||||||
"connect_statue" => {
|
"connect_statue" => {
|
||||||
res = ONLINE
|
res = ONLINE
|
||||||
@ -163,7 +163,7 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"uuid" => {
|
"uuid" => {
|
||||||
res = base64::encode(crate::get_uuid());
|
res = base64::encode(hbb_common::get_uuid());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("Unknown name of get_by_name: {}", name);
|
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
|
// Server Side
|
||||||
"update_password" => {
|
"update_password" => {
|
||||||
if value.is_empty() {
|
todo!()
|
||||||
Config::set_password(&Config::get_auto_password());
|
|
||||||
} else {
|
|
||||||
Config::set_password(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
"chat_server_mode" => {
|
"chat_server_mode" => {
|
||||||
|
@ -347,7 +347,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) {
|
|||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let mut msg_out = Message::new();
|
let mut msg_out = Message::new();
|
||||||
msg_out.set_audio_frame(AudioFrame {
|
msg_out.set_audio_frame(AudioFrame {
|
||||||
data,
|
data: data.into(),
|
||||||
timestamp: crate::common::get_time(),
|
timestamp: crate::common::get_time(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
@ -646,7 +646,7 @@ pub fn handle_one_frame_encoded(
|
|||||||
})?;
|
})?;
|
||||||
let mut send_conn_ids: HashSet<i32> = Default::default();
|
let mut send_conn_ids: HashSet<i32> = Default::default();
|
||||||
let vp9_frame = EncodedVideoFrame {
|
let vp9_frame = EncodedVideoFrame {
|
||||||
data: frame.to_vec(),
|
data: frame.to_vec().into(),
|
||||||
key: true,
|
key: true,
|
||||||
pts: ms,
|
pts: ms,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user