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