From 582fed02b659d7096890ae4ccddcd93f9ad6f36e Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Fri, 14 Jun 2024 13:13:19 -0500 Subject: [PATCH] refactor(gui-client): remove unused debug commands (#5363) It turns out they were all unused, but I like having a place to keep them for new features. --------- Signed-off-by: Reactor Scram --- rust/Cargo.lock | 1 - rust/gui-client/src-tauri/Cargo.toml | 2 - .../src-tauri/src/client/debug_commands.rs | 39 +-------- .../src-tauri/src/client/network_changes.rs | 2 +- .../src/client/network_changes/linux.rs | 10 --- .../src/client/network_changes/macos.rs | 8 -- .../src/client/network_changes/windows.rs | 87 +------------------ 7 files changed, 3 insertions(+), 146 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index c60e18d29..1b3166f74 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1941,7 +1941,6 @@ dependencies = [ "futures", "git-version", "hex", - "hostname 0.4.0", "keyring", "minidumper", "native-dialog", diff --git a/rust/gui-client/src-tauri/Cargo.toml b/rust/gui-client/src-tauri/Cargo.toml index e0cbcca58..acb7dca52 100644 --- a/rust/gui-client/src-tauri/Cargo.toml +++ b/rust/gui-client/src-tauri/Cargo.toml @@ -24,8 +24,6 @@ firezone-headless-client = { path = "../../headless-client" } futures = { version = "0.3", default-features = false } git-version = "0.3.9" hex = "0.4.3" -# Same crate Hickory uses -hostname = "0.4.0" keyring = "2.3.3" minidumper = "0.8.2" native-dialog = "0.7.0" diff --git a/rust/gui-client/src-tauri/src/client/debug_commands.rs b/rust/gui-client/src-tauri/src/client/debug_commands.rs index 6829f9709..62f99e387 100644 --- a/rust/gui-client/src-tauri/src/client/debug_commands.rs +++ b/rust/gui-client/src-tauri/src/client/debug_commands.rs @@ -1,16 +1,10 @@ //! CLI subcommands used to test features / dependencies before integrating //! them with the GUI, or to exercise features programmatically. -use crate::client; use anyhow::Result; #[derive(clap::Subcommand)] pub(crate) enum Cmd { - CheckForUpdates, - Crash, - DnsChanges, - Hostname, - NetworkChanges, SetAutostart(SetAutostartArgs), } @@ -22,46 +16,15 @@ pub(crate) struct SetAutostartArgs { pub fn run(cmd: Cmd) -> Result<()> { match cmd { - Cmd::CheckForUpdates => check_for_updates()?, - Cmd::Crash => crash()?, - Cmd::DnsChanges => client::network_changes::run_dns_debug()?, - Cmd::Hostname => hostname(), - Cmd::NetworkChanges => client::network_changes::run_debug()?, Cmd::SetAutostart(SetAutostartArgs { enabled }) => set_autostart(enabled)?, } Ok(()) } -fn check_for_updates() -> Result<()> { - firezone_headless_client::debug_command_setup()?; - - let rt = tokio::runtime::Runtime::new().unwrap(); - let version = rt.block_on(client::updates::check())?; - tracing::info!("{:?}", version); - - Ok(()) -} - -fn crash() -> Result<()> { - // `_` doesn't seem to work here, the log files end up empty - let _handles = client::logging::setup("debug")?; - tracing::info!("started log (DebugCrash)"); - - panic!("purposely panicking to see if it shows up in logs"); -} - -#[allow(clippy::print_stdout)] -fn hostname() { - println!( - "{:?}", - hostname::get().ok().and_then(|x| x.into_string().ok()) - ); -} - fn set_autostart(enabled: bool) -> Result<()> { firezone_headless_client::debug_command_setup()?; let rt = tokio::runtime::Runtime::new().unwrap(); - rt.block_on(client::gui::set_autostart(enabled))?; + rt.block_on(crate::client::gui::set_autostart(enabled))?; Ok(()) } diff --git a/rust/gui-client/src-tauri/src/client/network_changes.rs b/rust/gui-client/src-tauri/src/client/network_changes.rs index b6f6ed3d9..39e754729 100644 --- a/rust/gui-client/src-tauri/src/client/network_changes.rs +++ b/rust/gui-client/src-tauri/src/client/network_changes.rs @@ -13,4 +13,4 @@ mod imp; #[allow(clippy::unnecessary_wraps)] mod imp; -pub(crate) use imp::{check_internet, run_debug, run_dns_debug, DnsListener, Worker}; +pub(crate) use imp::{check_internet, DnsListener, Worker}; diff --git a/rust/gui-client/src-tauri/src/client/network_changes/linux.rs b/rust/gui-client/src-tauri/src/client/network_changes/linux.rs index fdf64c380..35fc6043c 100644 --- a/rust/gui-client/src-tauri/src/client/network_changes/linux.rs +++ b/rust/gui-client/src-tauri/src/client/network_changes/linux.rs @@ -5,16 +5,6 @@ use firezone_headless_client::dns_control::system_resolvers_for_gui; use std::net::IpAddr; use tokio::time::Interval; -pub(crate) fn run_dns_debug() -> Result<()> { - tracing::warn!("network_changes not implemented yet on Linux"); - Ok(()) -} - -pub(crate) fn run_debug() -> Result<()> { - tracing::warn!("network_changes not implemented yet on Linux"); - Ok(()) -} - /// TODO: Implement for Linux pub(crate) fn check_internet() -> Result { Ok(true) diff --git a/rust/gui-client/src-tauri/src/client/network_changes/macos.rs b/rust/gui-client/src-tauri/src/client/network_changes/macos.rs index 7f5d66f44..18a7bccd6 100644 --- a/rust/gui-client/src-tauri/src/client/network_changes/macos.rs +++ b/rust/gui-client/src-tauri/src/client/network_changes/macos.rs @@ -5,14 +5,6 @@ use anyhow::Result; #[derive(thiserror::Error, Debug)] pub(crate) enum Error {} -pub(crate) fn run_debug() -> Result<()> { - unimplemented!() -} - -pub(crate) fn run_dns_debug() -> Result<()> { - unimplemented!() -} - pub(crate) fn check_internet() -> Result { tracing::error!("This is not the real macOS client, so `network_changes` is not implemented"); Ok(true) diff --git a/rust/gui-client/src-tauri/src/client/network_changes/windows.rs b/rust/gui-client/src-tauri/src/client/network_changes/windows.rs index 547a427a7..f39e1a15f 100644 --- a/rust/gui-client/src-tauri/src/client/network_changes/windows.rs +++ b/rust/gui-client/src-tauri/src/client/network_changes/windows.rs @@ -65,7 +65,7 @@ //! Raymond Chen also explains it on his blog: use anyhow::Result; -use tokio::{runtime::Runtime, sync::mpsc}; +use tokio::sync::mpsc; use windows::{ core::{Interface, Result as WinResult, GUID}, Win32::{ @@ -93,58 +93,6 @@ pub(crate) enum Error { Unadvise(windows::core::Error), } -/// Debug subcommand to test network connectivity events -pub(crate) fn run_debug() -> Result<()> { - tracing_subscriber::fmt::init(); - - // Returns Err before COM is initialized - assert!(get_apartment_type().is_err()); - - let mut com_worker = Worker::new()?; - - // We have to initialize COM again for the main thread. This doesn't - // seem to be a problem in the main app since Tauri initializes COM for itself. - let _guard = ComGuard::new(); - - assert_eq!( - get_apartment_type(), - Ok((Com::APTTYPE_MTA, Com::APTTYPEQUALIFIER_NONE)) - ); - - let rt = Runtime::new()?; - - tracing::info!("Listening for network events..."); - - rt.block_on(async move { - loop { - tokio::select! { - _r = tokio::signal::ctrl_c() => break, - () = com_worker.notified() => {}, - }; - // Make sure whatever Tokio thread we're on is associated with COM - // somehow. - assert_eq!( - get_apartment_type()?, - (Com::APTTYPE_MTA, Com::APTTYPEQUALIFIER_NONE) - ); - - tracing::info!(have_internet = %check_internet()?); - } - Ok::<_, anyhow::Error>(()) - })?; - - Ok(()) -} - -/// Runs a debug subcommand that listens to the registry for DNS changes -/// -/// This actually listens to the entire IPv4 key, so it will have lots of false positives, -/// including when connlib changes anything on the Firezone tunnel. -/// It will often fire multiple events in quick succession. -pub(crate) fn run_dns_debug() -> Result<()> { - async_dns::run_debug() -} - /// Returns true if Windows thinks we have Internet access per [IsConnectedToInternet](https://learn.microsoft.com/en-us/windows/win32/api/netlistmgr/nf-netlistmgr-inetworklistmanager-get_isconnectedtointernet) /// /// Call this when `Listener` notifies you. @@ -393,17 +341,6 @@ impl Drop for Callback { } } -/// Checks what COM apartment the current thread is in. For debugging only. -fn get_apartment_type() -> WinResult<(Com::APTTYPE, Com::APTTYPEQUALIFIER)> { - let mut apt_type = Com::APTTYPE_CURRENT; - let mut apt_qualifier = Com::APTTYPEQUALIFIER_NONE; - - // SAFETY: We just created the variables, and they're out parameters, - // so Windows shouldn't store the pointers. - unsafe { Com::CoGetApartmentType(&mut apt_type, &mut apt_qualifier) }?; - Ok((apt_type, apt_qualifier)) -} - mod async_dns { use anyhow::{Context, Result}; use std::{ffi::c_void, net::IpAddr, ops::Deref, path::Path}; @@ -442,28 +379,6 @@ mod async_dns { )) } - pub(crate) fn run_debug() -> Result<()> { - tracing_subscriber::fmt::init(); - let rt = tokio::runtime::Runtime::new()?; - - let mut listener = CombinedListener::new()?; - - rt.block_on(async move { - loop { - let resolvers = tokio::select! { - _r = tokio::signal::ctrl_c() => break, - r = listener.notified() => r?, - }; - - tracing::info!(?resolvers); - } - - Ok::<_, anyhow::Error>(()) - })?; - - Ok(()) - } - pub(crate) struct CombinedListener { listener_4: Listener, listener_6: Listener,