Remove connection handling from swap execution

The swap should not be concerned with connection handling. This is
the responsibility of the overall application.

All but the execution-setup NetworkBehaviour are `request-response`
behaviours. These have built-in functionality to automatically emit
a dial attempt in case we are not connected at the time we want to
send a message. We remove all of the manual dialling code from the
swap in favor of this behaviour.

Additionally, we make sure to establish a connection as soon as the
EventLoop gets started. In case we ever loose the connection to Alice,
we try to re-establish it.
This commit is contained in:
Thomas Eizinger 2021-03-18 18:00:02 +11:00
parent 804b34f6b0
commit cde3f0f74a
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
11 changed files with 79 additions and 215 deletions

View file

@ -1,6 +1,6 @@
use crate::env::Config;
use crate::network::quote::BidQuote;
use crate::network::{encrypted_signature, peer_tracker, quote, spot_price, transfer_proof};
use crate::network::{encrypted_signature, quote, spot_price, transfer_proof};
use crate::protocol::alice::{execution_setup, State0, State3};
use crate::{bitcoin, monero};
use anyhow::{anyhow, Error, Result};
@ -11,7 +11,6 @@ use tracing::debug;
#[derive(Debug)]
pub enum OutEvent {
ConnectionEstablished(PeerId),
SpotPriceRequested {
request: spot_price::Request,
channel: ResponseChannel<spot_price::Response>,
@ -38,16 +37,6 @@ pub enum OutEvent {
},
}
impl From<peer_tracker::OutEvent> for OutEvent {
fn from(event: peer_tracker::OutEvent) -> Self {
match event {
peer_tracker::OutEvent::ConnectionEstablished(id) => {
OutEvent::ConnectionEstablished(id)
}
}
}
}
impl OutEvent {
fn unexpected_request(peer: PeerId) -> OutEvent {
OutEvent::Failure {
@ -177,7 +166,6 @@ impl From<execution_setup::OutEvent> for OutEvent {
#[behaviour(out_event = "OutEvent", event_process = false)]
#[allow(missing_debug_implementations)]
pub struct Behaviour {
pt: peer_tracker::Behaviour,
quote: quote::Behaviour,
spot_price: spot_price::Behaviour,
execution_setup: execution_setup::Behaviour,
@ -188,7 +176,6 @@ pub struct Behaviour {
impl Default for Behaviour {
fn default() -> Self {
Self {
pt: Default::default(),
quote: quote::alice(),
spot_price: spot_price::alice(),
execution_setup: Default::default(),