diff options
Diffstat (limited to 'mullvad-api/src')
| -rw-r--r-- | mullvad-api/src/address_cache.rs | 33 | ||||
| -rw-r--r-- | mullvad-api/src/https_client_with_sni.rs | 4 | ||||
| -rw-r--r-- | mullvad-api/src/lib.rs | 2 | ||||
| -rw-r--r-- | mullvad-api/src/proxy.rs | 4 | ||||
| -rw-r--r-- | mullvad-api/src/relay_list.rs | 8 | ||||
| -rw-r--r-- | mullvad-api/src/rest.rs | 2 |
6 files changed, 26 insertions, 27 deletions
diff --git a/mullvad-api/src/address_cache.rs b/mullvad-api/src/address_cache.rs index a8b1a91a44..d37d429e89 100644 --- a/mullvad-api/src/address_cache.rs +++ b/mullvad-api/src/address_cache.rs @@ -10,19 +10,16 @@ use tokio::{ #[error(no_from)] pub enum Error { #[error(display = "Failed to open the address cache file")] - OpenAddressCache(#[error(source)] io::Error), + Open(#[error(source)] io::Error), #[error(display = "Failed to read the address cache file")] - ReadAddressCache(#[error(source)] io::Error), + Read(#[error(source)] io::Error), #[error(display = "Failed to parse the address cache file")] - ParseAddressCache, + Parse, #[error(display = "Failed to update the address cache file")] - WriteAddressCache(#[error(source)] io::Error), - - #[error(display = "The address cache is empty")] - EmptyAddressCache, + Write(#[error(source)] io::Error), } #[derive(Clone)] @@ -68,7 +65,7 @@ impl AddressCache { self.inner.lock().await.address } - pub async fn set_address(&self, address: SocketAddr) -> io::Result<()> { + pub async fn set_address(&self, address: SocketAddr) -> Result<(), Error> { let mut inner = self.inner.lock().await; if address != inner.address { self.save_to_disk(&address).await?; @@ -77,17 +74,21 @@ impl AddressCache { Ok(()) } - async fn save_to_disk(&self, address: &SocketAddr) -> io::Result<()> { + async fn save_to_disk(&self, address: &SocketAddr) -> Result<(), Error> { let write_path = match self.write_path.as_ref() { Some(write_path) => write_path, None => return Ok(()), }; - let mut file = crate::fs::AtomicFile::new(write_path.to_path_buf()).await?; + let mut file = crate::fs::AtomicFile::new(write_path.to_path_buf()) + .await + .map_err(Error::Open)?; let mut contents = address.to_string(); contents += "\n"; - file.write_all(contents.as_bytes()).await?; - file.finalize().await + file.write_all(contents.as_bytes()) + .await + .map_err(Error::Write)?; + file.finalize().await.map_err(Error::Write) } } @@ -103,12 +104,10 @@ impl AddressCacheInner { } async fn read_address_file(path: &Path) -> Result<SocketAddr, Error> { - let mut file = fs::File::open(path) - .await - .map_err(Error::OpenAddressCache)?; + let mut file = fs::File::open(path).await.map_err(Error::Open)?; let mut address = String::new(); file.read_to_string(&mut address) .await - .map_err(Error::ReadAddressCache)?; - address.trim().parse().map_err(|_| Error::ParseAddressCache) + .map_err(Error::Read)?; + address.trim().parse().map_err(|_| Error::Parse) } diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs index 2920cf989d..0d85ddd790 100644 --- a/mullvad-api/src/https_client_with_sni.rs +++ b/mullvad-api/src/https_client_with_sni.rs @@ -304,7 +304,7 @@ impl Service<Uri> for HttpsConnectorWithSni { ) .await?; let tls_stream = TlsStream::connect_https(socket, &hostname).await?; - Ok::<_, io::Error>(ApiConnection::Direct(tls_stream)) + Ok::<_, io::Error>(ApiConnection::Direct(Box::new(tls_stream))) } InnerConnectionMode::Proxied(proxy_config) => { let socket = Self::open_socket( @@ -320,7 +320,7 @@ impl Service<Uri> for HttpsConnectorWithSni { addr, ); let tls_stream = TlsStream::connect_https(proxy, &hostname).await?; - Ok(ApiConnection::Proxied(tls_stream)) + Ok(ApiConnection::Proxied(Box::new(tls_stream))) } } }; diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index b1019ef155..d967791192 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -236,7 +236,7 @@ impl Runtime { new_address_callback: impl ApiEndpointUpdateCallback + Send + Sync + 'static, #[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>, ) -> rest::RequestServiceHandle { - let service_handle = rest::RequestService::new( + let service_handle = rest::RequestService::spawn( sni_hostname, self.api_availability.handle(), self.address_cache.clone(), diff --git a/mullvad-api/src/proxy.rs b/mullvad-api/src/proxy.rs index 21fa39c9c6..cc7ee3aa6c 100644 --- a/mullvad-api/src/proxy.rs +++ b/mullvad-api/src/proxy.rs @@ -132,8 +132,8 @@ impl ApiConnectionMode { /// Stream that is either a regular TLS stream or TLS via shadowsocks pub enum ApiConnection { - Direct(TlsStream<TcpStream>), - Proxied(TlsStream<ProxyClientStream<TcpStream>>), + Direct(Box<TlsStream<TcpStream>>), + Proxied(Box<TlsStream<ProxyClientStream<TcpStream>>>), } impl AsyncRead for ApiConnection { diff --git a/mullvad-api/src/relay_list.rs b/mullvad-api/src/relay_list.rs index 6bd4523652..a2d699e248 100644 --- a/mullvad-api/src/relay_list.rs +++ b/mullvad-api/src/relay_list.rs @@ -130,7 +130,7 @@ impl ServerRelayList { ) { let openvpn_endpoint_data = openvpn.ports; for mut openvpn_relay in openvpn.relays.into_iter() { - openvpn_relay.to_lower(); + openvpn_relay.convert_to_lowercase(); if let Some((country_code, city_code)) = split_location_code(&openvpn_relay.location) { if let Some(country) = countries.get_mut(country_code) { if let Some(city) = country @@ -184,7 +184,7 @@ impl ServerRelayList { }; for mut wireguard_relay in relays { - wireguard_relay.relay.to_lower(); + wireguard_relay.relay.convert_to_lowercase(); if let Some((country_code, city_code)) = split_location_code(&wireguard_relay.relay.location) { @@ -235,7 +235,7 @@ impl ServerRelayList { } = bridges; for mut bridge_relay in relays { - bridge_relay.to_lower(); + bridge_relay.convert_to_lowercase(); if let Some((country_code, city_code)) = split_location_code(&bridge_relay.location) { if let Some(country) = countries.get_mut(country_code) { if let Some(city) = country @@ -345,7 +345,7 @@ struct Relay { } impl Relay { - fn to_lower(&mut self) { + fn convert_to_lowercase(&mut self) { self.hostname = self.hostname.to_lowercase(); self.location = self.location.to_lowercase(); } diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs index 8a04c62e39..c80f01049a 100644 --- a/mullvad-api/src/rest.rs +++ b/mullvad-api/src/rest.rs @@ -130,7 +130,7 @@ impl< > RequestService<T, F> { /// Constructs a new request service. - pub async fn new( + pub async fn spawn( sni_hostname: Option<String>, api_availability: ApiAvailabilityHandle, address_cache: AddressCache, |
