diff options
| -rw-r--r-- | mullvad-rpc/Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-rpc/src/cached_dns_resolver.rs | 38 | ||||
| -rw-r--r-- | mullvad-rpc/src/https_client_with_sni.rs | 33 | ||||
| -rw-r--r-- | mullvad-rpc/src/lib.rs | 25 | ||||
| -rw-r--r-- | mullvad-rpc/src/rest.rs | 23 |
5 files changed, 53 insertions, 67 deletions
diff --git a/mullvad-rpc/Cargo.toml b/mullvad-rpc/Cargo.toml index bb55d9a796..ff9596d10f 100644 --- a/mullvad-rpc/Cargo.toml +++ b/mullvad-rpc/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Mullvad VPN <admin@mullvad.net>"] description = "Mullvad VPN RPC clients. Providing an interface to query our infrastructure for information." license = "GPL-3.0" +edition = "2018" [dependencies] chrono = { version = "0.4", features = ["serde"] } diff --git a/mullvad-rpc/src/cached_dns_resolver.rs b/mullvad-rpc/src/cached_dns_resolver.rs index a20c0db973..0b0640af28 100644 --- a/mullvad-rpc/src/cached_dns_resolver.rs +++ b/mullvad-rpc/src/cached_dns_resolver.rs @@ -1,13 +1,14 @@ -use log::{debug, info, warn}; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::net::{IpAddr, ToSocketAddrs}; -use std::path::{Path, PathBuf}; -use std::sync::mpsc; -use std::thread; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; - use error_chain::ChainedError; +use log::{debug, info, warn}; +use std::{ + fs::File, + io::{self, Read, Write}, + net::{IpAddr, ToSocketAddrs}, + path::{Path, PathBuf}, + sync::mpsc, + thread, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; static DNS_TIMEOUT: Duration = Duration::from_secs(2); @@ -217,17 +218,18 @@ impl<R: DnsResolver> CachedDnsResolver<R> { #[cfg(test)] mod tests { - extern crate filetime; - extern crate tempfile; - - use std::fs::{self, File}; - use std::io::{Read, Write}; - use std::sync::atomic::{AtomicBool, Ordering}; - use std::sync::Arc; + use std::{ + fs::{self, File}, + io::{Read, Write}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, + }; - use self::filetime::FileTime; - use self::tempfile::TempDir; use super::*; + use filetime::FileTime; + use tempfile::TempDir; #[test] fn uses_previously_cached_address() { diff --git a/mullvad-rpc/src/https_client_with_sni.rs b/mullvad-rpc/src/https_client_with_sni.rs index 62dc66df28..3f62372e73 100644 --- a/mullvad-rpc/src/https_client_with_sni.rs +++ b/mullvad-rpc/src/https_client_with_sni.rs @@ -1,22 +1,21 @@ -extern crate tokio_openssl; -extern crate tokio_service; - -use std::fmt; -use std::io; -use std::path::{Path, PathBuf}; -use std::str; -use std::sync::Arc; - use futures::{Future, Poll}; -use hyper::client::{Client, Connect, HttpConnector}; -use hyper::{Body, Uri}; -pub use hyper_openssl::openssl::error::ErrorStack; +use hyper::{ + client::{Client, Connect, HttpConnector}, + Body, Uri, +}; use hyper_openssl::openssl::ssl::{SslConnector, SslMethod}; use jsonrpc_client_http::ClientCreator; +use std::{ + fmt, io, + path::{Path, PathBuf}, + str, + sync::Arc, +}; use tokio_core::reactor::Handle; +use tokio_openssl::{SslConnectorExt, SslStream}; +use tokio_service::Service; -use self::tokio_openssl::{SslConnectorExt, SslStream}; -use self::tokio_service::Service; +pub use hyper_openssl::openssl::error::ErrorStack; pub struct HttpsClientWithSni { sni_hostname: String, @@ -97,7 +96,7 @@ impl<T> From<(T, SslConnector)> for HttpsConnectorWithSni<T> { } impl<T> fmt::Debug for HttpsConnectorWithSni<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("HttpsConnectorWithSni").finish() } } @@ -141,7 +140,7 @@ impl<T: Connect> Service for HttpsConnectorWithSni<T> { } } -type BoxedFut<T> = Box<Future<Item = SslStream<T>, Error = io::Error>>; +type BoxedFut<T> = Box<dyn Future<Item = SslStream<T>, Error = io::Error>>; /// A Future representing work to connect to a URL, and a TLS handshake. pub struct HttpsConnecting<T>(BoxedFut<T>); @@ -157,7 +156,7 @@ impl<T> Future for HttpsConnecting<T> { } impl<T> fmt::Debug for HttpsConnecting<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("HttpsConnecting") } } diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs index 0d886bfaaa..cd2f287a32 100644 --- a/mullvad-rpc/src/lib.rs +++ b/mullvad-rpc/src/lib.rs @@ -6,32 +6,15 @@ //! GNU General Public License as published by the Free Software Foundation, either version 3 of //! the License, or (at your option) any later version. -extern crate chrono; + #[macro_use] extern crate error_chain; -extern crate futures; -extern crate hyper; -extern crate hyper_openssl; -extern crate jsonrpc_client_core; -extern crate jsonrpc_client_http; -extern crate lazy_static; -extern crate log; -extern crate serde_json; -extern crate tokio_core; - -extern crate mullvad_types; -use chrono::offset::Utc; -use chrono::DateTime; +use chrono::{offset::Utc, DateTime}; use jsonrpc_client_core::{expand_params, jsonrpc_client}; use jsonrpc_client_http::header::Host; use jsonrpc_client_http::{HttpTransport, HttpTransportBuilder}; use lazy_static::lazy_static; -use tokio_core::reactor::Handle; - -pub use jsonrpc_client_core::{Error, ErrorKind}; -pub use jsonrpc_client_http::{Error as HttpError, HttpHandle}; - use mullvad_types::{account::AccountToken, relay_list::RelayList, version}; use std::{ collections::HashMap, @@ -39,6 +22,10 @@ use std::{ path::{Path, PathBuf}, time::Duration, }; +use tokio_core::reactor::Handle; + +pub use jsonrpc_client_core::{Error, ErrorKind}; +pub use jsonrpc_client_http::{Error as HttpError, HttpHandle}; pub mod event_loop; pub mod rest; diff --git a/mullvad-rpc/src/rest.rs b/mullvad-rpc/src/rest.rs index 05665e4fd0..546aec3b14 100644 --- a/mullvad-rpc/src/rest.rs +++ b/mullvad-rpc/src/rest.rs @@ -1,17 +1,14 @@ -use std::path::Path; - -use futures::sync::{mpsc, oneshot}; -use futures::{future, Future, Stream}; - -use hyper; -use hyper::client::Client; -use hyper::{Request, StatusCode, Uri}; +use crate::HttpsConnectorWithSni; +use futures::{ + future, + sync::{mpsc, oneshot}, + Future, Stream, +}; +use hyper::{client::Client, Request, StatusCode, Uri}; use hyper_openssl::openssl::error::ErrorStack; - +use std::path::Path; use tokio_core::reactor::Handle; -use crate::HttpsConnectorWithSni; - error_chain! { errors { /// When the http status code of the response is not 200 OK @@ -46,7 +43,7 @@ pub fn create_https_client<P: AsRef<Path>>(ca_path: P, handle: &Handle) -> Resul fn create_request_processing_future<CC: hyper::client::Connect>( request_rx: RequestReceiver, client: Client<CC, hyper::Body>, -) -> Box<Future<Item = (), Error = ()>> { +) -> Box<dyn Future<Item = (), Error = ()>> { let f = request_rx.for_each(move |(request, response_tx)| { log::trace!("Sending request to {}", request.uri()); client @@ -68,7 +65,7 @@ fn create_request_processing_future<CC: hyper::client::Connect>( Ok(()) }) }); - Box::new(f) as Box<Future<Item = (), Error = ()>> + Box::new(f) as Box<dyn Future<Item = (), Error = ()>> } pub fn create_get_request(uri: Uri) -> Request { |
