summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-04-24 10:30:35 +0200
committerLinus Färnstrand <linus@mullvad.net>2018-04-24 10:30:35 +0200
commit1e8f0508a357854e818e8b083449511ae991e262 (patch)
tree6940dfe98f646a9d2b720e17e6f430330d6f2b1d
parent72089123b63f0f6395998bcf688edfcaf413c9e4 (diff)
downloadmullvadvpn-1e8f0508a357854e818e8b083449511ae991e262.tar.xz
mullvadvpn-1e8f0508a357854e818e8b083449511ae991e262.zip
Move API IP up to global static. Remove word "master"
-rw-r--r--mullvad-rpc/Cargo.toml1
-rw-r--r--mullvad-rpc/src/lib.rs28
2 files changed, 16 insertions, 13 deletions
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)