mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-25 06:39:53 -04:00
Add support for swapping through Tor.
This PR does a few things. * It adds a TorTransport which either dials through Tor's socks5 proxy or via clearnet. * It enables ASB to register hidden services for each network it is listening on. We assume that we only care about different ports and re-use the same onion-address for all of them. The ASB requires to have access to Tor's control port. * It adds support to dial through a local Tor socks5 proxy. We assume that Tor is always available on localhost. Swap cli only requires Tor to be running so that it can send messages via Tor's socks5 proxy. * It adds a new e2e test which swaps through Tor. For this we assume that Tor is currently running on localhost. All other tests are running via clear net.
This commit is contained in:
parent
e262345b4f
commit
632293cf91
14 changed files with 856 additions and 116 deletions
|
@ -1,24 +1,53 @@
|
|||
use crate::network::transport;
|
||||
use crate::protocol::{alice, bob};
|
||||
use crate::seed::Seed;
|
||||
use crate::tor;
|
||||
use anyhow::Result;
|
||||
use libp2p::swarm::{NetworkBehaviour, SwarmBuilder};
|
||||
use libp2p::{PeerId, Swarm};
|
||||
|
||||
pub fn alice(seed: &Seed) -> Result<Swarm<alice::Behaviour>> {
|
||||
new(seed, alice::Behaviour::default())
|
||||
with_clear_net(seed, alice::Behaviour::default())
|
||||
}
|
||||
|
||||
pub fn bob(seed: &Seed, alice: PeerId) -> Result<Swarm<bob::Behaviour>> {
|
||||
new(seed, bob::Behaviour::new(alice))
|
||||
pub async fn bob(
|
||||
seed: &Seed,
|
||||
alice: PeerId,
|
||||
tor_socks5_port: u16,
|
||||
) -> Result<Swarm<bob::Behaviour>> {
|
||||
let client = tor::Client::new(tor_socks5_port);
|
||||
if client.assert_tor_running().await.is_ok() {
|
||||
return with_tor(seed, bob::Behaviour::new(alice), tor_socks5_port).await;
|
||||
}
|
||||
with_clear_net(seed, bob::Behaviour::new(alice))
|
||||
}
|
||||
|
||||
fn new<B>(seed: &Seed, behaviour: B) -> Result<Swarm<B>>
|
||||
fn with_clear_net<B>(seed: &Seed, behaviour: B) -> Result<Swarm<B>>
|
||||
where
|
||||
B: NetworkBehaviour,
|
||||
{
|
||||
tracing::info!("All connections will go through clear net.");
|
||||
let identity = seed.derive_libp2p_identity();
|
||||
let transport = transport::build(&identity)?;
|
||||
let transport = transport::build_clear_net(&identity)?;
|
||||
let peer_id = identity.public().into_peer_id();
|
||||
tracing::debug!("Our peer-id: {}", peer_id);
|
||||
|
||||
let swarm = SwarmBuilder::new(transport, behaviour, peer_id)
|
||||
.executor(Box::new(|f| {
|
||||
tokio::spawn(f);
|
||||
}))
|
||||
.build();
|
||||
|
||||
Ok(swarm)
|
||||
}
|
||||
|
||||
async fn with_tor<B>(seed: &Seed, behaviour: B, tor_socks5_port: u16) -> Result<Swarm<B>>
|
||||
where
|
||||
B: NetworkBehaviour,
|
||||
{
|
||||
tracing::info!("All connections will go through Tor socks5 proxy.");
|
||||
let identity = seed.derive_libp2p_identity();
|
||||
let transport = transport::build_tor(&identity, tor_socks5_port)?;
|
||||
let peer_id = identity.public().into_peer_id();
|
||||
tracing::debug!("Our peer-id: {}", peer_id);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue