Skip to content

Commit

Permalink
Rename mullvad_types::api_access.rs -> `mullvad_types::access_metho…
Browse files Browse the repository at this point in the history
…d.rs`
  • Loading branch information
MarkusPettersson98 committed Sep 26, 2023
1 parent 93be86e commit 3a7a84f
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 48 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::api_access::Socks5::Local(config) => {
mullvad_types::access_method::Socks5::Local(config) => {
InnerConnectionMode::Socks5(SocksConfig {
peer: SocketAddr::new("127.0.0.1".parse().unwrap(), config.port),
})
}
mullvad_types::api_access::Socks5::Remote(config) => {
mullvad_types::access_method::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::api_access;
use mullvad_types::access_method;
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(api_access::Shadowsocks),
Socks(api_access::Socks5),
Shadowsocks(access_method::Shadowsocks),
Socks(access_method::Socks5),
}

impl ProxyConfig {
Expand All @@ -46,8 +46,8 @@ impl ProxyConfig {
match self {
ProxyConfig::Shadowsocks(ss) => ss.peer,
ProxyConfig::Socks(socks) => match socks {
api_access::Socks5::Local(s) => s.peer,
api_access::Socks5::Remote(s) => s.peer,
access_method::Socks5::Local(s) => s.peer,
access_method::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 {
api_access::Socks5::Local(s) => {
access_method::Socks5::Local(s) => {
write!(f, "Socks5 {}/TCP via localhost:{}", s.peer, s.port)
}
api_access::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer),
access_method::Socks5::Remote(s) => write!(f, "Socks5 {}/TCP", s.peer),
},
}
}
Expand Down
16 changes: 8 additions & 8 deletions mullvad-cli/src/cmds/api_access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::api_access::{AccessMethod, AccessMethodSetting, CustomAccessMethod};
use mullvad_types::access_method::{AccessMethod, AccessMethodSetting, CustomAccessMethod};
use std::net::IpAddr;

use clap::{Args, Subcommand};
Expand Down Expand Up @@ -102,21 +102,21 @@ impl ApiAccess {
let port = cmd.params.port.unwrap_or(shadowsocks.peer.port());
let password = cmd.params.password.unwrap_or(shadowsocks.password);
let cipher = cmd.params.cipher.unwrap_or(shadowsocks.cipher);
mullvad_types::api_access::Shadowsocks::from_args(ip, port, cipher, password)
mullvad_types::access_method::Shadowsocks::from_args(ip, port, cipher, password)
.map(AccessMethod::from)
}
CustomAccessMethod::Socks5(socks) => match socks {
mullvad_types::api_access::Socks5::Local(local) => {
mullvad_types::access_method::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);
mullvad_types::api_access::Socks5Local::from_args(ip, port, local_port)
mullvad_types::access_method::Socks5Local::from_args(ip, port, local_port)
.map(AccessMethod::from)
}
mullvad_types::api_access::Socks5::Remote(remote) => {
mullvad_types::access_method::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());
mullvad_types::api_access::Socks5Remote::from_args(ip, port)
mullvad_types::access_method::Socks5Remote::from_args(ip, port)
.map(AccessMethod::from)
}
},
Expand Down Expand Up @@ -315,7 +315,7 @@ pub struct EditParams {
/// we define them in a hidden-away module.
mod conversions {
use anyhow::{anyhow, Error};
use mullvad_types::api_access as daemon_types;
use mullvad_types::access_method as daemon_types;

use super::{AddCustomCommands, AddSocks5Commands};

Expand Down Expand Up @@ -384,7 +384,7 @@ mod conversions {

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

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 @@ -2,7 +2,7 @@ use crate::{
settings::{self, MadeChanges},
Daemon, EventListener,
};
use mullvad_types::api_access::{AccessMethod, AccessMethodSetting, ApiAccessMethodId};
use mullvad_types::access_method::{AccessMethod, AccessMethodSetting, ApiAccessMethodId};

#[derive(err_derive::Error, Debug)]
pub enum Error {
Expand Down
17 changes: 9 additions & 8 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::api_access::{self, AccessMethod, BuiltInAccessMethod};
use mullvad_types::access_method::{self, AccessMethod, BuiltInAccessMethod};
use std::{
net::SocketAddr,
path::PathBuf,
Expand Down Expand Up @@ -131,11 +131,12 @@ impl ApiConnectionModeProvider {
.get_bridge_forced()
.and_then(|settings| match settings {
ProxySettings::Shadowsocks(ss_settings) => {
let ss_settings: api_access::Shadowsocks = api_access::Shadowsocks::new(
ss_settings.peer,
ss_settings.cipher,
ss_settings.password,
);
let ss_settings: access_method::Shadowsocks =
access_method::Shadowsocks::new(
ss_settings.peer,
ss_settings.cipher,
ss_settings.password,
);
Some(ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks(
ss_settings,
)))
Expand All @@ -148,10 +149,10 @@ impl ApiConnectionModeProvider {
.unwrap_or(ApiConnectionMode::Direct),
},
AccessMethod::Custom(access_method) => match &access_method {
api_access::CustomAccessMethod::Shadowsocks(shadowsocks_config) => {
access_method::CustomAccessMethod::Shadowsocks(shadowsocks_config) => {
ApiConnectionMode::Proxied(ProxyConfig::Shadowsocks(shadowsocks_config.clone()))
}
api_access::CustomAccessMethod::Socks5(socks_config) => {
access_method::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 @@ -39,8 +39,8 @@ use mullvad_relay_selector::{
RelaySelector, SelectorConfig,
};
use mullvad_types::{
access_method::{AccessMethod, AccessMethodSetting, ApiAccessMethodId},
account::{AccountData, AccountToken, VoucherSubmission},
api_access::{AccessMethod, AccessMethodSetting, ApiAccessMethodId},
auth_failed::AuthFailed,
custom_list::{CustomList, CustomListLocationUpdate},
device::{Device, DeviceEvent, DeviceEventCause, DeviceId, DeviceState, RemoveDeviceEvent},
Expand Down
8 changes: 4 additions & 4 deletions mullvad-daemon/src/management_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl ManagementService for ManagementServiceImpl {
request
.access_method
.ok_or(Status::invalid_argument("Could not find access method"))
.map(mullvad_types::api_access::AccessMethod::try_from)??,
.map(mullvad_types::access_method::AccessMethod::try_from)??,
))?;
self.wait_for_result(rx)
.await?
Expand All @@ -646,7 +646,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::api_access::ApiAccessMethodId::try_from(request.into_inner())?;
mullvad_types::access_method::ApiAccessMethodId::try_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 All @@ -661,7 +661,7 @@ impl ManagementService for ManagementServiceImpl {
) -> ServiceResult<()> {
log::debug!("update_api_access_method");
let access_method_update =
mullvad_types::api_access::AccessMethodSetting::try_from(request.into_inner())?;
mullvad_types::access_method::AccessMethodSetting::try_from(request.into_inner())?;
let (tx, rx) = oneshot::channel();
self.send_command_to_daemon(DaemonCommand::UpdateApiAccessMethod(
tx,
Expand All @@ -676,7 +676,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::api_access::ApiAccessMethodId::try_from(request.into_inner())?;
mullvad_types::access_method::ApiAccessMethodId::try_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;
use futures::{Stream, StreamExt};
use mullvad_types::{
access_method::{AccessMethod, AccessMethodSetting, ApiAccessMethodId},
account::{AccountData, AccountToken, VoucherSubmission},
api_access::{AccessMethod, AccessMethodSetting, ApiAccessMethodId},
custom_list::{CustomList, CustomListLocationUpdate},
device::{Device, DeviceEvent, DeviceId, DeviceState, RemoveDeviceEvent},
location::GeoIpLocation,
Expand Down
22 changes: 11 additions & 11 deletions mullvad-management-interface/src/types/conversions/access_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/// [`mullvad_types::access_method::Settings`] data type.
mod settings {
use crate::types::{proto, FromProtobufTypeError};
use mullvad_types::api_access;
use mullvad_types::access_method;

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

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

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

fn try_from(settings: proto::ApiAccessMethodSettings) -> Result<Self, Self::Error> {
Ok(Self {
access_method_settings: settings
.access_method_settings
.iter()
.map(api_access::AccessMethodSetting::try_from)
.collect::<Result<Vec<api_access::AccessMethodSetting>, _>>()?,
.map(access_method::AccessMethodSetting::try_from)
.collect::<Result<Vec<access_method::AccessMethodSetting>, _>>()?,
})
}
}
Expand All @@ -43,7 +43,7 @@ mod settings {
/// [`mullvad_types::access_method::AccessMethodSetting`] data type.
mod data {
use crate::types::{proto, FromProtobufTypeError};
use mullvad_types::api_access::{
use mullvad_types::access_method::{
AccessMethod, AccessMethodSetting, ApiAccessMethodId, BuiltInAccessMethod,
CustomAccessMethod, Shadowsocks, Socks5, Socks5Local, Socks5Remote,
};
Expand Down Expand Up @@ -179,10 +179,10 @@ mod data {
impl From<BuiltInAccessMethod> for proto::AccessMethod {
fn from(value: BuiltInAccessMethod) -> Self {
let access_method = match value {
mullvad_types::api_access::BuiltInAccessMethod::Direct => {
mullvad_types::access_method::BuiltInAccessMethod::Direct => {
proto::access_method::AccessMethod::Direct(proto::access_method::Direct {})
}
mullvad_types::api_access::BuiltInAccessMethod::Bridge => {
mullvad_types::access_method::BuiltInAccessMethod::Bridge => {
proto::access_method::AccessMethod::Bridges(proto::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::api_access::Settings::try_from(
api_access_methods: mullvad_types::access_method::Settings::try_from(
api_access_methods_settings,
)?,
})
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::{
api_access,
access_method,
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: api_access::Settings,
pub api_access_methods: access_method::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: api_access::Settings::default(),
api_access_methods: access_method::Settings::default(),
}
}
}
Expand Down

0 comments on commit 3a7a84f

Please sign in to comment.