-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test implementation of secure dns for websocket connection establishm…
…ent. depends on #5355
- Loading branch information
Showing
9 changed files
with
334 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use nym_http_api_client::dns::HickoryDnsResolver; | ||
use tokio::net::TcpStream; | ||
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream}; | ||
use tungstenite::{ | ||
error::{Error, UrlError}, | ||
handshake::client::Response, | ||
}; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub(crate) async fn connect_async( | ||
endpoint: &str, | ||
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), Error> { | ||
use std::net::SocketAddr; | ||
|
||
let resolver = HickoryDnsResolver::default(); | ||
|
||
let sock_addrs: Vec<SocketAddr> = resolver | ||
.resolve_str(endpoint) | ||
.await | ||
.map_err(|_| UrlError::NoPathOrQuery)? // failed to resolve | ||
.collect(); | ||
|
||
let stream = TcpStream::connect(&sock_addrs[..]).await?; | ||
|
||
tokio_tungstenite::client_async_tls(endpoint, stream).await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.