aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorrustdesk <[email protected]>2022-07-13 00:22:45 +0800
committerrustdesk <[email protected]>2022-07-13 00:22:45 +0800
commit39153ce1472417be101051baecb452da467f2652 (patch)
tree7ef2ed6d8d28a80fa3a7333460d7211a48b6e4a2 /libs
parent57cbac7079a6132388d81d3d76a39e6cd700baab (diff)
downloadrustdesk-server-39153ce1472417be101051baecb452da467f2652.tar.gz
rustdesk-server-39153ce1472417be101051baecb452da467f2652.zip
fix slow connection, '/' in pub key, and hbbr wait for key, and possible1.1.6
solution for https://github.com/rustdesk/rustdesk-server/issues/24
Diffstat (limited to 'libs')
-rw-r--r--libs/hbb_common/protos/message.proto6
-rw-r--r--libs/hbb_common/src/config.rs14
-rw-r--r--libs/hbb_common/src/fs.rs8
-rw-r--r--libs/hbb_common/src/lib.rs1
-rw-r--r--libs/hbb_common/src/socket_client.rs8
-rw-r--r--libs/hbb_common/src/udp.rs6
6 files changed, 35 insertions, 8 deletions
diff --git a/libs/hbb_common/protos/message.proto b/libs/hbb_common/protos/message.proto
index f95007d..15ee971 100644
--- a/libs/hbb_common/protos/message.proto
+++ b/libs/hbb_common/protos/message.proto
@@ -23,6 +23,7 @@ message VideoFrame {
RGB rgb = 7;
YUV yuv = 8;
}
+ int64 timestamp = 9;
}
message IdPk {
@@ -441,7 +442,10 @@ message AudioFormat {
uint32 channels = 2;
}
-message AudioFrame { bytes data = 1; }
+message AudioFrame {
+ bytes data = 1;
+ int64 timestamp = 2;
+}
message Misc {
oneof union {
diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs
index a7c1bc6..ea7dd6d 100644
--- a/libs/hbb_common/src/config.rs
+++ b/libs/hbb_common/src/config.rs
@@ -261,7 +261,7 @@ impl Config {
fn file_(suffix: &str) -> PathBuf {
let name = format!("{}{}", *APP_NAME.read().unwrap(), suffix);
- Self::path(name).with_extension("toml")
+ Config::with_extension(Self::path(name))
}
pub fn get_home() -> PathBuf {
@@ -677,6 +677,16 @@ impl Config {
lock.store();
true
}
+
+ fn with_extension(path: PathBuf) -> PathBuf {
+ let ext = path.extension();
+ if let Some(ext) = ext {
+ let ext = format!("{}.toml", ext.to_string_lossy());
+ path.with_extension(&ext)
+ } else {
+ path.with_extension("toml")
+ }
+ }
}
const PEERS: &str = "peers";
@@ -706,7 +716,7 @@ impl PeerConfig {
fn path(id: &str) -> PathBuf {
let path: PathBuf = [PEERS, id].iter().collect();
- Config::path(path).with_extension("toml")
+ Config::with_extension(Config::path(path))
}
pub fn peers() -> Vec<(String, SystemTime, PeerConfig)> {
diff --git a/libs/hbb_common/src/fs.rs b/libs/hbb_common/src/fs.rs
index 475f4df..69cd348 100644
--- a/libs/hbb_common/src/fs.rs
+++ b/libs/hbb_common/src/fs.rs
@@ -558,3 +558,11 @@ pub fn create_dir(dir: &str) -> ResultType<()> {
std::fs::create_dir_all(get_path(dir))?;
Ok(())
}
+
+#[inline]
+pub fn transform_windows_path(entries: &mut Vec<FileEntry>) {
+ for entry in entries {
+ entry.name = entry.name.replace("\\", "/");
+ }
+}
+
diff --git a/libs/hbb_common/src/lib.rs b/libs/hbb_common/src/lib.rs
index 0a9dace..5f23e46 100644
--- a/libs/hbb_common/src/lib.rs
+++ b/libs/hbb_common/src/lib.rs
@@ -35,7 +35,6 @@ pub use sodiumoxide;
pub use tokio_socks;
pub use tokio_socks::IntoTargetAddr;
pub use tokio_socks::TargetAddr;
-pub use lazy_static;
#[cfg(feature = "quic")]
pub type Stream = quic::Connection;
diff --git a/libs/hbb_common/src/socket_client.rs b/libs/hbb_common/src/socket_client.rs
index 0375b71..72ab73f 100644
--- a/libs/hbb_common/src/socket_client.rs
+++ b/libs/hbb_common/src/socket_client.rs
@@ -11,7 +11,10 @@ use tokio_socks::{IntoTargetAddr, TargetAddr};
fn to_socket_addr(host: &str) -> ResultType<SocketAddr> {
use std::net::ToSocketAddrs;
- host.to_socket_addrs()?.next().context("Failed to solve")
+ host.to_socket_addrs()?
+ .filter(|x| x.is_ipv4())
+ .next()
+ .context("Failed to solve")
}
pub fn get_target_addr(host: &str) -> ResultType<TargetAddr<'static>> {
@@ -60,8 +63,9 @@ pub async fn connect_tcp<'t, T: IntoTargetAddr<'t>>(
.await
} else {
let addr = std::net::ToSocketAddrs::to_socket_addrs(&target_addr)?
+ .filter(|x| x.is_ipv4())
.next()
- .context("Invalid target addr")?;
+ .context("Invalid target addr, no valid ipv4 address can be resolved.")?;
Ok(FramedStream::new(addr, local, ms_timeout).await?)
}
}
diff --git a/libs/hbb_common/src/udp.rs b/libs/hbb_common/src/udp.rs
index 0338618..3532dd1 100644
--- a/libs/hbb_common/src/udp.rs
+++ b/libs/hbb_common/src/udp.rs
@@ -27,6 +27,8 @@ fn new_socket(addr: SocketAddr, reuse: bool, buf_size: usize) -> Result<Socket,
socket.set_reuse_port(true)?;
socket.set_reuse_address(true)?;
}
+ // only nonblocking work with tokio, https://stackoverflow.com/questions/64649405/receiver-on-tokiompscchannel-only-receives-messages-when-buffer-is-full
+ socket.set_nonblocking(true)?;
if buf_size > 0 {
socket.set_recv_buffer_size(buf_size).ok();
}
@@ -47,7 +49,7 @@ impl FramedSocket {
#[allow(clippy::never_loop)]
pub async fn new_reuse<T: std::net::ToSocketAddrs>(addr: T) -> ResultType<Self> {
- for addr in addr.to_socket_addrs()? {
+ for addr in addr.to_socket_addrs()?.filter(|x| x.is_ipv4()) {
let socket = new_socket(addr, true, 0)?.into_udp_socket();
return Ok(Self::Direct(UdpFramed::new(
UdpSocket::from_std(socket)?,
@@ -61,7 +63,7 @@ impl FramedSocket {
addr: T,
buf_size: usize,
) -> ResultType<Self> {
- for addr in addr.to_socket_addrs()? {
+ for addr in addr.to_socket_addrs()?.filter(|x| x.is_ipv4()) {
return Ok(Self::Direct(UdpFramed::new(
UdpSocket::from_std(new_socket(addr, false, buf_size)?.into_udp_socket())?,
BytesCodec::new(),