Pass Swarm into EventLoop

This reduces the amount of arguments we need to pass into the eventloop
at the expense of slightly more setup of the swarm.
This commit is contained in:
Thomas Eizinger 2021-03-23 16:56:04 +11:00
parent 2c9ab4f6eb
commit 2200fce3f3
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
7 changed files with 61 additions and 84 deletions

View file

@ -7,7 +7,7 @@ use bitcoin_harness::{BitcoindRpcApi, Client};
use futures::Future;
use get_port::get_port;
use libp2p::core::Multiaddr;
use libp2p::PeerId;
use libp2p::{PeerId, Swarm};
use monero_harness::{image, Monero};
use std::convert::Infallible;
use std::path::{Path, PathBuf};
@ -17,6 +17,7 @@ use swap::asb::FixedRate;
use swap::bitcoin::{CancelTimelock, PunishTimelock};
use swap::database::Database;
use swap::env::{Config, GetConfig};
use swap::network::swarm;
use swap::protocol::alice::{AliceState, Swap};
use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob};
@ -70,12 +71,10 @@ impl BobParams {
}
pub fn new_eventloop(&self) -> Result<(bob::EventLoop, bob::EventLoopHandle)> {
bob::EventLoop::new(
&self.seed.derive_libp2p_identity(),
self.alice_peer_id,
self.alice_address.clone(),
self.bitcoin_wallet.clone(),
)
let mut swarm = swarm::new::<bob::Behaviour>(&self.seed)?;
swarm.add_address(self.alice_peer_id, self.alice_address.clone());
bob::EventLoop::new(swarm, self.alice_peer_id, self.bitcoin_wallet.clone())
}
}
@ -384,9 +383,11 @@ where
)
.await;
let mut alice_swarm = swarm::new::<alice::Behaviour>(&alice_seed).unwrap();
Swarm::listen_on(&mut alice_swarm, alice_listen_address.clone()).unwrap();
let (alice_event_loop, alice_swap_handle) = alice::EventLoop::new(
alice_listen_address.clone(),
alice_seed,
alice_swarm,
env_config,
alice_bitcoin_wallet.clone(),
alice_monero_wallet.clone(),