Skip to content

Commit

Permalink
Merge branch 'lints_and_formatting' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Jan 5, 2024
2 parents 616d064 + 5131624 commit b291200
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 45 deletions.
6 changes: 4 additions & 2 deletions ios/TunnelObfuscation/tunnel-obfuscator-proxy/src/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![cfg(target_os = "ios")]

use super::{TunnelObfuscatorHandle, TunnelObfuscatorRuntime};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::sync::Once;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
sync::Once,
};

static INIT_LOGGING: Once = Once::new();

Expand Down
3 changes: 1 addition & 2 deletions ios/TunnelObfuscation/tunnel-obfuscator-proxy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![cfg(target_os = "ios")]

use std::io;
use std::net::SocketAddr;
use std::{io, net::SocketAddr};
use tokio::sync::oneshot;
use tunnel_obfuscation::{create_obfuscator, Settings as ObfuscationSettings, Udp2TcpSettings};

Expand Down
2 changes: 1 addition & 1 deletion mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use mullvad_types::{
version::AppVersion,
};
use proxy::ApiConnectionMode;
use std::sync::OnceLock;
use std::{
cell::Cell,
collections::BTreeMap,
future::Future,
net::{IpAddr, Ipv4Addr, SocketAddr},
ops::Deref,
path::Path,
sync::OnceLock,
};
use talpid_types::{net::AllowedEndpoint, ErrorExt};

