mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-11 07:29:39 -05:00
Pass in CLI behaviour when creating swarm
This allows us to reuse the swarm setup with a different behaviour for discovering ASBs with a rendezvous node.
This commit is contained in:
parent
4cd27e372c
commit
ff8cca2e27
@ -91,14 +91,9 @@ async fn main() -> Result<()> {
|
||||
.context("Seller address must contain peer ID")?;
|
||||
db.insert_address(seller_peer_id, seller.clone()).await?;
|
||||
|
||||
let mut swarm = swarm::cli(
|
||||
&seed,
|
||||
seller_peer_id,
|
||||
tor_socks5_port,
|
||||
env_config,
|
||||
bitcoin_wallet.clone(),
|
||||
)
|
||||
.await?;
|
||||
let behaviour = cli::Behaviour::new(seller_peer_id, env_config, bitcoin_wallet.clone());
|
||||
let mut swarm =
|
||||
swarm::cli(seed.derive_libp2p_identity(), tor_socks5_port, behaviour).await?;
|
||||
swarm.behaviour_mut().add_address(seller_peer_id, seller);
|
||||
|
||||
tracing::debug!(peer_id = %swarm.local_peer_id(), "Network layer initialized");
|
||||
@ -191,14 +186,9 @@ async fn main() -> Result<()> {
|
||||
let seller_peer_id = db.get_peer_id(swap_id)?;
|
||||
let seller_addresses = db.get_addresses(seller_peer_id)?;
|
||||
|
||||
let mut swarm = swarm::cli(
|
||||
&seed,
|
||||
seller_peer_id,
|
||||
tor_socks5_port,
|
||||
env_config,
|
||||
bitcoin_wallet.clone(),
|
||||
)
|
||||
.await?;
|
||||
let behaviour = cli::Behaviour::new(seller_peer_id, env_config, bitcoin_wallet.clone());
|
||||
let mut swarm =
|
||||
swarm::cli(seed.derive_libp2p_identity(), tor_socks5_port, behaviour).await?;
|
||||
let our_peer_id = swarm.local_peer_id();
|
||||
tracing::debug!(peer_id = %our_peer_id, "Initializing network module");
|
||||
|
||||
|
@ -2,10 +2,9 @@ use crate::asb::LatestRate;
|
||||
use crate::seed::Seed;
|
||||
use crate::{asb, bitcoin, cli, env, tor};
|
||||
use anyhow::Result;
|
||||
use libp2p::swarm::SwarmBuilder;
|
||||
use libp2p::{PeerId, Swarm};
|
||||
use libp2p::swarm::{NetworkBehaviour, SwarmBuilder};
|
||||
use libp2p::{identity, Swarm};
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn asb<LR>(
|
||||
@ -34,21 +33,19 @@ where
|
||||
Ok(swarm)
|
||||
}
|
||||
|
||||
pub async fn cli(
|
||||
seed: &Seed,
|
||||
alice: PeerId,
|
||||
pub async fn cli<T>(
|
||||
identity: identity::Keypair,
|
||||
tor_socks5_port: u16,
|
||||
env_config: env::Config,
|
||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||
) -> Result<Swarm<cli::Behaviour>> {
|
||||
behaviour: T,
|
||||
) -> Result<Swarm<T>>
|
||||
where
|
||||
T: NetworkBehaviour,
|
||||
{
|
||||
let maybe_tor_socks5_port = match tor::Client::new(tor_socks5_port).assert_tor_running().await {
|
||||
Ok(()) => Some(tor_socks5_port),
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
let behaviour = cli::Behaviour::new(alice, env_config, bitcoin_wallet);
|
||||
|
||||
let identity = seed.derive_libp2p_identity();
|
||||
let transport = cli::transport::new(&identity, maybe_tor_socks5_port)?;
|
||||
let peer_id = identity.public().into_peer_id();
|
||||
|
||||
|
@ -445,12 +445,16 @@ impl BobParams {
|
||||
) -> Result<(cli::EventLoop, cli::EventLoopHandle)> {
|
||||
let tor_socks5_port = get_port()
|
||||
.expect("We don't care about Tor in the tests so we get a free port to disable it.");
|
||||
let mut swarm = swarm::cli(
|
||||
&self.seed,
|
||||
|
||||
let behaviour = cli::Behaviour::new(
|
||||
self.alice_peer_id,
|
||||
tor_socks5_port,
|
||||
self.env_config,
|
||||
self.bitcoin_wallet.clone(),
|
||||
);
|
||||
let mut swarm = swarm::cli(
|
||||
self.seed.derive_libp2p_identity(),
|
||||
tor_socks5_port,
|
||||
behaviour,
|
||||
)
|
||||
.await?;
|
||||
swarm
|
||||
|
Loading…
Reference in New Issue
Block a user