mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Prepare separation of event loop initialisation to swap initialisation
As for Alice, the event loop will be started with the program and will be the one starting swaps (`run_until`) based on libp2p events (swap request).
This commit is contained in:
parent
530b9b2ea8
commit
87be9aeb2a
@ -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)]
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user