mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 04:12:20 +08:00
tokio1, windows not test yet
This commit is contained in:
parent
25a83f6b4a
commit
dc3fcda2c9
113
Cargo.lock
generated
113
Cargo.lock
generated
@ -1,5 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.14.1"
|
||||
@ -1459,7 +1461,7 @@ name = "hbb_common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes 0.5.6",
|
||||
"bytes 1.0.1",
|
||||
"confy",
|
||||
"directories-next",
|
||||
"dirs-next",
|
||||
@ -1473,13 +1475,13 @@ dependencies = [
|
||||
"protobuf",
|
||||
"protobuf-codegen-pure",
|
||||
"quinn",
|
||||
"rand 0.7.3",
|
||||
"rand 0.8.3",
|
||||
"serde 1.0.125",
|
||||
"serde_derive",
|
||||
"serde_json 1.0.64",
|
||||
"socket2",
|
||||
"sodiumoxide",
|
||||
"tokio",
|
||||
"tokio 1.7.1",
|
||||
"tokio-util",
|
||||
"toml",
|
||||
"winapi 0.3.9",
|
||||
@ -1902,6 +1904,19 @@ dependencies = [
|
||||
"winapi 0.2.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.7.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"miow 0.3.7",
|
||||
"ntapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio-named-pipes"
|
||||
version = "0.1.7"
|
||||
@ -1909,22 +1924,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656"
|
||||
dependencies = [
|
||||
"log",
|
||||
"mio",
|
||||
"mio 0.6.23",
|
||||
"miow 0.3.7",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio-uds"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
|
||||
dependencies = [
|
||||
"iovec",
|
||||
"libc",
|
||||
"mio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miow"
|
||||
version = "0.2.2"
|
||||
@ -2084,6 +2088,15 @@ dependencies = [
|
||||
"version_check 0.9.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
|
||||
dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.3.3"
|
||||
@ -2276,8 +2289,8 @@ dependencies = [
|
||||
"log",
|
||||
"mio-named-pipes",
|
||||
"miow 0.3.7",
|
||||
"rand 0.7.3",
|
||||
"tokio",
|
||||
"rand 0.8.3",
|
||||
"tokio 1.7.1",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
@ -2551,11 +2564,11 @@ dependencies = [
|
||||
"err-derive 0.2.4",
|
||||
"futures",
|
||||
"libc",
|
||||
"mio",
|
||||
"mio 0.6.23",
|
||||
"quinn-proto",
|
||||
"rustls",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tokio 0.2.25",
|
||||
"tracing",
|
||||
"webpki",
|
||||
]
|
||||
@ -3532,28 +3545,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092"
|
||||
dependencies = [
|
||||
"bytes 0.5.6",
|
||||
"fnv",
|
||||
"futures-core",
|
||||
"iovec",
|
||||
"lazy_static",
|
||||
"mio 0.6.23",
|
||||
"pin-project-lite 0.1.12",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2"
|
||||
dependencies = [
|
||||
"autocfg 1.0.1",
|
||||
"bytes 1.0.1",
|
||||
"libc",
|
||||
"memchr",
|
||||
"mio",
|
||||
"mio-named-pipes",
|
||||
"mio-uds",
|
||||
"mio 0.7.13",
|
||||
"num_cpus",
|
||||
"pin-project-lite 0.1.12",
|
||||
"once_cell",
|
||||
"parking_lot 0.11.1",
|
||||
"pin-project-lite 0.2.6",
|
||||
"signal-hook-registry",
|
||||
"slab",
|
||||
"tokio-macros",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "0.2.6"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a"
|
||||
checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.26",
|
||||
"quote 1.0.9",
|
||||
@ -3562,17 +3584,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.3.1"
|
||||
version = "0.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499"
|
||||
checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592"
|
||||
dependencies = [
|
||||
"bytes 0.5.6",
|
||||
"bytes 1.0.1",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"log",
|
||||
"pin-project-lite 0.1.12",
|
||||
"tokio",
|
||||
"pin-project-lite 0.2.6",
|
||||
"slab",
|
||||
"tokio 1.7.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3956,9 +3979,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "whoami"
|
||||
version = "0.9.0"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7884773ab69074615cb8f8425d0e53f11710786158704fca70f53e71b0e05504"
|
||||
checksum = "4abacf325c958dfeaf1046931d37f2a901b6dfe0968ee965a29e94c6766b2af6"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
@ -4151,18 +4178,18 @@ checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71"
|
||||
|
||||
[[package]]
|
||||
name = "zstd"
|
||||
version = "0.5.4+zstd.1.4.7"
|
||||
version = "0.9.0+zstd.1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69996ebdb1ba8b1517f61387a883857818a66c8a295f487b1ffd8fd9d2c82910"
|
||||
checksum = "07749a5dc2cb6b36661290245e350f15ec3bbb304e493db54a1d354480522ccd"
|
||||
dependencies = [
|
||||
"zstd-safe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-safe"
|
||||
version = "2.0.6+zstd.1.4.7"
|
||||
version = "4.1.1+zstd.1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98aa931fb69ecee256d44589d19754e61851ae4769bf963b385119b1cc37a49e"
|
||||
checksum = "c91c90f2c593b003603e5e0493c837088df4469da25aafff8bce42ba48caf079"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"zstd-sys",
|
||||
@ -4170,12 +4197,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zstd-sys"
|
||||
version = "1.4.18+zstd.1.4.7"
|
||||
version = "1.6.1+zstd.1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1e6e8778706838f43f771d80d37787cb2fe06dafe89dd3aebaf6721b9eaec81"
|
||||
checksum = "615120c7a2431d16cf1cf979e7fc31ba7a5b5e5707b29c8a99e5dbf8a8392a33"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"glob",
|
||||
"itertools",
|
||||
"libc",
|
||||
]
|
||||
|
@ -16,7 +16,7 @@ cli = []
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
whoami = "0.9"
|
||||
whoami = "1.1"
|
||||
scrap = { path = "libs/scrap" }
|
||||
hbb_common = { path = "libs/hbb_common" }
|
||||
enigo = { path = "libs/enigo" }
|
||||
|
@ -8,19 +8,19 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
protobuf = { version = "3.0.0-pre", git = "https://github.com/stepancheg/rust-protobuf" }
|
||||
tokio = { version = "0.2", features = ["full"] }
|
||||
tokio-util = { version = "0.3", features = ["full"] }
|
||||
tokio = { version = "1.7", features = ["full"] }
|
||||
tokio-util = { version = "0.6", features = ["full"] }
|
||||
futures = "0.3"
|
||||
bytes = "0.5"
|
||||
bytes = "1.0"
|
||||
log = "0.4"
|
||||
env_logger = "0.8"
|
||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||
zstd = "0.5"
|
||||
zstd = "0.9"
|
||||
quinn = {version = "0.6", optional = true }
|
||||
anyhow = "1.0"
|
||||
futures-util = "0.3"
|
||||
directories-next = "2.0"
|
||||
rand = "0.7"
|
||||
rand = "0.8"
|
||||
serde_derive = "1.0"
|
||||
serde = "1.0"
|
||||
lazy_static = "1.4"
|
||||
|
@ -548,7 +548,7 @@ impl Config {
|
||||
// to-do: how about if one ip register a lot of ids?
|
||||
let id = Self::get_id();
|
||||
let mut rng = rand::thread_rng();
|
||||
let new_id = rng.gen_range(1_000_000_000, 2_000_000_000).to_string();
|
||||
let new_id = rng.gen_range(1_000_000_000..2_000_000_000).to_string();
|
||||
Config::set_id(&new_id);
|
||||
log::info!("id updated from {} to {}", id, new_id);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::prelude::*;
|
||||
use tokio::{fs::File, prelude::*};
|
||||
use tokio::{fs::File, io::*};
|
||||
|
||||
pub fn read_dir(path: &PathBuf, include_hidden: bool) -> ResultType<FileDirectory> {
|
||||
let mut dir = FileDirectory {
|
||||
|
@ -6,7 +6,6 @@ pub mod rendezvous_proto;
|
||||
pub use bytes;
|
||||
pub use futures;
|
||||
pub use protobuf;
|
||||
use socket2::{Domain, Socket, Type};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, BufRead},
|
||||
@ -36,7 +35,7 @@ pub type Stream = tcp::FramedStream;
|
||||
|
||||
#[inline]
|
||||
pub async fn sleep(sec: f32) {
|
||||
tokio::time::delay_for(time::Duration::from_secs_f32(sec)).await;
|
||||
tokio::time::sleep(time::Duration::from_secs_f32(sec)).await;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@ -61,30 +60,6 @@ pub fn timeout<T: std::future::Future>(ms: u64, future: T) -> tokio::time::Timeo
|
||||
tokio::time::timeout(std::time::Duration::from_millis(ms), future)
|
||||
}
|
||||
|
||||
fn new_socket(addr: SocketAddr, tcp: bool, reuse: bool) -> Result<Socket, std::io::Error> {
|
||||
let stype = {
|
||||
if tcp {
|
||||
Type::stream()
|
||||
} else {
|
||||
Type::dgram()
|
||||
}
|
||||
};
|
||||
let socket = match addr {
|
||||
SocketAddr::V4(..) => Socket::new(Domain::ipv4(), stype, None),
|
||||
SocketAddr::V6(..) => Socket::new(Domain::ipv6(), stype, None),
|
||||
}?;
|
||||
if reuse {
|
||||
// windows has no reuse_port, but it's reuse_address
|
||||
// almost equals to unix's reuse_port + reuse_address,
|
||||
// though may introduce nondeterministic bahavior
|
||||
#[cfg(unix)]
|
||||
socket.set_reuse_port(true)?;
|
||||
socket.set_reuse_address(true)?;
|
||||
}
|
||||
socket.bind(&addr.into())?;
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
pub type ResultType<F, E = anyhow::Error> = anyhow::Result<F, E>;
|
||||
|
||||
/// Certain router and firewalls scan the packet and if they
|
||||
@ -100,10 +75,10 @@ impl AddrMangle {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_micros() as u32) as u128;
|
||||
let ip = u32::from_ne_bytes(addr_v4.ip().octets()) as u128;
|
||||
let ip = u32::from_le_bytes(addr_v4.ip().octets()) as u128;
|
||||
let port = addr.port() as u128;
|
||||
let v = ((ip + tm) << 49) | (tm << 17) | (port + (tm & 0xFFFF));
|
||||
let bytes = v.to_ne_bytes();
|
||||
let bytes = v.to_le_bytes();
|
||||
let mut n_padding = 0;
|
||||
for i in bytes.iter().rev() {
|
||||
if i == &0u8 {
|
||||
@ -123,9 +98,9 @@ impl AddrMangle {
|
||||
pub fn decode(bytes: &[u8]) -> SocketAddr {
|
||||
let mut padded = [0u8; 16];
|
||||
padded[..bytes.len()].copy_from_slice(&bytes);
|
||||
let number = u128::from_ne_bytes(padded);
|
||||
let number = u128::from_le_bytes(padded);
|
||||
let tm = (number >> 17) & (u32::max_value() as u128);
|
||||
let ip = (((number >> 49) - tm) as u32).to_ne_bytes();
|
||||
let ip = (((number >> 49) - tm) as u32).to_le_bytes();
|
||||
let port = (number & 0xFFFFFF) - (tm & 0xFFFF);
|
||||
SocketAddr::V4(SocketAddrV4::new(
|
||||
Ipv4Addr::new(ip[0], ip[1], ip[2], ip[3]),
|
||||
|
@ -1,16 +1,13 @@
|
||||
use crate::{bail, bytes_codec::BytesCodec, ResultType};
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use futures::SinkExt;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use protobuf::Message;
|
||||
use sodiumoxide::crypto::secretbox::{self, Key, Nonce};
|
||||
use std::{
|
||||
io::{Error, ErrorKind},
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
use tokio::{
|
||||
net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||
stream::StreamExt,
|
||||
};
|
||||
use tokio::net::{lookup_host, TcpListener, TcpSocket, TcpStream, ToSocketAddrs};
|
||||
use tokio_util::codec::Framed;
|
||||
|
||||
pub struct FramedStream(Framed<TcpStream, BytesCodec>, Option<(Key, u64, u64)>);
|
||||
@ -29,25 +26,37 @@ impl DerefMut for FramedStream {
|
||||
}
|
||||
}
|
||||
|
||||
fn new_socket(addr: std::net::SocketAddr, reuse: bool) -> Result<TcpSocket, std::io::Error> {
|
||||
let socket = match addr {
|
||||
std::net::SocketAddr::V4(..) => TcpSocket::new_v4()?,
|
||||
std::net::SocketAddr::V6(..) => TcpSocket::new_v6()?,
|
||||
};
|
||||
if reuse {
|
||||
// windows has no reuse_port, but it's reuse_address
|
||||
// almost equals to unix's reuse_port + reuse_address,
|
||||
// though may introduce nondeterministic bahavior
|
||||
#[cfg(unix)]
|
||||
socket.set_reuseport(true)?;
|
||||
socket.set_reuseaddr(true)?;
|
||||
}
|
||||
socket.bind(addr)?;
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
impl FramedStream {
|
||||
pub async fn new<T: ToSocketAddrs, T2: ToSocketAddrs>(
|
||||
remote_addr: T,
|
||||
local_addr: T2,
|
||||
ms_timeout: u64,
|
||||
) -> ResultType<Self> {
|
||||
for local_addr in local_addr.to_socket_addrs().await? {
|
||||
for remote_addr in remote_addr.to_socket_addrs().await? {
|
||||
if let Ok(stream) = super::timeout(
|
||||
for local_addr in lookup_host(&local_addr).await? {
|
||||
for remote_addr in lookup_host(&remote_addr).await? {
|
||||
let stream = super::timeout(
|
||||
ms_timeout,
|
||||
TcpStream::connect_std(
|
||||
super::new_socket(local_addr, true, true)?.into_tcp_stream(),
|
||||
&remote_addr,
|
||||
),
|
||||
new_socket(local_addr, true)?.connect(remote_addr),
|
||||
)
|
||||
.await?
|
||||
{
|
||||
return Ok(Self(Framed::new(stream, BytesCodec::new()), None));
|
||||
}
|
||||
.await??;
|
||||
return Ok(Self(Framed::new(stream, BytesCodec::new()), None));
|
||||
}
|
||||
}
|
||||
bail!("could not resolve to any address");
|
||||
@ -124,22 +133,21 @@ impl FramedStream {
|
||||
|
||||
fn get_nonce(seqnum: u64) -> Nonce {
|
||||
let mut nonce = Nonce([0u8; secretbox::NONCEBYTES]);
|
||||
nonce.0[..std::mem::size_of_val(&seqnum)].copy_from_slice(&seqnum.to_ne_bytes());
|
||||
nonce.0[..std::mem::size_of_val(&seqnum)].copy_from_slice(&seqnum.to_le_bytes());
|
||||
nonce
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_BACKLOG: i32 = 128;
|
||||
const DEFAULT_BACKLOG: u32 = 128;
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
pub async fn new_listener<T: ToSocketAddrs>(addr: T, reuse: bool) -> ResultType<TcpListener> {
|
||||
if !reuse {
|
||||
Ok(TcpListener::bind(addr).await?)
|
||||
} else {
|
||||
for addr in addr.to_socket_addrs().await? {
|
||||
let socket = super::new_socket(addr, true, true)?;
|
||||
socket.listen(DEFAULT_BACKLOG)?;
|
||||
return Ok(TcpListener::from_std(socket.into_tcp_listener())?);
|
||||
for addr in lookup_host(&addr).await? {
|
||||
let socket = new_socket(addr, true)?;
|
||||
return Ok(socket.listen(DEFAULT_BACKLOG)?);
|
||||
}
|
||||
bail!("could not resolve to any address");
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
use crate::{bail, ResultType};
|
||||
use bytes::BytesMut;
|
||||
use futures::SinkExt;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use protobuf::Message;
|
||||
use socket2::{Domain, Socket, Type};
|
||||
use std::{
|
||||
io::Error,
|
||||
net::SocketAddr,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
use tokio::{net::ToSocketAddrs, net::UdpSocket, stream::StreamExt};
|
||||
use tokio::{net::ToSocketAddrs, net::UdpSocket};
|
||||
use tokio_util::{codec::BytesCodec, udp::UdpFramed};
|
||||
|
||||
pub struct FramedSocket(UdpFramed<BytesCodec>);
|
||||
@ -20,6 +21,23 @@ impl Deref for FramedSocket {
|
||||
}
|
||||
}
|
||||
|
||||
fn new_socket(addr: SocketAddr, reuse: bool) -> Result<Socket, std::io::Error> {
|
||||
let socket = match addr {
|
||||
SocketAddr::V4(..) => Socket::new(Domain::ipv4(), Type::dgram(), None),
|
||||
SocketAddr::V6(..) => Socket::new(Domain::ipv6(), Type::dgram(), None),
|
||||
}?;
|
||||
if reuse {
|
||||
// windows has no reuse_port, but it's reuse_address
|
||||
// almost equals to unix's reuse_port + reuse_address,
|
||||
// though may introduce nondeterministic bahavior
|
||||
#[cfg(unix)]
|
||||
socket.set_reuse_port(true)?;
|
||||
socket.set_reuse_address(true)?;
|
||||
}
|
||||
socket.bind(&addr.into())?;
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
impl DerefMut for FramedSocket {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
@ -33,10 +51,10 @@ impl FramedSocket {
|
||||
}
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
pub async fn new_reuse<T: ToSocketAddrs>(addr: T) -> ResultType<Self> {
|
||||
for addr in addr.to_socket_addrs().await? {
|
||||
pub async fn new_reuse<T: std::net::ToSocketAddrs>(addr: T) -> ResultType<Self> {
|
||||
for addr in addr.to_socket_addrs()? {
|
||||
return Ok(Self(UdpFramed::new(
|
||||
UdpSocket::from_std(super::new_socket(addr, false, true)?.into_udp_socket())?,
|
||||
UdpSocket::from_std(new_socket(addr, true)?.into_udp_socket())?,
|
||||
BytesCodec::new(),
|
||||
)));
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ futures = "0.3"
|
||||
log = "0.4"
|
||||
mio-named-pipes = "0.1"
|
||||
miow = "0.3"
|
||||
rand = "0.7"
|
||||
tokio = { version = "0.2", features = ["io-driver", "io-util", "uds", "stream", "rt-core", "macros", "time"] }
|
||||
rand = "0.8"
|
||||
tokio = { version = "1.7", features = ["full"] }
|
||||
libc = "0.2"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
@ -1,12 +1,11 @@
|
||||
use libc::chmod;
|
||||
use std::ffi::CString;
|
||||
use std::io::{self, Error};
|
||||
use tokio::prelude::*;
|
||||
use tokio::io::*;
|
||||
use tokio::net::{UnixListener, UnixStream};
|
||||
use std::path::Path;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
/// Socket permissions and ownership on UNIX
|
||||
pub struct SecurityAttributes {
|
||||
@ -127,15 +126,11 @@ impl Connection {
|
||||
}
|
||||
|
||||
impl AsyncRead for Connection {
|
||||
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
|
||||
self.inner.prepare_uninitialized_buffer(buf)
|
||||
}
|
||||
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
ctx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> Poll<io::Result<()>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_read(ctx, buf)
|
||||
}
|
||||
@ -146,17 +141,17 @@ impl AsyncWrite for Connection {
|
||||
self: Pin<&mut Self>,
|
||||
ctx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize, io::Error>> {
|
||||
) -> Poll<Result<usize>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_write(ctx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
||||
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_flush(ctx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
||||
fn poll_shutdown(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_shutdown(ctx)
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ use tokio::prelude::*;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use std::path::Path;
|
||||
use std::mem::MaybeUninit;
|
||||
use tokio::io::PollEvented;
|
||||
|
||||
type NamedPipe = PollEvented<mio_named_pipes::NamedPipe>;
|
||||
@ -178,15 +177,11 @@ impl Connection {
|
||||
}
|
||||
|
||||
impl AsyncRead for Connection {
|
||||
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
|
||||
self.inner.prepare_uninitialized_buffer(buf)
|
||||
}
|
||||
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
ctx: &mut Context<'_>,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> Poll<io::Result<()>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_read(ctx, buf)
|
||||
}
|
||||
@ -197,17 +192,17 @@ impl AsyncWrite for Connection {
|
||||
self: Pin<&mut Self>,
|
||||
ctx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize, io::Error>> {
|
||||
) -> Poll<Result<usize>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_write(ctx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
||||
fn poll_flush(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_flush(ctx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
||||
fn poll_shutdown(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
let this = Pin::into_inner(self);
|
||||
Pin::new(&mut this.inner).poll_shutdown(ctx)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ windowless = []
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2"
|
||||
lazy_static = "1.0"
|
||||
lazy_static = "1.4"
|
||||
|
||||
[target.x86_64-apple-darwin.dependencies]
|
||||
objc = "0.2"
|
||||
|
@ -78,7 +78,7 @@ impl Interface for Session {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn start_one_port_forward(id: String, port: i32, remote_host: String, remote_port: i32) {
|
||||
crate::common::test_rendezvous_server();
|
||||
crate::common::test_nat_type();
|
||||
|
@ -156,7 +156,7 @@ pub fn test_nat_type() {
|
||||
});
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn test_nat_type_() -> ResultType<bool> {
|
||||
log::info!("Testing nat ...");
|
||||
let start = std::time::Instant::now();
|
||||
@ -237,7 +237,7 @@ pub async fn get_nat_type(ms_timeout: u64) -> i32 {
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn test_rendezvous_server_() {
|
||||
let servers = Config::get_rendezvous_servers();
|
||||
hbb_common::config::ONLINE.lock().unwrap().clear();
|
||||
@ -345,7 +345,7 @@ pub fn check_software_update() {
|
||||
std::thread::spawn(move || allow_err!(_check_software_update()));
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn _check_software_update() -> hbb_common::ResultType<()> {
|
||||
sleep(3.).await;
|
||||
let rendezvous_server = get_rendezvous_server(1_000).await;
|
||||
|
10
src/ipc.rs
10
src/ipc.rs
@ -91,7 +91,7 @@ pub enum Data {
|
||||
Test,
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn start(postfix: &str) -> ResultType<()> {
|
||||
let mut incoming = new_listener(postfix).await?;
|
||||
loop {
|
||||
@ -336,7 +336,7 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn get_config(name: &str) -> ResultType<Option<String>> {
|
||||
get_config_async(name, 1_000).await
|
||||
}
|
||||
@ -352,7 +352,7 @@ async fn get_config_async(name: &str, ms_timeout: u64) -> ResultType<Option<Stri
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn set_config(name: &str, value: String) -> ResultType<()> {
|
||||
let mut c = connect(1000, "").await?;
|
||||
c.send_config(name, value).await?;
|
||||
@ -409,7 +409,7 @@ async fn get_options_(ms_timeout: u64) -> ResultType<HashMap<String, String>> {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn get_options() -> HashMap<String, String> {
|
||||
get_options_(1000).await.unwrap_or(Config::get_options())
|
||||
}
|
||||
@ -432,7 +432,7 @@ pub fn set_option(key: &str, value: &str) {
|
||||
set_options(options).ok();
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn set_options(value: HashMap<String, String>) -> ResultType<()> {
|
||||
Config::set_options(value.clone());
|
||||
connect(1000, "")
|
||||
|
@ -386,7 +386,7 @@ extern "C" {
|
||||
fn BlockInput(v: BOOL) -> BOOL;
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn run_service(_arguments: Vec<OsString>) -> ResultType<()> {
|
||||
let event_handler = move |control_event| -> ServiceControlHandlerResult {
|
||||
log::info!("Got service control event: {:?}", control_event);
|
||||
@ -546,7 +546,7 @@ pub fn run_as_user(arg: &str) -> ResultType<Option<std::process::Child>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn send_close(postfix: &str) -> ResultType<()> {
|
||||
send_close_async(postfix).await
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ use crate::client::*;
|
||||
use hbb_common::{
|
||||
allow_err, bail,
|
||||
config::CONNECT_TIMEOUT,
|
||||
futures::SinkExt,
|
||||
futures::{SinkExt, StreamExt},
|
||||
log,
|
||||
message_proto::*,
|
||||
protobuf::Message as _,
|
||||
tcp, timeout,
|
||||
tokio::{self, net::TcpStream, stream::StreamExt, sync::mpsc},
|
||||
tokio::{self, net::TcpStream, sync::mpsc},
|
||||
tokio_util::codec::{BytesCodec, Framed},
|
||||
ResultType, Stream,
|
||||
};
|
||||
|
@ -34,7 +34,7 @@ pub fn new() -> GenericService {
|
||||
#[cfg(target_os = "linux")]
|
||||
mod pa_impl {
|
||||
use super::*;
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn run(sp: GenericService) -> ResultType<()> {
|
||||
if let Ok(mut stream) = crate::ipc::connect(1000, "_pa").await {
|
||||
let mut encoder =
|
||||
|
@ -5,11 +5,10 @@ use crate::ipc;
|
||||
use hbb_common::{
|
||||
config::Config,
|
||||
fs,
|
||||
futures::SinkExt,
|
||||
futures::{SinkExt, StreamExt},
|
||||
sleep, timeout,
|
||||
tokio::{
|
||||
net::TcpStream,
|
||||
stream::StreamExt,
|
||||
sync::mpsc,
|
||||
time::{self, Duration, Instant, Interval},
|
||||
},
|
||||
|
@ -518,7 +518,7 @@ fn handle_key_(evt: &KeyEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn send_sas() -> ResultType<()> {
|
||||
let mut stream = crate::ipc::connect(1000, crate::POSTFIX_SERVICE).await?;
|
||||
timeout(1000, stream.send(&crate::ipc::Data::SAS)).await??;
|
||||
|
@ -595,7 +595,7 @@ pub fn check_zombie(childs: Childs) {
|
||||
|
||||
// notice: avoiding create ipc connecton repeatly,
|
||||
// because windows named pipe has serious memory leak issue.
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn check_connect_status_(
|
||||
reconnect: bool,
|
||||
status: Arc<Mutex<(i32, bool)>>,
|
||||
|
@ -330,7 +330,7 @@ impl sciter::EventHandler for ConnectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn start_ipc(cm: ConnectionManager) {
|
||||
match new_listener("_cm").await {
|
||||
Ok(mut incoming) => {
|
||||
@ -387,7 +387,7 @@ async fn start_ipc(cm: ConnectionManager) {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn start_pa() {
|
||||
use hbb_common::config::APP_NAME;
|
||||
use libpulse_binding as pulse;
|
||||
|
@ -1019,7 +1019,7 @@ async fn start_one_port_forward(
|
||||
log::info!("port forward (:{}) exit", port);
|
||||
}
|
||||
|
||||
#[tokio::main(basic_scheduler)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn io_loop(handler: Handler) {
|
||||
let (sender, mut receiver) = mpsc::unbounded_channel::<Data>();
|
||||
handler.write().unwrap().sender = Some(sender.clone());
|
||||
|
Loading…
Reference in New Issue
Block a user