diff options
| author | Emīls <emils@mullvad.net> | 2021-04-06 14:51:16 +0100 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2021-04-06 14:51:16 +0100 |
| commit | dde4dbcd7326f264b539f53b28a4d1187d112bce (patch) | |
| tree | 56a0c241fa2b4578468820697c146f0f4e0c2af8 | |
| parent | b07c517d8a6786857b8137c25aa20d46311a6acf (diff) | |
| parent | d0c4413c2c60fb5e5116604da5df19f6759d0818 (diff) | |
| download | mullvadvpn-dde4dbcd7326f264b539f53b28a4d1187d112bce.tar.xz mullvadvpn-dde4dbcd7326f264b539f53b28a4d1187d112bce.zip | |
Merge branch 'log-less-geoip-error'
| -rw-r--r-- | mullvad-daemon/Cargo.toml | 2 | ||||
| -rw-r--r-- | mullvad-daemon/src/geoip.rs | 45 |
2 files changed, 33 insertions, 14 deletions
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index 7db8b73511..f6cd0788d0 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -16,6 +16,7 @@ fern = { version = "0.6", features = ["colored"] } futures = "0.3" ipnetwork = "0.16" lazy_static = "1.0" +libc = "0.2" log = "0.4" log-panics = "2.0.0" parking_lot = "0.11" @@ -41,7 +42,6 @@ mullvad-management-interface = { path = "../mullvad-management-interface" } android_logger = "0.8" [target.'cfg(unix)'.dependencies] -libc = "0.2" nix = "0.19" simple-signal = "1.1" diff --git a/mullvad-daemon/src/geoip.rs b/mullvad-daemon/src/geoip.rs index 1047d3bb15..cc1fea8401 100644 --- a/mullvad-daemon/src/geoip.rs +++ b/mullvad-daemon/src/geoip.rs @@ -1,5 +1,8 @@ use futures::join; -use mullvad_rpc::{self, rest::RequestServiceHandle}; +use mullvad_rpc::{ + self, + rest::{Error, RequestServiceHandle}, +}; use mullvad_types::location::{AmIMullvad, GeoIpLocation}; use talpid_types::ErrorExt; @@ -8,16 +11,16 @@ const URI_V6: &str = "https://ipv6.am.i.mullvad.net/json"; pub async fn send_location_request( request_sender: RequestServiceHandle, -) -> Result<GeoIpLocation, mullvad_rpc::rest::Error> { +) -> Result<GeoIpLocation, Error> { let v4_sender = request_sender.clone(); let v4_future = async move { let location = send_location_request_internal(URI_V4, v4_sender).await?; - Ok::<GeoIpLocation, mullvad_rpc::rest::Error>(GeoIpLocation::from(location)) + Ok::<GeoIpLocation, Error>(GeoIpLocation::from(location)) }; let v6_sender = request_sender.clone(); let v6_future = async move { let location = send_location_request_internal(URI_V6, v6_sender).await?; - Ok::<GeoIpLocation, mullvad_rpc::rest::Error>(GeoIpLocation::from(location)) + Ok::<GeoIpLocation, Error>(GeoIpLocation::from(location)) }; let (v4_result, v6_result) = join!(v4_future, v6_future); @@ -29,17 +32,11 @@ pub async fn send_location_request( Ok(v4) } (Ok(v4), Err(e)) => { - log::debug!( - "{}", - e.display_chain_with_msg("Unable to fetch IPv6 GeoIP location") - ); + log_network_error(e, "IPv6"); Ok(v4) } (Err(e), Ok(v6)) => { - log::debug!( - "{}", - e.display_chain_with_msg("Unable to fetch IPv4 GeoIP location") - ); + log_network_error(e, "IPv4"); Ok(v6) } (Err(e_v4), Err(_)) => Err(e_v4), @@ -49,9 +46,31 @@ pub async fn send_location_request( async fn send_location_request_internal( uri: &'static str, service: RequestServiceHandle, -) -> Result<AmIMullvad, mullvad_rpc::rest::Error> { +) -> Result<AmIMullvad, Error> { let future_service = service.clone(); let request = mullvad_rpc::rest::RestRequest::get(uri)?; let response = future_service.request(request).await?; mullvad_rpc::rest::deserialize_body(response).await } + +fn log_network_error(err: Error, version: &'static str) { + let err_message = &format!("Unable to fetch {} GeoIP location", version); + match err { + Error::HyperError(hyper_err) if hyper_err.is_connect() => { + if let Some(cause) = hyper_err.into_cause() { + if let Some(err) = cause.downcast_ref::<std::io::Error>() { + // Don't log ENETUNREACH errors, they are not informative. + if err.raw_os_error() == Some(libc::ENETUNREACH) { + return; + } + log::debug!("{}: Hyper connect error: {}", err_message, cause); + } + } else { + log::error!("Hyper Connection error did not contain a cause!"); + } + } + any_other_error => { + log::debug!("{}", any_other_error.display_chain_with_msg(err_message)); + } + }; +} |
