diff --git a/swap/src/cli.rs b/swap/src/cli.rs index 6eb554e86..7fc460d2a 100644 --- a/swap/src/cli.rs +++ b/swap/src/cli.rs @@ -46,7 +46,7 @@ mod tests { rendezvous_peer_id, rendezvous_address, namespace, - 0, + None, identity::Keypair::generate_ed25519(), ); let sellers = tokio::time::timeout(Duration::from_secs(15), list_sellers) diff --git a/swap/src/cli/api/request.rs b/swap/src/cli/api/request.rs index de6274fce..53fb6b780 100644 --- a/swap/src/cli/api/request.rs +++ b/swap/src/cli/api/request.rs @@ -623,7 +623,12 @@ pub async fn buy_xmr( (seed.derive_libp2p_identity(), context.config.namespace), ); - let mut swarm = swarm::cli(seed.derive_libp2p_identity(), None, behaviour).await?; + let mut swarm = swarm::cli( + seed.derive_libp2p_identity(), + context.tor_client.clone(), + behaviour, + ) + .await?; swarm.add_peer_address(seller_peer_id, seller); @@ -808,7 +813,7 @@ pub async fn resume_swap( ), (seed.clone(), context.config.namespace), ); - let mut swarm = swarm::cli(seed.clone(), None, behaviour).await?; + let mut swarm = swarm::cli(seed.clone(), context.tor_client.clone(), behaviour).await?; let our_peer_id = swarm.local_peer_id(); tracing::debug!(peer_id = %our_peer_id, "Network layer initialized"); @@ -1078,7 +1083,7 @@ pub async fn list_sellers( rendezvous_node_peer_id, rendezvous_point, context.config.namespace, - context.config.tor_socks5_port, + context.tor_client.clone(), identity, ) .await?; diff --git a/swap/src/cli/list_sellers.rs b/swap/src/cli/list_sellers.rs index 12cb16672..1bbb5224e 100644 --- a/swap/src/cli/list_sellers.rs +++ b/swap/src/cli/list_sellers.rs @@ -2,6 +2,7 @@ use crate::network::quote::BidQuote; use crate::network::rendezvous::XmrBtcNamespace; use crate::network::{quote, swarm}; use anyhow::{Context, Result}; +use arti_client::TorClient; use futures::StreamExt; use libp2p::multiaddr::Protocol; use libp2p::request_response; @@ -12,7 +13,9 @@ use serde::Serialize; use serde_with::{serde_as, DisplayFromStr}; use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::sync::Arc; use std::time::Duration; +use tor_rtcompat::tokio::TokioRustlsRuntime; use typeshare::typeshare; /// Returns sorted list of sellers, with [Online](Status::Online) listed first. @@ -25,7 +28,7 @@ pub async fn list_sellers( rendezvous_node_peer_id: PeerId, rendezvous_node_addr: Multiaddr, namespace: XmrBtcNamespace, - tor_socks5_port: u16, + maybe_tor_client: Option>>, identity: identity::Keypair, ) -> Result> { let behaviour = Behaviour { @@ -33,7 +36,7 @@ pub async fn list_sellers( quote: quote::cli(), ping: ping::Behaviour::new(ping::Config::new().with_timeout(Duration::from_secs(60))), }; - let mut swarm = swarm::cli(identity, None, behaviour).await?; + let mut swarm = swarm::cli(identity, maybe_tor_client, behaviour).await?; swarm.add_peer_address(rendezvous_node_peer_id, rendezvous_node_addr.clone()); diff --git a/swap/src/cli/tor.rs b/swap/src/cli/tor.rs index d47d979ec..598d98ec4 100644 --- a/swap/src/cli/tor.rs +++ b/swap/src/cli/tor.rs @@ -7,6 +7,7 @@ use tor_rtcompat::tokio::TokioRustlsRuntime; pub async fn init_tor_client( data_dir: &PathBuf, ) -> Result>, Error> { + // We store the Tor state in the data directory let data_dir = data_dir.join("tor"); let state_dir = data_dir.join("state"); let cache_dir = data_dir.join("cache"); @@ -20,7 +21,7 @@ pub async fn init_tor_client( // Start the Arti client, and let it bootstrap a connection to the Tor network. // (This takes a while to gather the necessary directory information. // It uses cached information when possible.) - let tor_client = TorClient::create_bootstrapped(config).await?; + let tor_client = TorClient::::create_bootstrapped(config).await?; Ok(Arc::new(tor_client)) } diff --git a/swap/src/cli/transport.rs b/swap/src/cli/transport.rs index 51371a62e..f2a47814a 100644 --- a/swap/src/cli/transport.rs +++ b/swap/src/cli/transport.rs @@ -27,10 +27,14 @@ pub fn new( let tcp_with_dns = dns::tokio::Transport::system(tcp)?; let maybe_tor_transport: OptionalTransport = match maybe_tor_client { - Some(client) => OptionalTransport::some(libp2p_community_tor::TorTransport { - client, - conversion_mode: AddressConversion::IpAndDns, - }), + Some(client) => { + println!("Using Tor transport"); + + OptionalTransport::some(libp2p_community_tor::TorTransport::from_client( + client, + AddressConversion::IpAndDns, + )) + } None => OptionalTransport::none(), }; diff --git a/swap/src/common/tracing_util.rs b/swap/src/common/tracing_util.rs index 28971a116..1bc102eae 100644 --- a/swap/src/common/tracing_util.rs +++ b/swap/src/common/tracing_util.rs @@ -103,6 +103,10 @@ fn env_filter(level_filter: LevelFilter) -> Result { .add_directive(Directive::from_str(&format!("swap={}", &level_filter))?) .add_directive(Directive::from_str(&format!("arti={}", &level_filter))?) .add_directive(Directive::from_str(&format!("libp2p={}", &level_filter))?) + .add_directive(Directive::from_str(&format!( + "libp2p_community_tor={}", + &level_filter + ))?) .add_directive(Directive::from_str(&format!( "unstoppableswap-gui-rs={}", &level_filter diff --git a/swap/src/network/swarm.rs b/swap/src/network/swarm.rs index cb3d3ef09..9a89c2d58 100644 --- a/swap/src/network/swarm.rs +++ b/swap/src/network/swarm.rs @@ -2,7 +2,7 @@ use crate::asb::{LatestRate, RendezvousNode}; use crate::libp2p_ext::MultiAddrExt; use crate::network::rendezvous::XmrBtcNamespace; use crate::seed::Seed; -use crate::{asb, bitcoin, cli, env, tor}; +use crate::{asb, bitcoin, cli, env}; use anyhow::Result; use arti_client::TorClient; use libp2p::swarm::NetworkBehaviour;