Add the main menu #31

Merged
CoCo_Sol merged 25 commits from main-menu into main 2024-02-09 23:42:37 +00:00
3 changed files with 509 additions and 22 deletions
Showing only changes of commit 24dadce9cf - Show all commits

362
Cargo.lock generated
View file

@ -3,6 +3,7 @@
version = 3 version = 3
[[package]] [[package]]
<<<<<<< HEAD
name = "ab_glyph" name = "ab_glyph"
version = "0.2.23" version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -344,6 +345,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
=======
name = "aead"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
dependencies = [
"crypto-common",
"generic-array",
]
[[package]]
name = "aes"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "aes-gcm"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]]
name = "attohttpc"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdb8867f378f33f78a811a8eb9bf108ad99430d7aad43315dd9319c827ef6247"
dependencies = [
"http",
"log",
"url",
"wildmatch",
]
[[package]]
>>>>>>> origin/main
name = "base64" name = "base64"
version = "0.21.7" version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -352,6 +402,7 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]] [[package]]
name = "bevnet" name = "bevnet"
version = "0.2.0" version = "0.2.0"
<<<<<<< HEAD
[[package]] [[package]]
name = "bevy" name = "bevy"
@ -1207,11 +1258,19 @@ dependencies = [
"futures-lite 2.2.0", "futures-lite 2.2.0",
"piper", "piper",
"tracing", "tracing",
=======
dependencies = [
"aes-gcm",
"base64",
"igd",
"local-ip-address",
>>>>>>> origin/main
] ]
[[package]] [[package]]
name = "border-wars" name = "border-wars"
version = "0.1.0" version = "0.1.0"
<<<<<<< HEAD
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_egui", "bevy_egui",
@ -1242,6 +1301,8 @@ dependencies = [
"quote", "quote",
"syn 2.0.48", "syn 2.0.48",
] ]
=======
>>>>>>> origin/main
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -1256,6 +1317,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]] [[package]]
<<<<<<< HEAD
name = "cc" name = "cc"
version = "1.0.83" version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1281,12 +1343,15 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
<<<<<<< HEAD
name = "cfg_aliases" name = "cfg_aliases"
version = "0.1.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1399,10 +1464,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
=======
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"inout",
]
[[package]]
name = "cpufeatures"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
dependencies = [
>>>>>>> origin/main
"libc", "libc",
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.6" version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1554,6 +1637,25 @@ dependencies = [
"ahash", "ahash",
"epaint", "epaint",
"nohash-hasher", "nohash-hasher",
=======
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"rand_core",
"typenum",
]
[[package]]
name = "ctr"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
dependencies = [
"cipher",
>>>>>>> origin/main
] ]
[[package]] [[package]]
@ -1563,6 +1665,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]] [[package]]
<<<<<<< HEAD
name = "emath" name = "emath"
version = "0.24.1" version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1720,12 +1823,15 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
<<<<<<< HEAD
name = "foreign-types" name = "foreign-types"
version = "0.3.2" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1768,6 +1874,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "form_urlencoded" name = "form_urlencoded"
version = "1.2.1" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1777,6 +1885,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "futures-core" name = "futures-core"
version = "0.3.30" version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -1824,6 +1933,15 @@ checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177"
dependencies = [ dependencies = [
"libc", "libc",
"winapi", "winapi",
=======
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
>>>>>>> origin/main
] ]
[[package]] [[package]]
@ -1833,6 +1951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
<<<<<<< HEAD
"js-sys", "js-sys",
"libc", "libc",
"wasi", "wasi",
@ -2077,6 +2196,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
=======
"libc",
"wasi",
]
[[package]]
name = "ghash"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40"
dependencies = [
"opaque-debug",
"polyval",
]
[[package]]
name = "http"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb"
dependencies = [
"bytes",
"fnv",
"itoa",
>>>>>>> origin/main
] ]
[[package]] [[package]]
@ -2090,6 +2234,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "image" name = "image"
version = "0.24.8" version = "0.24.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -2178,6 +2323,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
dependencies = [ dependencies = [
"either", "either",
=======
name = "igd"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "556b5a75cd4adb7c4ea21c64af1c48cefb2ce7d43dc4352c720a1fe47c21f355"
dependencies = [
"attohttpc",
"log",
"rand",
"url",
"xmltree",
]
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array",
>>>>>>> origin/main
] ]
[[package]] [[package]]
@ -2187,6 +2353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]] [[package]]
<<<<<<< HEAD
name = "jni" name = "jni"
version = "0.19.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -2304,12 +2471,15 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "libc" name = "libc"
version = "0.2.153" version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]] [[package]]
<<<<<<< HEAD
name = "libloading" name = "libloading"
version = "0.7.4" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -2358,6 +2528,17 @@ checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"scopeguard", "scopeguard",
=======
name = "local-ip-address"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "612ed4ea9ce5acfb5d26339302528a5e1e59dfed95e9e11af3c083236ff1d15d"
dependencies = [
"libc",
"neli",
"thiserror",
"windows-sys",
>>>>>>> origin/main
] ]
[[package]] [[package]]
@ -2367,6 +2548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]] [[package]]
<<<<<<< HEAD
name = "mach2" name = "mach2"
version = "0.4.2" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -2828,6 +3010,37 @@ name = "paste"
version = "1.0.14" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
=======
name = "neli"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1100229e06604150b3becd61a4965d5c70f3be1759544ea7274166f4be41ef43"
dependencies = [
"byteorder",
"libc",
"log",
"neli-proc-macros",
]
[[package]]
name = "neli-proc-macros"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168194d373b1e134786274020dae7fc5513d565ea2ebb9bc9ff17ffb69106d4"
dependencies = [
"either",
"proc-macro2",
"quote",
"serde",
"syn 1.0.109",
]
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
>>>>>>> origin/main
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
@ -2836,6 +3049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]] [[package]]
<<<<<<< HEAD
name = "petgraph" name = "petgraph"
version = "0.6.4" version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -2899,6 +3113,24 @@ dependencies = [
"once_cell", "once_cell",
"toml_edit 0.19.15", "toml_edit 0.19.15",
] ]
=======
name = "polyval"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug",
"universal-hash",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
>>>>>>> origin/main
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
@ -2910,12 +3142,15 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "profiling" name = "profiling"
version = "1.0.14" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f0f7f43585c34e4fdd7497d746bc32e14458cf11c69341cc0587b1d825dde42" checksum = "0f0f7f43585c34e4fdd7497d746bc32e14458cf11c69341cc0587b1d825dde42"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "quote" name = "quote"
version = "1.0.35" version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -2925,6 +3160,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "radsort" name = "radsort"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3089,6 +3325,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
=======
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
>>>>>>> origin/main
name = "serde" name = "serde"
version = "1.0.196" version = "1.0.196"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3109,6 +3377,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "serde_json" name = "serde_json"
version = "1.0.113" version = "1.0.113"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3203,6 +3472,12 @@ name = "svg_fmt"
version = "0.4.1" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2" checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2"
=======
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
>>>>>>> origin/main
[[package]] [[package]]
name = "syn" name = "syn"
@ -3227,6 +3502,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "sysinfo" name = "sysinfo"
version = "0.29.11" version = "0.29.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3262,6 +3538,8 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "thiserror" name = "thiserror"
version = "1.0.56" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3271,6 +3549,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "thiserror-core" name = "thiserror-core"
version = "1.0.50" version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3291,6 +3570,8 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.56" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3302,6 +3583,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "thread_local" name = "thread_local"
version = "1.1.7" version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3323,6 +3605,8 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3338,6 +3622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
<<<<<<< HEAD
name = "toml_datetime" name = "toml_datetime"
version = "0.6.5" version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3463,6 +3748,12 @@ dependencies = [
"cfg-if", "cfg-if",
"static_assertions", "static_assertions",
] ]
=======
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
>>>>>>> origin/main
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
@ -3486,6 +3777,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "unicode-width" name = "unicode-width"
version = "0.1.11" version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3496,6 +3788,16 @@ name = "unicode-xid"
version = "0.2.4" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
=======
name = "universal-hash"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"crypto-common",
"subtle",
]
>>>>>>> origin/main
[[package]] [[package]]
name = "url" name = "url"
@ -3509,6 +3811,7 @@ dependencies = [
] ]
[[package]] [[package]]
<<<<<<< HEAD
name = "uuid" name = "uuid"
version = "1.7.0" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3531,12 +3834,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
<<<<<<< HEAD
name = "waker-fn" name = "waker-fn"
version = "1.1.1" version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3553,12 +3859,15 @@ dependencies = [
] ]
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
<<<<<<< HEAD
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.91" version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3891,6 +4200,12 @@ checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [ dependencies = [
"windows-targets 0.42.2", "windows-targets 0.42.2",
] ]
=======
name = "wildmatch"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f44b95f62d34113cf558c93511ac93027e03e9c29a60dd0fd70e6e025c7270a"
>>>>>>> origin/main
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
@ -3898,6 +4213,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [ dependencies = [
<<<<<<< HEAD
"windows-targets 0.48.5", "windows-targets 0.48.5",
] ]
@ -3923,6 +4239,9 @@ dependencies = [
"windows_x86_64_gnu 0.42.2", "windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2", "windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2", "windows_x86_64_msvc 0.42.2",
=======
"windows-targets",
>>>>>>> origin/main
] ]
[[package]] [[package]]
@ -3931,6 +4250,7 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [ dependencies = [
<<<<<<< HEAD
"windows_aarch64_gnullvm 0.48.5", "windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5", "windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5", "windows_i686_gnu 0.48.5",
@ -3962,12 +4282,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]] [[package]]
=======
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
>>>>>>> origin/main
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3980,12 +4313,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -3998,12 +4334,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -4016,12 +4355,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -4034,12 +4376,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -4052,12 +4397,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -4070,12 +4418,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]] [[package]]
<<<<<<< HEAD
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -4160,12 +4511,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a"
[[package]] [[package]]
=======
>>>>>>> origin/main
name = "xml-rs" name = "xml-rs"
version = "0.8.19" version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a"
[[package]] [[package]]
<<<<<<< HEAD
name = "zerocopy" name = "zerocopy"
version = "0.7.32" version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
@ -4183,4 +4537,12 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.48", "syn 2.0.48",
=======
name = "xmltree"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7d8a75eaf6557bb84a65ace8609883db44a29951042ada9b393151532e41fcb"
dependencies = [
"xml-rs",
>>>>>>> origin/main
] ]

