Use RwLock replace unsafe
This commit is contained in:
128
Cargo.lock
generated
128
Cargo.lock
generated
@@ -2,7 +2,7 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ace"
|
name = "ace"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -151,6 +151,11 @@ dependencies = [
|
|||||||
"synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fuchsia-cprng"
|
name = "fuchsia-cprng"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -172,79 +177,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures"
|
name = "futures"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-core"
|
name = "futures-core"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-executor"
|
name = "futures-executor"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-io"
|
name = "futures-io"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-macro"
|
name = "futures-macro"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-task"
|
name = "futures-task"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-util"
|
name = "futures-util"
|
||||||
version = "0.3.1"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-macro 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -361,7 +366,7 @@ name = "proc-macro-hack"
|
|||||||
version = "0.5.11"
|
version = "0.5.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
@@ -381,7 +386,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.6"
|
version = "1.0.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -400,7 +405,7 @@ name = "quote"
|
|||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -455,18 +460,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.3.3"
|
version = "1.3.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.12"
|
version = "0.6.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -504,7 +509,7 @@ name = "syn"
|
|||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
@@ -540,11 +545,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "0.2.9"
|
version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bytes 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -553,14 +559,15 @@ dependencies = [
|
|||||||
"mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"tokio-macros 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-macros"
|
name = "tokio-macros"
|
||||||
version = "0.2.3"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
@@ -577,16 +584,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "updns"
|
name = "updns"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ace 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ace 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tokio 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -628,7 +635,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum ace 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efcf59867ff84f1cae9358064c6bd2a17b856d3a2bcd1cb4660c60c6f4d21c0a"
|
"checksum ace 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77c9e271cdb57529662aa91421d9b47ec2a87b92e0f3fcdebb17a3949c65fa4a"
|
||||||
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
|
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
|
||||||
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
|
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
|
||||||
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
|
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
|
||||||
@@ -648,18 +655,19 @@ dependencies = [
|
|||||||
"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
|
"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
|
||||||
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
|
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
|
||||||
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
|
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
|
||||||
|
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||||
"checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987"
|
"checksum futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780"
|
||||||
"checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86"
|
"checksum futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8"
|
||||||
"checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866"
|
"checksum futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a"
|
||||||
"checksum futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231"
|
"checksum futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba"
|
||||||
"checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff"
|
"checksum futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6"
|
||||||
"checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764"
|
"checksum futures-macro 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7"
|
||||||
"checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16"
|
"checksum futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6"
|
||||||
"checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9"
|
"checksum futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
|
||||||
"checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76"
|
"checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5"
|
||||||
"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
|
"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
|
||||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
@@ -676,7 +684,7 @@ dependencies = [
|
|||||||
"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"
|
"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"
|
||||||
"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e"
|
"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e"
|
||||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
||||||
"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27"
|
"checksum proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
|
||||||
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
||||||
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
|
||||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||||
@@ -685,8 +693,8 @@ dependencies = [
|
|||||||
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||||
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
||||||
"checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d"
|
"checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d"
|
||||||
"checksum regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b5508c1941e4e7cb19965abef075d35a9a8b5cdf0846f30b4050e9b55dc55e87"
|
"checksum regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3"
|
||||||
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
|
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
|
||||||
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
|
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
|
||||||
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
||||||
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||||
@@ -695,8 +703,8 @@ dependencies = [
|
|||||||
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
|
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
|
||||||
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
||||||
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
|
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
|
||||||
"checksum tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ffa2fdcfa937b20cb3c822a635ceecd5fc1a27a6a474527e5516aa24b8c8820a"
|
"checksum tokio 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ee5a0dd887e37d37390c13ff8ac830f992307fe30a1fff0ab8427af67211ba28"
|
||||||
"checksum tokio-macros 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "50a61f268a3db2acee8dcab514efc813dc6dbe8a00e86076f935f94304b59a7a"
|
"checksum tokio-macros 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389"
|
||||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||||
|
|||||||
10
Cargo.toml
10
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "updns"
|
name = "updns"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
authors = ["wyhaya <wyhaya@gmail.com>"]
|
authors = ["wyhaya <wyhaya@gmail.com>"]
|
||||||
@@ -18,11 +18,11 @@ keywords = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ace = "0.1.0"
|
ace = "0.2.0"
|
||||||
dirs = "2.0.2"
|
dirs = "2.0.2"
|
||||||
futures = "0.3.1"
|
futures = "0.3.4"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = { version = "0.4.8", features = ["max_level_trace", "release_max_level_info"] }
|
log = { version = "0.4.8", features = ["max_level_trace", "release_max_level_info"] }
|
||||||
regex = "1.3.3"
|
regex = "1.3.6"
|
||||||
time = "0.1.42"
|
time = "0.1.42"
|
||||||
tokio = { version = "0.2.9", features = ["fs", "io-util", "macros", "net", "stream", "time"] }
|
tokio = { version = "0.2.16", features = ["fs", "io-util", "macros", "net", "stream", "time", "sync"] }
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::matcher::Matcher;
|
use crate::matcher::Matcher;
|
||||||
use futures::future::{BoxFuture, FutureExt};
|
use futures::future::{BoxFuture, FutureExt};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use log::error;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
@@ -58,6 +59,23 @@ pub struct Invalid {
|
|||||||
pub kind: InvalidType,
|
pub kind: InvalidType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait MultipleInvalid {
|
||||||
|
fn print(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MultipleInvalid for Vec<Invalid> {
|
||||||
|
fn print(&self) {
|
||||||
|
for invalid in self {
|
||||||
|
error!(
|
||||||
|
"[line:{}] {} `{}`",
|
||||||
|
invalid.line,
|
||||||
|
invalid.kind.description(),
|
||||||
|
invalid.source
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InvalidType {
|
pub enum InvalidType {
|
||||||
Regex,
|
Regex,
|
||||||
@@ -200,8 +218,7 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// match host
|
// match host
|
||||||
// example.com 0.0.0.0
|
// example.com 0.0.0.0 or 0.0.0.0 example.com
|
||||||
// 0.0.0.0 example.com
|
|
||||||
fn record(left: &str, right: &str) -> result::Result<(Matcher, IpAddr), InvalidType> {
|
fn record(left: &str, right: &str) -> result::Result<(Matcher, IpAddr), InvalidType> {
|
||||||
// ip domain
|
// ip domain
|
||||||
if let Ok(ip) = right.parse() {
|
if let Ok(ip) = right.parse() {
|
||||||
@@ -266,7 +283,7 @@ impl Parser {
|
|||||||
Err(_) => invalid!(InvalidType::Timeout),
|
Err(_) => invalid!(InvalidType::Timeout),
|
||||||
},
|
},
|
||||||
"import" => {
|
"import" => {
|
||||||
let mut path = Path::new(value).to_path_buf();
|
let mut path = PathBuf::from(value);
|
||||||
if path.is_relative() {
|
if path.is_relative() {
|
||||||
if let Some(parent) = self.path.parent() {
|
if let Some(parent) = self.path.parent() {
|
||||||
path = parent.join(path);
|
path = parent.join(path);
|
||||||
|
|||||||
92
src/main.rs
92
src/main.rs
@@ -5,11 +5,12 @@ mod matcher;
|
|||||||
mod watch;
|
mod watch;
|
||||||
|
|
||||||
use ace::App;
|
use ace::App;
|
||||||
use config::{Config, Hosts, Invalid, Parser};
|
use config::{Config, Hosts, MultipleInvalid, Parser};
|
||||||
use dirs;
|
use dirs;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use lib::*;
|
use lib::*;
|
||||||
use log::*;
|
use log::{error, info, warn};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
@@ -21,6 +22,7 @@ use std::{
|
|||||||
use tokio::{
|
use tokio::{
|
||||||
io::{Error, ErrorKind, Result},
|
io::{Error, ErrorKind, Result},
|
||||||
net::UdpSocket,
|
net::UdpSocket,
|
||||||
|
sync::RwLock,
|
||||||
time::timeout,
|
time::timeout,
|
||||||
};
|
};
|
||||||
use watch::Watch;
|
use watch::Watch;
|
||||||
@@ -33,9 +35,11 @@ const DEFAULT_TIMEOUT: Duration = Duration::from_millis(2000);
|
|||||||
|
|
||||||
const WATCH_INTERVAL: Duration = Duration::from_millis(5000);
|
const WATCH_INTERVAL: Duration = Duration::from_millis(5000);
|
||||||
|
|
||||||
static mut PROXY: Vec<SocketAddr> = Vec::new();
|
lazy_static! {
|
||||||
static mut HOSTS: Option<Hosts> = None;
|
static ref PROXY: RwLock<Vec<SocketAddr>> = RwLock::new(Vec::new());
|
||||||
static mut TIMEOUT: Duration = DEFAULT_TIMEOUT;
|
static ref HOSTS: RwLock<Hosts> = RwLock::new(Hosts::new());
|
||||||
|
static ref TIMEOUT: RwLock<Duration> = RwLock::new(DEFAULT_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! exit {
|
macro_rules! exit {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
@@ -48,9 +52,11 @@ macro_rules! exit {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let _ = logger::init();
|
logger::init().unwrap_or_else(|err| exit!("Log init failed:\n{:#?}", err));
|
||||||
|
|
||||||
let app = App::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
|
let app = App::new()
|
||||||
|
.name(env!("CARGO_PKG_NAME"))
|
||||||
|
.desc(env!("CARGO_PKG_VERSION"))
|
||||||
.cmd("add", "Add a DNS record")
|
.cmd("add", "Add a DNS record")
|
||||||
.cmd("ls", "Print all configured DNS records")
|
.cmd("ls", "Print all configured DNS records")
|
||||||
.cmd("config", "Call 'vim' to edit the configuration file")
|
.cmd("config", "Call 'vim' to edit the configuration file")
|
||||||
@@ -80,8 +86,9 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check profile interval
|
// Check profile interval
|
||||||
let watch_interval = match app.value("-i") {
|
let watch_interval = app
|
||||||
Some(values) => {
|
.value("-i")
|
||||||
|
.map(|values| {
|
||||||
if values.is_empty() {
|
if values.is_empty() {
|
||||||
exit!("'-i' missing a value: : [1ms, 1s, 1m, 1h, 1d]");
|
exit!("'-i' missing a value: : [1ms, 1s, 1m, 1h, 1d]");
|
||||||
}
|
}
|
||||||
@@ -91,9 +98,8 @@ async fn main() {
|
|||||||
&values[0]
|
&values[0]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
None => WATCH_INTERVAL,
|
.unwrap_or(WATCH_INTERVAL);
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(cmd) = app.command() {
|
if let Some(cmd) = app.command() {
|
||||||
match cmd.as_str() {
|
match cmd.as_str() {
|
||||||
@@ -124,7 +130,7 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"ls" => {
|
"ls" => {
|
||||||
let mut config = config_parse(&config_path).await;
|
let mut config = force_get_config(&config_path).await;
|
||||||
|
|
||||||
let n = config
|
let n = config
|
||||||
.hosts
|
.hosts
|
||||||
@@ -143,7 +149,7 @@ async fn main() {
|
|||||||
.unwrap_or_else(|err| exit!("Call 'vim' command failed\n{:?}", err));
|
.unwrap_or_else(|err| exit!("Call 'vim' command failed\n{:?}", err));
|
||||||
|
|
||||||
if status.success() {
|
if status.success() {
|
||||||
config_parse(&config_path).await;
|
force_get_config(&config_path).await;
|
||||||
} else {
|
} else {
|
||||||
println!("'vim' exits with a non-zero status code: {:?}", status);
|
println!("'vim' exits with a non-zero status code: {:?}", status);
|
||||||
}
|
}
|
||||||
@@ -165,7 +171,7 @@ async fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut config = config_parse(&config_path).await;
|
let mut config = force_get_config(&config_path).await;
|
||||||
if config.bind.is_empty() {
|
if config.bind.is_empty() {
|
||||||
warn!("Will bind the default address '{}'", DEFAULT_BIND);
|
warn!("Will bind the default address '{}'", DEFAULT_BIND);
|
||||||
config.bind.push(DEFAULT_BIND.parse().unwrap());
|
config.bind.push(DEFAULT_BIND.parse().unwrap());
|
||||||
@@ -177,7 +183,7 @@ async fn main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_config(config.proxy, config.hosts, config.timeout);
|
update_config(config.proxy, config.hosts, config.timeout).await;
|
||||||
|
|
||||||
// Run server
|
// Run server
|
||||||
for addr in config.bind {
|
for addr in config.bind {
|
||||||
@@ -187,21 +193,29 @@ async fn main() {
|
|||||||
watch_config(config_path, watch_interval).await;
|
watch_config(config_path, watch_interval).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_config(mut proxy: Vec<SocketAddr>, hosts: Hosts, timeout: Option<Duration>) {
|
async fn update_config(mut proxy: Vec<SocketAddr>, hosts: Hosts, timeout: Option<Duration>) {
|
||||||
if proxy.is_empty() {
|
if proxy.is_empty() {
|
||||||
proxy = DEFAULT_PROXY
|
proxy = DEFAULT_PROXY
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| p.parse().unwrap())
|
.map(|p| p.parse().unwrap())
|
||||||
.collect::<Vec<SocketAddr>>();
|
.collect::<Vec<SocketAddr>>();
|
||||||
}
|
}
|
||||||
unsafe {
|
|
||||||
PROXY = proxy;
|
{
|
||||||
HOSTS = Some(hosts);
|
let mut w = PROXY.write().await;
|
||||||
TIMEOUT = timeout.unwrap_or(DEFAULT_TIMEOUT);
|
*w = proxy;
|
||||||
};
|
}
|
||||||
|
{
|
||||||
|
let mut w = HOSTS.write().await;
|
||||||
|
*w = hosts;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut w = TIMEOUT.write().await;
|
||||||
|
*w = timeout.unwrap_or(DEFAULT_TIMEOUT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn config_parse(file: &PathBuf) -> Config {
|
async fn force_get_config(file: &PathBuf) -> Config {
|
||||||
let parser = Parser::new(file)
|
let parser = Parser::new(file)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| exit!("Failed to read config file {:?}\n{:?}", file, err));
|
.unwrap_or_else(|err| exit!("Failed to read config file {:?}\n{:?}", file, err));
|
||||||
@@ -211,21 +225,10 @@ async fn config_parse(file: &PathBuf) -> Config {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| exit!("Parsing config file failed\n{:?}", err));
|
.unwrap_or_else(|err| exit!("Parsing config file failed\n{:?}", err));
|
||||||
|
|
||||||
output_invalid(&config.invalid);
|
config.invalid.print();
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_invalid(errors: &[Invalid]) {
|
|
||||||
for invalid in errors {
|
|
||||||
error!(
|
|
||||||
"[line:{}] {} `{}`",
|
|
||||||
invalid.line,
|
|
||||||
invalid.kind.description(),
|
|
||||||
invalid.source
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn watch_config(p: PathBuf, t: Duration) {
|
async fn watch_config(p: PathBuf, t: Duration) {
|
||||||
let mut watch = Watch::new(&p, t).await;
|
let mut watch = Watch::new(&p, t).await;
|
||||||
|
|
||||||
@@ -233,8 +236,8 @@ async fn watch_config(p: PathBuf, t: Duration) {
|
|||||||
info!("Reload the configuration file: {:?}", &p);
|
info!("Reload the configuration file: {:?}", &p);
|
||||||
if let Ok(parser) = Parser::new(&p).await {
|
if let Ok(parser) = Parser::new(&p).await {
|
||||||
if let Ok(config) = parser.parse().await {
|
if let Ok(config) = parser.parse().await {
|
||||||
update_config(config.proxy, config.hosts, config.timeout);
|
update_config(config.proxy, config.hosts, config.timeout).await;
|
||||||
output_invalid(&config.invalid);
|
config.invalid.print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,12 +278,13 @@ async fn run_server(addr: SocketAddr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn proxy(buf: &[u8]) -> Result<Vec<u8>> {
|
async fn proxy(buf: &[u8]) -> Result<Vec<u8>> {
|
||||||
let proxy = unsafe { &PROXY };
|
let proxy = PROXY.read().await;
|
||||||
|
let duration = *TIMEOUT.read().await;
|
||||||
|
|
||||||
for addr in proxy.iter() {
|
for addr in proxy.iter() {
|
||||||
let mut socket = UdpSocket::bind(("0.0.0.0", 0)).await?;
|
let mut socket = UdpSocket::bind(("0.0.0.0", 0)).await?;
|
||||||
|
|
||||||
let data: Result<Vec<u8>> = timeout(unsafe { TIMEOUT }, async {
|
let data: Result<Vec<u8>> = timeout(duration, async {
|
||||||
socket.send_to(&buf, addr).await?;
|
socket.send_to(&buf, addr).await?;
|
||||||
let mut res = [0; 512];
|
let mut res = [0; 512];
|
||||||
let len = socket.recv(&mut res).await?;
|
let len = socket.recv(&mut res).await?;
|
||||||
@@ -304,9 +308,8 @@ async fn proxy(buf: &[u8]) -> Result<Vec<u8>> {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_answer(domain: &str, query: QueryType) -> Option<DnsRecord> {
|
async fn get_answer(domain: &str, query: QueryType) -> Option<DnsRecord> {
|
||||||
let hosts = unsafe { HOSTS.as_ref().unwrap() };
|
if let Some(ip) = HOSTS.read().await.get(domain) {
|
||||||
if let Some(ip) = hosts.get(domain) {
|
|
||||||
match query {
|
match query {
|
||||||
QueryType::A => {
|
QueryType::A => {
|
||||||
if let IpAddr::V4(addr) = ip {
|
if let IpAddr::V4(addr) = ip {
|
||||||
@@ -343,7 +346,7 @@ async fn handle(mut req: BytePacketBuffer, len: usize) -> Result<Vec<u8>> {
|
|||||||
info!("{} {:?}", query.name, query.qtype);
|
info!("{} {:?}", query.name, query.qtype);
|
||||||
|
|
||||||
// Whether to proxy
|
// Whether to proxy
|
||||||
let answer = match get_answer(&query.name, query.qtype) {
|
let answer = match get_answer(&query.name, query.qtype).await {
|
||||||
Some(record) => record,
|
Some(record) => record,
|
||||||
None => return proxy(&req.buf[..len]).await,
|
None => return proxy(&req.buf[..len]).await,
|
||||||
};
|
};
|
||||||
@@ -355,7 +358,6 @@ async fn handle(mut req: BytePacketBuffer, len: usize) -> Result<Vec<u8>> {
|
|||||||
let mut res_buffer = BytePacketBuffer::new();
|
let mut res_buffer = BytePacketBuffer::new();
|
||||||
request.write(&mut res_buffer)?;
|
request.write(&mut res_buffer)?;
|
||||||
|
|
||||||
let len = res_buffer.pos();
|
let data = res_buffer.get_range(0, res_buffer.pos())?;
|
||||||
let data = res_buffer.get_range(0, len)?;
|
|
||||||
Ok(data.to_vec())
|
Ok(data.to_vec())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user