From 161027d20a6416159bad201ac4ec44a1c6eaa4f4 Mon Sep 17 00:00:00 2001 From: zephyr Date: Sat, 15 Oct 2022 20:04:55 +0900 Subject: [PATCH] use standalone librealm --- Cargo.lock | 56 +++++++++++++++++++++++++++++++++++++++++----------- src/bin.rs | 36 +++++++++++++++++++++++++++------ src/lib.rs | 2 +- src/relay.rs | 29 --------------------------- 4 files changed, 75 insertions(+), 48 deletions(-) delete mode 100644 src/relay.rs diff --git a/Cargo.lock b/Cargo.lock index 0025d4be..ff7cad8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,9 +277,9 @@ dependencies = [ [[package]] name = "enum-as-inner" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" +checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" dependencies = [ "heck", "proc-macro2", @@ -987,7 +987,7 @@ dependencies = [ "pin-project", "proxy-protocol", "realm_hook 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "realm_io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "realm_io 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "realm_lb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "realm_syscall 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio", @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "realm_io" -version = "0.3.4" +version = "0.3.5" dependencies = [ "libc", "tokio", @@ -1022,9 +1022,9 @@ dependencies = [ [[package]] name = "realm_io" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765e31d68e3708d65d98c7f66023c3715711614553ec279499ef5c1a2544e256" +checksum = "dbc19053a7f2c352c5c5438a8eeb38d7db3205bdaa2b55ed25b181ea5380b1b9" dependencies = [ "libc", "tokio", @@ -1394,11 +1394,43 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + [[package]] name = "trust-dns-proto" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d" +checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" dependencies = [ "async-trait", "cfg-if", @@ -1410,32 +1442,32 @@ dependencies = [ "idna 0.2.3", "ipnet", "lazy_static", - "log", "rand", "smallvec", "thiserror", "tinyvec", "tokio", + "tracing", "url", ] [[package]] name = "trust-dns-resolver" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558" +checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe" dependencies = [ "cfg-if", "futures-util", "ipconfig", "lazy_static", - "log", "lru-cache", "parking_lot", "resolv-conf", "smallvec", "thiserror", "tokio", + "tracing", "trust-dns-proto", ] diff --git a/src/bin.rs b/src/bin.rs index 9daa39cb..fd5e534b 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -1,11 +1,8 @@ use std::env; use cfg_if::cfg_if; -use realm_core::dns; - use realm::cmd; use realm::conf::{Config, FullConf, LogConf, DnsConf, EndpointInfo}; -use realm::relay; use realm::ENV_CONFIG; cfg_if! { @@ -95,7 +92,7 @@ fn setup_dns(dns: DnsConf) { println!("dns: {}", &dns); let (conf, opts) = dns.build(); - dns::build(conf, opts); + realm::core::dns::build(conf, opts); } fn execute(eps: Vec) { @@ -105,7 +102,7 @@ fn execute(eps: Vec) { .enable_all() .build() .unwrap() - .block_on(relay::run(eps)) + .block_on(run(eps)) } #[cfg(not(feature = "multi-thread"))] @@ -114,6 +111,33 @@ fn execute(eps: Vec) { .enable_all() .build() .unwrap() - .block_on(relay::run(eps)) + .block_on(run(eps)) + } +} + +async fn run(endpoints: Vec) { + use realm::core::tcp::run_tcp; + use realm::core::udp::run_udp; + use futures::future::join_all; + + let mut workers = Vec::with_capacity(2 * endpoints.len()); + + for EndpointInfo { + endpoint, + no_tcp, + use_udp, + } in endpoints + { + if use_udp { + workers.push(tokio::spawn(run_udp(endpoint.clone()))); + } + + if !no_tcp { + workers.push(tokio::spawn(run_tcp(endpoint))); + } } + + workers.shrink_to_fit(); + + join_all(workers).await; } diff --git a/src/lib.rs b/src/lib.rs index d8c8a5ca..4769c003 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ pub mod cmd; pub mod conf; -pub mod relay; pub mod consts; +pub use realm_core as core; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const ENV_CONFIG: &str = "REALM_CONF"; diff --git a/src/relay.rs b/src/relay.rs deleted file mode 100644 index ae5498e2..00000000 --- a/src/relay.rs +++ /dev/null @@ -1,29 +0,0 @@ -use futures::future::join_all; - -use realm_core::tcp::run_tcp; -use realm_core::udp::run_udp; - -use crate::conf::EndpointInfo; - -pub async fn run(endpoints: Vec) { - let mut workers = Vec::with_capacity(2 * endpoints.len()); - - for EndpointInfo { - endpoint, - no_tcp, - use_udp, - } in endpoints - { - if use_udp { - workers.push(tokio::spawn(run_udp(endpoint.clone()))); - } - - if !no_tcp { - workers.push(tokio::spawn(run_tcp(endpoint))); - } - } - - workers.shrink_to_fit(); - - join_all(workers).await; -}