Skip to content

Commit 8ddf15a

Browse files
authored
refactor: replace torut with manual implementation (#5271)
1 parent aeb0136 commit 8ddf15a

10 files changed

Lines changed: 1228 additions & 275 deletions

File tree

Cargo.lock

Lines changed: 45 additions & 167 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,12 @@ criterion = "0.5"
220220
crossbeam = "0.8.2"
221221
crossbeam-channel = "0.5.1"
222222
ctrlc = "3.1"
223+
data-encoding = "2.6"
223224
daggy = "0.8.0"
224225
dashmap = "6.0"
225226
derive_more = { version = "1", default-features = false }
226227
eaglesong = "0.1"
228+
ed25519-dalek = "2.1"
227229
env_logger = "0.10"
228230
fail = "0.4"
229231
faster-hex = "0.6"
@@ -240,6 +242,7 @@ governor = { version = "0.10", default-features = false, features = [
240242
] }
241243
hex = "0.4"
242244
hickory-resolver = "0.24.2"
245+
hmac = "0.12"
243246
http-body-util = "0.1"
244247
hyper = "1"
245248
hyper-tls = "0.6"
@@ -288,6 +291,7 @@ secio = { version = "0.6.8", package = "tentacle-secio" }
288291
secp256k1 = "0.30"
289292
semver = "1.0"
290293
sentry = "0.34.0"
294+
sha2 = "0.10"
291295
serde = "1.0"
292296
serde_json = "1.0"
293297
serde_plain = "0.3.0"
@@ -305,7 +309,6 @@ tiny-keccak = "2.0"
305309
tokio = "1.35.0"
306310
tokio-util = "0.7.8"
307311
toml = "0.5"
308-
torut = "0.2.1"
309312
tower-http = "0.6"
310313
ubyte = "0.10"
311314
url = "2.2.2"

deny.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ ignore = [
8484
"RUSTSEC-2024-0436",
8585
# wait https://github.com/tikv/rust-prometheus/issues/538
8686
"RUSTSEC-2024-0437",
87-
# torut introduce these:
88-
# - https://rustsec.org/advisories/RUSTSEC-2022-0093
89-
# - https://rustsec.org/advisories/RUSTSEC-2024-0344
90-
# these won't have bad effect for ckb
91-
"RUSTSEC-2024-0344",
92-
"RUSTSEC-2022-0093",
9387
#"RUSTSEC-0000-0000",
9488
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
9589
#"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish

test/src/specs/tor/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod tor_basic;
22
mod tor_connect;
33
mod tor_hash_password;
44
mod tor_reconnect;
5-
use ckb_async_runtime::Runtime;
5+
use ckb_async_runtime::{Handle, Runtime};
66
use ckb_logger::{error, info};
77
use std::{path::Path, process::Child};
88
use tempfile::{TempDir, tempdir};
@@ -52,9 +52,15 @@ impl TorServer {
5252
pub fn tor_wait_bootstrap_done(&self) {
5353
let tor_controller_url = format!("127.0.0.1:{}", self.control_port);
5454
let controller_password = self.controller_password.clone();
55-
Runtime::new().unwrap().block_on(async {
56-
let tor_controller =
57-
ckb_onion::TorController::new(tor_controller_url, controller_password, None).await;
55+
let runtime = Runtime::new().unwrap();
56+
let handle = Handle::new(runtime.handle().clone(), None);
57+
handle.block_on(async {
58+
let tor_controller = ckb_onion::TorController::new(
59+
tor_controller_url,
60+
controller_password,
61+
handle.clone(),
62+
)
63+
.await;
5864
let mut tor_controller = tor_controller.unwrap();
5965
if let Err(err) = tor_controller.wait_tor_server_bootstrap_done().await {
6066
error!("wait tor server bootstrap done error: {:?}", err);

util/onion/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ repository = "https://github.com/nervosnetwork/ckb"
1010
rust-version = "1.95.0"
1111

1212
[dependencies]
13-
base64.workspace = true
13+
data-encoding.workspace = true
14+
ed25519-dalek = { workspace = true, features = ["hazmat"] }
15+
hmac.workspace = true
16+
hex.workspace = true
17+
rand.workspace = true
18+
sha2.workspace = true
19+
tiny-keccak = { workspace = true, features = ["sha3"] }
1420
tokio = { workspace = true, features = [ "full", "macros" ]}
15-
torut.workspace = true
1621
ckb-error.workspace = true
1722
ckb-async-runtime.workspace = true
1823
ckb-logger.workspace = true
1924
ckb-stop-handler.workspace = true
2025
ckb-network.workspace = true
21-
futures.workspace = true
26+
thiserror.workspace = true
27+
strum.workspace = true
2228

2329
[dev-dependencies]
2430
ckb-network.workspace = true

util/onion/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
33
use std::net::SocketAddr;
44

5-
use futures::future::BoxFuture;
6-
use torut::control::{AsyncEvent, ConnError};
7-
5+
mod onion;
86
/// Onion service module
97
pub mod onion_service;
8+
mod tor_connection;
109
/// Tor controller module
1110
pub mod tor_controller;
1211

12+
pub use onion::{OnionAddressV3, TorPublicKeyV3, TorSecretKeyV3};
13+
pub use tor_connection::ConnError;
1314
pub use tor_controller::TorController;
1415

15-
/// Tor event handler function
16-
pub type TorEventHandlerFn = fn(AsyncEvent<'_>) -> BoxFuture<'static, Result<(), ConnError>>;
17-
1816
/// Configuration for onion service
1917
pub struct OnionServiceConfig {
2018
/// path to store onion private key, default is ./data/network/onion_private_key

0 commit comments

Comments
 (0)