diff --git a/swap/src/network.rs b/swap/src/network.rs index fb4606fb..90fe06b6 100644 --- a/swap/src/network.rs +++ b/swap/src/network.rs @@ -6,6 +6,7 @@ pub mod json_pull_codec; pub mod quote; pub mod redial; pub mod spot_price; +pub mod swap_setup; pub mod swarm; pub mod tor_transport; pub mod transfer_proof; diff --git a/swap/src/network/swap_setup.rs b/swap/src/network/swap_setup.rs new file mode 100644 index 00000000..b34963f1 --- /dev/null +++ b/swap/src/network/swap_setup.rs @@ -0,0 +1,26 @@ +pub mod protocol { + use futures::future; + use libp2p::core::upgrade::{from_fn, FromFnUpgrade}; + use libp2p::core::Endpoint; + use libp2p::swarm::NegotiatedSubstream; + use void::Void; + + pub fn new() -> SwapSetup { + from_fn( + b"/comit/xmr/btc/swap_setup/1.0.0", + Box::new(|socket, _| future::ready(Ok(socket))), + ) + } + + pub type SwapSetup = FromFnUpgrade< + &'static [u8], + Box< + dyn Fn( + NegotiatedSubstream, + Endpoint, + ) -> future::Ready> + + Send + + 'static, + >, + >; +} diff --git a/swap/src/protocol/alice/swap_setup.rs b/swap/src/protocol/alice/swap_setup.rs index b324dd68..fff749a3 100644 --- a/swap/src/protocol/alice/swap_setup.rs +++ b/swap/src/protocol/alice/swap_setup.rs @@ -1,3 +1,4 @@ +use crate::network::swap_setup::protocol; use crate::protocol::alice::event_loop::LatestRate; use crate::protocol::alice::{State0, State3}; use crate::protocol::{alice, Message0, Message2, Message4}; @@ -6,8 +7,7 @@ use anyhow::{anyhow, Context as _, Result}; use futures::future::{BoxFuture, OptionFuture}; use futures::FutureExt; use libp2p::core::connection::ConnectionId; -use libp2p::core::upgrade::{from_fn, FromFnUpgrade}; -use libp2p::core::{upgrade, Endpoint}; +use libp2p::core::upgrade; use libp2p::swarm::{ KeepAlive, NegotiatedSubstream, NetworkBehaviour, NetworkBehaviourAction, PollParameters, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, @@ -17,12 +17,10 @@ use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use std::collections::VecDeque; use std::fmt::Debug; -use std::future; use std::task::{Context, Poll}; use std::time::Duration; use uuid::Uuid; use void::Void; -use std::time::Duration; #[derive(Debug)] pub enum OutEvent { @@ -532,34 +530,6 @@ where Ok(()) } -mod protocol { - use super::*; - - pub fn new() -> SwapSetup { - from_fn( - b"/comit/xmr/btc/swap_setup/1.0.0", - Box::new(|socket, endpoint| { - future::ready(match endpoint { - Endpoint::Listener => Ok(socket), - Endpoint::Dialer => todo!("return error"), - }) - }), - ) - } - - pub type SwapSetup = FromFnUpgrade< - &'static [u8], - Box< - dyn Fn( - NegotiatedSubstream, - Endpoint, - ) -> future::Ready> - + Send - + 'static, - >, - >; -} - // TODO: Differentiate between errors that we send back and shit that happens on // our side (IO, timeout) #[derive(Debug, thiserror::Error)]