Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
[client/network] Add support for /wss addresses (#13152)
Browse files Browse the repository at this point in the history
* join dns with another instance of WS transport

Secure Websocket transport needs unresolved addresses, so we join DNS transport with
yet another instance of Websocket transport.

Closes #12024

* WSS transport itself need to wrap DNS transport

in order to resolve addresses before passing them down to TCP transport

Refs libp2p/rust-libp2p#3330

* reverse order

* simplify code: remove WS from WSS inner DNS transport

* remove the 2nd instance of WS transport
  • Loading branch information
melekes authored and Ross Bulat committed Feb 3, 2023
1 parent 0b6c946 commit 28e72a8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions client/network/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,27 @@ pub fn build_transport(
) -> (Boxed<(PeerId, StreamMuxerBox)>, Arc<BandwidthSinks>) {
// Build the base layer of the transport.
let transport = if !memory_only {
// Main transport: DNS(TCP)
let tcp_config = tcp::Config::new().nodelay(true);
let desktop_trans = tcp::tokio::Transport::new(tcp_config.clone());
let desktop_trans = websocket::WsConfig::new(desktop_trans)
.or_transport(tcp::tokio::Transport::new(tcp_config.clone()));
let dns_init = dns::TokioDnsConfig::system(desktop_trans);
let tcp_trans = tcp::tokio::Transport::new(tcp_config.clone());
let dns_init = dns::TokioDnsConfig::system(tcp_trans);

EitherTransport::Left(if let Ok(dns) = dns_init {
EitherTransport::Left(dns)
// WS + WSS transport
//
// Main transport can't be used for `/wss` addresses because WSS transport needs
// unresolved addresses (BUT WSS transport itself needs an instance of DNS transport to
// resolve and dial addresses).
let tcp_trans = tcp::tokio::Transport::new(tcp_config);
let dns_for_wss = dns::TokioDnsConfig::system(tcp_trans)
.expect("same system_conf & resolver to work");
EitherTransport::Left(websocket::WsConfig::new(dns_for_wss).or_transport(dns))
} else {
let desktop_trans = tcp::tokio::Transport::new(tcp_config.clone());
let desktop_trans = websocket::WsConfig::new(desktop_trans)
// In case DNS can't be constructed, fallback to TCP + WS (WSS won't work)
let tcp_trans = tcp::tokio::Transport::new(tcp_config.clone());
let desktop_trans = websocket::WsConfig::new(tcp_trans)
.or_transport(tcp::tokio::Transport::new(tcp_config));
EitherTransport::Right(desktop_trans.map_err(dns::DnsErr::Transport))
EitherTransport::Right(desktop_trans)
})
} else {
EitherTransport::Right(OptionalTransport::some(
Expand Down

0 comments on commit 28e72a8

Please sign in to comment.