summaryrefslogtreecommitdiffhomepage
path: root/mullvad-api/src
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-20 15:36:01 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:08 +0200
commit43cb757d2cbb396a627fb6b970394a7b73d37dc5 (patch)
tree084fcd0a9152d50242ed1934fc5623efe8a0052d /mullvad-api/src
parent7fcaad31643ca324c5dd4a17ddf0f445ac679384 (diff)
downloadmullvadvpn-43cb757d2cbb396a627fb6b970394a7b73d37dc5.tar.xz
mullvadvpn-43cb757d2cbb396a627fb6b970394a7b73d37dc5.zip
Cleanup
- General code cleanup - Fix some typos - Add some doc comments - Address several `TODO` comments - Fix `clippy` warnings - Removed unused dependency `mullvad-api` from `mullvad-cli` - Removed unused dependency `rand` from `mullvad-daemon` - Rename `mullvad proxy` to `mullvad api-access` - Rename `mullvad_types::api_access_method` -> `mullvad_types::access_method` - Remove unused `mullvad api-access edit` arguments - Fix `Display` for `ProxyConfig` printing arguments in the wrong order - Re-phrase `mullvad api-access test` - If the API call failed, point out which tested access method that did not work. - Fix missing `socket_bypass_tx` value for Android - Refactor `ApiAccessMethod` proto definition - Simplify protobuf definitions of `SOCKS5` api access methods - Remove the `Socks5` enum in favor of implementing `Socks5Local` and `Socks5Remote` directly. - Move `enabled` and `name` out of the individual messages and put them next to the `oneof access_method` in `ApiAccessMethod` proto definition - Use derived `PartialEq` and `Hash` from `AccessMethod` - Instead of hand-rolling `Hash` and implementing an ad-hoc version of half of `PartialEq`, these can now be derived and used as one would imaging due to the refactoring wherer `name` and `enabled` was moved out of `AccessMethod` into `ApiAccessMethod`.
Diffstat (limited to 'mullvad-api/src')
-rw-r--r--mullvad-api/src/https_client_with_sni.rs47
-rw-r--r--mullvad-api/src/proxy.rs16
2 files changed, 47 insertions, 16 deletions
diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs
index 76130de185..cc7557a8d2 100644
--- a/mullvad-api/src/https_client_with_sni.rs
+++ b/mullvad-api/src/https_client_with_sni.rs
@@ -84,15 +84,38 @@ impl InnerConnectionMode {
&self,
hostname: &str,
addr: &SocketAddr,
+ #[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
) -> Result<ApiConnection, std::io::Error> {
use InnerConnectionMode::*;
match self {
- Direct => Self::handle_direct_connection(addr, hostname).await,
+ Direct => {
+ Self::handle_direct_connection(
+ addr,
+ hostname,
+ #[cfg(target_os = "android")]
+ socket_bypass_tx,
+ )
+ .await
+ }
Shadowsocks(config) => {
- Self::handle_shadowsocks_connection(config.clone(), addr, hostname).await
+ Self::handle_shadowsocks_connection(
+ config.clone(),
+ addr,
+ hostname,
+ #[cfg(target_os = "android")]
+ socket_bypass_tx,
+ )
+ .await
}
Socks5(proxy_config) => {
- Self::handle_socks_connection(proxy_config.clone(), addr, hostname).await
+ Self::handle_socks_connection(
+ proxy_config.clone(),
+ addr,
+ hostname,
+ #[cfg(target_os = "android")]
+ socket_bypass_tx,
+ )
+ .await
}
}
}
@@ -101,11 +124,12 @@ impl InnerConnectionMode {
async fn handle_direct_connection(
addr: &SocketAddr,
hostname: &str,
+ #[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
) -> Result<ApiConnection, io::Error> {
let socket = HttpsConnectorWithSni::open_socket(
*addr,
#[cfg(target_os = "android")]
- socket_bypass_tx.clone(),
+ socket_bypass_tx,
)
.await?;
#[cfg(feature = "api-override")]
@@ -122,11 +146,12 @@ impl InnerConnectionMode {
shadowsocks: ShadowsocksConfig,
addr: &SocketAddr,
hostname: &str,
+ #[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
) -> Result<ApiConnection, io::Error> {
let socket = HttpsConnectorWithSni::open_socket(
shadowsocks.params.peer,
#[cfg(target_os = "android")]
- socket_bypass_tx.clone(),
+ socket_bypass_tx,
)
.await?;
let proxy = ProxyClientStream::from_stream(
@@ -150,6 +175,7 @@ impl InnerConnectionMode {
proxy_config: SocksConfig,
addr: &SocketAddr,
hostname: &str,
+ #[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
) -> Result<ApiConnection, io::Error> {
let socket = HttpsConnectorWithSni::open_socket(
proxy_config.peer,
@@ -222,12 +248,12 @@ impl TryFrom<ApiConnectionMode> for InnerConnectionMode {
})
}
ProxyConfig::Socks(config) => match config {
- mullvad_types::api_access_method::Socks5::Local(config) => {
+ mullvad_types::access_method::Socks5::Local(config) => {
InnerConnectionMode::Socks5(SocksConfig {
peer: SocketAddr::new("127.0.0.1".parse().unwrap(), config.port),
})
}
- mullvad_types::api_access_method::Socks5::Remote(config) => {
+ mullvad_types::access_method::Socks5::Remote(config) => {
InnerConnectionMode::Socks5(SocksConfig { peer: config.peer })
}
},
@@ -424,7 +450,12 @@ impl Service<Uri> for HttpsConnectorWithSni {
let stream = loop {
let notify = abort_notify.notified();
let proxy_config = { inner.lock().unwrap().proxy_config.clone() };
- let stream_fut = proxy_config.connect(&hostname, &addr);
+ let stream_fut = proxy_config.connect(
+ &hostname,
+ &addr,
+ #[cfg(target_os = "android")]
+ socket_bypass_tx.clone(),
+ );
pin_mut!(stream_fut);
pin_mut!(notify);
diff --git a/mullvad-api/src/proxy.rs b/mullvad-api/src/proxy.rs
index 186eea2919..44a2309587 100644
--- a/mullvad-api/src/proxy.rs
+++ b/mullvad-api/src/proxy.rs
@@ -1,6 +1,6 @@
use futures::Stream;
use hyper::client::connect::Connected;
-use mullvad_types::api_access_method;
+use mullvad_types::access_method;
use serde::{Deserialize, Serialize};
use std::{
fmt, io,
@@ -36,8 +36,8 @@ impl fmt::Display for ApiConnectionMode {
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum ProxyConfig {
- Shadowsocks(api_access_method::Shadowsocks),
- Socks(api_access_method::Socks5),
+ Shadowsocks(access_method::Shadowsocks),
+ Socks(access_method::Socks5),
}
impl ProxyConfig {
@@ -46,8 +46,8 @@ impl ProxyConfig {
match self {
ProxyConfig::Shadowsocks(ss) => ss.peer,
ProxyConfig::Socks(socks) => match socks {
- api_access_method::Socks5::Local(s) => s.peer,
- api_access_method::Socks5::Remote(s) => s.peer,
+ access_method::Socks5::Local(s) => s.peer,
+ access_method::Socks5::Remote(s) => s.peer,
},
}
}
@@ -59,10 +59,10 @@ impl fmt::Display for ProxyConfig {
// TODO: Do not hardcode TCP
ProxyConfig::Shadowsocks(ss) => write!(f, "Shadowsocks {}/TCP", ss.peer),
ProxyConfig::Socks(socks) => match socks {
- api_access_method::Socks5::Local(s) => {
- write!(f, "Socks5 localhost:{} => {}/TCP", s.port, s.peer)
+ access_method::Socks5::Local(s) => {
+ write!(f, "Socks5 {}/TCP via localhost:{}", s.peer, s.port)
}
- api_access_method::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer),
+ access_method::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer),
},
}
}