From 95239fc148dc51ccad3f0644f97bd9626b0aab97 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 14 Jan 2022 23:02:08 +0800 Subject: [PATCH] change back to broadcast, because multicast has big problem if multiple interface with 0.0.0.0 binding --- Cargo.lock | 324 ++++++++----------------------------- Cargo.toml | 1 - libs/hbb_common/src/udp.rs | 26 +-- src/rendezvous_mediator.rs | 128 ++++++--------- 4 files changed, 117 insertions(+), 362 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5b399727..8959e3b88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5915f52fe2cf65e83924d037b6c5290b7cee097c6b5c8700746e6168a343fd6b" dependencies = [ "alsa-sys", - "bitflags 1.3.2", + "bitflags", "libc", "nix 0.23.1", ] @@ -69,7 +69,7 @@ dependencies = [ "android_log-sys", "env_logger 0.8.4", "lazy_static", - "log 0.4.14", + "log", ] [[package]] @@ -96,7 +96,7 @@ dependencies = [ "clipboard-win", "core-graphics 0.22.3", "image", - "log 0.4.14", + "log", "objc", "objc-foundation", "objc_id", @@ -126,7 +126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812b4911e210bd51b24596244523c856ca749e6223c50a7fbbba3f89ee37c426" dependencies = [ "atk-sys", - "bitflags 1.3.2", + "bitflags", "glib", "glib-sys", "gobject-sys", @@ -195,7 +195,7 @@ version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cexpr 0.4.0", "clang-sys", "lazy_static", @@ -214,14 +214,14 @@ version = "0.59.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cexpr 0.6.0", "clang-sys", "clap", "env_logger 0.9.0", "lazy_static", "lazycell", - "log 0.4.14", + "log", "peeking_take_while", "proc-macro2", "quote", @@ -231,12 +231,6 @@ dependencies = [ "which 4.2.2", ] -[[package]] -name = "bitflags" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" - [[package]] name = "bitflags" version = "1.3.2" @@ -288,7 +282,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5c0f2e047e8ca53d0ff249c54ae047931d7a6ebe05d00af73e0ffeb6e34bdb8" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cairo-sys-rs", "glib", "glib-sys", @@ -359,7 +353,7 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" dependencies = [ - "glob 0.3.0", + "glob", "libc", "libloading", ] @@ -372,7 +366,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", - "bitflags 1.3.2", + "bitflags", "strsim 0.8.0", "textwrap", "unicode-width", @@ -410,7 +404,7 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -428,7 +422,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7" dependencies = [ - "bitflags 1.3.2", + "bitflags", "block", "core-foundation 0.9.2", "core-graphics 0.21.0", @@ -443,7 +437,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832" dependencies = [ - "bitflags 1.3.2", + "bitflags", "block", "cocoa-foundation", "core-foundation 0.9.2", @@ -459,7 +453,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ - "bitflags 1.3.2", + "bitflags", "block", "core-foundation 0.9.2", "core-graphics-types", @@ -532,7 +526,7 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation 0.7.0", "foreign-types", "libc", @@ -544,7 +538,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation 0.9.2", "foreign-types", "libc", @@ -556,7 +550,7 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation 0.9.2", "core-graphics-types", "foreign-types", @@ -569,7 +563,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation 0.9.2", "foreign-types", "libc", @@ -581,7 +575,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" dependencies = [ - "bitflags 1.3.2", + "bitflags", "coreaudio-sys", ] @@ -1020,7 +1014,7 @@ version = "0.0.14" dependencies = [ "core-graphics 0.22.3", "libc", - "log 0.4.14", + "log", "objc", "pkg-config", "serde 1.0.133", @@ -1035,7 +1029,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ - "log 0.4.14", + "log", "regex", ] @@ -1047,7 +1041,7 @@ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", - "log 0.4.14", + "log", "regex", "termcolor", ] @@ -1126,9 +1120,9 @@ checksum = "0b51b4517f4422bfa0515dafcc10b4cc4cd3953d69a19608fd74afb3b19e227c" dependencies = [ "ansi_term", "atty", - "glob 0.3.0", + "glob", "lazy_static", - "log 0.4.14", + "log", "regex", "rustversion", "thiserror", @@ -1162,7 +1156,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" dependencies = [ - "bitflags 1.3.2", + "bitflags", "fsevent-sys", ] @@ -1187,7 +1181,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags 1.3.2", + "bitflags", "fuchsia-zircon-sys", ] @@ -1301,7 +1295,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db00839b2a68a7a10af3fa28dfb3febaba3a20c3a9ac2425a33b7df1f84a6b7d" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cairo-rs", "cairo-sys-rs", "gdk-pixbuf", @@ -1403,7 +1397,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fb60242bfff700772dae5d9e3a1f7aa2e4ebccf18b89662a16acb2822568561" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures", "futures-channel", "futures-core", @@ -1437,7 +1431,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c685013b7515e668f1b57a165b009d4d28cb139a8a989bbd699c10dad29d0c5" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures-channel", "futures-core", "futures-executor", @@ -1476,12 +1470,6 @@ dependencies = [ "system-deps", ] -[[package]] -name = "glob" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" - [[package]] name = "glob" version = "0.3.0" @@ -1505,7 +1493,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff5d0f7ff308ae37e6eb47b6ded17785bdea06e438a708cd09e0288c1862f33" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cfg-if 1.0.0", "futures-channel", "futures-core", @@ -1529,7 +1517,7 @@ version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc80888271338c3ede875d8cafc452eb207476ff5539dcbe0018a8f5b827af0e" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures-core", "futures-sink", "glib", @@ -1562,7 +1550,7 @@ version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bafd01c56f59cb10f4b5a10f97bb4bdf8c2b2784ae5b04da7e2d400cf6e6afcf" dependencies = [ - "bitflags 1.3.2", + "bitflags", "glib", "glib-sys", "gobject-sys", @@ -1603,7 +1591,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7bbb1485d87469849ec45c08e03c2f280d3ea20ff3c439d03185be54e3ce98e" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures-channel", "futures-util", "glib", @@ -1639,7 +1627,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f022f2054072b3af07666341984562c8e626a79daa8be27b955d12d06a5ad6a" dependencies = [ "atk", - "bitflags 1.3.2", + "bitflags", "cairo-rs", "cairo-sys-rs", "cc", @@ -1692,7 +1680,7 @@ dependencies = [ "futures", "futures-util", "lazy_static", - "log 0.4.14", + "log", "mac_address", "protobuf", "protobuf-codegen-pure", @@ -1789,7 +1777,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" dependencies = [ - "bitflags 1.3.2", + "bitflags", "inotify-sys", "libc", ] @@ -1821,15 +1809,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipnetwork" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c3eaab3ac0ede60ffa41add21970a7df7d91772c03383aac6c2c3d53cc716b" -dependencies = [ - "serde 1.0.133", -] - [[package]] name = "itertools" version = "0.9.0" @@ -1866,7 +1845,7 @@ dependencies = [ "cesu8", "combine", "jni-sys", - "log 0.4.14", + "log", "thiserror", "walkdir", ] @@ -1932,7 +1911,7 @@ dependencies = [ "gtk", "gtk-sys", "libappindicator-sys", - "log 0.4.14", + "log", ] [[package]] @@ -1975,7 +1954,7 @@ version = "2.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86835d7763ded6bc16b6c0061ec60214da7550dfcd4ef93745f6f0096129676a" dependencies = [ - "bitflags 1.3.2", + "bitflags", "libc", "libpulse-sys", "num-derive", @@ -2047,15 +2026,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.14", -] - [[package]] name = "log" version = "0.4.14" @@ -2163,7 +2133,7 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log 0.4.14", + "log", "miow 0.2.2", "net2", "slab", @@ -2177,7 +2147,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", - "log 0.4.14", + "log", "miow 0.3.7", "ntapi", "winapi 0.3.9", @@ -2190,7 +2160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", - "log 0.4.14", + "log", "mio 0.6.23", "slab", ] @@ -2201,7 +2171,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" dependencies = [ - "log 0.4.14", + "log", "mio 0.6.23", "miow 0.3.7", "winapi 0.3.9", @@ -2249,7 +2219,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d64d6af06fde0e527b1ba5c7b79a6cc89cfc46325b0b2887dffe8f70197e0c3c" dependencies = [ - "bitflags 1.3.2", + "bitflags", "jni-sys", "ndk-sys 0.2.2", "num_enum", @@ -2262,7 +2232,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" dependencies = [ - "bitflags 1.3.2", + "bitflags", "jni-sys", "ndk-sys 0.3.0", "num_enum", @@ -2277,7 +2247,7 @@ checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420" dependencies = [ "lazy_static", "libc", - "log 0.4.14", + "log", "ndk 0.4.0", "ndk-macro 0.2.0", "ndk-sys 0.2.2", @@ -2291,7 +2261,7 @@ checksum = "04c0d14b0858eb9962a5dac30b809b19f19da7e4547d64af2b0bb051d2e55d79" dependencies = [ "lazy_static", "libc", - "log 0.4.14", + "log", "ndk 0.6.0", "ndk-macro 0.3.0", "ndk-sys 0.3.0", @@ -2355,7 +2325,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cc", "cfg-if 1.0.0", "libc", @@ -2367,7 +2337,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cc", "cfg-if 1.0.0", "libc", @@ -2380,7 +2350,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cc", "cfg-if 1.0.0", "libc", @@ -2414,7 +2384,7 @@ version = "4.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" dependencies = [ - "bitflags 1.3.2", + "bitflags", "filetime", "fsevent", "fsevent-sys", @@ -2612,7 +2582,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9937068580bebd8ced19975938573803273ccbcbd598c58d4906efd4ac87c438" dependencies = [ - "bitflags 1.3.2", + "bitflags", "glib", "glib-sys", "gobject-sys", @@ -2640,7 +2610,7 @@ source = "git+https://github.com/open-trade/parity-tokio-ipc#52515618bd30ea8101b dependencies = [ "futures", "libc", - "log 0.4.14", + "log", "mio-named-pipes", "miow 0.4.0", "rand 0.8.4", @@ -2767,101 +2737,13 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" -[[package]] -name = "pnet" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b657d5b9a98a2c81b82549922b8b15984e49f8120cd130b11a09f81b9b55d633" -dependencies = [ - "ipnetwork", - "pnet_base", - "pnet_datalink", - "pnet_packet", - "pnet_sys", - "pnet_transport", -] - -[[package]] -name = "pnet_base" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4688aa497ef62129f302a5800ebde67825f8ff129f43690ca84099f6620bed" - -[[package]] -name = "pnet_datalink" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59001c9c4d9d23bf2f61afaaf134a766fd6932ba2557c606b9112157053b9ac7" -dependencies = [ - "ipnetwork", - "libc", - "pnet_base", - "pnet_sys", - "winapi 0.3.9", -] - -[[package]] -name = "pnet_macros" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d894a90dbdbe976e624453fc31b1912f658083778329442dda1cca94f76a3e76" -dependencies = [ - "regex", - "syntex", - "syntex_syntax", -] - -[[package]] -name = "pnet_macros_support" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b99269a458570bc06a9132254349f6543d9abc92e88b68d8de934aac9481f6c" -dependencies = [ - "pnet_base", -] - -[[package]] -name = "pnet_packet" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33f8238f4eb897a55ca06510cd71afb5b5ca7b4ff2d7188f1ca855fc1710133e" -dependencies = [ - "glob 0.2.11", - "pnet_base", - "pnet_macros", - "pnet_macros_support", - "syntex", -] - -[[package]] -name = "pnet_sys" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7589e4c4e7ed72a3ffdff8a65d3bea84e8c3a23e19d0a10e8f45efdf632fff15" -dependencies = [ - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "pnet_transport" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "326abdfd2e70e8e943bd58087b59686de170cac050a3b19c9fcc84db01690af5" -dependencies = [ - "libc", - "pnet_base", - "pnet_packet", - "pnet_sys", -] - [[package]] name = "png" version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ - "bitflags 1.3.2", + "bitflags", "crc32fast", "deflate", "miniz_oxide 0.3.7", @@ -2937,7 +2819,7 @@ version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ - "unicode-xid 0.2.2", + "unicode-xid", ] [[package]] @@ -2991,7 +2873,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f1f8b318a54d18fbe542513331e058f4f8ce6502e542e057c50c7e5e803fdab" dependencies = [ "anyhow", - "log 0.4.14", + "log", "thiserror", "which 4.2.2", ] @@ -3004,7 +2886,7 @@ dependencies = [ "cfg-if 1.0.0", "darwin-libproc", "derive_more", - "glob 0.3.0", + "glob", "mach", "nix 0.23.1", "num_cpus", @@ -3284,7 +3166,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -3375,7 +3257,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29cf25e25288b595458df0e00c3065db08c31afe4b4e5a74cbfc5a9b8e763cd" dependencies = [ - "log 0.4.14", + "log", "num-complex", "num-integer", "num-traits 0.2.14", @@ -3412,12 +3294,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - [[package]] name = "rustdesk" version = "1.1.8" @@ -3453,7 +3329,6 @@ dependencies = [ "notify", "objc", "parity-tokio-ipc", - "pnet", "psutil", "rdev", "repng", @@ -3620,7 +3495,7 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation 0.9.2", "core-foundation-sys 0.8.3", "libc", @@ -3843,7 +3718,7 @@ checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", - "unicode-xid 0.2.2", + "unicode-xid", ] [[package]] @@ -3855,56 +3730,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "unicode-xid 0.2.2", -] - -[[package]] -name = "syntex" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a30b08a6b383a22e5f6edc127d169670d48f905bb00ca79a00ea3e442ebe317" -dependencies = [ - "syntex_errors", - "syntex_syntax", -] - -[[package]] -name = "syntex_errors" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c48f32867b6114449155b2a82114b86d4b09e1bddb21c47ff104ab9172b646" -dependencies = [ - "libc", - "log 0.3.9", - "rustc-serialize", - "syntex_pos", - "term", - "unicode-xid 0.0.3", -] - -[[package]] -name = "syntex_pos" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fd49988e52451813c61fecbe9abb5cfd4e1b7bb6cdbb980a6fbcbab859171a6" -dependencies = [ - "rustc-serialize", -] - -[[package]] -name = "syntex_syntax" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7628a0506e8f9666fdabb5f265d0059b059edac9a3f810bda077abb5d826bd8d" -dependencies = [ - "bitflags 0.5.0", - "libc", - "log 0.3.9", - "rustc-serialize", - "syntex_errors", - "syntex_pos", - "term", - "unicode-xid 0.0.3", + "unicode-xid", ] [[package]] @@ -3944,7 +3770,7 @@ dependencies = [ "gtk", "libappindicator", "libc", - "log 0.4.14", + "log", "winapi 0.3.9", ] @@ -3973,16 +3799,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "term" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" -dependencies = [ - "kernel32-sys", - "winapi 0.2.8", -] - [[package]] name = "termcolor" version = "1.1.2" @@ -4129,7 +3945,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "log 0.4.14", + "log", "pin-project-lite", "slab", "tokio", @@ -4210,12 +4026,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" -[[package]] -name = "unicode-xid" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb" - [[package]] name = "unicode-xid" version = "0.2.2" @@ -4290,7 +4100,7 @@ checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", - "log 0.4.14", + "log", "proc-macro2", "quote", "syn", @@ -4465,7 +4275,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c643e10139d127d30d6d753398c8a6f0a43532e8370f6c9d29ebbff29b984ab" dependencies = [ - "bitflags 1.3.2", + "bitflags", "err-derive", "widestring", "winapi 0.3.9", @@ -4598,7 +4408,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c" dependencies = [ "libc", - "log 0.4.14", + "log", "quick-xml", ] diff --git a/Cargo.toml b/Cargo.toml index 01721bf18..4f10ec7d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ uuid = { version = "0.8", features = ["v4"] } clap = "2.34" rpassword = "5.0" base64 = "0.13" -pnet = "0.27" [target.'cfg(not(any(target_os = "android")))'.dependencies] cpal = { git = "https://github.com/open-trade/cpal" } diff --git a/libs/hbb_common/src/udp.rs b/libs/hbb_common/src/udp.rs index 977308df1..d1896bdbc 100644 --- a/libs/hbb_common/src/udp.rs +++ b/libs/hbb_common/src/udp.rs @@ -3,8 +3,8 @@ use anyhow::anyhow; use bytes::{Bytes, BytesMut}; use futures::{SinkExt, StreamExt}; use protobuf::Message; -use socket2::{Domain, Protocol, Socket, Type}; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; +use socket2::{Domain, Socket, Type}; +use std::net::SocketAddr; use tokio::net::{ToSocketAddrs, UdpSocket}; use tokio_socks::{udp::Socks5UdpFramed, IntoTargetAddr, TargetAddr, ToProxyAddrs}; use tokio_util::{codec::BytesCodec, udp::UdpFramed}; @@ -142,25 +142,3 @@ impl FramedSocket { } } } - -// const DEFAULT_MULTICAST: &str = "239.255.42.98"; - -pub fn bind_multicast( - maddr: Option, - interface: Ipv4Addr, -) -> ResultType { - let socket = Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))?; - socket.set_reuse_address(true)?; - if let Some(maddr) = maddr { - assert!(maddr.ip().is_multicast(), "Must be multcast address"); - let addr = SocketAddrV4::new(interface, maddr.port()); - socket.set_multicast_loop_v4(true)?; - socket.bind(&socket2::SockAddr::from(addr))?; - } else { - socket.bind(&socket2::SockAddr::from(SocketAddrV4::new(interface, 0)))?; - } - Ok(FramedSocket::Direct(UdpFramed::new( - UdpSocket::from_std(socket.into_udp_socket())?, - BytesCodec::new(), - ))) -} diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rs index a155a71fa..5558ed9fe 100644 --- a/src/rendezvous_mediator.rs +++ b/src/rendezvous_mediator.rs @@ -12,11 +12,11 @@ use hbb_common::{ self, select, time::{interval, Duration}, }, - udp::{self, FramedSocket}, + udp::FramedSocket, AddrMangle, IntoTargetAddr, ResultType, TargetAddr, }; use std::{ - net::{SocketAddr, SocketAddrV4}, + net::SocketAddr, sync::{ atomic::{AtomicBool, Ordering}, Arc, Mutex, @@ -59,8 +59,8 @@ impl RendezvousMediator { tokio::spawn(async move { allow_err!(direct_server(server_cloned).await); }); - tokio::spawn(async move { - allow_err!(lan_discovery().await); + std::thread::spawn(move || { + allow_err!(lan_discovery()); }); loop { Config::reset_online(); @@ -505,9 +505,9 @@ async fn direct_server(server: ServerPtr) -> ResultType<()> { } } -pub fn get_multicast_addr() -> SocketAddrV4 { - let port = (RENDEZVOUS_PORT + 3) as u16; - SocketAddrV4::new([239, 255, 42, 98].into(), port) +#[inline] +pub fn get_broadcast_port() -> u16 { + (RENDEZVOUS_PORT + 3) as _ } pub fn get_mac() -> String { @@ -518,82 +518,51 @@ pub fn get_mac() -> String { } } -async fn lan_discovery() -> ResultType<()> { - let mut jobs = Vec::new(); - for iface in pnet::datalink::interfaces() { - for i in 0..iface.ips.len() { - let x = iface.ips[i]; - if let pnet::ipnetwork::IpNetwork::V4(v) = x { - if v.prefix() >= 16 { - jobs.push(tokio::spawn(async move { - allow_err!(lan_discovery_interface(v.ip()).await); - })); - } - } - } - } - join_all(jobs).await; - Ok(()) -} - -async fn lan_discovery_interface(interface: std::net::Ipv4Addr) -> ResultType<()> { - let mut socket = udp::bind_multicast(Some(get_multicast_addr()), interface)?; - log::info!("lan discovery listener started on {:?}", interface); +fn lan_discovery() -> ResultType<()> { + let addr = SocketAddr::from(([0, 0, 0, 0], 3000)); + let socket = std::net::UdpSocket::bind(addr)?; + socket.set_read_timeout(Some(std::time::Duration::from_millis(1000)))?; + log::info!("lan discovery listener started"); loop { - select! { - Some(Ok((bytes, addr))) = socket.next_timeout(1000) => { - if let Ok(msg_in) = Message::parse_from_bytes(&bytes) { - match msg_in.union { - Some(rendezvous_message::Union::peer_discovery(p)) => { - if p.cmd == "ping" { - let mut msg_out = Message::new(); - let peer = PeerDiscovery { - cmd: "pong".to_owned(), - mac: get_mac(), - id: Config::get_id(), - hostname: whoami::hostname(), - username: crate::platform::get_active_username(), - platform: whoami::platform().to_string(), - ..Default::default() - }; - msg_out.set_peer_discovery(peer); - socket.send(&msg_out, addr).await?; - } + let mut buf = [0; 2048]; + if let Ok((len, addr)) = socket.recv_from(&mut buf) { + if let Ok(msg_in) = Message::parse_from_bytes(&buf[0..len]) { + match msg_in.union { + Some(rendezvous_message::Union::peer_discovery(p)) => { + if p.cmd == "ping" { + let mut msg_out = Message::new(); + let peer = PeerDiscovery { + cmd: "pong".to_owned(), + mac: get_mac(), + id: Config::get_id(), + hostname: whoami::hostname(), + username: crate::platform::get_active_username(), + platform: whoami::platform().to_string(), + ..Default::default() + }; + msg_out.set_peer_discovery(peer); + socket.send_to(&msg_out.write_to_bytes()?, addr).ok(); } - _ => {} } + _ => {} } } - else => {} // avoid select! all branches disabled panic } } } -#[tokio::main(flavor = "current_thread")] -pub async fn discover() -> ResultType<()> { - let maddr = SocketAddr::V4(get_multicast_addr()); - let mut sockets = Vec::new(); - for iface in pnet::datalink::interfaces() { - iface.ips.iter().for_each(|x| { - if let pnet::ipnetwork::IpNetwork::V4(v) = x { - if v.prefix() >= 16 { - if let Ok(s) = udp::bind_multicast(None, v.ip()) { - sockets.push(s); - } - } - } - }); - } +pub fn discover() -> ResultType<()> { + let addr = SocketAddr::from(([0, 0, 0, 0], 0)); + let socket = std::net::UdpSocket::bind(addr)?; + socket.set_broadcast(true)?; let mut msg_out = Message::new(); let peer = PeerDiscovery { cmd: "ping".to_owned(), ..Default::default() }; msg_out.set_peer_discovery(peer); - for i in 0..sockets.len() { - let socket = &mut sockets[i]; - socket.send(&msg_out, maddr).await?; - } + let maddr = SocketAddr::from(([255, 255, 255, 255], 3000)); + socket.send_to(&msg_out.write_to_bytes()?, maddr)?; log::info!("discover ping sent"); let mut last_recv_time = Instant::now(); let mut last_write_time = Instant::now(); @@ -601,22 +570,21 @@ pub async fn discover() -> ResultType<()> { // to-do: load saved peers, and update incrementally (then we can see offline) let mut peers = Vec::new(); let mac = get_mac(); + socket.set_read_timeout(Some(std::time::Duration::from_millis(10)))?; loop { - for i in 0..sockets.len() { - let socket = &mut sockets[i]; - if let Some(Ok((bytes, _))) = socket.next_timeout(10).await { - if let Ok(msg_in) = Message::parse_from_bytes(&bytes) { - match msg_in.union { - Some(rendezvous_message::Union::peer_discovery(p)) => { - last_recv_time = Instant::now(); - if p.cmd == "pong" { - if p.mac != mac { - peers.push((p.id, p.username, p.hostname, p.platform)); - } + let mut buf = [0; 2048]; + if let Ok((len, _)) = socket.recv_from(&mut buf) { + if let Ok(msg_in) = Message::parse_from_bytes(&buf[0..len]) { + match msg_in.union { + Some(rendezvous_message::Union::peer_discovery(p)) => { + last_recv_time = Instant::now(); + if p.cmd == "pong" { + if p.mac != mac { + peers.push((p.id, p.username, p.hostname, p.platform)); } } - _ => {} } + _ => {} } } }