diff options
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 33 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/bridge.rs | 4 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 4 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 32 | ||||
| -rw-r--r-- | mullvad-management-interface/proto/management_interface.proto | 2 | ||||
| -rw-r--r-- | mullvad-management-interface/src/types.rs | 12 |
6 files changed, 36 insertions, 51 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index a868208ac2..310a9a5c83 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -246,17 +246,10 @@ export class DaemonRpc { } } - public getRelayLocations(): Promise<IRelayList> { + public async getRelayLocations(): Promise<IRelayList> { if (this.isConnected) { - return new Promise((resolve, reject) => { - const relayLocations: IRelayListCountry[] = []; - const stream = this.client.getRelayLocations(new Empty()); - stream.on('data', (country: grpcTypes.RelayListCountry) => - relayLocations.push(convertFromRelayListCountry(country.toObject())), - ); - stream.on('end', () => resolve({ countries: relayLocations })); - stream.on('close', reject); - }); + const response = await this.callEmpty<grpcTypes.RelayList>(this.client.getRelayLocations); + return convertFromRelayList(response); } else { throw noConnectionError; } @@ -711,6 +704,16 @@ function liftConstraint<T>(constraint: Constraint<T> | undefined): T | undefined return undefined; } +function convertFromRelayList(relayList: grpcTypes.RelayList): IRelayList { + return { + countries: relayList + .getCountriesList() + .map((country: grpcTypes.RelayListCountry) => + convertFromRelayListCountry(country.toObject()), + ), + }; +} + function convertFromRelayListCountry( country: grpcTypes.RelayListCountry.AsObject, ): IRelayListCountry { @@ -1160,15 +1163,7 @@ function convertFromDaemonEvent(data: grpcTypes.DaemonEvent): DaemonEvent { const relayList = data.getRelayList(); if (relayList !== undefined) { - return { - relayList: { - countries: relayList - .getCountriesList() - ?.map((country: grpcTypes.RelayListCountry) => - convertFromRelayListCountry(country.toObject()), - ), - }, - }; + return { relayList: convertFromRelayList(relayList) }; } const deviceConfig = data.getDevice(); diff --git a/mullvad-cli/src/cmds/bridge.rs b/mullvad-cli/src/cmds/bridge.rs index 27532f1416..6e09b75084 100644 --- a/mullvad-cli/src/cmds/bridge.rs +++ b/mullvad-cli/src/cmds/bridge.rs @@ -424,7 +424,7 @@ impl Bridge { async fn list_bridge_relays() -> Result<()> { let mut rpc = new_rpc_client().await?; - let mut locations = rpc + let relay_list = rpc .get_relay_locations(()) .await .map_err(|error| Error::RpcFailedExt("Failed to obtain relay locations", error))? @@ -432,7 +432,7 @@ impl Bridge { let mut countries = Vec::new(); - while let Some(mut country) = locations.message().await? { + for mut country in relay_list.countries { country.cities = country .cities .into_iter() diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index 8e68adda6c..22bf4788f2 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -718,7 +718,7 @@ impl Relay { async fn get_filtered_relays() -> Result<Vec<types::RelayListCountry>> { let mut rpc = new_rpc_client().await?; - let mut locations = rpc + let relay_list = rpc .get_relay_locations(()) .await .map_err(|error| Error::RpcFailedExt("Failed to obtain relay locations", error))? @@ -726,7 +726,7 @@ impl Relay { let mut countries = Vec::new(); - while let Some(mut country) = locations.message().await? { + for mut country in relay_list.countries { country.cities = country .cities .into_iter() diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 26ad5e39c0..8ef8ac7b98 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -24,13 +24,12 @@ use parking_lot::RwLock; #[cfg(windows)] use std::path::PathBuf; use std::{ - cmp, convert::{TryFrom, TryInto}, sync::Arc, time::Duration, }; use talpid_types::ErrorExt; -use tokio_stream::wrappers::{ReceiverStream, UnboundedReceiverStream}; +use tokio_stream::wrappers::UnboundedReceiverStream; #[derive(err_derive::Error, Debug)] #[error(no_from)] @@ -54,7 +53,6 @@ const USED_VOUCHER_MESSAGE: &str = "This voucher code has already been used"; #[mullvad_management_interface::async_trait] impl ManagementService for ManagementServiceImpl { - type GetRelayLocationsStream = ReceiverStream<Result<types::RelayListCountry, Status>>; type GetSplitTunnelProcessesStream = UnboundedReceiverStream<Result<i32, Status>>; type EventsListenStream = EventsListenerReceiver; @@ -189,34 +187,14 @@ impl ManagementService for ManagementServiceImpl { .map_err(map_settings_error) } - async fn get_relay_locations( - &self, - _: Request<()>, - ) -> ServiceResult<Self::GetRelayLocationsStream> { + async fn get_relay_locations(&self, _: Request<()>) -> ServiceResult<types::RelayList> { log::debug!("get_relay_locations"); let (tx, rx) = oneshot::channel(); self.send_command_to_daemon(DaemonCommand::GetRelayLocations(tx))?; - let locations = self.wait_for_result(rx).await?; - - let (stream_tx, stream_rx) = - tokio::sync::mpsc::channel(cmp::max(1, locations.countries.len())); - - tokio::spawn(async move { - for country in locations.countries.into_iter() { - if let Err(error) = stream_tx - .send(Ok(types::RelayListCountry::from(country))) - .await - { - log::error!( - "Error while sending relays to client: {}", - error.display_chain() - ); - } - } - }); - - Ok(Response::new(ReceiverStream::new(stream_rx))) + self.wait_for_result(rx) + .await + .map(|relays| Response::new(types::RelayList::from(relays))) } async fn get_current_location(&self, _: Request<()>) -> ServiceResult<types::GeoIpLocation> { diff --git a/mullvad-management-interface/proto/management_interface.proto b/mullvad-management-interface/proto/management_interface.proto index 4c6ee5ab71..ea12c22c0f 100644 --- a/mullvad-management-interface/proto/management_interface.proto +++ b/mullvad-management-interface/proto/management_interface.proto @@ -29,7 +29,7 @@ service ManagementService { // Relays and tunnel constraints rpc UpdateRelayLocations(google.protobuf.Empty) returns (google.protobuf.Empty) {} rpc UpdateRelaySettings(RelaySettingsUpdate) returns (google.protobuf.Empty) {} - rpc GetRelayLocations(google.protobuf.Empty) returns (stream RelayListCountry) {} + rpc GetRelayLocations(google.protobuf.Empty) returns (RelayList) {} rpc GetCurrentLocation(google.protobuf.Empty) returns (GeoIpLocation) {} rpc SetBridgeSettings(BridgeSettings) returns (google.protobuf.Empty) {} rpc SetBridgeState(BridgeState) returns (google.protobuf.Empty) {} diff --git a/mullvad-management-interface/src/types.rs b/mullvad-management-interface/src/types.rs index d3404e2298..ff1f632e3e 100644 --- a/mullvad-management-interface/src/types.rs +++ b/mullvad-management-interface/src/types.rs @@ -694,6 +694,18 @@ impl From<&mullvad_types::settings::TunnelOptions> for TunnelOptions { } } +impl From<mullvad_types::relay_list::RelayList> for RelayList { + fn from(relay_list: mullvad_types::relay_list::RelayList) -> Self { + let mut proto_list = RelayList { countries: vec![] }; + proto_list.countries = relay_list + .countries + .into_iter() + .map(RelayListCountry::from) + .collect(); + proto_list + } +} + impl From<mullvad_types::relay_list::RelayListCountry> for RelayListCountry { fn from(country: mullvad_types::relay_list::RelayListCountry) -> Self { let mut proto_country = RelayListCountry { |
