From 9f7a3dede9feaa0100f798bac64b9c7289eb9d4e Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 2 Dec 2024 13:14:42 +0800 Subject: [PATCH] Add proxy support for ckb Signed-off-by: Eval EXEC --- Cargo.lock | 59 ++++---------------------- network/Cargo.toml | 6 +-- network/src/network.rs | 9 ++++ util/app-config/Cargo.toml | 4 +- util/app-config/src/configs/network.rs | 10 +++++ 5 files changed, 32 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a16b98cda8..2cf4fc216b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,8 +707,8 @@ dependencies = [ "serde", "serde_json", "tempfile", - "tentacle-multiaddr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle-secio 0.6.4", + "tentacle-multiaddr", + "tentacle-secio", "toml", "ubyte", "url", @@ -4077,7 +4077,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -6568,13 +6568,13 @@ dependencies = [ [[package]] name = "tentacle" -version = "0.6.4" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" +version = "0.6.5" dependencies = [ "async-trait", "bytes", "futures", "futures-timer", + "httparse", "igd-next", "js-sys", "libc", @@ -6586,8 +6586,8 @@ dependencies = [ "shadowsocks", "shadowsocks-service", "socket2", - "tentacle-multiaddr 0.3.4 (git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy)", - "tentacle-secio 0.6.3", + "tentacle-multiaddr", + "tentacle-secio", "thiserror", "tokio", "tokio-tungstenite", @@ -6601,20 +6601,6 @@ dependencies = [ [[package]] name = "tentacle-multiaddr" version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9e71b28bf0bbf274b92f47cb2c5b42755d84a11e2246cf7bcb7b65c89483b9" -dependencies = [ - "bs58", - "bytes", - "serde", - "sha2", - "unsigned-varint", -] - -[[package]] -name = "tentacle-multiaddr" -version = "0.3.4" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" dependencies = [ "bs58", "bytes", @@ -6623,37 +6609,9 @@ dependencies = [ "unsigned-varint", ] -[[package]] -name = "tentacle-secio" -version = "0.6.3" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" -dependencies = [ - "bs58", - "bytes", - "chacha20poly1305", - "futures", - "getrandom 0.2.15", - "hmac", - "log", - "molecule", - "openssl", - "openssl-sys", - "rand 0.8.5", - "rand_core 0.6.4", - "ring", - "secp256k1", - "sha2", - "tokio", - "tokio-util", - "unsigned-varint", - "x25519-dalek", -] - [[package]] name = "tentacle-secio" version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d53673d63399e1d557c2e884b045d242811079d3b2f17a569310e5c3f1db33" dependencies = [ "bs58", "bytes", @@ -6975,8 +6933,7 @@ dependencies = [ [[package]] name = "tokio-yamux" -version = "0.3.9" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" +version = "0.3.10" dependencies = [ "bytes", "futures", diff --git a/network/Cargo.toml b/network/Cargo.toml index dad4401147..6931e9327c 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -34,10 +34,10 @@ serde_json = "1.0" bloom-filters = "0.1" ckb-spawn = { path = "../util/spawn", version = "= 0.121.0-pre" } bitflags = "1.0" -p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false } +p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false } [target.'cfg(not(target_family = "wasm"))'.dependencies] -p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false, features = [ +p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false, features = [ "upnp", "parking_lot", "openssl-vendored", @@ -48,7 +48,7 @@ p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", pa socket2 = "0.5" [target.'cfg(target_family = "wasm")'.dependencies] -p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false, features = [ +p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false, features = [ "wasm-timer", ] } idb = "0.6" diff --git a/network/src/network.rs b/network/src/network.rs index a8003aa3d3..26ec80707e 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -28,6 +28,7 @@ use ckb_systemtime::{Duration, Instant}; use ckb_util::{Condvar, Mutex, RwLock}; use futures::{channel::mpsc::Sender, Future}; use ipnetwork::IpNetwork; +use p2p::service::ProxyConfig; use p2p::{ async_trait, builder::ServiceBuilder, @@ -1015,6 +1016,14 @@ impl NetworkService { }; init.transform(TransportType::Tcp); service_builder = service_builder.tcp_config(bind_fn); + + if config.proxy_config.enable { + let proxy_config = Some(ProxyConfig { + proxy_url: config.proxy_config.proxy_url.clone(), + }); + service_builder = + service_builder.tcp_proxy_config(proxy_config); + } } } TransportType::Ws => { diff --git a/util/app-config/Cargo.toml b/util/app-config/Cargo.toml index 8e12714fd6..4c11e257f1 100644 --- a/util/app-config/Cargo.toml +++ b/util/app-config/Cargo.toml @@ -22,8 +22,8 @@ ckb-pow = { path = "../../pow", version = "= 0.121.0-pre" } ckb-resource = { path = "../../resource", version = "= 0.121.0-pre" } ckb-build-info = { path = "../build-info", version = "= 0.121.0-pre" } ckb-types = { path = "../types", version = "= 0.121.0-pre" } -secio = { version = "0.6", package = "tentacle-secio" } -multiaddr = { version = "0.3.0", package = "tentacle-multiaddr" } +secio = { path="/home/exec/Projects/github.com/nervosnetwork/tentacle/secio", package = "tentacle-secio" } +multiaddr = { path="/home/exec/Projects/github.com/nervosnetwork/tentacle/multiaddr", package = "tentacle-multiaddr" } rand = "0.8" sentry = { version = "0.34.0", optional = true } ckb-systemtime = { path = "../systemtime", version = "= 0.121.0-pre" } diff --git a/util/app-config/src/configs/network.rs b/util/app-config/src/configs/network.rs index 34eac57790..4eafa7df87 100644 --- a/util/app-config/src/configs/network.rs +++ b/util/app-config/src/configs/network.rs @@ -95,6 +95,16 @@ pub struct Config { #[cfg(target_family = "wasm")] #[serde(skip)] pub secret_key: [u8; 32], + + #[serde(default)] + pub proxy_config: ProxyConfig, +} + +/// Proxy related config options +#[derive(Clone, Debug, Serialize, Deserialize, Default)] +pub struct ProxyConfig { + pub enable: bool, + pub proxy_url: String, } /// Chain synchronization config options.