Skip to content

Commit 64a88ab

Browse files
authored
Merge pull request #319 from rustaceanrob/remove-arti-3-29
Remove `arti` dependency in favor of tor proxy
2 parents 4eaf7c8 + 64c9046 commit 64a88ab

File tree

15 files changed

+554
-3973
lines changed

15 files changed

+554
-3973
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,10 @@ tokio = { version = "1", default-features = false, features = [
3131

3232
# Optional dependencies
3333
rusqlite = { version = "0.31.0", features = ["bundled"], optional = true }
34-
arti-client = { version = "0.21.0", features = [
35-
"rustls",
36-
"tokio",
37-
"onion-service-client",
38-
"experimental-api",
39-
], default-features = false, optional = true }
40-
tor-rtcompat = { version = "0.21.0", features = ["tokio"], optional = true }
4134

4235
[features]
4336
default = ["database"]
4437
database = ["rusqlite"]
45-
tor = ["arti-client", "tor-rtcompat"]
4638
filter-control = []
4739

4840
[dev-dependencies]
@@ -73,11 +65,6 @@ path = "example/testnet4.rs"
7365
name = "rescan"
7466
path = "example/rescan.rs"
7567

76-
[[example]]
77-
name = "tor"
78-
path = "example/tor.rs"
79-
required-features = ["tor"]
80-
8168
[[example]]
8269
name = "managed"
8370
path = "example/managed.rs"

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ async fn main() {
101101

102102
The `kyoto` core library with default features supports an MSRV of Rust 1.63.
103103

104-
While connections over the Tor protocol are supported by the feature `tor`, the dependencies required cannot support the MSRV. As such, no MSRV guarantees will be made when using Tor, and the feature should be considered experimental.
105-
106104
## Integration Testing
107105

108106
The preferred workflow is by using `just`. If you do not have `just` installed, check out the [installation page](https://just.systems/man/en/chapter_4.html).

example/tor.rs

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/builder.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ use crate::db::error::SqlInitializationError;
1111
#[cfg(feature = "database")]
1212
use crate::db::sqlite::{headers::SqliteHeaderDb, peers::SqlitePeerDb};
1313
use crate::network::dns::{DnsResolver, DNS_RESOLVER_PORT};
14+
use crate::network::ConnectionType;
1415
use crate::{
1516
chain::checkpoints::HeaderCheckpoint,
1617
db::traits::{HeaderStore, PeerStore},
1718
};
18-
use crate::{ConnectionType, FilterSyncPolicy, LogLevel, PeerStoreSizeConfig, TrustedPeer};
19+
use crate::{FilterSyncPolicy, LogLevel, PeerStoreSizeConfig, TrustedPeer};
1920

2021
#[cfg(feature = "database")]
2122
/// The default node returned from the [`NodeBuilder`](crate::core).
@@ -149,12 +150,6 @@ impl NodeBuilder {
149150
self
150151
}
151152

152-
/// Set the desired communication channel. Either directly over TCP or over the Tor network.
153-
pub fn connection_type(mut self, connection_type: ConnectionType) -> Self {
154-
self.config.connection_type = connection_type;
155-
self
156-
}
157-
158153
/// Set the time duration a peer has to respond to a message from the local node.
159154
///
160155
/// ## Note
@@ -193,6 +188,15 @@ impl NodeBuilder {
193188
self
194189
}
195190

191+
/// Route network traffic through a Tor daemon using a Socks5 proxy. Currently, proxies
192+
/// must be reachable by IP address.
193+
pub fn socks5_proxy(mut self, proxy: impl Into<SocketAddr>) -> Self {
194+
let ip_addr = proxy.into();
195+
let connection = ConnectionType::Socks5Proxy(ip_addr);
196+
self.config.connection_type = connection;
197+
self
198+
}
199+
196200
/// Stop the node from downloading and checking compact block filters until an explicit command by the client is made.
197201
/// This is only useful if the scripts to check for may not be known do to some expensive computation, like in a silent
198202
/// payments context.

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::{collections::HashSet, path::PathBuf, time::Duration};
33
use bitcoin::ScriptBuf;
44

55
use crate::{
6-
chain::checkpoints::HeaderCheckpoint, network::dns::DnsResolver, ConnectionType,
6+
chain::checkpoints::HeaderCheckpoint,
7+
network::{dns::DnsResolver, ConnectionType},
78
FilterSyncPolicy, LogLevel, PeerStoreSizeConfig, TrustedPeer,
89
};
910

src/lib.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@
7676
//! `database`: use the default `rusqlite` database implementations. Default and recommend feature.
7777
//!
7878
//! `filter-control`: check filters and request blocks directly. Recommended for silent payments or strict chain ordering implementations.
79-
//!
80-
//! `tor` *No MSRV guarantees*: connect to nodes over the Tor network.
8179
8280
#![warn(missing_docs)]
8381
pub mod chain;
@@ -116,11 +114,6 @@ use std::collections::HashSet;
116114

117115
use std::net::{IpAddr, SocketAddr};
118116

119-
#[cfg(feature = "tor")]
120-
pub use arti_client::{TorClient, TorClientConfig};
121-
#[cfg(feature = "tor")]
122-
use tor_rtcompat::PreferredRuntime;
123-
124117
// Re-exports
125118
#[doc(inline)]
126119
pub use chain::checkpoints::{
@@ -320,21 +313,6 @@ impl TrustedPeer {
320313
}
321314
}
322315

323-
/// Create a new peer from a TorV3 service and port.
324-
#[cfg(feature = "tor")]
325-
pub fn new_from_tor_v3(
326-
public_key: [u8; 32],
327-
port: Option<u16>,
328-
services: ServiceFlags,
329-
) -> Self {
330-
let address = AddrV2::TorV3(public_key);
331-
Self {
332-
address,
333-
port,
334-
known_services: services,
335-
}
336-
}
337-
338316
/// Create a new trusted peer using the default port for the network.
339317
pub fn from_ip(ip_addr: impl Into<IpAddr>) -> Self {
340318
let address = match ip_addr.into() {
@@ -362,17 +340,6 @@ impl TrustedPeer {
362340
}
363341
}
364342

365-
/// Create a new peer from a TorV3 service.
366-
#[cfg(feature = "tor")]
367-
pub fn from_tor_v3(public_key: [u8; 32]) -> Self {
368-
let address = AddrV2::TorV3(public_key);
369-
Self {
370-
address,
371-
port: None,
372-
known_services: ServiceFlags::NONE,
373-
}
374-
}
375-
376343
/// The IP address of the trusted peer.
377344
pub fn address(&self) -> AddrV2 {
378345
self.address.clone()
@@ -422,18 +389,6 @@ impl From<SocketAddr> for TrustedPeer {
422389
}
423390
}
424391

425-
/// How to connect to peers on the peer-to-peer network
426-
#[derive(Default, Clone)]
427-
#[non_exhaustive]
428-
pub enum ConnectionType {
429-
/// Version one peer-to-peer connections
430-
#[default]
431-
ClearNet,
432-
/// Connect to peers over Tor
433-
#[cfg(feature = "tor")]
434-
Tor(TorClient<PreferredRuntime>),
435-
}
436-
437392
/// Configure how many peers will be stored.
438393
#[derive(Debug, Default, Clone)]
439394
pub enum PeerStoreSizeConfig {

src/network/error.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl_sourceless_error!(PeerReadError);
2929

3030
// TODO: (@leonardo) Should the error variants wrap inner errors for richer information ?
3131
#[derive(Debug)]
32-
pub enum PeerError {
32+
pub(crate) enum PeerError {
3333
ConnectionFailed,
3434
MessageEncryption,
3535
MessageSerialization,
@@ -39,6 +39,7 @@ pub enum PeerError {
3939
DisconnectCommand,
4040
Reader,
4141
UnreachableSocketAddr,
42+
Socks5(Socks5Error),
4243
}
4344

4445
impl core::fmt::Display for PeerError {
@@ -68,12 +69,50 @@ impl core::fmt::Display for PeerError {
6869
PeerError::MessageEncryption => {
6970
write!(f, "encrypting a serialized message failed.")
7071
}
72+
PeerError::Socks5(err) => {
73+
write!(f, "could not connect via Socks5 proxy: {err}")
74+
}
7175
}
7276
}
7377
}
7478

7579
impl_sourceless_error!(PeerError);
7680

81+
#[derive(Debug, Clone)]
82+
pub(crate) enum Socks5Error {
83+
WrongVersion,
84+
AuthRequired,
85+
ConnectionTimeout,
86+
ConnectionFailed,
87+
IO,
88+
}
89+
90+
impl core::fmt::Display for Socks5Error {
91+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
92+
match self {
93+
Socks5Error::WrongVersion => write!(f, "server responded with an unsupported version."),
94+
Socks5Error::AuthRequired => write!(f, "server requires authentication."),
95+
Socks5Error::ConnectionTimeout => write!(f, "connection to server timed out."),
96+
Socks5Error::ConnectionFailed => write!(
97+
f,
98+
"the server could not connect to the requested destination."
99+
),
100+
Socks5Error::IO => write!(
101+
f,
102+
"reading or writing to the TCP stream failed unexpectedly."
103+
),
104+
}
105+
}
106+
}
107+
108+
impl_sourceless_error!(Socks5Error);
109+
110+
impl From<std::io::Error> for Socks5Error {
111+
fn from(_value: std::io::Error) -> Self {
112+
Socks5Error::IO
113+
}
114+
}
115+
77116
#[derive(Debug)]
78117
pub(crate) enum DnsBootstrapError {
79118
NotEnoughPeersError,

0 commit comments

Comments
 (0)