Expand Down
3 changes: 1 addition & 2 deletions mullvad-api/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use std::{
pin::Pin,
task::{self, Poll},
};
use talpid_types::net::proxy;
use talpid_types::{
net::{AllowedClients, Endpoint, TransportProtocol},
net::{proxy, AllowedClients, Endpoint, TransportProtocol},
ErrorExt,
};
use tokio::{
Expand Down
6 changes: 4 additions & 2 deletions mullvad-cli/src/cmds/api_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ pub enum ApiAccess {
Enable(SelectItem),
/// Disable an API access method
Disable(SelectItem),
/// Try to use a specific API access method (If the API is unreachable, reverts back to the previous access method)
/// Try to use a specific API access method (If the API is unreachable, reverts back to the
/// previous access method)
///
/// Selecting "Direct" will connect to the Mullvad API without going through any proxy. This connection use https and is therefore encrypted.
/// Selecting "Direct" will connect to the Mullvad API without going through any proxy. This
/// connection use https and is therefore encrypted.
///
/// Selecting "Mullvad Bridges" respects your current bridge settings
Use(SelectItem),
Expand Down
4 changes: 2 additions & 2 deletions mullvad-cli/src/cmds/import_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::{
/// Maximum size of a settings patch. Bigger files/streams cause the read to fail.
const MAX_PATCH_BYTES: usize = 10 * 1024;

/// If source is specified, read from the provided file and send it as a settings patch to the daemon.
/// Otherwise, read the patch from standard input.
/// If source is specified, read from the provided file and send it as a settings patch to the
/// daemon. Otherwise, read the patch from standard input.
pub async fn handle(source: String) -> Result<()> {
let json_blob = tokio::task::spawn_blocking(|| get_blob(source))
.await
Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl std::fmt::Display for Message {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Message::Get(_) => f.write_str("Get"),
Message::Set(_, _) => f.write_str("Set"),
Message::Set(..) => f.write_str("Set"),
Message::Next(_) => f.write_str("Next"),
Message::Update(_, _) => f.write_str("Update"),
Message::Update(..) => f.write_str("Update"),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions mullvad-daemon/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,7 @@ impl TunnelStateChangeHandler {

#[cfg(test)]
mod test {
use super::TunnelStateChangeHandler;
use super::{Error, WG_DEVICE_CHECK_THRESHOLD};
use super::{Error, TunnelStateChangeHandler, WG_DEVICE_CHECK_THRESHOLD};
use mullvad_relay_selector::RelaySelector;
use std::sync::{
atomic::{AtomicBool, Ordering},
Expand Down
7 changes: 5 additions & 2 deletions mullvad-daemon/src/exception_logging/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
use libc::siginfo_t;
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};

use std::ffi::{c_int, c_void};
use std::{convert::TryFrom, sync::Once};
use std::{
convert::TryFrom,
ffi::{c_int, c_void},
sync::Once,
};

static INIT_ONCE: Once = Once::new();

Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
//! # Creating a migration
//!
//! 1. Copy `vX.rs.template` to `vX.rs` where `X` is the latest settings version right now.
//! 1. Add the new version (`Y = X+1`) to `SettingsVersion` and bump `CURRENT_SETTINGS_VERSION`
//! to `Y`.
//! 1. Add the new version (`Y = X+1`) to `SettingsVersion` and bump `CURRENT_SETTINGS_VERSION` to
//! `Y`.
//! 1. Write a comment in the new module about how the format changed, what it needs to migrate.
//! 1. Implement the migration and add adequate tests.
//! 1. Add to the changelog: "Settings format updated to `vY`"
Expand Down
2 changes: 0 additions & 2 deletions mullvad-daemon/src/migrations/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub struct ShadowsocksProxySettings {
/// - shadowsocks.peer to shadowsocks.endpoint
/// - socks5_remote.authentication to socks5_remote.auth
/// - socks5_remote.peer to socks5_remote.endpoint
///
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
return Ok(());
Expand Down Expand Up @@ -254,7 +253,6 @@ mod test {
use crate::migrations::v7::{migrate_api_access_settings, migrate_bridge_settings};

use super::{migrate, version_matches};
use serde_json;

pub const V7_SETTINGS: &str = r#"
{
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ mod test {
);

assert!(
settings.block_when_disconnected == false,
!settings.block_when_disconnected,
"The daemon should not block the internet if settings are missing"
);
}
Expand Down
3 changes: 2 additions & 1 deletion mullvad-daemon/src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ impl InnerParametersGenerator {
private_key: data.device.wg_data.private_key,
addresses: vec![IpAddr::from(tunnel_ipv4), IpAddr::from(tunnel_ipv6)],
};
// FIXME: Used for debugging purposes during the migration to same IP. Remove when the migration is over.
// FIXME: Used for debugging purposes during the migration to same IP. Remove when
// the migration is over.
if tunnel_ipv4 == *SAME_IP_V4 || tunnel_ipv6 == *SAME_IP_V6 {
log::debug!("Same IP is being used");
} else {
Expand Down
4 changes: 2 additions & 2 deletions mullvad-nsis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum Status {
/// Max path size allowed
const MAX_PATH_SIZE: isize = 32_767;

/// SAFETY: path needs to be a windows path encoded as a string of u16 that terminates in 0 (two nul-bytes).
/// The string is also not allowed to be greater than `MAX_PATH_SIZE`.
/// SAFETY: path needs to be a windows path encoded as a string of u16 that terminates in 0 (two
/// nul-bytes). The string is also not allowed to be greater than `MAX_PATH_SIZE`.
#[no_mangle]
pub unsafe extern "C" fn create_privileged_directory(path: *const u16) -> Status {
catch_and_log_unwind(|| {
Expand Down
14 changes: 9 additions & 5 deletions mullvad-paths/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ fn get_wide_str<S: AsRef<OsStr>>(string: S) -> Vec<u16> {

/// Recursively creates directories, if set_security_permissions is true it will set
/// file permissions corresponding to Authenticated Users - Read Only and Administrators - Full
/// Access. Only directories that do not already exist and the leaf directory will have their permissions set.
/// Access. Only directories that do not already exist and the leaf directory will have their
/// permissions set.
pub fn create_dir_recursive(path: &Path, set_security_permissions: bool) -> Result<()> {
if set_security_permissions {
create_dir_with_permissions_recursive(path)
Expand Down Expand Up @@ -114,7 +115,8 @@ fn create_dir_with_permissions_recursive(path: &Path) -> Result<()> {
// Create parent directory
Some(parent) => create_dir_with_permissions_recursive(parent)?,
None => {
// Reached the top of the tree but when creating directories only got NotFound for some reason
// Reached the top of the tree but when creating directories only got NotFound for some
// reason
return Err(Error::CreateDirFailed(
path.display().to_string(),
io::Error::new(
Expand All @@ -129,13 +131,15 @@ fn create_dir_with_permissions_recursive(path: &Path) -> Result<()> {
set_security_permissions(path)
}

/// Recursively creates directories for the given path with permissions that give full access to admins and read only access to authenticated users.
/// If any of the directories already exist this will not return an error, instead it will apply the permissions and if successful return Ok(()).
/// Recursively creates directories for the given path with permissions that give full access to
/// admins and read only access to authenticated users. If any of the directories already exist this
/// will not return an error, instead it will apply the permissions and if successful return Ok(()).
pub fn create_privileged_directory(path: &Path) -> Result<()> {
create_dir_with_permissions_recursive(path)
}

/// Sets security permissions for path such that admin has full ownership and access while authenticated users only have read access.
/// Sets security permissions for path such that admin has full ownership and access while
/// authenticated users only have read access.
fn set_security_permissions(path: &Path) -> Result<()> {
let wide_path = get_wide_str(path);
let security_information = Security::DACL_SECURITY_INFORMATION
Expand Down
3 changes: 2 additions & 1 deletion mullvad-types/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ pub struct VoucherSubmission {
pub new_expiry: DateTime<Utc>,
}

/// `PlayPurchase` is provided to google in order to verify that a google play purchase was acknowledged.
/// `PlayPurchase` is provided to google in order to verify that a google play purchase was
/// acknowledged.
#[derive(Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(target_os = "android", derive(FromJava))]
#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))]
Expand Down
6 changes: 3 additions & 3 deletions talpid-core/src/dns/windows/iphlpapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl IphlpApi {
return Err(Error::LoadDll(io::Error::last_os_error()));
}

// This function is loaded at runtime since it may be unavailable. See the module-level docs.
// TODO: `windows_sys` can be used directly when support for versions older than Windows 10,
// 2004, is dropped.
// This function is loaded at runtime since it may be unavailable. See the module-level
// docs. TODO: `windows_sys` can be used directly when support for versions older
// than Windows 10, 2004, is dropped.
let set_interface_dns_settings =
unsafe { GetProcAddress(module, s!("SetInterfaceDnsSettings")) };
let set_interface_dns_settings = set_interface_dns_settings.ok_or_else(|| {
Expand Down
4 changes: 2 additions & 2 deletions talpid-core/src/firewall/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ impl Firewall {
builder.build()
}

/// Produces a rule that allows traffic to flow to the API. Allows the app (or other apps if configured)
/// to reach the API in blocked states.
/// Produces a rule that allows traffic to flow to the API. Allows the app (or other apps if
/// configured) to reach the API in blocked states.
fn get_allowed_endpoint_rule(
&self,
allowed_endpoint: &AllowedEndpoint,
Expand Down
7 changes: 4 additions & 3 deletions talpid-core/src/firewall/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl Firewall {
protocol: WinFwProt::from(endpoint.endpoint.protocol),
};

// SAFETY: `endpoint1_ip`, `endpoint2_ip`, `endpoint1`, `endpoint2`, `relay_client_wstrs` must not be dropped
// until `WinFw_ApplyPolicyConnecting` has returned.
// SAFETY: `endpoint1_ip`, `endpoint2_ip`, `endpoint1`, `endpoint2`, `relay_client_wstrs`
// must not be dropped until `WinFw_ApplyPolicyConnecting` has returned.

let relay_client_wstrs: Vec<_> = endpoint
.clients
Expand Down Expand Up @@ -274,7 +274,8 @@ impl Firewall {
None => ptr::null(),
};

// SAFETY: `relay_client_wstrs` must not be dropped until `WinFw_ApplyPolicyConnected` has returned.
// SAFETY: `relay_client_wstrs` must not be dropped until `WinFw_ApplyPolicyConnected` has
// returned.
let relay_client_wstrs: Vec<_> = endpoint
.clients
.iter()
Expand Down
3 changes: 1 addition & 2 deletions talpid-openvpn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,7 @@ mod event_server {
task::{Context, Poll},
};
use talpid_tunnel::TunnelMetadata;
use talpid_types::net::proxy::CustomProxy;
use talpid_types::ErrorExt;
use talpid_types::{net::proxy::CustomProxy, ErrorExt};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tonic::{
self,
Expand Down
4 changes: 2 additions & 2 deletions talpid-openvpn/src/process/openvpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ impl OpenVpnProcHandle {
})
}

/// Begins to kill the process, causing `wait()` to return. This function does not wait for the operation
/// to complete.
/// Begins to kill the process, causing `wait()` to return. This function does not wait for the
/// operation to complete.
pub fn kill(&mut self, timeout: std::time::Duration) {
if let Some(tx) = self.stop_tx.take() {
let _ = tx.send(timeout);
Expand Down
2 changes: 1 addition & 1 deletion talpid-routing/src/unix/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use futures::{
stream::{FusedStream, StreamExt},
};
use ipnetwork::IpNetwork;
use std::sync::Weak;
use std::{
collections::{BTreeMap, HashSet},
pin::Pin,
sync::Weak,
time::Duration,
};
use talpid_types::ErrorExt;
Expand Down
2 changes: 1 addition & 1 deletion talpid-windows/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
use talpid_types::win32_err;
use windows_sys::{
core::GUID,
Win32::Networking::WinSock::SOCKADDR_STORAGE as sockaddr_storage,
Win32::{
Foundation::{ERROR_NOT_FOUND, HANDLE},
NetworkManagement::{
Expand All @@ -30,6 +29,7 @@ use windows_sys::{
IpDadStateDeprecated, IpDadStateDuplicate, IpDadStateInvalid, IpDadStatePreferred,
IpDadStateTentative, AF_INET, AF_INET6, AF_UNSPEC, IN6_ADDR, IN_ADDR, NL_DAD_STATE,
SOCKADDR_IN as sockaddr_in, SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_INET,
SOCKADDR_STORAGE as sockaddr_storage,
},
},
};
Expand Down

0 comments on commit b291200

Please sign in to comment.