Skip to content

Commit

Permalink
Merge branch 'geoip-check'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Oct 23, 2023
2 parents 1104b74 + 02100cf commit f54f4b9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mullvad-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ publish.workspace = true
api-override = []

[dependencies]
libc = "0.2"
chrono = { workspace = true }
err-derive = { workspace = true }
futures = "0.3"
Expand Down
17 changes: 16 additions & 1 deletion mullvad-api/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use hyper::{
};
use mullvad_types::account::AccountToken;
use std::{
error::Error as StdError,
future::Future,
str::FromStr,
sync::{Arc, Weak},
Expand Down Expand Up @@ -88,14 +89,28 @@ impl Error {
matches!(self, Error::HyperError(_) | Error::TimeoutError)
}

/// Return true if there was no route to the destination
pub fn is_offline(&self) -> bool {
match self {
Error::HyperError(error) if error.is_connect() => {
if let Some(cause) = error.source() {
if let Some(err) = cause.downcast_ref::<std::io::Error>() {
return err.raw_os_error() == Some(libc::ENETUNREACH);
}
}
false
}
_ => false,
}
}

pub fn is_aborted(&self) -> bool {
matches!(self, Error::Aborted)
}

/// Returns a new instance for which `abortable_stream::Aborted` is mapped to `Self::Aborted`.
fn map_aborted(self) -> Self {
if let Error::HyperError(error) = &self {
use std::error::Error;
let mut source = error.source();
while let Some(error) = source {
let io_error: Option<&std::io::Error> = error.downcast_ref();
Expand Down
24 changes: 4 additions & 20 deletions mullvad-daemon/src/geoip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,8 @@ async fn send_location_request_internal(
}

fn log_network_error(err: Error, version: &'static str) {
use std::sync::Arc;
let err_message = &format!("Unable to fetch {version} GeoIP location");
match err {
Error::HyperError(hyper_err) if hyper_err.is_connect() => {
if let Some(cause) = Arc::into_inner(hyper_err).and_then(|x| x.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));
}
};
if !err.is_offline() {
let err_message = &format!("Unable to fetch {version} GeoIP location");
log::debug!("{}", err.display_chain_with_msg(err_message));
}
}

0 comments on commit f54f4b9

Please sign in to comment.