Skip to content

Commit

Permalink
Make EncryptedDNSForwarder::from_stream infallibe
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Nov 30, 2024
1 parent 5e5bc4e commit 40f5371
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mullvad-api/src/https_client_with_sni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ impl InnerConnectionMode {
InnerConnectionMode::EncryptedDnsProxy(proxy_config) => {
let first_hop = SocketAddr::V4(proxy_config.addr);
let make_proxy_stream = |tcp_stream| async {
EncryptedDNSForwarder::from_stream(&proxy_config, tcp_stream)
let forwarder = EncryptedDNSForwarder::from_stream(&proxy_config, tcp_stream);
Ok(forwarder)
};
Self::connect_proxied(
first_hop,
Expand Down
8 changes: 4 additions & 4 deletions mullvad-encrypted-dns-proxy/src/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
S: AsyncRead + AsyncWrite + Unpin,
{
/// Create a [`Forwarder`] with a connected `stream` to an encrypted DNS proxy server
pub fn from_stream(proxy_config: &crate::config::ProxyConfig, stream: S) -> io::Result<Self> {
pub fn from_stream(proxy_config: &crate::config::ProxyConfig, stream: S) -> Self {
let (read_obfuscator, write_obfuscator) =
if let Some(obfuscation_config) = &proxy_config.obfuscation {
(
Expand All @@ -35,11 +35,11 @@ where
(None, None)
};

Ok(Self {
Self {
read_obfuscator,
write_obfuscator,
stream,
})
}
}
}

Expand All @@ -48,7 +48,7 @@ impl Forwarder<TcpStream> {
/// Create a forwarder that will connect to a given proxy endpoint.
pub async fn connect(proxy_config: &crate::config::ProxyConfig) -> io::Result<Self> {
let server_connection = TcpStream::connect(proxy_config.addr).await?;
Self::from_stream(proxy_config, server_connection)
Ok(Self::from_stream(proxy_config, server_connection))
}

/// Forwards traffic from the client stream to the remote proxy, obfuscating and deobfuscating
Expand Down

0 comments on commit 40f5371

Please sign in to comment.