change back to broadcast, because multicast has big problem if multiple

interface with 0.0.0.0 binding
This commit is contained in:
rustdesk 2022-01-14 23:02:08 +08:00
parent 0a2bc1cf8a
commit 95239fc148
4 changed files with 117 additions and 362 deletions

324
Cargo.lock generated
View File

@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5915f52fe2cf65e83924d037b6c5290b7cee097c6b5c8700746e6168a343fd6b" checksum = "5915f52fe2cf65e83924d037b6c5290b7cee097c6b5c8700746e6168a343fd6b"
dependencies = [ dependencies = [
"alsa-sys", "alsa-sys",
"bitflags 1.3.2", "bitflags",
"libc", "libc",
"nix 0.23.1", "nix 0.23.1",
] ]
@ -69,7 +69,7 @@ dependencies = [
"android_log-sys", "android_log-sys",
"env_logger 0.8.4", "env_logger 0.8.4",
"lazy_static", "lazy_static",
"log 0.4.14", "log",
] ]
[[package]] [[package]]
@ -96,7 +96,7 @@ dependencies = [
"clipboard-win", "clipboard-win",
"core-graphics 0.22.3", "core-graphics 0.22.3",
"image", "image",
"log 0.4.14", "log",
"objc", "objc",
"objc-foundation", "objc-foundation",
"objc_id", "objc_id",
@ -126,7 +126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812b4911e210bd51b24596244523c856ca749e6223c50a7fbbba3f89ee37c426" checksum = "812b4911e210bd51b24596244523c856ca749e6223c50a7fbbba3f89ee37c426"
dependencies = [ dependencies = [
"atk-sys", "atk-sys",
"bitflags 1.3.2", "bitflags",
"glib", "glib",
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -195,7 +195,7 @@ version = "0.56.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cexpr 0.4.0", "cexpr 0.4.0",
"clang-sys", "clang-sys",
"lazy_static", "lazy_static",
@ -214,14 +214,14 @@ version = "0.59.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cexpr 0.6.0", "cexpr 0.6.0",
"clang-sys", "clang-sys",
"clap", "clap",
"env_logger 0.9.0", "env_logger 0.9.0",
"lazy_static", "lazy_static",
"lazycell", "lazycell",
"log 0.4.14", "log",
"peeking_take_while", "peeking_take_while",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -231,12 +231,6 @@ dependencies = [
"which 4.2.2", "which 4.2.2",
] ]
[[package]]
name = "bitflags"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -288,7 +282,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5c0f2e047e8ca53d0ff249c54ae047931d7a6ebe05d00af73e0ffeb6e34bdb8" checksum = "c5c0f2e047e8ca53d0ff249c54ae047931d7a6ebe05d00af73e0ffeb6e34bdb8"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cairo-sys-rs", "cairo-sys-rs",
"glib", "glib",
"glib-sys", "glib-sys",
@ -359,7 +353,7 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90"
dependencies = [ dependencies = [
"glob 0.3.0", "glob",
"libc", "libc",
"libloading", "libloading",
] ]
@ -372,7 +366,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
"bitflags 1.3.2", "bitflags",
"strsim 0.8.0", "strsim 0.8.0",
"textwrap", "textwrap",
"unicode-width", "unicode-width",
@ -410,7 +404,7 @@ version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
] ]
[[package]] [[package]]
@ -428,7 +422,7 @@ version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7" checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"block", "block",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-graphics 0.21.0", "core-graphics 0.21.0",
@ -443,7 +437,7 @@ version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832" checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"block", "block",
"cocoa-foundation", "cocoa-foundation",
"core-foundation 0.9.2", "core-foundation 0.9.2",
@ -459,7 +453,7 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"block", "block",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-graphics-types", "core-graphics-types",
@ -532,7 +526,7 @@ version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"core-foundation 0.7.0", "core-foundation 0.7.0",
"foreign-types", "foreign-types",
"libc", "libc",
@ -544,7 +538,7 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978" checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"foreign-types", "foreign-types",
"libc", "libc",
@ -556,7 +550,7 @@ version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-graphics-types", "core-graphics-types",
"foreign-types", "foreign-types",
@ -569,7 +563,7 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"foreign-types", "foreign-types",
"libc", "libc",
@ -581,7 +575,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"coreaudio-sys", "coreaudio-sys",
] ]
@ -1020,7 +1014,7 @@ version = "0.0.14"
dependencies = [ dependencies = [
"core-graphics 0.22.3", "core-graphics 0.22.3",
"libc", "libc",
"log 0.4.14", "log",
"objc", "objc",
"pkg-config", "pkg-config",
"serde 1.0.133", "serde 1.0.133",
@ -1035,7 +1029,7 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
dependencies = [ dependencies = [
"log 0.4.14", "log",
"regex", "regex",
] ]
@ -1047,7 +1041,7 @@ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
dependencies = [ dependencies = [
"atty", "atty",
"humantime", "humantime",
"log 0.4.14", "log",
"regex", "regex",
"termcolor", "termcolor",
] ]
@ -1126,9 +1120,9 @@ checksum = "0b51b4517f4422bfa0515dafcc10b4cc4cd3953d69a19608fd74afb3b19e227c"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
"glob 0.3.0", "glob",
"lazy_static", "lazy_static",
"log 0.4.14", "log",
"regex", "regex",
"rustversion", "rustversion",
"thiserror", "thiserror",
@ -1162,7 +1156,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"fsevent-sys", "fsevent-sys",
] ]
@ -1187,7 +1181,7 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"fuchsia-zircon-sys", "fuchsia-zircon-sys",
] ]
@ -1301,7 +1295,7 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db00839b2a68a7a10af3fa28dfb3febaba3a20c3a9ac2425a33b7df1f84a6b7d" checksum = "db00839b2a68a7a10af3fa28dfb3febaba3a20c3a9ac2425a33b7df1f84a6b7d"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cairo-rs", "cairo-rs",
"cairo-sys-rs", "cairo-sys-rs",
"gdk-pixbuf", "gdk-pixbuf",
@ -1403,7 +1397,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb60242bfff700772dae5d9e3a1f7aa2e4ebccf18b89662a16acb2822568561" checksum = "1fb60242bfff700772dae5d9e3a1f7aa2e4ebccf18b89662a16acb2822568561"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"futures", "futures",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -1437,7 +1431,7 @@ version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c685013b7515e668f1b57a165b009d4d28cb139a8a989bbd699c10dad29d0c5" checksum = "0c685013b7515e668f1b57a165b009d4d28cb139a8a989bbd699c10dad29d0c5"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-executor", "futures-executor",
@ -1476,12 +1470,6 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.0" version = "0.3.0"
@ -1505,7 +1493,7 @@ version = "0.16.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff5d0f7ff308ae37e6eb47b6ded17785bdea06e438a708cd09e0288c1862f33" checksum = "9ff5d0f7ff308ae37e6eb47b6ded17785bdea06e438a708cd09e0288c1862f33"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -1529,7 +1517,7 @@ version = "0.16.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc80888271338c3ede875d8cafc452eb207476ff5539dcbe0018a8f5b827af0e" checksum = "cc80888271338c3ede875d8cafc452eb207476ff5539dcbe0018a8f5b827af0e"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"glib", "glib",
@ -1562,7 +1550,7 @@ version = "0.16.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bafd01c56f59cb10f4b5a10f97bb4bdf8c2b2784ae5b04da7e2d400cf6e6afcf" checksum = "bafd01c56f59cb10f4b5a10f97bb4bdf8c2b2784ae5b04da7e2d400cf6e6afcf"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"glib", "glib",
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -1603,7 +1591,7 @@ version = "0.16.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7bbb1485d87469849ec45c08e03c2f280d3ea20ff3c439d03185be54e3ce98e" checksum = "f7bbb1485d87469849ec45c08e03c2f280d3ea20ff3c439d03185be54e3ce98e"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"glib", "glib",
@ -1639,7 +1627,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f022f2054072b3af07666341984562c8e626a79daa8be27b955d12d06a5ad6a" checksum = "2f022f2054072b3af07666341984562c8e626a79daa8be27b955d12d06a5ad6a"
dependencies = [ dependencies = [
"atk", "atk",
"bitflags 1.3.2", "bitflags",
"cairo-rs", "cairo-rs",
"cairo-sys-rs", "cairo-sys-rs",
"cc", "cc",
@ -1692,7 +1680,7 @@ dependencies = [
"futures", "futures",
"futures-util", "futures-util",
"lazy_static", "lazy_static",
"log 0.4.14", "log",
"mac_address", "mac_address",
"protobuf", "protobuf",
"protobuf-codegen-pure", "protobuf-codegen-pure",
@ -1789,7 +1777,7 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"inotify-sys", "inotify-sys",
"libc", "libc",
] ]
@ -1821,15 +1809,6 @@ dependencies = [
"libc", "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]] [[package]]
name = "itertools" name = "itertools"
version = "0.9.0" version = "0.9.0"
@ -1866,7 +1845,7 @@ dependencies = [
"cesu8", "cesu8",
"combine", "combine",
"jni-sys", "jni-sys",
"log 0.4.14", "log",
"thiserror", "thiserror",
"walkdir", "walkdir",
] ]
@ -1932,7 +1911,7 @@ dependencies = [
"gtk", "gtk",
"gtk-sys", "gtk-sys",
"libappindicator-sys", "libappindicator-sys",
"log 0.4.14", "log",
] ]
[[package]] [[package]]
@ -1975,7 +1954,7 @@ version = "2.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86835d7763ded6bc16b6c0061ec60214da7550dfcd4ef93745f6f0096129676a" checksum = "86835d7763ded6bc16b6c0061ec60214da7550dfcd4ef93745f6f0096129676a"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"libc", "libc",
"libpulse-sys", "libpulse-sys",
"num-derive", "num-derive",
@ -2047,15 +2026,6 @@ dependencies = [
"scopeguard", "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]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.14"
@ -2163,7 +2133,7 @@ dependencies = [
"iovec", "iovec",
"kernel32-sys", "kernel32-sys",
"libc", "libc",
"log 0.4.14", "log",
"miow 0.2.2", "miow 0.2.2",
"net2", "net2",
"slab", "slab",
@ -2177,7 +2147,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
dependencies = [ dependencies = [
"libc", "libc",
"log 0.4.14", "log",
"miow 0.3.7", "miow 0.3.7",
"ntapi", "ntapi",
"winapi 0.3.9", "winapi 0.3.9",
@ -2190,7 +2160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
dependencies = [ dependencies = [
"lazycell", "lazycell",
"log 0.4.14", "log",
"mio 0.6.23", "mio 0.6.23",
"slab", "slab",
] ]
@ -2201,7 +2171,7 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656"
dependencies = [ dependencies = [
"log 0.4.14", "log",
"mio 0.6.23", "mio 0.6.23",
"miow 0.3.7", "miow 0.3.7",
"winapi 0.3.9", "winapi 0.3.9",
@ -2249,7 +2219,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d64d6af06fde0e527b1ba5c7b79a6cc89cfc46325b0b2887dffe8f70197e0c3c" checksum = "d64d6af06fde0e527b1ba5c7b79a6cc89cfc46325b0b2887dffe8f70197e0c3c"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"jni-sys", "jni-sys",
"ndk-sys 0.2.2", "ndk-sys 0.2.2",
"num_enum", "num_enum",
@ -2262,7 +2232,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"jni-sys", "jni-sys",
"ndk-sys 0.3.0", "ndk-sys 0.3.0",
"num_enum", "num_enum",
@ -2277,7 +2247,7 @@ checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"log 0.4.14", "log",
"ndk 0.4.0", "ndk 0.4.0",
"ndk-macro 0.2.0", "ndk-macro 0.2.0",
"ndk-sys 0.2.2", "ndk-sys 0.2.2",
@ -2291,7 +2261,7 @@ checksum = "04c0d14b0858eb9962a5dac30b809b19f19da7e4547d64af2b0bb051d2e55d79"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"log 0.4.14", "log",
"ndk 0.6.0", "ndk 0.6.0",
"ndk-macro 0.3.0", "ndk-macro 0.3.0",
"ndk-sys 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cc", "cc",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
@ -2367,7 +2337,7 @@ version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cc", "cc",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
@ -2380,7 +2350,7 @@ version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"cc", "cc",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
@ -2414,7 +2384,7 @@ version = "4.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"filetime", "filetime",
"fsevent", "fsevent",
"fsevent-sys", "fsevent-sys",
@ -2612,7 +2582,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9937068580bebd8ced19975938573803273ccbcbd598c58d4906efd4ac87c438" checksum = "9937068580bebd8ced19975938573803273ccbcbd598c58d4906efd4ac87c438"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"glib", "glib",
"glib-sys", "glib-sys",
"gobject-sys", "gobject-sys",
@ -2640,7 +2610,7 @@ source = "git+https://github.com/open-trade/parity-tokio-ipc#52515618bd30ea8101b
dependencies = [ dependencies = [
"futures", "futures",
"libc", "libc",
"log 0.4.14", "log",
"mio-named-pipes", "mio-named-pipes",
"miow 0.4.0", "miow 0.4.0",
"rand 0.8.4", "rand 0.8.4",
@ -2767,101 +2737,13 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" 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]] [[package]]
name = "png" name = "png"
version = "0.16.8" version = "0.16.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"crc32fast", "crc32fast",
"deflate", "deflate",
"miniz_oxide 0.3.7", "miniz_oxide 0.3.7",
@ -2937,7 +2819,7 @@ version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [ dependencies = [
"unicode-xid 0.2.2", "unicode-xid",
] ]
[[package]] [[package]]
@ -2991,7 +2873,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f1f8b318a54d18fbe542513331e058f4f8ce6502e542e057c50c7e5e803fdab" checksum = "1f1f8b318a54d18fbe542513331e058f4f8ce6502e542e057c50c7e5e803fdab"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log 0.4.14", "log",
"thiserror", "thiserror",
"which 4.2.2", "which 4.2.2",
] ]
@ -3004,7 +2886,7 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"darwin-libproc", "darwin-libproc",
"derive_more", "derive_more",
"glob 0.3.0", "glob",
"mach", "mach",
"nix 0.23.1", "nix 0.23.1",
"num_cpus", "num_cpus",
@ -3284,7 +3166,7 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
] ]
[[package]] [[package]]
@ -3375,7 +3257,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29cf25e25288b595458df0e00c3065db08c31afe4b4e5a74cbfc5a9b8e763cd" checksum = "d29cf25e25288b595458df0e00c3065db08c31afe4b4e5a74cbfc5a9b8e763cd"
dependencies = [ dependencies = [
"log 0.4.14", "log",
"num-complex", "num-complex",
"num-integer", "num-integer",
"num-traits 0.2.14", "num-traits 0.2.14",
@ -3412,12 +3294,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]] [[package]]
name = "rustdesk" name = "rustdesk"
version = "1.1.8" version = "1.1.8"
@ -3453,7 +3329,6 @@ dependencies = [
"notify", "notify",
"objc", "objc",
"parity-tokio-ipc", "parity-tokio-ipc",
"pnet",
"psutil", "psutil",
"rdev", "rdev",
"repng", "repng",
@ -3620,7 +3495,7 @@ version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"core-foundation 0.9.2", "core-foundation 0.9.2",
"core-foundation-sys 0.8.3", "core-foundation-sys 0.8.3",
"libc", "libc",
@ -3843,7 +3718,7 @@ checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"unicode-xid 0.2.2", "unicode-xid",
] ]
[[package]] [[package]]
@ -3855,56 +3730,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
"unicode-xid 0.2.2", "unicode-xid",
]
[[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]] [[package]]
@ -3944,7 +3770,7 @@ dependencies = [
"gtk", "gtk",
"libappindicator", "libappindicator",
"libc", "libc",
"log 0.4.14", "log",
"winapi 0.3.9", "winapi 0.3.9",
] ]
@ -3973,16 +3799,6 @@ dependencies = [
"winapi 0.3.9", "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]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.2" version = "1.1.2"
@ -4129,7 +3945,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-io", "futures-io",
"futures-sink", "futures-sink",
"log 0.4.14", "log",
"pin-project-lite", "pin-project-lite",
"slab", "slab",
"tokio", "tokio",
@ -4210,12 +4026,6 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.2" version = "0.2.2"
@ -4290,7 +4100,7 @@ checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
"log 0.4.14", "log",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -4465,7 +4275,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c643e10139d127d30d6d753398c8a6f0a43532e8370f6c9d29ebbff29b984ab" checksum = "0c643e10139d127d30d6d753398c8a6f0a43532e8370f6c9d29ebbff29b984ab"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"err-derive", "err-derive",
"widestring", "widestring",
"winapi 0.3.9", "winapi 0.3.9",
@ -4598,7 +4408,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c" checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c"
dependencies = [ dependencies = [
"libc", "libc",
"log 0.4.14", "log",
"quick-xml", "quick-xml",
] ]

View File

@ -43,7 +43,6 @@ uuid = { version = "0.8", features = ["v4"] }
clap = "2.34" clap = "2.34"
rpassword = "5.0" rpassword = "5.0"
base64 = "0.13" base64 = "0.13"
pnet = "0.27"
[target.'cfg(not(any(target_os = "android")))'.dependencies] [target.'cfg(not(any(target_os = "android")))'.dependencies]
cpal = { git = "https://github.com/open-trade/cpal" } cpal = { git = "https://github.com/open-trade/cpal" }

View File

@ -3,8 +3,8 @@ use anyhow::anyhow;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};
use protobuf::Message; use protobuf::Message;
use socket2::{Domain, Protocol, Socket, Type}; use socket2::{Domain, Socket, Type};
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::net::SocketAddr;
use tokio::net::{ToSocketAddrs, UdpSocket}; use tokio::net::{ToSocketAddrs, UdpSocket};
use tokio_socks::{udp::Socks5UdpFramed, IntoTargetAddr, TargetAddr, ToProxyAddrs}; use tokio_socks::{udp::Socks5UdpFramed, IntoTargetAddr, TargetAddr, ToProxyAddrs};
use tokio_util::{codec::BytesCodec, udp::UdpFramed}; 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<SocketAddrV4>,
interface: Ipv4Addr,
) -> ResultType<FramedSocket> {
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(),
)))
}

