mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
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 <ReactorScram@users.noreply.github.com>
This commit is contained in:
1
rust/Cargo.lock
generated
1
rust/Cargo.lock
generated
@@ -1941,7 +1941,6 @@ dependencies = [
|
||||
"futures",
|
||||
"git-version",
|
||||
"hex",
|
||||
"hostname 0.4.0",
|
||||
"keyring",
|
||||
"minidumper",
|
||||
"native-dialog",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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<bool> {
|
||||
Ok(true)
|
||||
|
||||
@@ -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<bool> {
|
||||
tracing::error!("This is not the real macOS client, so `network_changes` is not implemented");
|
||||
Ok(true)
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
//! Raymond Chen also explains it on his blog: <https://devblogs.microsoft.com/oldnewthing/20191125-00/?p=103135>
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user