View file

@ -10,3 +10,9 @@ categories = ["network-programming", "game-development"]
[lints] [lints]
workspace = true workspace = true
[dependencies]
local-ip-address = "0.5.7"
aes-gcm = "0.10.3"
base64 = "0.21.7"
igd = "0.12.1"

View file

@ -2,20 +2,26 @@
use std::collections::LinkedList; use std::collections::LinkedList;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::net::{TcpListener, TcpStream, ToSocketAddrs}; use std::net::{IpAddr, Ipv4Addr, SocketAddrV4, TcpListener, TcpStream};
use aes_gcm::aead::{Aead, AeadCore, KeyInit, OsRng};
use aes_gcm::{Aes128Gcm, Key, Nonce};
use base64::prelude::*;
use igd::{Gateway, PortMappingProtocol};
use local_ip_address::local_ip;
/// A non-blocking tcp connection. /// A non-blocking tcp connection.
/// ///
/// # Example /// # Example
/// ///
/// ```rust /// ```no_run
/// use std::io; /// use std::io;
/// ///
/// use bevnet::{Connection, Listener}; /// use bevnet::{Connection, Listener};
/// ///
/// # fn main() -> io::Result<()> { /// # fn main() -> io::Result<()> {
/// let listener = Listener::bind("127.0.0.1:23732")?; /// let listener = Listener::new()?;
/// let mut connection = Connection::connect("127.0.0.1:23732")?; /// let mut connection = Connection::connect(&listener.connection_string())?;
/// ///
/// // The accept operation is not blocking. So we need to loop here. /// // The accept operation is not blocking. So we need to loop here.
/// let mut server_connection; /// let mut server_connection;
@ -56,6 +62,9 @@ pub struct Connection {
/// `None` if the message length is not yet received. /// `None` if the message length is not yet received.
receive_message_len: Option<u16>, receive_message_len: Option<u16>,
/// The nonce used for encryption.
receive_message_nonce: Option<Vec<u8>>,
/// The length of the received byte block. /// The length of the received byte block.
/// ///
/// Used by [Connection::receive_partial] to determine if the block is /// Used by [Connection::receive_partial] to determine if the block is
@ -64,26 +73,52 @@ pub struct Connection {
/// The buffer used to receive a byte block. /// The buffer used to receive a byte block.
receive_buffer: Vec<u8>, receive_buffer: Vec<u8>,
/// The secret key used for encryption.
secret_key: Aes128Gcm,
} }
impl Connection { impl Connection {
/// Creates a new [Connection] from a [TcpStream]. /// Creates a new [Connection] from a [TcpStream].
fn new(stream: TcpStream) -> io::Result<Self> { fn new(stream: TcpStream, secret_key: &Key<Aes128Gcm>) -> io::Result<Self> {
stream.set_nonblocking(true)?; stream.set_nonblocking(true)?;
Ok(Self { Ok(Self {
stream, stream,
send_buffers: LinkedList::new(), send_buffers: LinkedList::new(),
receive_message_len: None, receive_message_len: None,
receive_message_nonce: None,
receive_filled_len: 0, receive_filled_len: 0,
receive_buffer: Vec::new(), receive_buffer: Vec::new(),
secret_key: Aes128Gcm::new(secret_key),
}) })
} }
/// Creates a new [Connection] that connects to the given address. /// Creates a new [Connection] that connects to the given connection string.
/// ///
/// This function is blocking. /// This function is blocking.
pub fn connect(address: impl ToSocketAddrs) -> io::Result<Self> { pub fn connect(connection_string: &str) -> io::Result<Self> {
Self::new(TcpStream::connect(address)?) let data = BASE64_URL_SAFE_NO_PAD
.decode(connection_string)
.map_err(io::Error::other)?;
if data.len() != 22 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("invalid connection string: {}", connection_string),
));
}
let address = SocketAddrV4::new(
Ipv4Addr::new(data[0], data[1], data[2], data[3]),
u16::from_ne_bytes(data[4..=5].try_into().map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!("invalid connection string: {}", connection_string),
)
})?),
);
Self::new(
TcpStream::connect(address)?,
Key::<Aes128Gcm>::from_slice(&data[6..]),
)
} }
/// Sends a message over the connection. /// Sends a message over the connection.
@ -93,6 +128,15 @@ impl Connection {
/// ///
/// This function is not blocking. /// This function is not blocking.
pub fn send(&mut self, message: &[u8]) -> io::Result<bool> { pub fn send(&mut self, message: &[u8]) -> io::Result<bool> {
// Encrypt the message.
let nonce = Aes128Gcm::generate_nonce(OsRng);
let message = self.secret_key.encrypt(&nonce, message).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("failed to encrypt message: {}", e),
)
})?;
// Get the length of the message as a u16. // Get the length of the message as a u16.
let message_len: u16 = match message.len().try_into() { let message_len: u16 = match message.len().try_into() {
Ok(len) => len, Ok(len) => len,
@ -105,10 +149,10 @@ impl Connection {
}; };
// Add a new buffer to the send queue. // Add a new buffer to the send queue.
let mut buffer = Vec::with_capacity(message_len as usize + 2); self.send_buffers
buffer.extend(message_len.to_ne_bytes()); .push_back((0, message_len.to_ne_bytes().to_vec()));
buffer.extend(message); self.send_buffers.push_back((0, nonce.to_vec()));
self.send_buffers.push_back((0, buffer)); self.send_buffers.push_back((0, message));
// Update the connection. // Update the connection.
self.update() self.update()
@ -171,6 +215,12 @@ impl Connection {
let receive_buffer = &mut self.receive_buffer[start_index..start_index + len]; let receive_buffer = &mut self.receive_buffer[start_index..start_index + len];
let received_len = self.stream.read(receive_buffer); let received_len = self.stream.read(receive_buffer);
self.receive_filled_len += match received_len { self.receive_filled_len += match received_len {
Ok(0) => {
return Err(io::Error::new(
io::ErrorKind::ConnectionAborted,
"connection closed by remote peer",
));
}
Ok(n) => n, Ok(n) => n,
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => return Ok(false), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => return Ok(false),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => return Ok(false), Err(ref e) if e.kind() == io::ErrorKind::Interrupted => return Ok(false),
@ -190,7 +240,7 @@ impl Connection {
/// If no message is available, returns `None`. /// If no message is available, returns `None`.
/// ///
/// This function is not blocking. /// This function is not blocking.
pub fn receive(&mut self) -> io::Result<Option<&[u8]>> { pub fn receive(&mut self) -> io::Result<Option<Vec<u8>>> {
// Receiving the message length. // Receiving the message length.
let message_len = match self.receive_message_len { let message_len = match self.receive_message_len {
Some(message_len) => message_len, Some(message_len) => message_len,
@ -212,26 +262,58 @@ impl Connection {
} }
}; };
if self.receive_message_nonce.is_none() {
// If the nonce is not received yet, return `None`.
if !self.receive_partial(12)? {
return Ok(None);
}
// Setting the nonce.
self.receive_message_nonce = Some(self.receive_buffer[..12].to_vec());
}
// Receiving the message. // Receiving the message.
if !self.receive_partial(message_len)? { if !self.receive_partial(message_len)? {
return Ok(None); return Ok(None);
} }
let message = &self.receive_buffer[..message_len as usize];
// Getting the nonce.
let nonce = self
.receive_message_nonce
.as_ref()
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "missing nonce"))?;
// Decrypting the message.
let message = self
.secret_key
.decrypt(Nonce::from_slice(nonce), message)
.map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("failed to decrypt message: {}", e),
)
})?;
// Resetting the message length and nonce.
self.receive_message_len = None;
self.receive_message_nonce = None;
// Returning the message. // Returning the message.
Ok(Some(&self.receive_buffer[..message_len as usize])) Ok(Some(message))
} }
} }
/// A non-blocking tcp listener. /// A non-blocking tcp listener.
/// ///
/// ```rust /// ```no_run
/// use std::io; /// use std::io;
/// ///
/// use bevnet::{Connection, Listener}; /// use bevnet::{Connection, Listener};
/// ///
/// # fn main() -> io::Result<()> { /// # fn main() -> io::Result<()> {
/// let listener = Listener::bind("127.0.0.1:23732")?; /// let listener = Listener::new()?;
/// let mut connection = Connection::connect("127.0.0.1:23732")?; /// let mut connection = Connection::connect(&listener.connection_string())?;
/// ///
/// // The accept operation is not blocking. So we need to loop here. /// // The accept operation is not blocking. So we need to loop here.
/// let mut server_connection; /// let mut server_connection;
@ -244,14 +326,33 @@ impl Connection {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
pub struct Listener(TcpListener); pub struct Listener(TcpListener, Gateway, SocketAddrV4, Key<Aes128Gcm>);
impl Listener { impl Listener {
/// Creates a new listener. /// Creates a new listener.
pub fn bind(addr: impl ToSocketAddrs) -> io::Result<Listener> { pub fn new() -> io::Result<Self> {
let listener = TcpListener::bind(addr)?; let local_address = match local_ip().map_err(io::Error::other)? {
IpAddr::V4(address) => address,
IpAddr::V6(_) => unreachable!(),
};
let listener = TcpListener::bind(SocketAddrV4::new(local_address, 0))?;
let gateway = igd::search_gateway(Default::default()).map_err(io::Error::other)?;
let opened_port = gateway
.add_any_port(
PortMappingProtocol::TCP,
SocketAddrV4::new(local_address, listener.local_addr()?.port()),
3600 * 24,
"bevnet",
)
.map_err(io::Error::other)?;
let external_address = gateway.get_external_ip().map_err(io::Error::other)?;
listener.set_nonblocking(true)?; listener.set_nonblocking(true)?;
Ok(Listener(listener)) Ok(Self(
listener,
gateway,
SocketAddrV4::new(external_address, opened_port),
Aes128Gcm::generate_key(OsRng),
))
} }
/// Accepts a new [Connection]. /// Accepts a new [Connection].
@ -259,10 +360,28 @@ impl Listener {
/// This function is not blocking. /// This function is not blocking.
pub fn accept(&self) -> io::Result<Option<Connection>> { pub fn accept(&self) -> io::Result<Option<Connection>> {
match self.0.accept() { match self.0.accept() {
Ok((stream, _)) => Connection::new(stream).map(Some), Ok((stream, _)) => Connection::new(stream, &self.3).map(Some),
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Ok(None), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Ok(None),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => Ok(None), Err(ref e) if e.kind() == io::ErrorKind::Interrupted => Ok(None),
Err(e) => Err(e), Err(e) => Err(e),
} }
} }
/// Returns the connection string that can be used to connect to th
/// listener.
pub fn connection_string(&self) -> String {
let mut data = Vec::with_capacity(22);
data.extend(self.2.ip().octets());
data.extend(self.2.port().to_ne_bytes());
data.extend(self.3);
BASE64_URL_SAFE_NO_PAD.encode(&data)
}
}
impl Drop for Listener {
fn drop(&mut self) {
self.1
.remove_port(PortMappingProtocol::TCP, self.2.port())
.ok();
}
} }