summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-04-23 08:06:34 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-04-23 08:06:34 -0300
commit6d50bd44ac6b9d60f52c6f095b8b7ce4117ebc67 (patch)
treeea785d4664712aca59378a9f9bae956cf9f0d9f7
parent858d9e06102af8017e11c175a7286786bbf0d682 (diff)
parent52b4069881dab747e6d275349d5c34722f6a82a3 (diff)
downloadmullvadvpn-6d50bd44ac6b9d60f52c6f095b8b7ce4117ebc67.tar.xz
mullvadvpn-6d50bd44ac6b9d60f52c6f095b8b7ce4117ebc67.zip
Merge branch 'reduce-master-rpc-timeout'
-rw-r--r--CHANGELOG.md1
-rw-r--r--Cargo.lock6
-rw-r--r--mullvad-rpc/src/lib.rs21
3 files changed, 18 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90e4886b75..0057f4fc39 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -50,6 +50,7 @@ Line wrap the file at 100 chars. Th
- Redact all 16 digit numbers from problem report logs. Extra safety against accidentally sending
account numbers.
- Fix OpenVPN plugin search directory to be the installation directory.
+- Reduce RPC timeout to Mullvad API server.
## [2018.1] - 2018-03-01
diff --git a/Cargo.lock b/Cargo.lock
index b096d0c5b0..b9a35b29cc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -451,7 +451,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "jsonrpc-client-core"
version = "0.3.0"
-source = "git+https://github.com/mullvad/jsonrpc-client-rs#853f03cfeaf45af070c5e5ea608479094cfce79c"
+source = "git+https://github.com/mullvad/jsonrpc-client-rs#99edc032afe46f5d3c8cc878220da8e149d7cb25"
dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -464,15 +464,13 @@ dependencies = [
[[package]]
name = "jsonrpc-client-http"
version = "0.3.0"
-source = "git+https://github.com/mullvad/jsonrpc-client-rs#853f03cfeaf45af070c5e5ea608479094cfce79c"
+source = "git+https://github.com/mullvad/jsonrpc-client-rs#99edc032afe46f5d3c8cc878220da8e149d7cb25"
dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.11.21 (registry+https://github.com/rust-lang/crates.io-index)",
- "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)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs
index 82f26b9f28..9cdfc69112 100644
--- a/mullvad-rpc/src/lib.rs
+++ b/mullvad-rpc/src/lib.rs
@@ -26,7 +26,7 @@ extern crate mullvad_types;
use chrono::offset::Utc;
use chrono::DateTime;
use jsonrpc_client_http::header::Host;
-use jsonrpc_client_http::HttpTransport;
+use jsonrpc_client_http::{HttpTransport, HttpTransportBuilder};
use tokio_core::reactor::Handle;
pub use jsonrpc_client_core::{Error, ErrorKind};
@@ -39,6 +39,7 @@ use mullvad_types::version;
use std::collections::HashMap;
use std::net::IpAddr;
use std::path::Path;
+use std::time::Duration;
pub mod event_loop;
pub mod rest;
@@ -50,6 +51,7 @@ 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);
/// A type that helps with the creation of RPC connections.
@@ -80,8 +82,7 @@ impl MullvadRpcFactory {
/// Spawns a tokio core on a new thread and returns a `HttpHandle` running on that core.
pub fn new_connection(&mut self) -> Result<HttpHandle, HttpError> {
- let client = HttpsClientWithSni::new(MASTER_API_HOST.to_owned());
- self.setup_connection(HttpTransport::with_client(client)?)
+ self.setup_connection(HttpTransportBuilder::standalone)
}
/// Create and returns a `HttpHandle` running on the given core handle.
@@ -89,11 +90,19 @@ impl MullvadRpcFactory {
&mut self,
handle: &Handle,
) -> Result<HttpHandle, HttpError> {
- let client = HttpsClientWithSni::new(MASTER_API_HOST.to_owned());
- self.setup_connection(HttpTransport::with_client_shared(client, handle)?)
+ self.setup_connection(move |transport| transport.shared(handle))
}
- fn setup_connection(&mut self, transport: HttpTransport) -> Result<HttpHandle, HttpError> {
+ fn setup_connection<F>(&mut self, create_transport: F) -> Result<HttpHandle, HttpError>
+ where
+ 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 transport = create_transport(transport_builder)?;
let mut handle = transport.handle(&self.api_uri())?;
handle.set_header(Host::new(MASTER_API_HOST, None));