diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2019-06-12 15:52:48 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2019-06-12 15:52:48 +0200 |
| commit | aad18e3f08e798a660d445d78184d441d7eae2f8 (patch) | |
| tree | c38a9bfd9cb23378a4a06296a192f4ba9a798e44 | |
| parent | d4a6e0b411b72f9e14eb6caee6c91dd31b612acf (diff) | |
| parent | 7f06e0a42b8479a018c0bd14371d1395d2625def (diff) | |
| download | mullvadvpn-aad18e3f08e798a660d445d78184d441d7eae2f8.tar.xz mullvadvpn-aad18e3f08e798a660d445d78184d441d7eae2f8.zip | |
Merge branch 'clippy-cleanup'
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 2 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 4 | ||||
| -rw-r--r-- | mullvad-daemon/src/account_history.rs | 4 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 5 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 14 | ||||
| -rw-r--r-- | mullvad-types/src/endpoint.rs | 6 | ||||
| -rw-r--r-- | mullvad-types/src/relay_list.rs | 6 | ||||
| -rw-r--r-- | talpid-core/src/firewall/linux.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/proxy/shadowsocks.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/routing/linux/mod.rs | 8 | ||||
| -rw-r--r-- | talpid-core/src/routing/mod.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 5 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/wireguard_go.rs | 4 |
13 files changed, 30 insertions, 38 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index 965107057d..c9bf61be43 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -222,7 +222,7 @@ impl Relay { let mut private_key_str = String::new(); println!("Reading private key from standard input"); let _ = io::stdin().lock().read_line(&mut private_key_str); - if private_key_str.trim().len() == 0 { + if private_key_str.trim().is_empty() { eprintln!("Expected to read private key from standard input"); } let private_key = Self::validate_wireguard_key(&private_key_str).into(); diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index 136290d5bb..7eacdddb78 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -134,7 +134,7 @@ impl Tunnel { .wireguard .mtu .map(|mtu| mtu.to_string()) - .unwrap_or("unset".into()) + .unwrap_or_else(|| "unset".to_owned()) ); Ok(()) } @@ -193,7 +193,7 @@ impl Tunnel { tunnel_options .openvpn .mssfix - .map_or_else(|| "unset".to_string(), |v| v.to_string()) + .map_or_else(|| "unset".to_owned(), |v| v.to_string()) ); Ok(()) } diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs index 2857de510f..c8bb92c7a9 100644 --- a/mullvad-daemon/src/account_history.rs +++ b/mullvad-daemon/src/account_history.rs @@ -83,7 +83,7 @@ impl AccountHistory { reader.seek(io::SeekFrom::Start(0)).map_err(Error::Read)?; Ok(serde_json::from_reader(reader) .map(|old_format: OldFormat| old_format.accounts) - .unwrap_or(vec![])) + .unwrap_or_else(|_| Vec::new())) } /// Gets account data for a certain account id and bumps it's entry to the top of the list if @@ -111,7 +111,7 @@ impl AccountHistory { /// Bumps history of an account token. If the account token is not in history, it will be /// added. pub fn bump_history(&mut self, account: &AccountToken) -> Result<()> { - if let None = self.get(account)? { + if self.get(account)?.is_none() { let new_entry = AccountEntry { account: account.to_string(), wireguard: None, diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 42c87d0024..6b3c061398 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -799,7 +799,7 @@ where tx: oneshot::Sender<()>, account_token: AccountToken, ) { - if let Ok(_) = self.account_history.remove_account(&account_token) { + if self.account_history.remove_account(&account_token).is_ok() { Self::oneshot_send(tx, (), "remove_account_from_history response"); } } @@ -1021,7 +1021,7 @@ where let account_token = self .settings .get_account_token() - .ok_or("No account token set".to_string())?; + .ok_or_else(|| "No account token set".to_owned())?; let mut account_entry = self .account_history @@ -1116,7 +1116,6 @@ where .check_wg_key(account, public_key.clone()) .map(|is_valid| { Self::oneshot_send(tx, is_valid, "verify_wireguard_key response"); - () }) .map_err(|e| log::error!("Failed to verify wireguard key - {}", e)); if let Err(e) = self.tokio_remote.execute(fut) { diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index e9c02c6214..fceaf45ffb 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -286,7 +286,7 @@ impl RelaySelector { } // For now, only TCP tunnels are supported. - if let &Constraint::Only(TransportProtocol::Udp) = &bridge_constraints.transport_protocol { + if let Constraint::Only(TransportProtocol::Udp) = bridge_constraints.transport_protocol { return None; } @@ -315,18 +315,18 @@ impl RelaySelector { .filter_map(|relay| Self::matching_bridge_relay(relay, constraints)) .collect(); - if matching_relays.len() == 0 { + if matching_relays.is_empty() { return None; } matching_relays.sort_by_cached_key(|relay| { (relay.location.as_ref().unwrap().distance_from(&location) * 1000.0) as i64 }); - return matching_relays.get(0).and_then(|relay| { + matching_relays.get(0).and_then(|relay| { (self .pick_random_bridge(&relay) .map(|bridge| (bridge, relay.clone()))) - }); + }) } @@ -364,7 +364,7 @@ impl RelaySelector { Constraint::Any => relay.clone(), Constraint::Only(ref tunnel_constraints) => { let mut relay = relay.clone(); - relay.tunnels = Self::matching_tunnels(&mut relay.tunnels, tunnel_constraints); + relay.tunnels = Self::matching_tunnels(&relay.tunnels, tunnel_constraints); relay } }; @@ -423,7 +423,7 @@ impl RelaySelector { .bridges .shadowsocks .retain(|bridge| constraints.transport_protocol.matches(&bridge.protocol)); - if filtered_relay.bridges.shadowsocks.len() == 0 { + if filtered_relay.bridges.shadowsocks.is_empty() { return None; } @@ -570,7 +570,7 @@ impl RelaySelector { if port_index < ports_in_range { return Some(port_index as u16 + range.0); } - port_index = port_index - ports_in_range; + port_index -= ports_in_range; } panic!("Port selection algorithm is broken") } diff --git a/mullvad-types/src/endpoint.rs b/mullvad-types/src/endpoint.rs index 4a2371472e..06f8f4f774 100644 --- a/mullvad-types/src/endpoint.rs +++ b/mullvad-types/src/endpoint.rs @@ -24,11 +24,7 @@ impl MullvadEndpoint { pub fn to_endpoint(&self) -> Endpoint { match self { MullvadEndpoint::OpenVpn(endpoint) => *endpoint, - MullvadEndpoint::Wireguard { - peer, - ipv4_gateway: _, - ipv6_gateway: _, - } => Endpoint::new( + MullvadEndpoint::Wireguard { peer, .. } => Endpoint::new( peer.endpoint.ip(), peer.endpoint.port(), TransportProtocol::Udp, diff --git a/mullvad-types/src/relay_list.rs b/mullvad-types/src/relay_list.rs index dc0a44acfa..370b8e134f 100644 --- a/mullvad-types/src/relay_list.rs +++ b/mullvad-types/src/relay_list.rs @@ -146,11 +146,11 @@ pub struct ShadowsocksEndpointData { } impl ShadowsocksEndpointData { - pub fn to_proxy_settings(self, addr: IpAddr) -> ProxySettings { + pub fn to_proxy_settings(&self, addr: IpAddr) -> ProxySettings { ProxySettings::Shadowsocks(ShadowsocksProxySettings { peer: SocketAddr::new(addr, self.port), - password: self.password, - cipher: self.cipher, + password: self.password.clone(), + cipher: self.cipher.clone(), }) } } diff --git a/talpid-core/src/firewall/linux.rs b/talpid-core/src/firewall/linux.rs index a49d0ce578..b56d223a99 100644 --- a/talpid-core/src/firewall/linux.rs +++ b/talpid-core/src/firewall/linux.rs @@ -395,8 +395,8 @@ impl<'a> PolicyBatch<'a> { fn add_allow_icmp_pingable_hosts(&mut self, pingable_hosts: &[IpAddr]) { for host in pingable_hosts { let icmp_proto = match &host { - &IpAddr::V4(_) => libc::IPPROTO_ICMP as u8, - &IpAddr::V6(_) => libc::IPPROTO_ICMPV6 as u8, + IpAddr::V4(_) => libc::IPPROTO_ICMP as u8, + IpAddr::V6(_) => libc::IPPROTO_ICMPV6 as u8, }; let mut out_rule = Rule::new(&self.out_chain); diff --git a/talpid-core/src/proxy/shadowsocks.rs b/talpid-core/src/proxy/shadowsocks.rs index 91da5e3b59..890767a001 100644 --- a/talpid-core/src/proxy/shadowsocks.rs +++ b/talpid-core/src/proxy/shadowsocks.rs @@ -212,7 +212,7 @@ impl ShadowsocksProxyMonitor { })?); } - return Err(Error::new(ErrorKind::Other, "No port number present")); + Err(Error::new(ErrorKind::Other, "No port number present")) } } diff --git a/talpid-core/src/routing/linux/mod.rs b/talpid-core/src/routing/linux/mod.rs index c5056f08eb..c39431acda 100644 --- a/talpid-core/src/routing/linux/mod.rs +++ b/talpid-core/src/routing/linux/mod.rs @@ -261,7 +261,7 @@ of route monitor -{}", if self .pending_change .as_ref() - .map(|pending_change| &pending_change.change != &route_change) + .map(|pending_change| pending_change.change != route_change) .unwrap_or(true) && self .needed_changes @@ -330,7 +330,7 @@ of route monitor -{}", } } - Ok(self.pending_change.is_none() && self.needed_changes.len() == 0) + Ok(self.pending_change.is_none() && self.needed_changes.is_empty()) } fn route_cmd(action: &str, route: &Route) -> Command { @@ -432,7 +432,7 @@ enum IpVersion { } impl IpVersion { - fn to_route_arg(&self) -> &'static str { + fn to_route_arg(self) -> &'static str { match self { IpVersion::V4 => "-4", IpVersion::V6 => "-6", @@ -460,7 +460,7 @@ impl Future for RouteManagerImpl { let all_changes_applied = self.apply_route_table_changes()?; if all_changes_applied && self.should_shut_down { if let Some(tx) = self.shutdown_finished_tx.take() { - if let Err(_) = tx.send(()) { + if tx.send(()).is_err() { log::error!("RouteManagerHandle already stopped"); } } diff --git a/talpid-core/src/routing/mod.rs b/talpid-core/src/routing/mod.rs index 2651e9e2f7..f6153fa41c 100644 --- a/talpid-core/src/routing/mod.rs +++ b/talpid-core/src/routing/mod.rs @@ -62,12 +62,12 @@ impl RouteManager { pub fn stop(&mut self) { if let Some(tx) = self.tx.take() { let (wait_tx, wait_rx) = oneshot::channel(); - if let Err(_) = tx.send(wait_tx) { + if tx.send(wait_tx).is_err() { log::error!("RouteManager already down!"); return; } - if let Err(_) = wait_rx.wait() { + if wait_rx.wait().is_err() { log::error!("RouteManager paniced while shutting down"); } } diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index 810aadff49..4af0ca2344 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -175,10 +175,7 @@ impl WireguardMonitor { // route endpoints with specific routes for peer in config.peers.iter() { - routes.insert( - peer.endpoint.ip().into(), - routing::NetNode::DefaultNode.into(), - ); + routes.insert(peer.endpoint.ip().into(), routing::NetNode::DefaultNode); } routes diff --git a/talpid-core/src/tunnel/wireguard/wireguard_go.rs b/talpid-core/src/tunnel/wireguard/wireguard_go.rs index f72371eb11..ee5a6f1226 100644 --- a/talpid-core/src/tunnel/wireguard/wireguard_go.rs +++ b/talpid-core/src/tunnel/wireguard/wireguard_go.rs @@ -61,7 +61,7 @@ impl WgGoTunnel { fn create_tunnel_config(config: &Config, routes: impl Iterator<Item = IpNetwork>) -> TunConfig { let mut dns_servers = vec![IpAddr::V4(config.ipv4_gateway)]; - dns_servers.extend(config.ipv6_gateway.clone().map(IpAddr::V6)); + dns_servers.extend(config.ipv6_gateway.map(IpAddr::V6)); TunConfig { addresses: config.tunnel.addresses.clone(), @@ -92,7 +92,7 @@ impl WgGoTunnel { return Err(Error::StopWireguardError { status }); } } - return Ok(()); + Ok(()) } } |
