mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2024-11-24 04:12:34 +08:00
refactor and add failure and register response
This commit is contained in:
parent
8b498cb9a7
commit
a21a47a2a6
55
Cargo.lock
generated
55
Cargo.lock
generated
@ -33,6 +33,14 @@ name = "bytes"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"jobserver 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
@ -151,6 +159,11 @@ dependencies = [
|
||||
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hbb_common"
|
||||
version = "0.1.0"
|
||||
@ -164,6 +177,7 @@ dependencies = [
|
||||
"socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zstd 0.5.1+zstd.1.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -197,6 +211,14 @@ dependencies = [
|
||||
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
@ -545,12 +567,40 @@ dependencies = [
|
||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd"
|
||||
version = "0.5.1+zstd.1.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"zstd-safe 2.0.3+zstd.1.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-safe"
|
||||
version = "2.0.3+zstd.1.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zstd-sys 1.4.15+zstd.1.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-sys"
|
||||
version = "1.4.15+zstd.1.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
|
||||
"checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff"
|
||||
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
"checksum bytes 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
|
||||
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||
@ -565,9 +615,11 @@ dependencies = [
|
||||
"checksum futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6"
|
||||
"checksum futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
|
||||
"checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5"
|
||||
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
"checksum hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8"
|
||||
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
||||
"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
|
||||
"checksum jobserver 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
"checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
|
||||
@ -610,3 +662,6 @@ dependencies = [
|
||||
"checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
|
||||
"checksum zstd 0.5.1+zstd.1.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c5d978b793ae64375b80baf652919b148f6a496ac8802922d9999f5a553194f"
|
||||
"checksum zstd-safe 2.0.3+zstd.1.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bee25eac9753cfedd48133fa1736cbd23b774e253d89badbeac7d12b23848d3f"
|
||||
"checksum zstd-sys 1.4.15+zstd.1.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "89719b034dc22d240d5b407fb0a3fe6d29952c181cff9a9f95c0bd40b4f8f7d8"
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 4ecfa0eaf40080ec2e7e75abfab33791a625deb5
|
||||
Subproject commit 9a2d8c3925eb69c76aba9f798fdc84a40aa68e86
|
@ -45,10 +45,12 @@ impl RendezvousServer {
|
||||
match msg_in.union {
|
||||
Some(RendezvousMessage_oneof_union::register_peer(rp)) => {
|
||||
// B registered
|
||||
if rp.hbb_addr.len() > 0 {
|
||||
log::debug!("New peer registered: {:?} {:?}", &rp.hbb_addr, &addr);
|
||||
self.peer_map
|
||||
.insert(rp.hbb_addr, Peer { socket_addr: addr });
|
||||
if rp.id.len() > 0 {
|
||||
log::debug!("New peer registered: {:?} {:?}", &rp.id, &addr);
|
||||
self.peer_map.insert(rp.id, Peer { socket_addr: addr });
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
msg_out.set_register_peer_response(RegisterPeerResponse::default());
|
||||
socket.send(&msg_out, addr).await?
|
||||
}
|
||||
}
|
||||
Some(RendezvousMessage_oneof_union::punch_hole_request(ph)) => {
|
||||
@ -57,7 +59,7 @@ impl RendezvousServer {
|
||||
// fetch local addrs if in same intranet.
|
||||
// because punch hole won't work if in the same intranet,
|
||||
// all routers will drop such self-connections.
|
||||
if let Some(peer) = self.peer_map.get(&ph.hbb_addr) {
|
||||
if let Some(peer) = self.peer_map.get(&ph.id) {
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
let same_intranet = match peer.socket_addr {
|
||||
SocketAddr::V4(a) => match addr {
|
||||
@ -72,19 +74,19 @@ impl RendezvousServer {
|
||||
let socket_addr = AddrMangle::encode(&addr);
|
||||
if same_intranet {
|
||||
log::debug!(
|
||||
"Fetch local addrs {:?} {:?} request from {:?}",
|
||||
&ph.hbb_addr,
|
||||
"Fetch local addr {:?} {:?} request from {:?}",
|
||||
&ph.id,
|
||||
&peer.socket_addr,
|
||||
&addr
|
||||
);
|
||||
msg_out.set_fetch_local_addrs(FetchLocalAddrs {
|
||||
msg_out.set_fetch_local_addr(FetchLocalAddr {
|
||||
socket_addr,
|
||||
..Default::default()
|
||||
});
|
||||
} else {
|
||||
log::debug!(
|
||||
"Punch hole {:?} {:?} request from {:?}",
|
||||
&ph.hbb_addr,
|
||||
&ph.id,
|
||||
&peer.socket_addr,
|
||||
&addr
|
||||
);
|
||||
@ -94,6 +96,13 @@ impl RendezvousServer {
|
||||
});
|
||||
}
|
||||
socket.send(&msg_out, peer.socket_addr).await?;
|
||||
} else {
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
msg_out.set_punch_hole_response(PunchHoleResponse {
|
||||
failure: PunchHoleResponse_Failure::ID_NOT_EXIST,
|
||||
..Default::default()
|
||||
});
|
||||
socket.send(&msg_out, addr).await?
|
||||
}
|
||||
}
|
||||
Some(RendezvousMessage_oneof_union::punch_hole_sent(phs)) => {
|
||||
@ -107,13 +116,13 @@ impl RendezvousServer {
|
||||
});
|
||||
socket.send(&msg_out, addr_a).await?;
|
||||
}
|
||||
Some(RendezvousMessage_oneof_union::local_addrs(la)) => {
|
||||
Some(RendezvousMessage_oneof_union::local_addr(la)) => {
|
||||
// forward local addrs of B to A
|
||||
let addr_a = AddrMangle::decode(&la.socket_addr);
|
||||
log::debug!("Local addrs response to {:?} from {:?}", &addr_a, &addr);
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
msg_out.set_local_addrs_response(LocalAddrsResponse {
|
||||
socket_addrs: la.local_addrs,
|
||||
msg_out.set_punch_hole_response(PunchHoleResponse {
|
||||
socket_addr: la.local_addr,
|
||||
..Default::default()
|
||||
});
|
||||
socket.send(&msg_out, addr_a).await?;
|
||||
@ -128,7 +137,7 @@ impl RendezvousServer {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use hbb_common::{new_error, tokio};
|
||||
use hbb_common::{tokio};
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
#[tokio::main]
|
||||
@ -152,7 +161,7 @@ mod tests {
|
||||
let local_addr_b = socket_b.get_ref().local_addr().unwrap();
|
||||
let mut msg_out = RendezvousMessage::new();
|
||||
msg_out.set_register_peer(RegisterPeer {
|
||||
hbb_addr: "123".to_string(),
|
||||
id: "123".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
socket_b.send(&msg_out, addr_server).await?;
|
||||
@ -161,7 +170,7 @@ mod tests {
|
||||
let mut socket_a = FramedSocket::new("127.0.0.1:0").await?;
|
||||
let local_addr_a = socket_a.get_ref().local_addr().unwrap();
|
||||
msg_out.set_punch_hole_request(PunchHoleRequest {
|
||||
hbb_addr: "123".to_string(),
|
||||
id: "123".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
socket_a.send(&msg_out, addr_server).await?;
|
||||
@ -204,7 +213,7 @@ mod tests {
|
||||
panic!("failed");
|
||||
}
|
||||
|
||||
Err(new_error("done"))
|
||||
Err("done".into())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user