mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 22:42:35 -04:00
Refactor transports to construct them specific for each application
Instead of splitting up the transports into capabilities, we compose them directly for each application. This allows us to remove the websocket transport for the CLI which is really only needed for the ASB to allow retrieval of quotes via the browser.
This commit is contained in:
parent
90deb6451c
commit
8a30ef725c
7 changed files with 111 additions and 104 deletions
32
swap/src/cli/transport.rs
Normal file
32
swap/src/cli/transport.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use crate::network::tor_transport::TorDialOnlyTransport;
|
||||
use crate::network::transport::authenticate_and_multiplex;
|
||||
use anyhow::Result;
|
||||
use libp2p::core::muxing::StreamMuxerBox;
|
||||
use libp2p::core::transport::{Boxed, OptionalTransport};
|
||||
use libp2p::dns::TokioDnsConfig;
|
||||
use libp2p::tcp::TokioTcpConfig;
|
||||
use libp2p::{identity, PeerId, Transport};
|
||||
|
||||
/// Creates the libp2p transport for the swap CLI.
|
||||
///
|
||||
/// The CLI's transport needs the following capabilities:
|
||||
/// - Establish TCP connections
|
||||
/// - Resolve DNS entries
|
||||
/// - Dial onion-addresses through a running Tor daemon by connecting to the
|
||||
/// socks5 port. If the port is not given, we will fall back to the regular
|
||||
/// TCP transport.
|
||||
pub fn new(
|
||||
identity: &identity::Keypair,
|
||||
maybe_tor_socks5_port: Option<u16>,
|
||||
) -> Result<Boxed<(PeerId, StreamMuxerBox)>> {
|
||||
let tcp = TokioTcpConfig::new().nodelay(true);
|
||||
let tcp_with_dns = TokioDnsConfig::system(tcp)?;
|
||||
let maybe_tor_transport = match maybe_tor_socks5_port {
|
||||
Some(port) => OptionalTransport::some(TorDialOnlyTransport::new(port)),
|
||||
None => OptionalTransport::none(),
|
||||
};
|
||||
|
||||
let transport = maybe_tor_transport.or_transport(tcp_with_dns).boxed();
|
||||
|
||||
authenticate_and_multiplex(transport, identity)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue