Skip to content

Commit

Permalink
Add proxy support for ckb
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Dec 18, 2024
1 parent 8367136 commit 9f7a3de
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 56 deletions.
59 changes: 8 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions util/app-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 10 additions & 0 deletions util/app-config/src/configs/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9f7a3de

Please sign in to comment.