Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EncryptedDNSForwarder::from_stream infallibe #7267

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 7 additions & 8 deletions mullvad-encrypted-dns-proxy/src/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use tokio::{
net::TcpStream,
};

use crate::config::Obfuscator;
use crate::config::{Obfuscator, ProxyConfig};

/// Forwards local traffic to a proxy endpoint, obfuscating it if the proxy config says so.
///
/// Obtain [`ProxyConfig`](crate::config::ProxyConfig)s with
/// [resolve_configs](crate::config_resolver::resolve_configs).
/// Obtain [`ProxyConfig`](ProxyConfig)s with [resolve_configs](crate::config_resolver::resolve_configs).
pub struct Forwarder<S> {
read_obfuscator: Option<Box<dyn Obfuscator>>,
write_obfuscator: Option<Box<dyn Obfuscator>>,
Expand All @@ -24,7 +23,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: &ProxyConfig, stream: S) -> Self {
let (read_obfuscator, write_obfuscator) =
if let Some(obfuscation_config) = &proxy_config.obfuscation {
(
Expand All @@ -35,20 +34,20 @@ where
(None, None)
};

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

/// Forward TCP traffic over various proxy configurations.
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> {
pub async fn connect(proxy_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
Loading