From 0a2bc1cf8a731800c3639d52f82f68bacc5879f0 Mon Sep 17 00:00:00 2001 From: open-trade Date: Fri, 14 Jan 2022 18:16:00 +0800 Subject: [PATCH] try out muliticast on multiple interface --- Cargo.lock | 324 +++++++++++++++++++++++++++++-------- Cargo.toml | 1 + libs/hbb_common/src/udp.rs | 18 +-- src/rendezvous_mediator.rs | 73 ++++++--- src/server.rs | 12 +- 5 files changed, 322 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8959e3b88..f5b399727 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", + "bitflags 1.3.2", "libc", "nix 0.23.1", ] @@ -69,7 +69,7 @@ dependencies = [ "android_log-sys", "env_logger 0.8.4", "lazy_static", - "log", + "log 0.4.14", ] [[package]] @@ -96,7 +96,7 @@ dependencies = [ "clipboard-win", "core-graphics 0.22.3", "image", - "log", + "log 0.4.14", "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", + "bitflags 1.3.2", "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", + "bitflags 1.3.2", "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", + "bitflags 1.3.2", "cexpr 0.6.0", "clang-sys", "clap", "env_logger 0.9.0", "lazy_static", "lazycell", - "log", + "log 0.4.14", "peeking_take_while", "proc-macro2", "quote", @@ -231,6 +231,12 @@ 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" @@ -282,7 +288,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5c0f2e047e8ca53d0ff249c54ae047931d7a6ebe05d00af73e0ffeb6e34bdb8" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-sys-rs", "glib", "glib-sys", @@ -353,7 +359,7 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" dependencies = [ - "glob", + "glob 0.3.0", "libc", "libloading", ] @@ -366,7 +372,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", - "bitflags", + "bitflags 1.3.2", "strsim 0.8.0", "textwrap", "unicode-width", @@ -404,7 +410,7 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -422,7 +428,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "block", "core-foundation 0.9.2", "core-graphics 0.21.0", @@ -437,7 +443,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832" dependencies = [ - "bitflags", + "bitflags 1.3.2", "block", "cocoa-foundation", "core-foundation 0.9.2", @@ -453,7 +459,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ - "bitflags", + "bitflags 1.3.2", "block", "core-foundation 0.9.2", "core-graphics-types", @@ -526,7 +532,7 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.7.0", "foreign-types", "libc", @@ -538,7 +544,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.2", "foreign-types", "libc", @@ -550,7 +556,7 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.2", "core-graphics-types", "foreign-types", @@ -563,7 +569,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.2", "foreign-types", "libc", @@ -575,7 +581,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" dependencies = [ - "bitflags", + "bitflags 1.3.2", "coreaudio-sys", ] @@ -1014,7 +1020,7 @@ version = "0.0.14" dependencies = [ "core-graphics 0.22.3", "libc", - "log", + "log 0.4.14", "objc", "pkg-config", "serde 1.0.133", @@ -1029,7 +1035,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ - "log", + "log 0.4.14", "regex", ] @@ -1041,7 +1047,7 @@ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", - "log", + "log 0.4.14", "regex", "termcolor", ] @@ -1120,9 +1126,9 @@ checksum = "0b51b4517f4422bfa0515dafcc10b4cc4cd3953d69a19608fd74afb3b19e227c" dependencies = [ "ansi_term", "atty", - "glob", + "glob 0.3.0", "lazy_static", - "log", + "log 0.4.14", "regex", "rustversion", "thiserror", @@ -1156,7 +1162,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fsevent-sys", ] @@ -1181,7 +1187,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fuchsia-zircon-sys", ] @@ -1295,7 +1301,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db00839b2a68a7a10af3fa28dfb3febaba3a20c3a9ac2425a33b7df1f84a6b7d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-rs", "cairo-sys-rs", "gdk-pixbuf", @@ -1397,7 +1403,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fb60242bfff700772dae5d9e3a1f7aa2e4ebccf18b89662a16acb2822568561" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures", "futures-channel", "futures-core", @@ -1431,7 +1437,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c685013b7515e668f1b57a165b009d4d28cb139a8a989bbd699c10dad29d0c5" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-channel", "futures-core", "futures-executor", @@ -1470,6 +1476,12 @@ 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" @@ -1493,7 +1505,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff5d0f7ff308ae37e6eb47b6ded17785bdea06e438a708cd09e0288c1862f33" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "futures-channel", "futures-core", @@ -1517,7 +1529,7 @@ version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc80888271338c3ede875d8cafc452eb207476ff5539dcbe0018a8f5b827af0e" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-core", "futures-sink", "glib", @@ -1550,7 +1562,7 @@ version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bafd01c56f59cb10f4b5a10f97bb4bdf8c2b2784ae5b04da7e2d400cf6e6afcf" dependencies = [ - "bitflags", + "bitflags 1.3.2", "glib", "glib-sys", "gobject-sys", @@ -1591,7 +1603,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7bbb1485d87469849ec45c08e03c2f280d3ea20ff3c439d03185be54e3ce98e" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-channel", "futures-util", "glib", @@ -1627,7 +1639,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f022f2054072b3af07666341984562c8e626a79daa8be27b955d12d06a5ad6a" dependencies = [ "atk", - "bitflags", + "bitflags 1.3.2", "cairo-rs", "cairo-sys-rs", "cc", @@ -1680,7 +1692,7 @@ dependencies = [ "futures", "futures-util", "lazy_static", - "log", + "log 0.4.14", "mac_address", "protobuf", "protobuf-codegen-pure", @@ -1777,7 +1789,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" dependencies = [ - "bitflags", + "bitflags 1.3.2", "inotify-sys", "libc", ] @@ -1809,6 +1821,15 @@ 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" @@ -1845,7 +1866,7 @@ dependencies = [ "cesu8", "combine", "jni-sys", - "log", + "log 0.4.14", "thiserror", "walkdir", ] @@ -1911,7 +1932,7 @@ dependencies = [ "gtk", "gtk-sys", "libappindicator-sys", - "log", + "log 0.4.14", ] [[package]] @@ -1954,7 +1975,7 @@ version = "2.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86835d7763ded6bc16b6c0061ec60214da7550dfcd4ef93745f6f0096129676a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "libc", "libpulse-sys", "num-derive", @@ -2026,6 +2047,15 @@ 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" @@ -2133,7 +2163,7 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log", + "log 0.4.14", "miow 0.2.2", "net2", "slab", @@ -2147,7 +2177,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", - "log", + "log 0.4.14", "miow 0.3.7", "ntapi", "winapi 0.3.9", @@ -2160,7 +2190,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", - "log", + "log 0.4.14", "mio 0.6.23", "slab", ] @@ -2171,7 +2201,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" dependencies = [ - "log", + "log 0.4.14", "mio 0.6.23", "miow 0.3.7", "winapi 0.3.9", @@ -2219,7 +2249,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d64d6af06fde0e527b1ba5c7b79a6cc89cfc46325b0b2887dffe8f70197e0c3c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "jni-sys", "ndk-sys 0.2.2", "num_enum", @@ -2232,7 +2262,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" dependencies = [ - "bitflags", + "bitflags 1.3.2", "jni-sys", "ndk-sys 0.3.0", "num_enum", @@ -2247,7 +2277,7 @@ checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420" dependencies = [ "lazy_static", "libc", - "log", + "log 0.4.14", "ndk 0.4.0", "ndk-macro 0.2.0", "ndk-sys 0.2.2", @@ -2261,7 +2291,7 @@ checksum = "04c0d14b0858eb9962a5dac30b809b19f19da7e4547d64af2b0bb051d2e55d79" dependencies = [ "lazy_static", "libc", - "log", + "log 0.4.14", "ndk 0.6.0", "ndk-macro 0.3.0", "ndk-sys 0.3.0", @@ -2325,7 +2355,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -2337,7 +2367,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -2350,7 +2380,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -2384,7 +2414,7 @@ version = "4.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" dependencies = [ - "bitflags", + "bitflags 1.3.2", "filetime", "fsevent", "fsevent-sys", @@ -2582,7 +2612,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9937068580bebd8ced19975938573803273ccbcbd598c58d4906efd4ac87c438" dependencies = [ - "bitflags", + "bitflags 1.3.2", "glib", "glib-sys", "gobject-sys", @@ -2610,7 +2640,7 @@ source = "git+https://github.com/open-trade/parity-tokio-ipc#52515618bd30ea8101b dependencies = [ "futures", "libc", - "log", + "log 0.4.14", "mio-named-pipes", "miow 0.4.0", "rand 0.8.4", @@ -2737,13 +2767,101 @@ 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", + "bitflags 1.3.2", "crc32fast", "deflate", "miniz_oxide 0.3.7", @@ -2819,7 +2937,7 @@ version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2", ] [[package]] @@ -2873,7 +2991,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f1f8b318a54d18fbe542513331e058f4f8ce6502e542e057c50c7e5e803fdab" dependencies = [ "anyhow", - "log", + "log 0.4.14", "thiserror", "which 4.2.2", ] @@ -2886,7 +3004,7 @@ dependencies = [ "cfg-if 1.0.0", "darwin-libproc", "derive_more", - "glob", + "glob 0.3.0", "mach", "nix 0.23.1", "num_cpus", @@ -3166,7 +3284,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -3257,7 +3375,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29cf25e25288b595458df0e00c3065db08c31afe4b4e5a74cbfc5a9b8e763cd" dependencies = [ - "log", + "log 0.4.14", "num-complex", "num-integer", "num-traits 0.2.14", @@ -3294,6 +3412,12 @@ 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" @@ -3329,6 +3453,7 @@ dependencies = [ "notify", "objc", "parity-tokio-ipc", + "pnet", "psutil", "rdev", "repng", @@ -3495,7 +3620,7 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.2", "core-foundation-sys 0.8.3", "libc", @@ -3718,7 +3843,7 @@ checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-xid 0.2.2", ] [[package]] @@ -3730,7 +3855,56 @@ dependencies = [ "proc-macro2", "quote", "syn", - "unicode-xid", + "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", ] [[package]] @@ -3770,7 +3944,7 @@ dependencies = [ "gtk", "libappindicator", "libc", - "log", + "log 0.4.14", "winapi 0.3.9", ] @@ -3799,6 +3973,16 @@ 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" @@ -3945,7 +4129,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "log", + "log 0.4.14", "pin-project-lite", "slab", "tokio", @@ -4026,6 +4210,12 @@ 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" @@ -4100,7 +4290,7 @@ checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", - "log", + "log 0.4.14", "proc-macro2", "quote", "syn", @@ -4275,7 +4465,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c643e10139d127d30d6d753398c8a6f0a43532e8370f6c9d29ebbff29b984ab" dependencies = [ - "bitflags", + "bitflags 1.3.2", "err-derive", "widestring", "winapi 0.3.9", @@ -4408,7 +4598,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c" dependencies = [ "libc", - "log", + "log 0.4.14", "quick-xml", ] diff --git a/Cargo.toml b/Cargo.toml index 4f10ec7d5..01721bf18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ 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 f0c731b15..977308df1 100644 --- a/libs/hbb_common/src/udp.rs +++ b/libs/hbb_common/src/udp.rs @@ -145,25 +145,19 @@ impl FramedSocket { // const DEFAULT_MULTICAST: &str = "239.255.42.98"; -pub fn bind_multicast(maddr: Option) -> ResultType { - // todo: https://github.com/bltavares/multicast-socket - // 0.0.0.0 bind to default interface, if there are two interfaces, there will be problem. +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)?; - // somehow without this, timer.tick() under tokio::select! does not work - socket.set_read_timeout(Some(std::time::Duration::from_millis(100)))?; if let Some(maddr) = maddr { assert!(maddr.ip().is_multicast(), "Must be multcast address"); - let addr = SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0).into(), maddr.port()); - socket.join_multicast_v4(maddr.ip(), addr.ip())?; + let addr = SocketAddrV4::new(interface, maddr.port()); socket.set_multicast_loop_v4(true)?; socket.bind(&socket2::SockAddr::from(addr))?; } else { - socket.set_multicast_if_v4(&Ipv4Addr::new(0, 0, 0, 0))?; - socket.bind(&socket2::SockAddr::from(SocketAddr::new( - Ipv4Addr::new(0, 0, 0, 0).into(), - 0, - )))?; + socket.bind(&socket2::SockAddr::from(SocketAddrV4::new(interface, 0)))?; } Ok(FramedSocket::Direct(UdpFramed::new( UdpSocket::from_std(socket.into_udp_socket())?, diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rs index bd6ea971c..a155a71fa 100644 --- a/src/rendezvous_mediator.rs +++ b/src/rendezvous_mediator.rs @@ -519,11 +519,29 @@ pub fn get_mac() -> String { } async fn lan_discovery() -> ResultType<()> { - let mut socket = udp::bind_multicast(Some(get_multicast_addr()))?; - log::info!("lan discovery listener started"); + 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); loop { select! { - Some(Ok((bytes, addr))) = socket.next() => { + 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)) => { @@ -553,18 +571,30 @@ async fn lan_discovery() -> ResultType<()> { #[tokio::main(flavor = "current_thread")] pub async fn discover() -> ResultType<()> { - let mut socket = udp::bind_multicast(None)?; + 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); + } + } + } + }); + } let mut msg_out = Message::new(); let peer = PeerDiscovery { cmd: "ping".to_owned(), ..Default::default() }; msg_out.set_peer_discovery(peer); - let maddr = SocketAddr::V4(get_multicast_addr()); - socket.send(&msg_out, maddr).await?; - log::debug!("discover ping sent"); - const TIMER_OUT: Duration = Duration::from_millis(100); - let mut timer = interval(TIMER_OUT); + for i in 0..sockets.len() { + let socket = &mut sockets[i]; + socket.send(&msg_out, maddr).await?; + } + log::info!("discover ping sent"); let mut last_recv_time = Instant::now(); let mut last_write_time = Instant::now(); let mut last_write_n = 0; @@ -572,8 +602,9 @@ pub async fn discover() -> ResultType<()> { let mut peers = Vec::new(); let mac = get_mac(); loop { - select! { - Some(Ok((bytes, _))) = socket.next() => { + 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)) => { @@ -587,20 +618,18 @@ pub async fn discover() -> ResultType<()> { _ => {} } } - }, - _ = timer.tick() => { - if last_write_time.elapsed().as_millis() > 300 && last_write_n != peers.len() { - config::LanPeers::store(serde_json::to_string(&peers)?); - last_write_time = Instant::now(); - last_write_n = peers.len(); - } - if last_recv_time.elapsed().as_millis() > 3_000 { - break; - } } } + if last_write_time.elapsed().as_millis() > 300 && last_write_n != peers.len() { + config::LanPeers::store(serde_json::to_string(&peers)?); + last_write_time = Instant::now(); + last_write_n = peers.len(); + } + if last_recv_time.elapsed().as_millis() > 3_000 { + break; + } } - log::debug!("discover ping done"); + log::info!("discover ping done"); config::LanPeers::store(serde_json::to_string(&peers)?); Ok(()) } diff --git a/src/server.rs b/src/server.rs index 70e254fb2..8a507d72b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,4 +1,6 @@ -use crate::ipc::{ConnectionTmpl, Data}; +#[cfg(target_os = "macos")] +use crate::ipc::ConnectionTmpl; +use crate::ipc::Data; use connection::{ConnInner, Connection}; use hbb_common::{ allow_err, @@ -15,14 +17,14 @@ use hbb_common::{ }; #[cfg(target_os = "macos")] use notify::{watcher, RecursiveMode, Watcher}; +#[cfg(target_os = "macos")] use parity_tokio_ipc::ConnectionClient; use service::{GenericService, Service, ServiceTmpl, Subscriber}; -use std::path::PathBuf; -use std::time::Duration; use std::{ collections::HashMap, net::SocketAddr, sync::{Arc, Mutex, RwLock, Weak}, + time::Duration, }; mod audio_service; @@ -261,7 +263,7 @@ pub fn check_zombie() { } } drop(lock); - std::thread::sleep(std::time::Duration::from_millis(100)); + std::thread::sleep(Duration::from_millis(100)); }); } @@ -407,7 +409,7 @@ async fn sync_config_to_user(conn: &mut ConnectionTmpl) -> Res #[cfg(target_os = "macos")] async fn sync_config_to_root( conn: &mut ConnectionTmpl, - from: PathBuf, + from: std::path::PathBuf, ) -> ResultType<()> { allow_err!( conn.send(&Data::SyncConfigToRootReq {