diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-04-24 12:45:11 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-04-24 12:45:11 +0200 |
| commit | c03640de300efcf5b7ada700a64850dca3a7541e (patch) | |
| tree | a674ea668bacb4ff9863382e63f7932378d613bd | |
| parent | b6a2b10cbcff62ccba5f6f23678bf04420850669 (diff) | |
| parent | e61a90b314778fbc9a5d2e421be6a663dcb83489 (diff) | |
| download | mullvadvpn-c03640de300efcf5b7ada700a64850dca3a7541e.tar.xz mullvadvpn-c03640de300efcf5b7ada700a64850dca3a7541e.zip | |
Merge branch 'move-api-ip-to-global'
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 4 | ||||
| -rw-r--r-- | mullvad-rpc/Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-rpc/src/lib.rs | 28 | ||||
| -rw-r--r-- | talpid-core/build.rs | 6 |
5 files changed, 20 insertions, 20 deletions
diff --git a/Cargo.lock b/Cargo.lock index 6c10aa9925..6027f62ab6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -749,6 +749,7 @@ dependencies = [ "hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-client-core 0.3.0 (git+https://github.com/mullvad/jsonrpc-client-rs)", "jsonrpc-client-http 0.3.0 (git+https://github.com/mullvad/jsonrpc-client-rs)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "mullvad-types 0.1.0", "native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index ef86bcef0a..a0f8ece9e2 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -411,7 +411,7 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem .and_then(|rpc_future| { rpc_future.map_err(|error: mullvad_rpc::Error| { error!( - "Unable to get account data from master: {}", + "Unable to get account data from API: {}", error.display_chain() ); Self::map_rpc_error(error) @@ -621,7 +621,7 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem .and_then(|version_future| { version_future.map_err(|error| { error!( - "Unable to get version data from master: {}", + "Unable to get version data from API: {}", error.display_chain() ); Self::map_rpc_error(error) diff --git a/mullvad-rpc/Cargo.toml b/mullvad-rpc/Cargo.toml index 55bcd350f1..e62505dd2e 100644 --- a/mullvad-rpc/Cargo.toml +++ b/mullvad-rpc/Cargo.toml @@ -11,6 +11,7 @@ error-chain = "0.11" futures = "0.1.15" jsonrpc-client-core = { git = "https://github.com/mullvad/jsonrpc-client-rs" } jsonrpc-client-http = { git = "https://github.com/mullvad/jsonrpc-client-rs" } +lazy_static = "1.0" serde_json = "1.0" tokio-core = "0.1" hyper = "0.11" diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs index 9cdfc69112..b8e1bd5865 100644 --- a/mullvad-rpc/src/lib.rs +++ b/mullvad-rpc/src/lib.rs @@ -16,6 +16,8 @@ extern crate hyper_tls; extern crate jsonrpc_client_core; extern crate jsonrpc_client_http; #[macro_use] +extern crate lazy_static; +#[macro_use] extern crate log; extern crate native_tls; extern crate serde_json; @@ -37,7 +39,7 @@ use mullvad_types::relay_list::RelayList; use mullvad_types::version; use std::collections::HashMap; -use std::net::IpAddr; +use std::net::{IpAddr, Ipv4Addr}; use std::path::Path; use std::time::Duration; @@ -50,8 +52,12 @@ use cached_dns_resolver::CachedDnsResolver; mod https_client_with_sni; use https_client_with_sni::HttpsClientWithSni; -static MASTER_API_HOST: &str = "api.mullvad.net"; -static MASTER_RPC_TIMEOUT: Duration = Duration::from_secs(5); +static API_HOST: &str = "api.mullvad.net"; +static RPC_TIMEOUT: Duration = Duration::from_secs(5); +static API_IP_CACHE_FILENAME: &str = "api_ip_address.txt"; +lazy_static! { + static ref API_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(193, 138, 219, 46)); +} /// A type that helps with the creation of RPC connections. @@ -69,11 +75,8 @@ impl MullvadRpcFactory { /// Create a new `MullvadRpcFactory` using the specified cache directory. pub fn with_cache_dir(cache_dir: &Path) -> Self { - let hostname = MASTER_API_HOST.to_owned(); - let cache_file = cache_dir.join("api_ip_address.txt"); - let fallback_address = IpAddr::from([193, 138, 219, 46]); - - let cached_dns_resolver = CachedDnsResolver::new(hostname, cache_file, fallback_address); + let cache_file = cache_dir.join(API_IP_CACHE_FILENAME); + let cached_dns_resolver = CachedDnsResolver::new(API_HOST.to_owned(), cache_file, *API_IP); MullvadRpcFactory { address_cache: Some(cached_dns_resolver), @@ -98,14 +101,13 @@ impl MullvadRpcFactory { F: FnOnce(HttpTransportBuilder<HttpsClientWithSni>) -> jsonrpc_client_http::Result<HttpTransport>, { - let client = HttpsClientWithSni::new(MASTER_API_HOST.to_owned()); - let transport_builder = - HttpTransportBuilder::with_client(client).timeout(MASTER_RPC_TIMEOUT); + let client = HttpsClientWithSni::new(API_HOST.to_owned()); + let transport_builder = HttpTransportBuilder::with_client(client).timeout(RPC_TIMEOUT); let transport = create_transport(transport_builder)?; let mut handle = transport.handle(&self.api_uri())?; - handle.set_header(Host::new(MASTER_API_HOST, None)); + handle.set_header(Host::new(API_HOST, None)); Ok(handle) } @@ -114,7 +116,7 @@ impl MullvadRpcFactory { let address = if let Some(ref mut address_cache) = self.address_cache { address_cache.resolve().to_string() } else { - MASTER_API_HOST.to_owned() + API_HOST.to_owned() }; format!("https://{}/rpc/", address) diff --git a/talpid-core/build.rs b/talpid-core/build.rs index a9a80d11eb..87fb943322 100644 --- a/talpid-core/build.rs +++ b/talpid-core/build.rs @@ -14,11 +14,7 @@ mod win { _ => panic!("uncrecognized target: {}", target), }; - let mut lib_dir = manifest_dir(); - lib_dir.push(WFP_BUILD_DIR); - lib_dir.push(&target_dir); - - lib_dir + manifest_dir().join(WFP_BUILD_DIR).join(&target_dir) } fn manifest_dir() -> PathBuf { |
