Removed askForRouterIP packet due to lack of need
Removed some comments Changed some stuff modified: Cargo.lock modified: Cargo.toml modified: src/client.rs modified: src/server.rs modified: src/udp.rs
This commit is contained in:
parent
0684364121
commit
64d8601fff
153
Cargo.lock
generated
153
Cargo.lock
generated
@ -135,7 +135,7 @@ dependencies = [
|
||||
"ndk-context",
|
||||
"ndk-sys 0.6.0+11769913",
|
||||
"num_enum",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -321,7 +321,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -361,7 +361,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -378,7 +378,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -587,7 +587,7 @@ checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -604,18 +604,18 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3"
|
||||
|
||||
[[package]]
|
||||
name = "c2rust-bitfields"
|
||||
version = "0.18.0"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b43c3f07ab0ef604fa6f595aa46ec2f8a22172c975e186f6f5bf9829a3b72c41"
|
||||
checksum = "367e5d1b30f28be590b6b3868da1578361d29d9bfac516d22f497d28ed7c9055"
|
||||
dependencies = [
|
||||
"c2rust-bitfields-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "c2rust-bitfields-derive"
|
||||
version = "0.18.0"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3cbc102e2597c9744c8bd8c15915d554300601c91a079430d309816b0912545"
|
||||
checksum = "a279db9c50c4024eeca1a763b6e0f033848ce74e83e47454bcf8a8a98f7b0b56"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -633,7 +633,7 @@ dependencies = [
|
||||
"polling",
|
||||
"rustix",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -766,7 +766,7 @@ version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4274ea815e013e0f9f04a2633423e14194e408a0576c943ce3d14ca56c50031c"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"x11rb",
|
||||
]
|
||||
|
||||
@ -1109,7 +1109,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1370,7 +1370,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1541,7 +1541,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1658,7 +1658,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1803,7 +1803,7 @@ checksum = "6f56f6318968d03c18e1bcf4857ff88c61157e9da8e47c5f29055d60e1228884"
|
||||
dependencies = [
|
||||
"log",
|
||||
"presser",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"winapi",
|
||||
"windows",
|
||||
]
|
||||
@ -1902,7 +1902,7 @@ dependencies = [
|
||||
"com",
|
||||
"libc",
|
||||
"libloading 0.8.5",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"widestring",
|
||||
"winapi",
|
||||
]
|
||||
@ -2101,7 +2101,7 @@ dependencies = [
|
||||
"iced_renderer",
|
||||
"iced_widget",
|
||||
"iced_winit",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2120,7 +2120,7 @@ dependencies = [
|
||||
"palette",
|
||||
"rustc-hash 2.0.0",
|
||||
"smol_str",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
@ -2168,7 +2168,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"raw-window-handle",
|
||||
"rustc-hash 2.0.0",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
@ -2182,7 +2182,7 @@ dependencies = [
|
||||
"iced_tiny_skia",
|
||||
"iced_wgpu",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2195,7 +2195,7 @@ dependencies = [
|
||||
"iced_core",
|
||||
"iced_futures",
|
||||
"raw-window-handle",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2230,7 +2230,7 @@ dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"rustc-hash 2.0.0",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"wgpu",
|
||||
]
|
||||
|
||||
@ -2245,7 +2245,7 @@ dependencies = [
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"rustc-hash 2.0.0",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
@ -2260,7 +2260,7 @@ dependencies = [
|
||||
"iced_runtime",
|
||||
"log",
|
||||
"rustc-hash 2.0.0",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"tracing",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
@ -2344,7 +2344,7 @@ dependencies = [
|
||||
"combine",
|
||||
"jni-sys",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
@ -2358,7 +2358,7 @@ dependencies = [
|
||||
"combine",
|
||||
"jni-sys",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
@ -2373,7 +2373,7 @@ dependencies = [
|
||||
"combine",
|
||||
"jni-sys",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"walkdir",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
@ -2537,7 +2537,7 @@ dependencies = [
|
||||
"serde-value",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"thread-id",
|
||||
"typemap-ors",
|
||||
"winapi",
|
||||
@ -2662,7 +2662,7 @@ dependencies = [
|
||||
"rustc-hash 1.1.0",
|
||||
"spirv",
|
||||
"termcolor",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
@ -2678,7 +2678,7 @@ dependencies = [
|
||||
"ndk-sys 0.6.0+11769913",
|
||||
"num_enum",
|
||||
"raw-window-handle",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2713,7 +2713,7 @@ checksum = "433419f898328beca4f2c6c73a1b52540658d92b0a99f0269330457e0fd998d5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
@ -2786,7 +2786,7 @@ dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3114,7 +3114,7 @@ dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"byteorder",
|
||||
"hwaddr",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3144,7 +3144,7 @@ dependencies = [
|
||||
"by_address",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3252,7 +3252,7 @@ dependencies = [
|
||||
"phf_shared 0.11.2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3290,7 +3290,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3444,7 +3444,7 @@ dependencies = [
|
||||
"itertools",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3587,7 +3587,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libredox",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3825,7 +3825,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3848,7 +3848,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3968,7 +3968,7 @@ dependencies = [
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
@ -4120,9 +4120,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.79"
|
||||
version = "2.0.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
|
||||
checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -4187,7 +4187,16 @@ version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
"thiserror-impl 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4198,7 +4207,18 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4302,7 +4322,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4458,7 +4478,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4528,20 +4548,19 @@ checksum = "5902c5d130972a0000f60860bfbf46f7ca3db5391eddfedd1b8728bd9dc96c0e"
|
||||
|
||||
[[package]]
|
||||
name = "tun2"
|
||||
version = "2.0.9"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b139b40733b3e81560335ccad94948916c4d03ed1ded505a8675428879075b4"
|
||||
checksum = "21afe73d3d42581a7400fbf5aec057a646ffe3f8bb5ae3f61d88c7e7f4ac77be"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"cfg-if",
|
||||
"futures",
|
||||
"futures-core",
|
||||
"ipnet",
|
||||
"libc",
|
||||
"libloading 0.8.5",
|
||||
"log",
|
||||
"nix",
|
||||
"rustversion",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"windows-sys 0.59.0",
|
||||
@ -4744,7 +4763,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@ -4778,7 +4797,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@ -4978,7 +4997,7 @@ dependencies = [
|
||||
"raw-window-handle",
|
||||
"rustc-hash 1.1.0",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"web-sys",
|
||||
"wgpu-hal",
|
||||
"wgpu-types",
|
||||
@ -5022,7 +5041,7 @@ dependencies = [
|
||||
"renderdoc-sys",
|
||||
"rustc-hash 1.1.0",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"wgpu-types",
|
||||
@ -5088,7 +5107,7 @@ dependencies = [
|
||||
"clipboard_wayland",
|
||||
"clipboard_x11",
|
||||
"raw-window-handle",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5406,14 +5425,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wintun-bindings"
|
||||
version = "0.6.4"
|
||||
version = "0.7.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3af47a132f449a64ff858f9ad876a3d1812df30e9500cddfdcabb2266ab68c0d"
|
||||
checksum = "a8aed5bc5516ca7a52018b0a198911566edfa07584bdbfd71ea39161aa13806e"
|
||||
dependencies = [
|
||||
"blocking",
|
||||
"c2rust-bitfields",
|
||||
"futures",
|
||||
"libloading 0.8.5",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 2.0.3",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
@ -5555,7 +5576,7 @@ dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
@ -5594,7 +5615,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5614,7 +5635,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5639,7 +5660,7 @@ dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
@ -5651,5 +5672,5 @@ checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
@ -38,7 +38,7 @@ socket2 = "0.4"
|
||||
env_logger = "0.9"
|
||||
log = "0.4.20"
|
||||
futures = "0.3.30"
|
||||
tun2 = { version = "2", features = ["async"] }
|
||||
tun2 = { version = "4.0.0", features = ["async"] }
|
||||
packet = "0.1.4"
|
||||
crossbeam-channel = "0.5.13"
|
||||
hex = "0.4"
|
||||
|
@ -1,16 +1,6 @@
|
||||
use crossbeam_channel::unbounded;
|
||||
use socket2::SockAddr;
|
||||
|
||||
/*
|
||||
What the fuck I want to implement?
|
||||
I need to make abstract class VPNClient which should be extended by several others:
|
||||
AndroidClient
|
||||
DesktopClient
|
||||
|
||||
Both of child classes should trigger the same "core vpn client" module
|
||||
|
||||
*/
|
||||
|
||||
pub mod general {
|
||||
use crate::config::ClientConfiguration;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@ -24,8 +14,8 @@ pub mod general {
|
||||
use std::net::Ipv4Addr;
|
||||
use std::pin::pin;
|
||||
use x25519_dalek::{PublicKey, StaticSecret};
|
||||
use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable, UDPVpnRouterIP};
|
||||
use tun2::{platform::Device, Configuration, DeviceReader, DeviceWriter};
|
||||
use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable};
|
||||
use tun2::{AbstractDevice, AsyncDevice, Configuration, DeviceReader, DeviceWriter};
|
||||
|
||||
trait ReadWrapper {
|
||||
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, ()>;
|
||||
@ -61,20 +51,37 @@ pub mod general {
|
||||
}
|
||||
|
||||
trait WriteWrapper {
|
||||
async fn write(&mut self, buf: &[u8]) -> Result<usize, ()>;
|
||||
async fn write(&mut self, msg: WriterMessage) -> Result<usize, ()>;
|
||||
}
|
||||
|
||||
pub enum WriterMessage {
|
||||
Plain(Vec<u8>),
|
||||
Gateway(Ipv4Addr)
|
||||
}
|
||||
|
||||
pub struct DevWriter {
|
||||
pub dr: DeviceWriter
|
||||
pub dr: DeviceWriter,
|
||||
//pub dev: AsyncDevice
|
||||
}
|
||||
|
||||
// TODO: implement custom Error
|
||||
impl WriteWrapper for DevWriter {
|
||||
async fn write(&mut self, buf: &[u8]) -> Result<usize, ()> {
|
||||
if let Ok(a) = self.dr.write(buf).await {
|
||||
return Ok(a);
|
||||
async fn write(&mut self, msg: WriterMessage) -> Result<usize, ()> {
|
||||
match msg {
|
||||
WriterMessage::Plain(buf) => {
|
||||
if let Ok(a) = self.dr.write(&buf).await {
|
||||
return Ok(a);
|
||||
}
|
||||
Err(())
|
||||
},
|
||||
WriterMessage::Gateway(addr) => {
|
||||
/* if self.dev.set_destination(addr.into()).is_err() {
|
||||
return Err(());
|
||||
}*/
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
Err(())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,11 +90,16 @@ pub mod general {
|
||||
}
|
||||
|
||||
impl WriteWrapper for FdWriter {
|
||||
async fn write(&mut self, buf: &[u8]) -> Result<usize, ()> {
|
||||
if let Ok(a) = self.br.write(buf).await {
|
||||
return Ok(a);
|
||||
async fn write(&mut self, msg: WriterMessage) -> Result<usize, ()> {
|
||||
match msg {
|
||||
WriterMessage::Plain(buf) => {
|
||||
if let Ok(a) = self.br.write(&buf).await {
|
||||
return Ok(a);
|
||||
}
|
||||
Err(())
|
||||
},
|
||||
WriterMessage::Gateway(_addr) => {Ok(0)}
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +145,7 @@ pub mod general {
|
||||
|
||||
let s_cipher = cipher_shared.clone();
|
||||
|
||||
self.dev_writer.write(&handshake.serialize()).await;
|
||||
self.dev_writer.write(WriterMessage::Plain(handshake.serialize())).await;
|
||||
|
||||
let mut buf = vec![0; 1400]; // mtu
|
||||
let mut buf1 = vec![0; 4096];
|
||||
@ -149,7 +161,7 @@ pub mod general {
|
||||
rr = rx.recv() => {
|
||||
if let Some(bytes) = rr {
|
||||
info!("Write to tun.");
|
||||
if let Err(e) = self.dev_writer.write(&bytes).await {
|
||||
if let Err(e) = self.dev_writer.write(WriterMessage::Plain(bytes)).await {
|
||||
error!("Writing error: {:?}", e);
|
||||
}
|
||||
/* if let Err(e) = self.dev_writer.flush().await {
|
||||
@ -219,10 +231,6 @@ pub mod general {
|
||||
}
|
||||
}, // payload
|
||||
2 => { info!("Got keepalive packet"); },
|
||||
3 => {
|
||||
let router_packet = UDPVpnRouterIP::deserialize(&(buf1[..l].to_vec()));
|
||||
// todo: set of the router ip
|
||||
},
|
||||
_ => { error!("Unexpected header value."); }
|
||||
}
|
||||
},
|
||||
@ -313,7 +321,7 @@ pub mod desktop {
|
||||
if !ip_output.status.success() {
|
||||
error!("Failed to route all traffic: {:?}", String::from_utf8_lossy(&ip_output.stderr));
|
||||
}
|
||||
|
||||
// TODO: replace 192.168.0.1 with relative variable
|
||||
ip_output = Command::new("sudo")
|
||||
.arg("ip")
|
||||
.arg("route")
|
||||
@ -342,7 +350,8 @@ pub mod desktop {
|
||||
let mut config = tun2::Configuration::default();
|
||||
config.address(&self.client_config.client.address)
|
||||
.netmask("255.255.255.255")
|
||||
.destination("10.66.66.1")
|
||||
.destination(&self.client_config.client.address)
|
||||
.mtu(1400)
|
||||
.tun_name("tun0")
|
||||
.up();
|
||||
|
||||
@ -351,7 +360,7 @@ pub mod desktop {
|
||||
sock.connect(&self.client_config.server.endpoint).await.unwrap();
|
||||
|
||||
let dev = tun2::create_as_async(&config).unwrap();
|
||||
let (mut dev_writer, mut dev_reader) = dev.split().unwrap();
|
||||
let (dev_writer, dev_reader) = dev.split().unwrap();
|
||||
let mut client = CoreVpnClient{ client_config: self.client_config.clone(), dev_reader: DevReader{ dr: dev_reader }, dev_writer: DevWriter{dr: dev_writer}, close_token: tokio_util::sync::CancellationToken::new()};
|
||||
let s_a: SocketAddr = self.client_config.server.endpoint.parse().unwrap();
|
||||
|
||||
|
@ -14,7 +14,7 @@ use network_interface::NetworkInterface;
|
||||
use network_interface::NetworkInterfaceConfig;
|
||||
|
||||
use crate::config::{ ServerConfiguration, ServerPeer};
|
||||
use crate::udp::{UDPKeepAlive, UDPSerializable, UDPVpnAskForIP, UDPVpnHandshake, UDPVpnPacket, UDPVpnRouterIP};
|
||||
use crate::udp::{UDPKeepAlive, UDPSerializable, UDPVpnHandshake, UDPVpnPacket};
|
||||
|
||||
fn configure_routes(s_interface: Option<&str>) {
|
||||
let interfaces = NetworkInterface::show().unwrap();
|
||||
@ -189,7 +189,7 @@ pub async fn server_mode(server_config: ServerConfiguration, s_interface: Option
|
||||
Some(h) => {
|
||||
match h {
|
||||
0 => {
|
||||
let handshake = UDPVpnHandshake::deserialize(&buf); // todo: replace &buf reference with length dependent reference.
|
||||
let handshake = UDPVpnHandshake::deserialize(&buf);
|
||||
info!("Got handshake from {:?}", handshake.request_ip);
|
||||
let skey = BASE64_STANDARD.encode(&handshake.public_key);
|
||||
if plp.iter().any(|c| c.ip == handshake.request_ip && c.public_key == skey) {
|
||||
@ -228,13 +228,6 @@ pub async fn server_mode(server_config: ServerConfiguration, s_interface: Option
|
||||
});
|
||||
}, // payload
|
||||
2 => { }, // got keepalive packet
|
||||
3 => {
|
||||
if let Ok(_packet) = UDPVpnAskForIP::deserialize(&(buf[..len].to_vec())) {
|
||||
info!("Router address requested");
|
||||
let response = UDPVpnRouterIP {router_ip: server_config.interface.internal_address.parse::<Ipv4Addr>().unwrap()};
|
||||
let _ = send2hnd_ssr.send((response.serialize(), addr));
|
||||
}
|
||||
}, // fake router address request
|
||||
_ => error!("Unexpected header value.")
|
||||
}
|
||||
},
|
||||
|
37
src/udp.rs
37
src/udp.rs
@ -30,43 +30,6 @@ impl UDPVpnPacket {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UDPVpnRouterIP {
|
||||
pub router_ip: Ipv4Addr // [u8; 4]
|
||||
}
|
||||
|
||||
impl UDPSerializable for UDPVpnRouterIP {
|
||||
fn serialize(&self) -> Vec<u8> {
|
||||
let h: &[u8] = &[3];
|
||||
[h, &self.router_ip.octets()].concat() // [u8; 5]
|
||||
}
|
||||
}
|
||||
|
||||
impl UDPVpnRouterIP {
|
||||
pub fn deserialize(data: &Vec<u8>) -> Self {
|
||||
UDPVpnRouterIP { router_ip: Ipv4Addr::new(data[1], data[2], data[3], data[4]) }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UDPVpnAskForIP {}
|
||||
|
||||
impl UDPVpnAskForIP {
|
||||
pub fn deserialize(data: &Vec<u8>) -> Result<UDPVpnAskForIP, ()> {
|
||||
if data.len() == 33 {
|
||||
return Ok(UDPVpnAskForIP {});
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
impl UDPSerializable for UDPVpnAskForIP {
|
||||
fn serialize(&self) -> Vec<u8> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let h: &[u8] = &[3];
|
||||
let a: [u8; 32] = rng.gen();
|
||||
[h, &a].concat()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UDPVpnHandshake {
|
||||
pub public_key: Vec<u8>,
|
||||
pub request_ip: Ipv4Addr // [u8; 4]
|
||||
|
Loading…
x
Reference in New Issue
Block a user