fix: android build & CONFIG deadlock

This commit is contained in:
csf 2022-07-28 22:06:59 +08:00
parent 6bbfe13028
commit da2906c95f
7 changed files with 36 additions and 18 deletions

View File

@ -584,6 +584,17 @@ impl Config {
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>) {
// lock here to make sure no gen_keypair more than once
let mut config = CONFIG.write().unwrap();

View File

@ -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,12 +206,16 @@ 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();
}
Config::get_key_pair().1
Config::get_sk_uuid()
}
pub fn get_uuid() -> Vec<u8> {
UUID.to_owned()
}
#[cfg(test)]

View File

@ -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,

View File

@ -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 {

View File

@ -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" => {

View File

@ -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()
});

View File

@ -646,7 +646,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()