Skip to content

Commit

Permalink
[client/network] Add support for /wss addresses (paritytech#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 paritytech#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 ltfschoen committed Feb 22, 2023
1 parent d861080 commit de3b371
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 de3b371

Please sign in to comment.