Skip to content

Commit

Permalink
Add GetApiAddresses now returns a list of API addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Oct 2, 2023
1 parent c41ece1 commit 1e44ea1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mullvad-daemon/src/management_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<types::ApiAddresses> {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions mullvad-management-interface/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<std::net::SocketAddr>> {
self.0
.get_api_addresses(())
.await
.map_err(Error::Rpc)
.map(tonic::Response::into_inner)
.and_then(|api_addresses| {
Vec::<std::net::SocketAddr>::try_from(api_addresses).map_err(Error::InvalidResponse)
})
}

pub async fn update_relay_locations(&mut self) -> Result<()> {
Expand Down
21 changes: 21 additions & 0 deletions mullvad-management-interface/src/types/conversions/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ impl From<proto::IpVersion> for proto::IpVersionConstraint {
}
}

impl TryFrom<proto::ApiAddresses> for Vec<SocketAddr> {
type Error = FromProtobufTypeError;

fn try_from(value: proto::ApiAddresses) -> Result<Self, Self::Error> {
value
.api_addresses
.iter()
.map(|api_address| api_address.parse::<SocketAddr>())
.collect::<Result<_, _>>()
.map_err(|_| FromProtobufTypeError::InvalidArgument("Invalid socket address"))
}
}

impl From<Vec<SocketAddr>> for proto::ApiAddresses {
fn from(value: Vec<SocketAddr>) -> Self {
Self {
api_addresses: value.iter().map(SocketAddr::to_string).collect(),
}
}
}

pub fn try_tunnel_type_from_i32(
tunnel_type: i32,
) -> Result<talpid_types::net::TunnelType, FromProtobufTypeError> {
Expand Down

0 comments on commit 1e44ea1

Please sign in to comment.