mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-02-22 07:39:56 -05:00
Move protocol definition to network module
This commit is contained in:
parent
39e0b45da9
commit
301d5be127
@ -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;
|
||||
|
26
swap/src/network/swap_setup.rs
Normal file
26
swap/src/network/swap_setup.rs
Normal file
@ -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<Result<NegotiatedSubstream, Void>>
|
||||
+ Send
|
||||
+ 'static,
|
||||
>,
|
||||
>;
|
||||
}
|
@ -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<Result<NegotiatedSubstream, Void>>
|
||||
+ Send
|
||||
+ 'static,
|
||||
>,
|
||||
>;
|
||||
}
|
||||
|
||||
// TODO: Differentiate between errors that we send back and shit that happens on
|
||||
// our side (IO, timeout)
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user