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();
|
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>) {
|
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,23 @@ 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();
|
id.into()
|
||||||
|
} else {
|
||||||
|
Config::get_key_pair().1
|
||||||
}
|
}
|
||||||
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)]
|
#[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
|
||||||
@ -1212,15 +1212,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 {
|
||||||
|
@ -3,7 +3,7 @@ use crate::mobile::connection_manager::{self, get_clients_length, get_clients_st
|
|||||||
use crate::mobile::{self, Session};
|
use crate::mobile::{self, Session};
|
||||||
use crate::common::{make_fd_to_json};
|
use crate::common::{make_fd_to_json};
|
||||||
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer};
|
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer};
|
||||||
use hbb_common::ResultType;
|
use hbb_common::{ResultType, init_uuid};
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
config::{self, Config, LocalConfig, PeerConfig, ONLINE},
|
config::{self, Config, LocalConfig, PeerConfig, ONLINE},
|
||||||
fs, log,
|
fs, log,
|
||||||
@ -16,7 +16,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn initialize(app_dir: &str) {
|
fn initialize(app_dir: &str) {
|
||||||
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
{
|
{
|
||||||
android_logger::init_once(
|
android_logger::init_once(
|
||||||
@ -30,6 +29,8 @@ fn initialize(app_dir: &str) {
|
|||||||
use hbb_common::env_logger::*;
|
use hbb_common::env_logger::*;
|
||||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "debug"));
|
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_rendezvous_server();
|
||||||
crate::common::test_nat_type();
|
crate::common::test_nat_type();
|
||||||
#[cfg(target_os = "android")]
|
#[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();
|
res = Config::get_id();
|
||||||
}
|
}
|
||||||
"server_password" => {
|
"server_password" => {
|
||||||
res = Config::get_password();
|
todo!()
|
||||||
}
|
}
|
||||||
"connect_statue" => {
|
"connect_statue" => {
|
||||||
res = ONLINE
|
res = ONLINE
|
||||||
@ -163,7 +164,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 +459,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()
|
||||||
});
|
});
|
||||||
|
@ -644,7 +644,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