diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index cf9b883b..c228b136 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -7,7 +7,6 @@ use crate::{ monero, network::{ peer_tracker::{self, PeerTracker}, - transport::build, Seed as NetworkSeed, }, protocol::{bob::EncryptedSignature, SwapAmounts}, @@ -113,7 +112,8 @@ impl Builder { .make_initial_state(swap_amounts.btc, swap_amounts.xmr) .await?; - let (event_loop, event_loop_handle) = self.init_event_loop()?; + let (event_loop, event_loop_handle) = + EventLoop::new(self.identity.clone(), self.listen_address(), self.peer_id)?; Ok(( Swap { @@ -139,7 +139,8 @@ impl Builder { ) }; - let (event_loop, event_loop_handle) = self.init_event_loop()?; + let (event_loop, event_loop_handle) = + EventLoop::new(self.identity.clone(), self.listen_address(), self.peer_id)?; Ok(( Swap { @@ -186,17 +187,6 @@ impl Builder { Ok(AliceState::Started { amounts, state0 }) } - - fn init_event_loop(&self) -> Result<(EventLoop, EventLoopHandle)> { - let alice_behaviour = Behaviour::default(); - let alice_transport = build(self.identity.clone())?; - EventLoop::new( - alice_transport, - alice_behaviour, - self.listen_address(), - self.peer_id, - ) - } } #[derive(Debug)] diff --git a/swap/src/protocol/alice/event_loop.rs b/swap/src/protocol/alice/event_loop.rs index b2b3873c..2cc0af2a 100644 --- a/swap/src/protocol/alice/event_loop.rs +++ b/swap/src/protocol/alice/event_loop.rs @@ -1,6 +1,6 @@ use crate::{ execution_params::ExecutionParams, - network::{transport::SwapTransport, TokioExecutor}, + network::{transport, TokioExecutor}, protocol::{ alice::{Behaviour, OutEvent, State0, State3, SwapResponse, TransferProof}, bob::{EncryptedSignature, SwapRequest}, @@ -135,11 +135,13 @@ pub struct EventLoop { impl EventLoop { pub fn new( - transport: SwapTransport, - behaviour: Behaviour, + identity: libp2p::identity::Keypair, listen: Multiaddr, peer_id: PeerId, ) -> Result<(Self, EventLoopHandle)> { + let behaviour = Behaviour::default(); + let transport = transport::build(identity)?; + let mut swarm = libp2p::swarm::SwarmBuilder::new(transport, behaviour, peer_id) .executor(Box::new(TokioExecutor { handle: tokio::runtime::Handle::current(),