View File

@ -12,11 +12,11 @@ use hbb_common::{
self, select, self, select,
time::{interval, Duration}, time::{interval, Duration},
}, },
udp::{self, FramedSocket}, udp::FramedSocket,
AddrMangle, IntoTargetAddr, ResultType, TargetAddr, AddrMangle, IntoTargetAddr, ResultType, TargetAddr,
}; };
use std::{ use std::{
net::{SocketAddr, SocketAddrV4}, net::SocketAddr,
sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Mutex, Arc, Mutex,
@ -59,8 +59,8 @@ impl RendezvousMediator {
tokio::spawn(async move { tokio::spawn(async move {
allow_err!(direct_server(server_cloned).await); allow_err!(direct_server(server_cloned).await);
}); });
tokio::spawn(async move { std::thread::spawn(move || {
allow_err!(lan_discovery().await); allow_err!(lan_discovery());
}); });
loop { loop {
Config::reset_online(); Config::reset_online();
@ -505,9 +505,9 @@ async fn direct_server(server: ServerPtr) -> ResultType<()> {
} }
} }
pub fn get_multicast_addr() -> SocketAddrV4 { #[inline]
let port = (RENDEZVOUS_PORT + 3) as u16; pub fn get_broadcast_port() -> u16 {
SocketAddrV4::new([239, 255, 42, 98].into(), port) (RENDEZVOUS_PORT + 3) as _
} }
pub fn get_mac() -> String { pub fn get_mac() -> String {
@ -518,82 +518,51 @@ pub fn get_mac() -> String {
} }
} }
async fn lan_discovery() -> ResultType<()> { fn lan_discovery() -> ResultType<()> {
let mut jobs = Vec::new(); let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
for iface in pnet::datalink::interfaces() { let socket = std::net::UdpSocket::bind(addr)?;
for i in 0..iface.ips.len() { socket.set_read_timeout(Some(std::time::Duration::from_millis(1000)))?;
let x = iface.ips[i]; log::info!("lan discovery listener started");
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 { loop {
select! { let mut buf = [0; 2048];
Some(Ok((bytes, addr))) = socket.next_timeout(1000) => { if let Ok((len, addr)) = socket.recv_from(&mut buf) {
if let Ok(msg_in) = Message::parse_from_bytes(&bytes) { if let Ok(msg_in) = Message::parse_from_bytes(&buf[0..len]) {
match msg_in.union { match msg_in.union {
Some(rendezvous_message::Union::peer_discovery(p)) => { Some(rendezvous_message::Union::peer_discovery(p)) => {
if p.cmd == "ping" { if p.cmd == "ping" {
let mut msg_out = Message::new(); let mut msg_out = Message::new();
let peer = PeerDiscovery { let peer = PeerDiscovery {
cmd: "pong".to_owned(), cmd: "pong".to_owned(),
mac: get_mac(), mac: get_mac(),
id: Config::get_id(), id: Config::get_id(),
hostname: whoami::hostname(), hostname: whoami::hostname(),
username: crate::platform::get_active_username(), username: crate::platform::get_active_username(),
platform: whoami::platform().to_string(), platform: whoami::platform().to_string(),
..Default::default() ..Default::default()
}; };
msg_out.set_peer_discovery(peer); msg_out.set_peer_discovery(peer);
socket.send(&msg_out, addr).await?; socket.send_to(&msg_out.write_to_bytes()?, addr).ok();
}
} }
_ => {}
} }
_ => {}
} }
} }
else => {} // avoid select! all branches disabled panic
} }
} }
} }
#[tokio::main(flavor = "current_thread")] pub fn discover() -> ResultType<()> {
pub async fn discover() -> ResultType<()> { let addr = SocketAddr::from(([0, 0, 0, 0], 0));
let maddr = SocketAddr::V4(get_multicast_addr()); let socket = std::net::UdpSocket::bind(addr)?;
let mut sockets = Vec::new(); socket.set_broadcast(true)?;
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 mut msg_out = Message::new();
let peer = PeerDiscovery { let peer = PeerDiscovery {
cmd: "ping".to_owned(), cmd: "ping".to_owned(),
..Default::default() ..Default::default()
}; };
msg_out.set_peer_discovery(peer); msg_out.set_peer_discovery(peer);
for i in 0..sockets.len() { let maddr = SocketAddr::from(([255, 255, 255, 255], 3000));
let socket = &mut sockets[i]; socket.send_to(&msg_out.write_to_bytes()?, maddr)?;
socket.send(&msg_out, maddr).await?;
}
log::info!("discover ping sent"); log::info!("discover ping sent");
let mut last_recv_time = Instant::now(); let mut last_recv_time = Instant::now();
let mut last_write_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) // to-do: load saved peers, and update incrementally (then we can see offline)
let mut peers = Vec::new(); let mut peers = Vec::new();
let mac = get_mac(); let mac = get_mac();
socket.set_read_timeout(Some(std::time::Duration::from_millis(10)))?;
loop { loop {
for i in 0..sockets.len() { let mut buf = [0; 2048];
let socket = &mut sockets[i]; if let Ok((len, _)) = socket.recv_from(&mut buf) {
if let Some(Ok((bytes, _))) = socket.next_timeout(10).await { if let Ok(msg_in) = Message::parse_from_bytes(&buf[0..len]) {
if let Ok(msg_in) = Message::parse_from_bytes(&bytes) { match msg_in.union {
match msg_in.union { Some(rendezvous_message::Union::peer_discovery(p)) => {
Some(rendezvous_message::Union::peer_discovery(p)) => { last_recv_time = Instant::now();
last_recv_time = Instant::now(); if p.cmd == "pong" {
if p.cmd == "pong" { if p.mac != mac {
if p.mac != mac { peers.push((p.id, p.username, p.hostname, p.platform));
peers.push((p.id, p.username, p.hostname, p.platform));
}
} }
} }
_ => {}
} }
_ => {}
} }
} }
} }