diff options
author | rustdesk <[email protected]> | 2022-07-13 00:22:45 +0800 |
---|---|---|
committer | rustdesk <[email protected]> | 2022-07-13 00:22:45 +0800 |
commit | 39153ce1472417be101051baecb452da467f2652 (patch) | |
tree | 7ef2ed6d8d28a80fa3a7333460d7211a48b6e4a2 | |
parent | 57cbac7079a6132388d81d3d76a39e6cd700baab (diff) | |
download | rustdesk-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
-rw-r--r-- | Cargo.lock | 267 | ||||
-rw-r--r-- | Cargo.toml | 12 | ||||
-rw-r--r-- | db_v2.sqlite3 | bin | 24576 -> 24576 bytes | |||
-rw-r--r-- | libs/hbb_common/protos/message.proto | 6 | ||||
-rw-r--r-- | libs/hbb_common/src/config.rs | 14 | ||||
-rw-r--r-- | libs/hbb_common/src/fs.rs | 8 | ||||
-rw-r--r-- | libs/hbb_common/src/lib.rs | 1 | ||||
-rw-r--r-- | libs/hbb_common/src/socket_client.rs | 8 | ||||
-rw-r--r-- | libs/hbb_common/src/udp.rs | 6 | ||||
-rw-r--r-- | src/common.rs | 23 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/relay_server.rs | 2 | ||||
-rw-r--r-- | src/rendezvous_server.rs | 97 | ||||
-rw-r--r-- | src/version.rs | 2 |
14 files changed, 269 insertions, 178 deletions
@@ -67,9 +67,9 @@ dependencies = [ [[package]] name = "atoi" -version = "0.4.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" dependencies = [ "num-traits", ] @@ -118,7 +118,7 @@ dependencies = [ "sync_wrapper", "tokio", "tower", - "tower-http 0.3.3", + "tower-http", "tower-layer", "tower-service", ] @@ -145,9 +145,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bcrypt" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe4fef31efb0f76133ae8e3576a88e58edb7cfc5584c81c758c349ba46b43fc" +checksum = "a7e7c93a3fb23b2fdde989b2c9ec4dd153063ec81f408507f84c090cd91c6641" dependencies = [ "base64", "blowfish", @@ -163,15 +163,6 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-buffer" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" @@ -283,6 +274,12 @@ dependencies = [ ] [[package]] +name = "const-sha1" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d" + +[[package]] name = "core-foundation" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -309,18 +306,18 @@ dependencies = [ [[package]] name = "crc" -version = "2.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49fc9a695bca7f35f5f4c15cddc84415f66a74ea78eef08e90c5024f2b540e23" +checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "1.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" +checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" [[package]] name = "crossbeam" @@ -416,20 +413,11 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "block-buffer 0.10.2", + "block-buffer", "crypto-common", ] @@ -505,6 +493,12 @@ dependencies = [ ] [[package]] +name = "event-listener" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" + +[[package]] name = "fastrand" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -719,9 +713,6 @@ name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] [[package]] name = "hashbrown" @@ -734,11 +725,11 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +checksum = "d452c155cb93fecdfb02a73dd57b5d8e442c2063bd7aac72f1bc5e4263a43086" dependencies = [ - "hashbrown 0.11.2", + "hashbrown 0.12.1", ] [[package]] @@ -777,7 +768,7 @@ dependencies = [ [[package]] name = "hbbs" -version = "1.1.5" +version = "1.1.6" dependencies = [ "async-speed-limit", "async-trait", @@ -791,8 +782,10 @@ dependencies = [ "hbb_common", "headers", "http", + "ipnetwork", "jsonwebtoken", "lazy_static", + "local-ip-address", "mac_address", "machine-uid", "minreq", @@ -805,7 +798,7 @@ dependencies = [ "sodiumoxide", "sqlx", "tokio-tungstenite", - "tower-http 0.2.5", + "tower-http", "tungstenite", "uuid", "whoami", @@ -838,9 +831,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" dependencies = [ "unicode-segmentation", ] @@ -969,6 +962,15 @@ dependencies = [ ] [[package]] +name = "ipnetwork" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" +dependencies = [ + "serde", +] + +[[package]] name = "itertools" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1054,9 +1056,9 @@ dependencies = [ [[package]] name = "libsqlite3-sys" -version = "0.23.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cafc7c74096c336d9d27145f7ebd4f4b6f95ba16aa5a282387267e6925cb58" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" dependencies = [ "cc", "pkg-config", @@ -1064,6 +1066,19 @@ dependencies = [ ] [[package]] +name = "local-ip-address" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b143c6ef86e36328caa40a7578e95d1544aca8a1740235fd2b416a69441a5c7" +dependencies = [ + "libc", + "memalloc", + "neli", + "thiserror", + "windows", +] + +[[package]] name = "lock_api" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1114,6 +1129,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" [[package]] +name = "memalloc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df39d232f5c40b0891c10216992c2f250c054105cb1e56f0fc9032db6203ecc1" + +[[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1195,6 +1216,16 @@ dependencies = [ ] [[package]] +name = "neli" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9053554eb5dcb7e10d9cdab1206965bde870eed5d0d341532ca035e3ba221508" +dependencies = [ + "byteorder", + "libc", +] + +[[package]] name = "nix" version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1293,12 +1324,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1519,11 +1544,11 @@ dependencies = [ "fxhash", "quinn-proto", "quinn-udp", - "rustls 0.20.4", + "rustls", "thiserror", "tokio", "tracing", - "webpki 0.22.0", + "webpki", ] [[package]] @@ -1536,14 +1561,14 @@ dependencies = [ "fxhash", "rand", "ring", - "rustls 0.20.4", + "rustls", "rustls-native-certs", "rustls-pemfile 0.2.1", "slab", "thiserror", "tinyvec", "tracing", - "webpki 0.22.0", + "webpki", ] [[package]] @@ -1673,26 +1698,14 @@ dependencies = [ [[package]] name = "rustls" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" -dependencies = [ - "base64", - "log", - "ring", - "sct 0.6.1", - "webpki 0.21.4", -] - -[[package]] -name = "rustls" version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921" dependencies = [ + "log", "ring", - "sct 0.7.0", - "webpki 0.22.0", + "sct", + "webpki", ] [[package]] @@ -1764,16 +1777,6 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "sct" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" @@ -1856,20 +1859,18 @@ checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.3", + "digest", ] [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ - "block-buffer 0.9.0", "cfg-if", "cpufeatures", - "digest 0.9.0", - "opaque-debug", + "digest", ] [[package]] @@ -1972,8 +1973,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.5.11" -source = "git+https://github.com/open-trade/sqlx#81392f03ba36fbd670447517dbc122fddb206de7" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f82cbe94f41641d6c410ded25bbf5097c240cefdf8e3b06d04198d0a96af6a4" dependencies = [ "sqlx-core", "sqlx-macros", @@ -1981,8 +1983,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.11" -source = "git+https://github.com/open-trade/sqlx#81392f03ba36fbd670447517dbc122fddb206de7" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b69bf218860335ddda60d6ce85ee39f6cf6e5630e300e19757d1de15886a093" dependencies = [ "ahash", "atoi", @@ -1993,6 +1996,7 @@ dependencies = [ "crc", "crossbeam-queue", "either", + "event-listener", "flume", "futures-channel", "futures-core", @@ -2010,7 +2014,8 @@ dependencies = [ "once_cell", "paste", "percent-encoding", - "rustls 0.19.1", + "rustls", + "rustls-pemfile 1.0.0", "serde", "serde_json", "sha2", @@ -2021,14 +2026,14 @@ dependencies = [ "thiserror", "tokio-stream", "url", - "webpki 0.21.4", "webpki-roots", ] [[package]] name = "sqlx-macros" -version = "0.5.11" -source = "git+https://github.com/open-trade/sqlx#81392f03ba36fbd670447517dbc122fddb206de7" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40c63177cf23d356b159b60acd27c54af7423f1736988502e36bae9a712118f" dependencies = [ "dotenv", "either", @@ -2046,8 +2051,9 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.5.11" -source = "git+https://github.com/open-trade/sqlx#81392f03ba36fbd670447517dbc122fddb206de7" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "874e93a365a598dc3dadb197565952cb143ae4aa716f7bcc933a8d836f6bf89f" dependencies = [ "once_cell", "tokio", @@ -2222,13 +2228,13 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.22.0" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.19.1", + "rustls", "tokio", - "webpki 0.21.4", + "webpki", ] [[package]] @@ -2327,9 +2333,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.2.5" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aba3f3efabf7fb41fae8534fc20a817013dd1c12cb45441efb6c82e6556b4cd8" +checksum = "7d342c6d58709c0a6d48d48dabbb62d4ef955cf5f0f3bbfd845838e7ae88dbae" dependencies = [ "bitflags", "bytes", @@ -2345,28 +2351,10 @@ dependencies = [ "pin-project-lite", "tokio", "tokio-util 0.7.1", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-http" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d342c6d58709c0a6d48d48dabbb62d4ef955cf5f0f3bbfd845838e7ae88dbae" -dependencies = [ - "bitflags", - "bytes", - "futures-core", - "futures-util", - "http", - "http-body", - "http-range-header", - "pin-project-lite", "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -2519,9 +2507,9 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "uuid" -version = "0.8.2" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" dependencies = [ "getrandom", ] @@ -2643,16 +2631,6 @@ dependencies = [ [[package]] name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki" version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" @@ -2663,11 +2641,11 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.21.1" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" dependencies = [ - "webpki 0.21.4", + "webpki", ] [[package]] @@ -2723,6 +2701,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] +name = "windows" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68088239696c06152844eadc03d262f088932cce50c67e4ace86e19d95e976fe" +dependencies = [ + "const-sha1", + "windows_gen", + "windows_macros", +] + +[[package]] name = "windows-sys" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2742,6 +2731,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] +name = "windows_gen" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf583322dc423ee021035b358e535015f7fd163058a31e2d37b99a939141121d" + +[[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2754,6 +2749,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] +name = "windows_macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58acfb8832e9f707f8997bd161e537a1c1f603e60a5bd9c3cf53484fdcc998f3" +dependencies = [ + "syn", + "windows_gen", +] + +[[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1,6 +1,6 @@ [package] name = "hbbs" -version = "1.1.5" +version = "1.1.6" authors = ["open-trade <[email protected]>"] edition = "2021" build = "build.rs" @@ -26,12 +26,12 @@ mac_address = "1.1" whoami = "1.2" base64 = "0.13" axum = { version = "0.5", features = ["headers"] } -sqlx = { git = "https://github.com/open-trade/sqlx", features = [ "runtime-tokio-rustls", "sqlite", "macros", "chrono", "json" ] } +sqlx = { version = "0.6", features = [ "runtime-tokio-rustls", "sqlite", "macros", "chrono", "json" ] } deadpool = "0.8" async-trait = "0.1" async-speed-limit = { git = "https://github.com/open-trade/async-speed-limit" } -uuid = { version = "0.8", features = ["v4"] } -bcrypt = "0.12" +uuid = { version = "1.0", features = ["v4"] } +bcrypt = "0.13" chrono = "0.4" jsonwebtoken = "8" headers = "0.3" @@ -40,9 +40,11 @@ sodiumoxide = "0.2" tokio-tungstenite = "0.17" tungstenite = "0.17" regex = "1.4" -tower-http = { version = "0.2", features = ["fs", "trace", "cors"] } +tower-http = { version = "0.3", features = ["fs", "trace", "cors"] } http = "0.2" flexi_logger = { version = "0.22", features = ["async", "use_chrono_for_offset"] } +ipnetwork = "0.20" +local-ip-address = "0.4" [build-dependencies] hbb_common = { path = "libs/hbb_common" } diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 Binary files differindex 1985922..245eb7e 100644 --- a/db_v2.sqlite3 +++ b/db_v2.sqlite3 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(), diff --git a/src/common.rs b/src/common.rs index 473d730..74b9e78 100644 --- a/src/common.rs +++ b/src/common.rs @@ -95,8 +95,11 @@ pub fn now() -> u64 { .unwrap_or_default() } -pub fn gen_sk() -> (String, Option<sign::SecretKey>) { +pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) { let sk_file = "id_ed25519"; + if wait > 0 && !std::path::Path::new(sk_file).exists() { + std::thread::sleep(std::time::Duration::from_millis(wait)); + } if let Ok(mut file) = std::fs::File::open(sk_file) { let mut contents = String::new(); if file.read_to_string(&mut contents).is_ok() { @@ -110,16 +113,26 @@ pub fn gen_sk() -> (String, Option<sign::SecretKey>) { } } } else { - let (pk, sk) = sign::gen_keypair(); + let gen_func = || { + let (tmp, sk) = sign::gen_keypair(); + (base64::encode(tmp), sk) + }; + let (mut pk, mut sk) = gen_func(); + for _ in 0..300 { + if !pk.contains("/") { + break; + } + (pk, sk) = gen_func(); + } let pub_file = format!("{}.pub", sk_file); if let Ok(mut f) = std::fs::File::create(&pub_file) { - f.write_all(base64::encode(pk).as_bytes()).ok(); + f.write_all(pk.as_bytes()).ok(); if let Ok(mut f) = std::fs::File::create(sk_file) { let s = base64::encode(&sk); if f.write_all(s.as_bytes()).is_ok() { log::info!("Private/public key written to {}/{}", sk_file, pub_file); - log::debug!("Public key: {:?}", pk); - return (base64::encode(pk), Some(sk)); + log::debug!("Public key: {}", pk); + return (pk, Some(sk)); } } } diff --git a/src/main.rs b/src/main.rs index d715bd3..09119c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ fn main() -> ResultType<()> { -u, --software-url=[URL] 'Sets download url of RustDesk software of newest version' -r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon' -M, --rmem=[NUMBER(default={})] 'Sets UDP recv buffer size, set system rmem_max first, e.g., sudo sysctl -w net.core.rmem_max=52428800. vi /etc/sysctl.conf, net.core.rmem_max=52428800, sudo sysctl –p' + , --mask=[MASK] 'Determine if the connection comes from LAN, e.g. 192.168.0.0/16' -k, --key=[KEY] 'Only allow the client with the same key'", RENDEZVOUS_PORT, RMEM, diff --git a/src/relay_server.rs b/src/relay_server.rs index 9eccfe1..b6c677c 100644 --- a/src/relay_server.rs +++ b/src/relay_server.rs @@ -566,7 +566,7 @@ fn get_server_sk(key: &str) -> String { } if key == "-" || key == "_" { - let (pk, _) = crate::common::gen_sk(); + let (pk, _) = crate::common::gen_sk(300); key = pk; } diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 37a4eb4..835933f 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -28,6 +28,7 @@ use hbb_common::{ udp::FramedSocket, AddrMangle, ResultType, }; +use ipnetwork::Ipv4Network; use sodiumoxide::crypto::sign; use std::{ collections::HashMap, @@ -59,17 +60,24 @@ static CHECK_RELAY_TIMEOUT: u64 = 3_000; static mut ALWAYS_USE_RELAY: bool = false; #[derive(Clone)] +struct Inner { + serial: i32, + version: String, + software_url: String, + mask: Option<Ipv4Network>, + local_ip: String, + sk: Option<sign::SecretKey>, +} + +#[derive(Clone)] pub struct RendezvousServer { tcp_punch: Arc<Mutex<HashMap<SocketAddr, Sink>>>, pm: PeerMap, tx: Sender, relay_servers: Arc<RelayServers>, relay_servers0: Arc<RelayServers>, - serial: i32, rendezvous_servers: Arc<Vec<String>>, - version: String, - software_url: String, - sk: Option<sign::SecretKey>, + inner: Arc<Inner>, } enum LoopFailure { @@ -87,6 +95,7 @@ impl RendezvousServer { key: &str, rmem: usize, ) -> ResultType<()> { + let (key, sk) = Self::get_server_sk(key); let addr = format!("0.0.0.0:{}", port); let addr2 = format!("0.0.0.0:{}", port - 1); let addr3 = format!("0.0.0.0:{}", port + 2); @@ -109,13 +118,23 @@ impl RendezvousServer { tx: tx.clone(), relay_servers: Default::default(), relay_servers0: Default::default(), - serial, rendezvous_servers: Arc::new(rendezvous_servers), - version, - software_url, - sk: None, + inner: Arc::new(Inner { + serial, + version, + software_url, + sk, + mask: get_arg("mask").parse().ok(), + local_ip: get_arg_or( + "local-ip", + local_ip_address::local_ip() + .map(|x| x.to_string()) + .unwrap_or_default(), + ), + }), }; - let key = rs.get_server_sk(key); + log::info!("mask: {:?}", rs.inner.mask); + log::info!("local-ip: {:?}", rs.inner.local_ip); std::env::set_var("PORT_FOR_API", port.to_string()); rs.parse_relay_servers(&get_arg("relay-servers")); let pm = rs.pm.clone(); @@ -284,10 +303,10 @@ impl RendezvousServer { if rp.id.len() > 0 { log::trace!("New peer registered: {:?} {:?}", &rp.id, &addr); self.update_addr(rp.id, addr, socket).await?; - if self.serial > rp.serial { + if self.inner.serial > rp.serial { let mut msg_out = RendezvousMessage::new(); msg_out.set_configure_update(ConfigUpdate { - serial: self.serial, + serial: self.inner.serial, rendezvous_servers: (*self.rendezvous_servers).clone(), ..Default::default() }); @@ -401,8 +420,10 @@ impl RendezvousServer { self.handle_local_addr(la, addr, Some(socket)).await?; } Some(rendezvous_message::Union::configure_update(mut cu)) => { - if addr.ip() == ADDR_127 && cu.serial > self.serial { - self.serial = cu.serial; + if addr.ip() == ADDR_127 && cu.serial > self.inner.serial { + let mut inner: Inner = (*self.inner).clone(); + inner.serial = cu.serial; + self.inner = Arc::new(inner); self.rendezvous_servers = Arc::new( cu.rendezvous_servers .drain(..) @@ -414,16 +435,16 @@ impl RendezvousServer { ); log::info!( "configure updated: serial={} rendezvous-servers={:?}", - self.serial, + self.inner.serial, self.rendezvous_servers ); } } Some(rendezvous_message::Union::software_update(su)) => { - if !self.version.is_empty() && su.url != self.version { + if !self.inner.version.is_empty() && su.url != self.inner.version { let mut msg_out = RendezvousMessage::new(); msg_out.set_software_update(SoftwareUpdate { - url: self.software_url.clone(), + url: self.inner.software_url.clone(), ..Default::default() }); socket.send(&msg_out, addr).await?; @@ -477,6 +498,10 @@ impl RendezvousServer { rr.set_pk(pk); } let mut msg_out = RendezvousMessage::new(); + if self.is_lan(addr_b) { + // https://github.com/rustdesk/rustdesk-server/issues/24 + rr.relay_server = self.inner.local_ip.clone(); + } msg_out.set_relay_response(rr); allow_err!(self.send_to_tcp_sync(msg_out, addr_b).await); } @@ -492,9 +517,9 @@ impl RendezvousServer { port: addr.port() as _, ..Default::default() }; - if self.serial > tar.serial { + if self.inner.serial > tar.serial { let mut cu = ConfigUpdate::new(); - cu.serial = self.serial; + cu.serial = self.inner.serial; cu.rendezvous_servers = (*self.rendezvous_servers).clone(); res.cu = MessageField::from_option(Some(cu)); } @@ -662,8 +687,15 @@ impl RendezvousServer { return Ok((msg_out, None)); } let mut msg_out = RendezvousMessage::new(); - if unsafe { ALWAYS_USE_RELAY } { - let relay_server = self.get_relay_server(addr.ip(), peer_addr.ip()); + let peer_is_lan = self.is_lan(peer_addr); + let is_lan = self.is_lan(addr); + if unsafe { ALWAYS_USE_RELAY } || (peer_is_lan ^ is_lan) { + let relay_server = if peer_is_lan { + // https://github.com/rustdesk/rustdesk-server/issues/24 + self.inner.local_ip.clone() + } else { + self.get_relay_server(addr.ip(), peer_addr.ip()) + }; if !relay_server.is_empty() { msg_out.set_request_relay(RequestRelay { relay_server, @@ -1077,7 +1109,7 @@ impl RendezvousServer { #[inline] async fn get_pk(&mut self, version: &str, id: String) -> Vec<u8> { - if version.is_empty() || self.sk.is_none() { + if version.is_empty() || self.inner.sk.is_none() { Vec::new() } else { match self.pm.get(&id).await { @@ -1091,7 +1123,7 @@ impl RendezvousServer { } .write_to_bytes() .unwrap_or_default(), - &self.sk.as_ref().unwrap(), + &self.inner.sk.as_ref().unwrap(), ) } _ => Vec::new(), @@ -1100,7 +1132,8 @@ impl RendezvousServer { } #[inline] - fn get_server_sk(&mut self, key: &str) -> String { + fn get_server_sk(key: &str) -> (String, Option<sign::SecretKey>) { + let mut out_sk = None; let mut key = key.to_owned(); if let Ok(sk) = base64::decode(&key) { if sk.len() == sign::SECRETKEYBYTES { @@ -1108,13 +1141,13 @@ impl RendezvousServer { key = base64::encode(&sk[(sign::SECRETKEYBYTES / 2)..]); let mut tmp = [0u8; sign::SECRETKEYBYTES]; tmp[..].copy_from_slice(&sk); - self.sk = Some(sign::SecretKey(tmp)); + out_sk = Some(sign::SecretKey(tmp)); } } if key.is_empty() || key == "-" || key == "_" { - let (pk, sk) = crate::common::gen_sk(); - self.sk = sk; + let (pk, sk) = crate::common::gen_sk(0); + out_sk = sk; if !key.is_empty() { key = pk; } else { @@ -1126,7 +1159,17 @@ impl RendezvousServer { log::info!("Key: {}", key); std::env::set_var("KEY_FOR_API", key.clone()); } - key + (key, out_sk) + } + + #[inline] + fn is_lan(&self, addr: SocketAddr) -> bool { + if let Some(network) = &self.inner.mask { + if let SocketAddr::V4(addr) = addr { + return network.contains(*addr.ip()); + } + } + false } } diff --git a/src/version.rs b/src/version.rs index 75f232c..a68926b 100644 --- a/src/version.rs +++ b/src/version.rs @@ -1 +1 @@ -pub const VERSION: &str = "1.1.5";
\ No newline at end of file +pub const VERSION: &str = "1.1.6";
\ No newline at end of file |