Skip to content

Commit

Permalink
Rename mullvad_types::access_method to mullvad_types::api_access
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Sep 25, 2023
1 parent ca9c7b5 commit 9f52fdc
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions mullvad-api/src/https_client_with_sni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ impl TryFrom<ApiConnectionMode> for InnerConnectionMode {
})
}
ProxyConfig::Socks(config) => match config {
mullvad_types::access_method::Socks5::Local(config) => {
mullvad_types::api_access::Socks5::Local(config) => {
InnerConnectionMode::Socks5(SocksConfig {
peer: SocketAddr::new("127.0.0.1".parse().unwrap(), config.port),
})
}
mullvad_types::access_method::Socks5::Remote(config) => {
mullvad_types::api_access::Socks5::Remote(config) => {
InnerConnectionMode::Socks5(SocksConfig { peer: config.peer })
}
},
Expand Down
14 changes: 7 additions & 7 deletions mullvad-api/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use futures::Stream;
use hyper::client::connect::Connected;
use mullvad_types::access_method;
use mullvad_types::api_access;
use serde::{Deserialize, Serialize};
use std::{
fmt, io,
Expand Down Expand Up @@ -36,8 +36,8 @@ impl fmt::Display for ApiConnectionMode {

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum ProxyConfig {
Shadowsocks(access_method::Shadowsocks),
Socks(access_method::Socks5),
Shadowsocks(api_access::Shadowsocks),
Socks(api_access::Socks5),
}

impl ProxyConfig {
Expand All @@ -46,8 +46,8 @@ impl ProxyConfig {
match self {
ProxyConfig::Shadowsocks(ss) => ss.peer,
ProxyConfig::Socks(socks) => match socks {
access_method::Socks5::Local(s) => s.peer,
access_method::Socks5::Remote(s) => s.peer,
api_access::Socks5::Local(s) => s.peer,
api_access::Socks5::Remote(s) => s.peer,
},
}
}
Expand All @@ -59,10 +59,10 @@ impl fmt::Display for ProxyConfig {
// TODO: Do not hardcode TCP
ProxyConfig::Shadowsocks(ss) => write!(f, "Shadowsocks {}/TCP", ss.peer),
ProxyConfig::Socks(socks) => match socks {
access_method::Socks5::Local(s) => {
api_access::Socks5::Local(s) => {
write!(f, "Socks5 {}/TCP via localhost:{}", s.peer, s.port)
}
access_method::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer),
api_access::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer),
},
}
}
Expand Down
21 changes: 11 additions & 10 deletions mullvad-cli/src/cmds/api_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{anyhow, Result};
use mullvad_management_interface::{
types::rpc::api_access_method_update::ApiAccessMethodUpdate, MullvadProxyClient,
};
use mullvad_types::access_method::{AccessMethod, ApiAccessMethod, CustomAccessMethod};
use mullvad_types::api_access::{AccessMethod, ApiAccessMethod, CustomAccessMethod};
use std::net::IpAddr;

use clap::{Args, Subcommand};
Expand Down Expand Up @@ -107,27 +107,28 @@ impl ApiAccess {
let cipher = cmd.params.cipher.unwrap_or(shadowsocks.cipher);
let name = cmd.params.name.unwrap_or(api_access_method.name);
let enabled = api_access_method.enabled;
mullvad_types::access_method::Shadowsocks::from_args(ip, port, cipher, password)
.map(|shadowsocks| {
mullvad_types::api_access::Shadowsocks::from_args(ip, port, cipher, password).map(
|shadowsocks| {
ApiAccessMethod::new(name, enabled, AccessMethod::from(shadowsocks))
})
},
)
}
CustomAccessMethod::Socks5(socks) => match socks {
mullvad_types::access_method::Socks5::Local(local) => {
mullvad_types::api_access::Socks5::Local(local) => {
let ip = cmd.params.ip.unwrap_or(local.peer.ip()).to_string();
let port = cmd.params.port.unwrap_or(local.peer.port());
let local_port = cmd.params.local_port.unwrap_or(local.port);
let name = cmd.params.name.unwrap_or(api_access_method.get_name());
let enabled = api_access_method.enabled();
mullvad_types::access_method::Socks5Local::from_args(ip, port, local_port)
mullvad_types::api_access::Socks5Local::from_args(ip, port, local_port)
.map(|socks| ApiAccessMethod::new(name, enabled, AccessMethod::from(socks)))
}
mullvad_types::access_method::Socks5::Remote(remote) => {
mullvad_types::api_access::Socks5::Remote(remote) => {
let ip = cmd.params.ip.unwrap_or(remote.peer.ip()).to_string();
let port = cmd.params.port.unwrap_or(remote.peer.port());
let name = cmd.params.name.unwrap_or(api_access_method.get_name());
let enabled = api_access_method.enabled();
mullvad_types::access_method::Socks5Remote::from_args(ip, port)
mullvad_types::api_access::Socks5Remote::from_args(ip, port)
.map(|socks| ApiAccessMethod::new(name, enabled, AccessMethod::from(socks)))
}
},
Expand Down Expand Up @@ -310,7 +311,7 @@ pub struct EditParams {
/// we define them in a hidden-away module.
mod conversions {
use anyhow::{anyhow, Error};
use mullvad_types::access_method as daemon_types;
use mullvad_types::api_access as daemon_types;

use super::{AddCustomCommands, Socks5AddCommands};

Expand Down Expand Up @@ -394,7 +395,7 @@ mod conversions {

/// Pretty printing of [`ApiAccessMethod`]s
mod pp {
use mullvad_types::access_method::{AccessMethod, ApiAccessMethod, CustomAccessMethod, Socks5};
use mullvad_types::api_access::{AccessMethod, ApiAccessMethod, CustomAccessMethod, Socks5};

pub struct ApiAccessMethodFormatter<'a> {
api_access_method: &'a ApiAccessMethod,
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/access_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
Daemon, EventListener,
};
use mullvad_management_interface::types::rpc::api_access_method_update::ApiAccessMethodUpdate;
use mullvad_types::access_method::{ApiAccessMethod, ApiAccessMethodId};
use mullvad_types::api_access::{ApiAccessMethod, ApiAccessMethodId};

#[derive(err_derive::Error, Debug)]
pub enum Error {
Expand Down
17 changes: 8 additions & 9 deletions mullvad-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mullvad_api::{
ApiEndpointUpdateCallback,
};
use mullvad_relay_selector::RelaySelector;
use mullvad_types::access_method::{self, AccessMethod, BuiltInAccessMethod};
use mullvad_types::api_access::{self, AccessMethod, BuiltInAccessMethod};
use std::{
net::SocketAddr,
path::PathBuf,
Expand Down Expand Up @@ -131,12 +131,11 @@ impl ApiConnectionModeProvider {
.get_bridge_forced()
.and_then(|settings| match settings {
ProxySettings::Shadowsocks(ss_settings) => {
let ss_settings: access_method::Shadowsocks =
access_method::Shadowsocks::new(
ss_settings.peer,
ss_settings.cipher,
ss_settings.password,
);
let ss_settings: api_access::Shadowsocks = api_access::Shadowsocks::new(
ss_settings.peer,
ss_settings.cipher,
ss_settings.password,
);
Some(ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks(
ss_settings,
)))
Expand All @@ -149,10 +148,10 @@ impl ApiConnectionModeProvider {
.unwrap_or(ApiConnectionMode::Direct),
},
AccessMethod::Custom(access_method) => match &access_method {
access_method::CustomAccessMethod::Shadowsocks(shadowsocks_config) => {
api_access::CustomAccessMethod::Shadowsocks(shadowsocks_config) => {
ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks(shadowsocks_config.clone()))
}
access_method::CustomAccessMethod::Socks5(socks_config) => {
api_access::CustomAccessMethod::Socks5(socks_config) => {
ApiConnectionMode::Proxied(ProxyConfig::Socks(socks_config.clone()))
}
},
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use mullvad_relay_selector::{
RelaySelector, SelectorConfig,
};
use mullvad_types::{
access_method::{ApiAccessMethod, ApiAccessMethodId},
account::{AccountData, AccountToken, VoucherSubmission},
api_access::{ApiAccessMethod, ApiAccessMethodId},
auth_failed::AuthFailed,
custom_list::{CustomList, CustomListLocationUpdate},
device::{Device, DeviceEvent, DeviceEventCause, DeviceId, DeviceState, RemoveDeviceEvent},
Expand Down
6 changes: 3 additions & 3 deletions mullvad-daemon/src/management_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ impl ManagementService for ManagementServiceImpl {
) -> ServiceResult<()> {
log::debug!("add_api_access_method");
let api_access_method =
mullvad_types::access_method::ApiAccessMethod::try_from(request.into_inner())?;
mullvad_types::api_access::ApiAccessMethod::try_from(request.into_inner())?;
let (tx, rx) = oneshot::channel();
self.send_command_to_daemon(DaemonCommand::AddApiAccessMethod(tx, api_access_method))?;
self.wait_for_result(rx)
Expand All @@ -638,7 +638,7 @@ impl ManagementService for ManagementServiceImpl {
async fn remove_api_access_method(&self, request: Request<types::Uuid>) -> ServiceResult<()> {
log::debug!("remove_api_access_method");
let api_access_method =
mullvad_types::access_method::ApiAccessMethodId::from(request.into_inner());
mullvad_types::api_access::ApiAccessMethodId::from(request.into_inner());
let (tx, rx) = oneshot::channel();
self.send_command_to_daemon(DaemonCommand::RemoveApiAccessMethod(tx, api_access_method))?;
self.wait_for_result(rx)
Expand Down Expand Up @@ -670,7 +670,7 @@ impl ManagementService for ManagementServiceImpl {
async fn set_api_access_method(&self, request: Request<types::Uuid>) -> ServiceResult<()> {
log::debug!("set_api_access_method");
let api_access_method =
mullvad_types::access_method::ApiAccessMethodId::from(request.into_inner());
mullvad_types::api_access::ApiAccessMethodId::from(request.into_inner());
let (tx, rx) = oneshot::channel();
self.send_command_to_daemon(DaemonCommand::SetApiAccessMethod(tx, api_access_method))?;
self.wait_for_result(rx)
Expand Down
2 changes: 1 addition & 1 deletion mullvad-management-interface/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::types::{self, rpc};
use futures::{Stream, StreamExt};
use mullvad_types::{
access_method::{ApiAccessMethod, ApiAccessMethodId},
account::{AccountData, AccountToken, VoucherSubmission},
api_access::{ApiAccessMethod, ApiAccessMethodId},
custom_list::{CustomList, CustomListLocationUpdate},
device::{Device, DeviceEvent, DeviceId, DeviceState, RemoveDeviceEvent},
location::GeoIpLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pub mod settings {
use crate::types::{
proto, rpc::api_access_method_update::ApiAccessMethodUpdate, FromProtobufTypeError,
};
use mullvad_types::access_method;
use mullvad_types::api_access;

impl From<&access_method::Settings> for proto::ApiAccessMethodSettings {
fn from(settings: &access_method::Settings) -> Self {
impl From<&api_access::Settings> for proto::ApiAccessMethodSettings {
fn from(settings: &api_access::Settings) -> Self {
Self {
api_access_methods: settings
.api_access_methods
Expand All @@ -19,22 +19,22 @@ pub mod settings {
}
}

impl From<access_method::Settings> for proto::ApiAccessMethodSettings {
fn from(settings: access_method::Settings) -> Self {
impl From<api_access::Settings> for proto::ApiAccessMethodSettings {
fn from(settings: api_access::Settings) -> Self {
proto::ApiAccessMethodSettings::from(&settings)
}
}

impl TryFrom<proto::ApiAccessMethodSettings> for access_method::Settings {
impl TryFrom<proto::ApiAccessMethodSettings> for api_access::Settings {
type Error = FromProtobufTypeError;

fn try_from(settings: proto::ApiAccessMethodSettings) -> Result<Self, Self::Error> {
Ok(Self {
api_access_methods: settings
.api_access_methods
.iter()
.map(access_method::ApiAccessMethod::try_from)
.collect::<Result<Vec<access_method::ApiAccessMethod>, _>>()?,
.map(api_access::ApiAccessMethod::try_from)
.collect::<Result<Vec<api_access::ApiAccessMethod>, _>>()?,
})
}
}
Expand All @@ -57,14 +57,14 @@ pub mod settings {
.ok_or(FromProtobufTypeError::InvalidArgument(
"Could not convert Access Method from protobuf",
))
.and_then(access_method::ApiAccessMethod::try_from)?;
.and_then(api_access::ApiAccessMethod::try_from)?;

let id = value
.id
.ok_or(FromProtobufTypeError::InvalidArgument(
"Could not convert Access Method from protobuf",
))
.map(access_method::ApiAccessMethodId::from)?;
.map(api_access::ApiAccessMethodId::from)?;

Ok(ApiAccessMethodUpdate {
id,
Expand All @@ -79,7 +79,7 @@ pub mod settings {
/// [`mullvad_types::access_method::AccessMethod`] data type.
mod data {
use crate::types::{proto, FromProtobufTypeError};
use mullvad_types::access_method::{
use mullvad_types::api_access::{
AccessMethod, ApiAccessMethod, ApiAccessMethodId, BuiltInAccessMethod, CustomAccessMethod,
Shadowsocks, Socks5, Socks5Local, Socks5Remote,
};
Expand Down Expand Up @@ -204,12 +204,12 @@ mod data {
}
},
AccessMethod::BuiltIn(value) => match value {
mullvad_types::access_method::BuiltInAccessMethod::Direct => {
mullvad_types::api_access::BuiltInAccessMethod::Direct => {
proto::api_access_method::AccessMethod::Direct(
proto::api_access_method::Direct {},
)
}
mullvad_types::access_method::BuiltInAccessMethod::Bridge => {
mullvad_types::api_access::BuiltInAccessMethod::Bridge => {
proto::api_access_method::AccessMethod::Bridges(
proto::api_access_method::Bridges {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl TryFrom<proto::Settings> for mullvad_types::settings::Settings {
custom_lists: mullvad_types::custom_list::CustomListsSettings::try_from(
custom_lists_settings,
)?,
api_access_methods: mullvad_types::access_method::Settings::try_from(
api_access_methods: mullvad_types::api_access::Settings::try_from(
api_access_methods_settings,
)?,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// A short-lived datastructure used in the `ApiAccessMethodUpdate` RPC call.
use mullvad_types::access_method::{ApiAccessMethod, ApiAccessMethodId};
use mullvad_types::api_access::{ApiAccessMethod, ApiAccessMethodId};
/// Argument to gRPC call `UpdateApiAccessMethod`.
#[derive(Debug, Clone, PartialEq)]
pub struct ApiAccessMethodUpdate {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mullvad-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(rust_2018_idioms)]

pub mod access_method;
pub mod account;
pub mod api_access;
pub mod auth_failed;
pub mod custom_list;
pub mod device;
Expand Down
6 changes: 3 additions & 3 deletions mullvad-types/src/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
access_method,
api_access,
custom_list::CustomListsSettings,
relay_constraints::{
BridgeConstraints, BridgeSettings, BridgeState, Constraint, GeographicLocationConstraint,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct Settings {
pub custom_lists: CustomListsSettings,
/// API access methods.
#[cfg_attr(target_os = "android", jnix(skip))]
pub api_access_methods: access_method::Settings,
pub api_access_methods: api_access::Settings,
/// If the daemon should allow communication with private (LAN) networks.
pub allow_lan: bool,
/// Extra level of kill switch. When this setting is on, the disconnected state will block
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Default for Settings {
split_tunnel: SplitTunnelSettings::default(),
settings_version: CURRENT_SETTINGS_VERSION,
custom_lists: CustomListsSettings::default(),
api_access_methods: access_method::Settings::default(),
api_access_methods: api_access::Settings::default(),
}
}
}
Expand Down

0 comments on commit 9f52fdc

Please sign in to comment.