mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
fix conflicts
This commit is contained in:
115
src/common.rs
115
src/common.rs
@@ -18,7 +18,6 @@ pub use arboard::Clipboard as ClipboardContext;
|
||||
use hbb_common::compress::decompress;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::bail,
|
||||
compress::compress as compress_func,
|
||||
config::{self, Config, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT},
|
||||
get_version_number, log,
|
||||
@@ -52,7 +51,7 @@ lazy_static::lazy_static! {
|
||||
pub fn global_init() -> bool {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if !scrap::is_x11() {
|
||||
if !*IS_X11 {
|
||||
crate::server::wayland::set_wayland_scrap_map_err();
|
||||
}
|
||||
}
|
||||
@@ -293,15 +292,7 @@ async fn test_nat_type_() -> ResultType<bool> {
|
||||
let start = std::time::Instant::now();
|
||||
let (rendezvous_server, _, _) = get_rendezvous_server(1_000).await;
|
||||
let server1 = rendezvous_server;
|
||||
let tmp: Vec<&str> = server1.split(":").collect();
|
||||
if tmp.len() != 2 {
|
||||
bail!("Invalid server address: {}", server1);
|
||||
}
|
||||
let port: u16 = tmp[1].parse()?;
|
||||
if port == 0 {
|
||||
bail!("Invalid server address: {}", server1);
|
||||
}
|
||||
let server2 = format!("{}:{}", tmp[0], port - 1);
|
||||
let server2 = crate::increase_port(&server1, -1);
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
let serial = Config::get_serial();
|
||||
msg_out.set_test_nat_request(TestNatRequest {
|
||||
@@ -310,21 +301,18 @@ async fn test_nat_type_() -> ResultType<bool> {
|
||||
});
|
||||
let mut port1 = 0;
|
||||
let mut port2 = 0;
|
||||
let server1 = socket_client::get_target_addr(&server1)?;
|
||||
let server2 = socket_client::get_target_addr(&server2)?;
|
||||
let mut addr = Config::get_any_listen_addr();
|
||||
for i in 0..2 {
|
||||
let mut socket = socket_client::connect_tcp(
|
||||
if i == 0 {
|
||||
server1.clone()
|
||||
} else {
|
||||
server2.clone()
|
||||
},
|
||||
addr,
|
||||
if i == 0 { &*server1 } else { &*server2 },
|
||||
RENDEZVOUS_TIMEOUT,
|
||||
)
|
||||
.await?;
|
||||
addr = socket.local_addr();
|
||||
if i == 0 {
|
||||
Config::set_option(
|
||||
"local-ip-addr".to_owned(),
|
||||
socket.local_addr().ip().to_string(),
|
||||
);
|
||||
}
|
||||
socket.send(&msg_out).await?;
|
||||
if let Some(Ok(bytes)) = socket.next_timeout(RENDEZVOUS_TIMEOUT).await {
|
||||
if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) {
|
||||
@@ -347,7 +335,6 @@ async fn test_nat_type_() -> ResultType<bool> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Config::set_option("local-ip-addr".to_owned(), addr.ip().to_string());
|
||||
let ok = port1 > 0 && port2 > 0;
|
||||
if ok {
|
||||
let t = if port1 == port2 {
|
||||
@@ -368,13 +355,7 @@ pub async fn get_rendezvous_server(ms_timeout: u64) -> (String, Vec<String>, boo
|
||||
let (mut a, mut b) = get_rendezvous_server_(ms_timeout).await;
|
||||
let mut b: Vec<String> = b
|
||||
.drain(..)
|
||||
.map(|x| {
|
||||
if !x.contains(":") {
|
||||
format!("{}:{}", x, config::RENDEZVOUS_PORT)
|
||||
} else {
|
||||
x
|
||||
}
|
||||
})
|
||||
.map(|x| socket_client::check_port(x, config::RENDEZVOUS_PORT))
|
||||
.collect();
|
||||
let c = if b.contains(&a) {
|
||||
b = b.drain(..).filter(|x| x != &a).collect();
|
||||
@@ -424,7 +405,6 @@ async fn test_rendezvous_server_() {
|
||||
let tm = std::time::Instant::now();
|
||||
if socket_client::connect_tcp(
|
||||
crate::check_port(&host, RENDEZVOUS_PORT),
|
||||
Config::get_any_listen_addr(),
|
||||
RENDEZVOUS_TIMEOUT,
|
||||
)
|
||||
.await
|
||||
@@ -481,11 +461,12 @@ pub fn username() -> String {
|
||||
|
||||
#[inline]
|
||||
pub fn check_port<T: std::string::ToString>(host: T, port: i32) -> String {
|
||||
let host = host.to_string();
|
||||
if !host.contains(":") {
|
||||
return format!("{}:{}", host, port);
|
||||
}
|
||||
return host;
|
||||
hbb_common::socket_client::check_port(host, port)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn increase_port<T: std::string::ToString>(host: T, offset: i32) -> String {
|
||||
hbb_common::socket_client::increase_port(host, offset)
|
||||
}
|
||||
|
||||
pub const POSTFIX_SERVICE: &'static str = "_service";
|
||||
@@ -524,10 +505,9 @@ pub fn check_software_update() {
|
||||
async fn check_software_update_() -> hbb_common::ResultType<()> {
|
||||
sleep(3.).await;
|
||||
|
||||
let rendezvous_server =
|
||||
socket_client::get_target_addr(&format!("rs-sg.rustdesk.com:{}", config::RENDEZVOUS_PORT))?;
|
||||
let mut socket =
|
||||
socket_client::new_udp(Config::get_any_listen_addr(), RENDEZVOUS_TIMEOUT).await?;
|
||||
let rendezvous_server = format!("rs-sg.rustdesk.com:{}", config::RENDEZVOUS_PORT);
|
||||
let (mut socket, rendezvous_server) =
|
||||
socket_client::new_udp_for(&rendezvous_server, RENDEZVOUS_TIMEOUT).await?;
|
||||
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
msg_out.set_software_update(SoftwareUpdate {
|
||||
@@ -567,12 +547,6 @@ pub fn get_full_name() -> String {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn is_ip(id: &str) -> bool {
|
||||
hbb_common::regex::Regex::new(r"^\d+\.\d+\.\d+\.\d+(:\d+)?$")
|
||||
.unwrap()
|
||||
.is_match(id)
|
||||
}
|
||||
|
||||
pub fn is_setup(name: &str) -> bool {
|
||||
name.to_lowercase().ends_with("install.exe")
|
||||
}
|
||||
@@ -603,29 +577,24 @@ pub fn get_api_server(api: String, custom: String) -> String {
|
||||
return lic.api.clone();
|
||||
}
|
||||
}
|
||||
let s = get_custom_rendezvous_server(custom);
|
||||
if !s.is_empty() {
|
||||
if s.contains(':') {
|
||||
let tmp: Vec<&str> = s.split(":").collect();
|
||||
if tmp.len() == 2 {
|
||||
let port: u16 = tmp[1].parse().unwrap_or(0);
|
||||
if port > 2 {
|
||||
return format!("http://{}:{}", tmp[0], port - 2);
|
||||
}
|
||||
}
|
||||
let s0 = get_custom_rendezvous_server(custom);
|
||||
if !s0.is_empty() {
|
||||
let s = crate::increase_port(&s0, -2);
|
||||
if s == s0 {
|
||||
format!("http://{}:{}", s, config::RENDEZVOUS_PORT - 2);
|
||||
} else {
|
||||
return format!("http://{}:{}", s, config::RENDEZVOUS_PORT - 2);
|
||||
format!("http://{}", s);
|
||||
}
|
||||
}
|
||||
"https://admin.rustdesk.com".to_owned()
|
||||
}
|
||||
|
||||
pub fn get_audit_server(api: String, custom: String) -> String {
|
||||
pub fn get_audit_server(api: String, custom: String, typ: String) -> String {
|
||||
let url = get_api_server(api, custom);
|
||||
if url.is_empty() || url.contains("rustdesk.com") {
|
||||
return "".to_owned();
|
||||
}
|
||||
format!("{}/api/audit", url)
|
||||
format!("{}/api/audit/{}", url, typ)
|
||||
}
|
||||
|
||||
pub async fn post_request(url: String, body: String, header: &str) -> ResultType<String> {
|
||||
@@ -669,7 +638,7 @@ pub async fn post_request(url: String, body: String, header: &str) -> ResultType
|
||||
if !res.is_empty() {
|
||||
return Ok(res);
|
||||
}
|
||||
bail!(String::from_utf8_lossy(&output.stderr).to_string());
|
||||
hbb_common::bail!(String::from_utf8_lossy(&output.stderr).to_string());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,11 +676,35 @@ pub fn get_supported_keyboard_modes(version: i64) -> Vec<KeyboardMode> {
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref IS_X11: Mutex<bool> = Mutex::new(false);
|
||||
pub static ref IS_X11: bool = false;
|
||||
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref IS_X11: Mutex<bool> = Mutex::new("x11" == hbb_common::platform::linux::get_display_server());
|
||||
pub static ref IS_X11: bool = "x11" == hbb_common::platform::linux::get_display_server();
|
||||
}
|
||||
|
||||
pub fn make_fd_to_json(id: i32, path: String, entries: &Vec<FileEntry>) -> String {
|
||||
use serde_json::json;
|
||||
let mut fd_json = serde_json::Map::new();
|
||||
fd_json.insert("id".into(), json!(id));
|
||||
fd_json.insert("path".into(), json!(path));
|
||||
|
||||
let mut entries_out = vec![];
|
||||
for entry in entries {
|
||||
let mut entry_map = serde_json::Map::new();
|
||||
entry_map.insert("entry_type".into(), json!(entry.entry_type.value()));
|
||||
entry_map.insert("name".into(), json!(entry.name));
|
||||
entry_map.insert("size".into(), json!(entry.size));
|
||||
entry_map.insert("modified_time".into(), json!(entry.modified_time));
|
||||
entries_out.push(entry_map);
|
||||
}
|
||||
fd_json.insert("entries".into(), json!(entries_out));
|
||||
serde_json::to_string(&fd_json).unwrap_or("".into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_common {
|
||||
use super::*;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user