diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index f92b895ba8fd..993f0f9ece0b 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -700,13 +700,13 @@ impl ManagementService for ManagementServiceImpl { .map_err(map_daemon_error) } - async fn get_api_addresses(&self, _: Request<()>) -> ServiceResult<()> { + async fn get_api_addresses(&self, _: Request<()>) -> ServiceResult { log::debug!("get_api_addresses"); let (tx, rx) = oneshot::channel(); self.send_command_to_daemon(DaemonCommand::GetApiAddresses(tx))?; self.wait_for_result(rx) .await? - .map(drop) + .map(types::ApiAddresses::from) .map(Response::new) .map_err(map_daemon_error) } diff --git a/mullvad-management-interface/proto/management_interface.proto b/mullvad-management-interface/proto/management_interface.proto index 1bbb7f501281..24bfe2284b7f 100644 --- a/mullvad-management-interface/proto/management_interface.proto +++ b/mullvad-management-interface/proto/management_interface.proto @@ -22,7 +22,7 @@ service ManagementService { rpc GetCurrentVersion(google.protobuf.Empty) returns (google.protobuf.StringValue) {} rpc GetVersionInfo(google.protobuf.Empty) returns (AppVersionInfo) {} - rpc GetApiAddresses(google.protobuf.Empty) returns (google.protobuf.Empty) {} + rpc GetApiAddresses(google.protobuf.Empty) returns (ApiAddresses) {} rpc IsPerformingPostUpgrade(google.protobuf.Empty) returns (google.protobuf.BoolValue) {} @@ -112,6 +112,8 @@ message AccountData { google.protobuf.Timestamp expiry = 1; } message AccountHistory { google.protobuf.StringValue token = 1; } +message ApiAddresses { repeated google.protobuf.StringValue api_addresses = 1; } + message VoucherSubmission { uint64 seconds_added = 1; google.protobuf.Timestamp new_expiry = 2; diff --git a/mullvad-management-interface/src/client.rs b/mullvad-management-interface/src/client.rs index a4d56dd4450b..417083e16123 100644 --- a/mullvad-management-interface/src/client.rs +++ b/mullvad-management-interface/src/client.rs @@ -202,9 +202,15 @@ impl MullvadProxyClient { }) } - pub async fn get_api_addresses(&mut self) -> Result<()> { - self.0.get_api_addresses(()).await.map_err(Error::Rpc)?; - Ok(()) + pub async fn get_api_addresses(&mut self) -> Result> { + self.0 + .get_api_addresses(()) + .await + .map_err(Error::Rpc) + .map(tonic::Response::into_inner) + .and_then(|api_addresses| { + Vec::::try_from(api_addresses).map_err(Error::InvalidResponse) + }) } pub async fn update_relay_locations(&mut self) -> Result<()> { diff --git a/mullvad-management-interface/src/types/conversions/net.rs b/mullvad-management-interface/src/types/conversions/net.rs index d0dcc975d0fc..ea5dcf99a53d 100644 --- a/mullvad-management-interface/src/types/conversions/net.rs +++ b/mullvad-management-interface/src/types/conversions/net.rs @@ -174,6 +174,27 @@ impl From for proto::IpVersionConstraint { } } +impl TryFrom for Vec { + type Error = FromProtobufTypeError; + + fn try_from(value: proto::ApiAddresses) -> Result { + value + .api_addresses + .iter() + .map(|api_address| api_address.parse::()) + .collect::>() + .map_err(|_| FromProtobufTypeError::InvalidArgument("Invalid socket address")) + } +} + +impl From> for proto::ApiAddresses { + fn from(value: Vec) -> Self { + Self { + api_addresses: value.iter().map(SocketAddr::to_string).collect(), + } + } +} + pub fn try_tunnel_type_from_i32( tunnel_type: i32, ) -> Result {