mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-26 23:37:01 -05:00
Construct tor transport for Bob
This commit is contained in:
parent
3b008c38a6
commit
7afd316210
@ -2,6 +2,7 @@ use libp2p::core::Multiaddr;
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
|
#[structopt(name = "xmr-btc-swap", about = "Trustless XMR BTC swaps")]
|
||||||
pub enum Options {
|
pub enum Options {
|
||||||
Alice {
|
Alice {
|
||||||
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
||||||
@ -22,5 +23,8 @@ pub enum Options {
|
|||||||
|
|
||||||
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
#[structopt(default_value = "http://127.0.0.1:8332", long = "bitcoind")]
|
||||||
bitcoind_url: Url,
|
bitcoind_url: Url,
|
||||||
|
|
||||||
|
#[structopt(long = "tor")]
|
||||||
|
tor: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ async fn main() -> Result<()> {
|
|||||||
let onion_address_string = format!("/onion3/{}:{}", onion_address, tor_port);
|
let onion_address_string = format!("/onion3/{}:{}", onion_address, tor_port);
|
||||||
let addr: Multiaddr = onion_address_string.parse()?;
|
let addr: Multiaddr = onion_address_string.parse()?;
|
||||||
let ac = create_tor_service(tor_secret_key, tor_port).await?;
|
let ac = create_tor_service(tor_secret_key, tor_port).await?;
|
||||||
let transport = build_tor(local_key_pair, addr.clone(), tor_port)?;
|
let transport = build_tor(local_key_pair, Some((addr.clone(), tor_port)))?;
|
||||||
(addr, Some(ac), transport)
|
(addr, Some(ac), transport)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@ -88,13 +88,17 @@ async fn main() -> Result<()> {
|
|||||||
alice_addr,
|
alice_addr,
|
||||||
satoshis,
|
satoshis,
|
||||||
bitcoind_url: url,
|
bitcoind_url: url,
|
||||||
|
tor,
|
||||||
} => {
|
} => {
|
||||||
info!("running swap node as Bob ...");
|
info!("running swap node as Bob ...");
|
||||||
|
|
||||||
let behaviour = Bob::default();
|
let behaviour = Bob::default();
|
||||||
let local_key_pair = behaviour.identity();
|
let local_key_pair = behaviour.identity();
|
||||||
|
|
||||||
let transport = build(local_key_pair)?;
|
let transport = match tor {
|
||||||
|
true => build_tor(local_key_pair, None)?,
|
||||||
|
false => build(local_key_pair)?,
|
||||||
|
};
|
||||||
|
|
||||||
let bitcoin_wallet = Wallet::new("bob", &url)
|
let bitcoin_wallet = Wallet::new("bob", &url)
|
||||||
.await
|
.await
|
||||||
|
@ -5,7 +5,7 @@ use libp2p::{
|
|||||||
muxing::StreamMuxerBox,
|
muxing::StreamMuxerBox,
|
||||||
transport::Boxed,
|
transport::Boxed,
|
||||||
upgrade::{SelectUpgrade, Version},
|
upgrade::{SelectUpgrade, Version},
|
||||||
Multiaddr, Transport,
|
Transport,
|
||||||
},
|
},
|
||||||
dns::DnsConfig,
|
dns::DnsConfig,
|
||||||
mplex::MplexConfig,
|
mplex::MplexConfig,
|
||||||
@ -46,13 +46,15 @@ pub fn build(id_keys: identity::Keypair) -> Result<SwapTransport> {
|
|||||||
/// - multiplexing via yamux or mplex
|
/// - multiplexing via yamux or mplex
|
||||||
pub fn build_tor(
|
pub fn build_tor(
|
||||||
id_keys: identity::Keypair,
|
id_keys: identity::Keypair,
|
||||||
addr: libp2p::core::Multiaddr,
|
address_port_pair: Option<(libp2p::core::Multiaddr, u16)>,
|
||||||
port: u16,
|
|
||||||
) -> Result<SwapTransport> {
|
) -> Result<SwapTransport> {
|
||||||
use libp2p_tokio_socks5::Socks5TokioTcpConfig;
|
use libp2p_tokio_socks5::Socks5TokioTcpConfig;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
let map: HashMap<Multiaddr, u16> = [(addr, port)].iter().cloned().collect();
|
let mut map = HashMap::new();
|
||||||
|
if let Some((addr, port)) = address_port_pair {
|
||||||
|
map.insert(addr, port);
|
||||||
|
}
|
||||||
|
|
||||||
let dh_keys = noise::Keypair::<X25519Spec>::new().into_authentic(&id_keys)?;
|
let dh_keys = noise::Keypair::<X25519Spec>::new().into_authentic(&id_keys)?;
|
||||||
let noise = NoiseConfig::xx(dh_keys).into_authenticated();
|
let noise = NoiseConfig::xx(dh_keys).into_authenticated();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user