From 3a5395d7a568aeee89343529a60ec1dc6b8bc52d Mon Sep 17 00:00:00 2001 From: Philipp Hoenisch Date: Thu, 22 Apr 2021 15:35:58 +1000 Subject: [PATCH] Optimize torut features. OnionV2 addresses are being deprecated and will be fully phased out on 15.10.2021: https://blog.torproject.org/v2-deprecation-timeline --- Cargo.lock | 49 +------------------------------ Cargo.toml | 3 ++ swap/Cargo.toml | 2 +- swap/src/network/tor_transport.rs | 27 +++++------------ 4 files changed, 12 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2908019c..70ad6601 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1086,21 +1086,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -2417,33 +2402,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-sys", -] - -[[package]] -name = "openssl-sys" -version = "0.9.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" -dependencies = [ - "autocfg 1.0.1", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parity-multiaddr" version = "0.11.2" @@ -4175,8 +4133,7 @@ dependencies = [ [[package]] name = "torut" version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08dc613abef9de8afce27c7bb73aa735d60d0e479a81ba50a4cd3c382fc46fa3" +source = "git+https://github.com/bonomat/torut/?branch=feature-flag-tor-secret-keys#d4f9858e3b4452c2056ff7ee4e50836cdcb62572" dependencies = [ "base32", "base64 0.10.1", @@ -4184,11 +4141,7 @@ dependencies = [ "ed25519-dalek", "hex 0.4.3", "hmac 0.7.1", - "openssl", "rand 0.7.3", - "serde", - "serde_derive", - "sha1", "sha2 0.8.2", "sha3", "tokio 1.5.0", diff --git a/Cargo.toml b/Cargo.toml index 8ddab59e..ed293ea0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,5 @@ [workspace] members = ["monero-harness", "monero-rpc", "swap"] + +[patch.crates-io] +torut = { git = "https://github.com/bonomat/torut/", branch = "feature-flag-tor-secret-keys", default-features = false, features = ["v3", "control"] } diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 9d0608f5..dac3dacb 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -54,7 +54,7 @@ tokio-socks = "0.5" tokio-tungstenite = { version = "0.14", features = [ "rustls-tls" ] } tokio-util = { version = "0.6", features = ["io"] } toml = "0.5" -torut = "0.1" +torut = { version = "0.1", default-features = false, features = ["v3", "control"] } tracing = { version = "0.1", features = ["attributes"] } tracing-appender = "0.1" tracing-futures = { version = "0.2", features = ["std-future", "futures-03"] } diff --git a/swap/src/network/tor_transport.rs b/swap/src/network/tor_transport.rs index 33abd376..3511ac82 100644 --- a/swap/src/network/tor_transport.rs +++ b/swap/src/network/tor_transport.rs @@ -13,7 +13,7 @@ use std::pin::Pin; use tokio_socks::tcp::Socks5Stream; use tokio_socks::IntoTargetAddr; -/// Represents the configuration for a TCP/IP transport capability for libp2p. +/// Represents the configuration for a Tor transport for libp2p. #[derive(Clone)] pub struct TorTcpConfig { inner: GenTcpConfig, @@ -79,25 +79,12 @@ impl Transport for TorTcpConfig { fn to_address_string(multi: Multiaddr) -> Option { let components = multi.iter(); for protocol in components { - match protocol { - Protocol::Onion(addr, port) => { - tracing::warn!("Onion service v2 is being deprecated, consider upgrading to v3"); - return Some(format!( - "{}.onion:{}", - BASE32.encode(addr.as_ref()).to_lowercase(), - port - )); - } - Protocol::Onion3(addr) => { - return Some(format!( - "{}.onion:{}", - BASE32.encode(addr.hash()).to_lowercase(), - addr.port() - )); - } - _ => { - // ignore - } + if let Protocol::Onion3(addr) = protocol { + return Some(format!( + "{}.onion:{}", + BASE32.encode(addr.hash()).to_lowercase(), + addr.port() + )); } }