summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2022-03-22 16:45:36 +0100
committerDavid Lönnhager <david.l@mullvad.net>2022-03-23 16:39:22 +0100
commit918e6588d2276122e391fb426be3245d0664e245 (patch)
treef762f61e1ed40bb4be8558122f3bdc4fff59570f
parentdf569e33f797e7c03591491ca7a88316d9cadd9a (diff)
downloadmullvadvpn-918e6588d2276122e391fb426be3245d0664e245.tar.xz
mullvadvpn-918e6588d2276122e391fb426be3245d0664e245.zip
Rename `mullvad_api::MullvadRpcRuntime` to `mullvad_api::Runtime`
-rw-r--r--mullvad-api/src/bin/relay_list.rs8
-rw-r--r--mullvad-api/src/lib.rs14
-rw-r--r--mullvad-daemon/src/device.rs4
-rw-r--r--mullvad-daemon/src/lib.rs44
-rw-r--r--mullvad-daemon/src/relays/mod.rs4
-rw-r--r--mullvad-daemon/src/relays/updater.rs16
-rw-r--r--mullvad-daemon/src/version_check.rs6
-rw-r--r--mullvad-problem-report/src/lib.rs8
-rw-r--r--mullvad-setup/src/main.rs6
9 files changed, 54 insertions, 56 deletions
diff --git a/mullvad-api/src/bin/relay_list.rs b/mullvad-api/src/bin/relay_list.rs
index 7d64ef35a4..2139e51f54 100644
--- a/mullvad-api/src/bin/relay_list.rs
+++ b/mullvad-api/src/bin/relay_list.rs
@@ -2,16 +2,14 @@
//! Used by the installer artifact packer to bundle the latest available
//! relay list at the time of creating the installer.
-use mullvad_api::{
- proxy::ApiConnectionMode, rest::Error as RestError, MullvadRpcRuntime, RelayListProxy,
-};
+use mullvad_api::{self, proxy::ApiConnectionMode, rest::Error as RestError, RelayListProxy};
use std::process;
use talpid_types::ErrorExt;
#[tokio::main]
async fn main() {
- let runtime =
- MullvadRpcRuntime::new(tokio::runtime::Handle::current()).expect("Failed to load runtime");
+ let runtime = mullvad_api::Runtime::new(tokio::runtime::Handle::current())
+ .expect("Failed to load runtime");
let relay_list_request = RelayListProxy::new(
runtime
diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs
index f93d27262a..40742fe41d 100644
--- a/mullvad-api/src/lib.rs
+++ b/mullvad-api/src/lib.rs
@@ -124,8 +124,8 @@ impl ApiEndpoint {
}
}
-/// A type that helps with the creation of RPC connections.
-pub struct MullvadRpcRuntime {
+/// A type that helps with the creation of API connections.
+pub struct Runtime {
handle: tokio::runtime::Handle,
pub address_cache: AddressCache,
api_availability: availability::ApiAvailability,
@@ -158,8 +158,8 @@ where
type AcceptedNewEndpoint = T;
}
-impl MullvadRpcRuntime {
- /// Create a new `MullvadRpcRuntime`.
+impl Runtime {
+ /// Create a new `Runtime`.
pub fn new(handle: tokio::runtime::Handle) -> Result<Self, Error> {
Self::new_inner(
handle,
@@ -172,7 +172,7 @@ impl MullvadRpcRuntime {
handle: tokio::runtime::Handle,
#[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
) -> Result<Self, Error> {
- Ok(MullvadRpcRuntime {
+ Ok(Runtime {
handle,
address_cache: AddressCache::new(None)?,
api_availability: ApiAvailability::new(availability::State::default()),
@@ -181,7 +181,7 @@ impl MullvadRpcRuntime {
})
}
- /// Create a new `MullvadRpcRuntime` using the specified directories.
+ /// Create a new `Runtime` using the specified directories.
/// Try to use the cache directory first, and fall back on the bundled address otherwise.
pub async fn with_cache(
cache_dir: &Path,
@@ -219,7 +219,7 @@ impl MullvadRpcRuntime {
}
};
- Ok(MullvadRpcRuntime {
+ Ok(Runtime {
handle,
address_cache,
api_availability: ApiAvailability::new(availability::State::default()),
diff --git a/mullvad-daemon/src/device.rs b/mullvad-daemon/src/device.rs
index 96f004ec6e..bdd5620297 100644
--- a/mullvad-daemon/src/device.rs
+++ b/mullvad-daemon/src/device.rs
@@ -975,11 +975,11 @@ impl AccountService {
}
pub fn spawn_account_service(
- rpc_handle: MullvadRestHandle,
+ api_handle: MullvadRestHandle,
token: Option<String>,
api_availability: ApiAvailabilityHandle,
) -> AccountService {
- let accounts_proxy = AccountsProxy::new(rpc_handle);
+ let accounts_proxy = AccountsProxy::new(api_handle);
api_availability.pause_background();
let api_availability_copy = api_availability.clone();
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index fcc0ba0198..27aea9b79a 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -572,8 +572,8 @@ pub struct Daemon<L: EventListener> {
account_history: account_history::AccountHistory,
device_checker: device::TunnelStateChangeHandler,
account_manager: device::AccountManagerHandle,
- rpc_runtime: mullvad_api::MullvadRpcRuntime,
- rpc_handle: mullvad_api::rest::MullvadRestHandle,
+ api_runtime: mullvad_api::Runtime,
+ api_handle: mullvad_api::rest::MullvadRestHandle,
version_updater_handle: version_check::VersionUpdaterHandle,
relay_selector: relays::RelaySelector,
last_generated_relay: Option<Relay>,
@@ -610,7 +610,7 @@ where
let (internal_event_tx, internal_event_rx) = command_channel.destructure();
- let rpc_runtime = mullvad_api::MullvadRpcRuntime::with_cache(
+ let api_runtime = mullvad_api::Runtime::with_cache(
&cache_dir,
true,
#[cfg(target_os = "android")]
@@ -619,7 +619,7 @@ where
.await
.map_err(Error::InitRpcFactory)?;
- let api_availability = rpc_runtime.availability_handle();
+ let api_availability = api_runtime.availability_handle();
api_availability.suspend();
let endpoint_updater = api::ApiEndpointUpdaterHandle::new();
@@ -628,14 +628,14 @@ where
internal_event_tx.to_specialized_sender(),
ApiConnectionMode::Direct,
);
- let rpc_handle = rpc_runtime
+ let api_handle = api_runtime
.mullvad_rest_handle(proxy_provider, endpoint_updater.callback())
.await;
if let Err(error) = migrations::migrate_all(
&cache_dir,
&settings_dir,
- rpc_handle.clone(),
+ api_handle.clone(),
internal_event_tx.clone(),
)
.await
@@ -652,7 +652,7 @@ where
};
let account_manager = device::AccountManager::spawn(
- rpc_handle.clone(),
+ api_handle.clone(),
api_availability.clone(),
&settings_dir,
settings
@@ -699,7 +699,7 @@ where
};
let initial_api_endpoint =
- api::get_allowed_endpoint(rpc_runtime.address_cache.get_address().await);
+ api::get_allowed_endpoint(api_runtime.address_cache.get_address().await);
let (offline_state_tx, offline_state_rx) = mpsc::unbounded();
#[cfg(target_os = "windows")]
@@ -739,7 +739,7 @@ where
};
let relay_selector = relays::RelaySelector::new(
- rpc_handle.clone(),
+ api_handle.clone(),
on_relay_list_update,
&resource_dir,
&cache_dir,
@@ -748,7 +748,7 @@ where
let app_version_info = version_check::load_cache(&cache_dir).await;
let (version_updater, version_updater_handle) = version_check::VersionUpdater::new(
- rpc_handle.clone(),
+ api_handle.clone(),
api_availability.clone(),
cache_dir.clone(),
internal_event_tx.to_specialized_sender(),
@@ -775,8 +775,8 @@ where
account_history,
device_checker: device::TunnelStateChangeHandler::new(account_manager.clone()),
account_manager,
- rpc_runtime,
- rpc_handle,
+ api_runtime,
+ api_handle,
version_updater_handle,
relay_selector,
last_generated_relay: None,
@@ -858,7 +858,7 @@ where
}
async fn finalize(self) {
- let (event_listener, shutdown_tasks, rpc_runtime, tunnel_state_machine_handle) =
+ let (event_listener, shutdown_tasks, api_runtime, tunnel_state_machine_handle) =
self.shutdown();
for future in shutdown_tasks {
future.await;
@@ -866,8 +866,8 @@ where
tunnel_state_machine_handle.try_join().await;
- mem::drop(event_listener);
- mem::drop(rpc_runtime);
+ drop(event_listener);
+ drop(api_runtime);
#[cfg(any(target_os = "macos", target_os = "linux"))]
if let Err(err) = fs::remove_file(mullvad_paths::get_rpc_socket_path()).await {
@@ -884,13 +884,13 @@ where
) -> (
L,
Vec<Pin<Box<dyn Future<Output = ()>>>>,
- mullvad_api::MullvadRpcRuntime,
+ mullvad_api::Runtime,
tunnel_state_machine::JoinHandle,
) {
let Daemon {
event_listener,
mut shutdown_tasks,
- rpc_runtime,
+ api_runtime,
tunnel_state_machine_handle,
target_state,
account_manager,
@@ -903,7 +903,7 @@ where
(
event_listener,
shutdown_tasks,
- rpc_runtime,
+ api_runtime,
tunnel_state_machine_handle,
)
}
@@ -999,7 +999,7 @@ where
match (&self.tunnel_state, &tunnel_state_transition) {
// only reset the API sockets if when connected or leaving the connected state
(&TunnelState::Connected { .. }, _) | (_, &TunnelStateTransition::Connected(_)) => {
- self.rpc_handle.service().reset().await;
+ self.api_handle.service().reset().await;
}
_ => (),
};
@@ -1500,9 +1500,9 @@ where
}
async fn get_geo_location(&mut self) -> impl Future<Output = Result<GeoIpLocation, ()>> {
- let rpc_service = self.rpc_runtime.rest_handle().await;
+ let rest_service = self.api_runtime.rest_handle().await;
async {
- geoip::send_location_request(rpc_service)
+ geoip::send_location_request(rest_service)
.await
.map_err(|e| {
log::warn!("Unable to fetch GeoIP location: {}", e.display_chain());
@@ -2454,7 +2454,7 @@ where
}
fn connect_tunnel(&mut self) {
- self.rpc_runtime.availability_handle().resume_background();
+ self.api_runtime.availability_handle().resume_background();
self.send_tunnel_command(TunnelCommand::Connect);
}
diff --git a/mullvad-daemon/src/relays/mod.rs b/mullvad-daemon/src/relays/mod.rs
index 28bc896c0d..6f6a0279ba 100644
--- a/mullvad-daemon/src/relays/mod.rs
+++ b/mullvad-daemon/src/relays/mod.rs
@@ -211,7 +211,7 @@ impl RelaySelector {
/// Returns a new `RelaySelector` backed by relays cached on disk. Use the `update` method
/// to refresh the relay list from the internet.
pub fn new(
- rpc_handle: MullvadRestHandle,
+ api_handle: MullvadRestHandle,
on_update: impl Fn(&RelayList) + Send + 'static,
resource_dir: &Path,
cache_dir: &Path,
@@ -236,7 +236,7 @@ impl RelaySelector {
let parsed_relays = Arc::new(Mutex::new(unsynchronized_parsed_relays));
let updater = RelayListUpdater::new(
- rpc_handle,
+ api_handle,
cache_path,
parsed_relays.clone(),
Box::new(on_update),
diff --git a/mullvad-daemon/src/relays/updater.rs b/mullvad-daemon/src/relays/updater.rs
index a7370f59ac..ae55a998f6 100644
--- a/mullvad-daemon/src/relays/updater.rs
+++ b/mullvad-daemon/src/relays/updater.rs
@@ -41,7 +41,7 @@ impl RelayListUpdaterHandle {
}
pub struct RelayListUpdater {
- rpc_client: RelayListProxy,
+ api_client: RelayListProxy,
cache_path: PathBuf,
parsed_relays: Arc<Mutex<ParsedRelays>>,
on_update: Box<dyn Fn(&RelayList) + Send + 'static>,
@@ -51,16 +51,16 @@ pub struct RelayListUpdater {
impl RelayListUpdater {
pub(super) fn new(
- rpc_handle: MullvadRestHandle,
+ api_handle: MullvadRestHandle,
cache_path: PathBuf,
parsed_relays: Arc<Mutex<ParsedRelays>>,
on_update: Box<dyn Fn(&RelayList) + Send + 'static>,
api_availability: ApiAvailabilityHandle,
) -> RelayListUpdaterHandle {
let (tx, cmd_rx) = mpsc::channel(1);
- let rpc_client = RelayListProxy::new(rpc_handle);
+ let api_client = RelayListProxy::new(api_handle);
let updater = RelayListUpdater {
- rpc_client,
+ api_client,
cache_path,
parsed_relays,
on_update,
@@ -86,7 +86,7 @@ impl RelayListUpdater {
_check_update = ticker.select_next_some() => {
if download_future.is_terminated() && self.should_update() {
let tag = self.parsed_relays.lock().tag().map(|tag| tag.to_string());
- download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.rpc_client.clone(), tag).fuse());
+ download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.api_client.clone(), tag).fuse());
self.earliest_next_try = Instant::now() + UPDATE_INTERVAL;
}
},
@@ -99,7 +99,7 @@ impl RelayListUpdater {
match cmd {
Some(()) => {
let tag = self.parsed_relays.lock().tag().map(|tag| tag.to_string());
- download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.rpc_client.clone(), tag).fuse());
+ download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.api_client.clone(), tag).fuse());
},
None => {
log::trace!("Relay list updater shutting down");
@@ -149,12 +149,12 @@ impl RelayListUpdater {
fn download_relay_list(
api_handle: ApiAvailabilityHandle,
- rpc_handle: RelayListProxy,
+ proxy: RelayListProxy,
tag: Option<String>,
) -> impl Future<Output = Result<Option<RelayList>, mullvad_api::Error>> + 'static {
let download_futures = move || {
let available = api_handle.wait_background();
- let req = rpc_handle.relay_list(tag.clone());
+ let req = proxy.relay_list(tag.clone());
async move {
available.await?;
req.await.map_err(mullvad_api::Error::from)
diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs
index 6bca3fe575..13792383de 100644
--- a/mullvad-daemon/src/version_check.rs
+++ b/mullvad-daemon/src/version_check.rs
@@ -151,15 +151,15 @@ impl VersionUpdaterHandle {
impl VersionUpdater {
pub fn new(
- mut rpc_handle: MullvadRestHandle,
+ mut api_handle: MullvadRestHandle,
availability_handle: ApiAvailabilityHandle,
cache_dir: PathBuf,
update_sender: DaemonEventSender<AppVersionInfo>,
last_app_version_info: Option<AppVersionInfo>,
show_beta_releases: bool,
) -> (Self, VersionUpdaterHandle) {
- rpc_handle.factory.timeout = DOWNLOAD_TIMEOUT;
- let version_proxy = AppVersionProxy::new(rpc_handle);
+ api_handle.factory.timeout = DOWNLOAD_TIMEOUT;
+ let version_proxy = AppVersionProxy::new(api_handle);
let cache_path = cache_dir.join(VERSION_INFO_FILENAME);
let (tx, rx) = mpsc::channel(1);
let platform_version = talpid_platform_metadata::short_version();
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs
index af198737b0..2570aa6c78 100644
--- a/mullvad-problem-report/src/lib.rs
+++ b/mullvad-problem-report/src/lib.rs
@@ -293,7 +293,7 @@ async fn send_problem_report_inner(
) -> Result<(), Error> {
let metadata =
ProblemReport::parse_metadata(&report_content).unwrap_or_else(|| metadata::collect());
- let rpc_runtime = mullvad_api::MullvadRpcRuntime::with_cache(
+ let api_runtime = mullvad_api::Runtime::with_cache(
cache_dir,
false,
#[cfg(target_os = "android")]
@@ -302,8 +302,8 @@ async fn send_problem_report_inner(
.await
.map_err(Error::CreateRpcClientError)?;
- let rpc_client = mullvad_api::ProblemReportProxy::new(
- rpc_runtime
+ let api_client = mullvad_api::ProblemReportProxy::new(
+ api_runtime
.mullvad_rest_handle(
ApiConnectionMode::try_from_cache(cache_dir)
.await
@@ -314,7 +314,7 @@ async fn send_problem_report_inner(
);
for _attempt in 0..MAX_SEND_ATTEMPTS {
- match rpc_client
+ match api_client
.problem_report(user_email, user_message, &report_content, &metadata)
.await
{
diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs
index c002a30ecc..10ebb36981 100644
--- a/mullvad-setup/src/main.rs
+++ b/mullvad-setup/src/main.rs
@@ -1,5 +1,5 @@
use clap::{crate_authors, crate_description, crate_name, App};
-use mullvad_api::{proxy::ApiConnectionMode, MullvadRpcRuntime};
+use mullvad_api::{self, proxy::ApiConnectionMode};
use mullvad_management_interface::new_rpc_client;
use mullvad_types::version::ParsedAppVersion;
use std::{path::PathBuf, process, time::Duration};
@@ -168,12 +168,12 @@ async fn remove_device() -> Result<(), Error> {
.await
.map_err(Error::ReadDeviceCacheError)?;
if let Some(device) = data {
- let rpc_runtime = MullvadRpcRuntime::with_cache(&cache_path, false)
+ let api_runtime = mullvad_api::Runtime::with_cache(&cache_path, false)
.await
.map_err(Error::RpcInitializationError)?;
let proxy = mullvad_api::DevicesProxy::new(
- rpc_runtime
+ api_runtime
.mullvad_rest_handle(
ApiConnectionMode::try_from_cache(&cache_path)
.await