Skip to content

Commit

Permalink
close all warnings from clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
doroved committed Oct 25, 2024
1 parent ba8175d commit 97b8db2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "proxer"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["doroved"]
description = "Proxy all macOS network requests with domain-based filtering. Basic spoof DPI for direct connections."
Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ pub async fn handle_request(
let found_proxy = find_matching_proxy(config.as_ref(), host);

if req.method() == Method::CONNECT {
if let Some(_) = req.uri().authority().map(|auth| auth.to_string()) {
if req.uri().authority().map(|auth| auth.to_string()).is_some() {
tokio::spawn(async move {
match tunnel(req, found_proxy.clone()).await {
Ok(_) => {}
Err(e) => {
let error_msg = e.to_string();

if options.log_error_all {
eprintln!("\x1B[31m\x1B[1m[{time}] {addr} → {error_msg}\x1B[0m");
} else if error_msg.contains("os error 60")
// Combined error logging condition
if options.log_error_all
|| error_msg.contains("os error 60")
|| error_msg.contains("Proxy connection failed")
|| error_msg.contains("deadline has elapsed")
{
Expand Down Expand Up @@ -256,7 +256,7 @@ async fn tunnel(
_ => return Err(format!("Unsupported proxy scheme: {}", proxy.scheme).into()),
}

return Ok(());
Ok(())
} else {
println!("\x1b[1m[{time}] {addr} → Direct connection\x1b[0m");

Expand Down Expand Up @@ -311,7 +311,7 @@ async fn tunnel(
// Wait for both tasks to complete
tokio::try_join!(client_to_server, server_to_client)?;

return Ok(());
Ok(())
}
}

Expand All @@ -331,7 +331,7 @@ fn package_info() -> Package {
let content = include_str!("../Cargo.toml");

// Parse the content of the file
let cargo: CargoToml = from_str(&content).expect("Error parsing Cargo.toml");
let cargo: CargoToml = from_str(content).expect("Error parsing Cargo.toml");

// Return the package information
cargo.package
Expand All @@ -340,7 +340,7 @@ fn package_info() -> Package {
// Kill all proxer processes
pub fn terminate_proxer() {
let _ = Command::new("sh")
.args(&["-c", "kill $(pgrep proxer)"])
.args(["-c", "kill $(pgrep proxer)"])
.output()
.expect("Failed to execute `kill $(pgrep proxer)` command to terminate proxer processes");
}
Expand Down Expand Up @@ -403,7 +403,7 @@ async fn handle_http_proxy(
addr: &str,
proxy: &ProxyConfig,
) -> Result<(), Box<dyn std::error::Error>> {
send_connect_request(req, &mut tcp_stream, addr, &proxy).await?;
send_connect_request(req, &mut tcp_stream, addr, proxy).await?;
Ok(())
}

Expand All @@ -420,7 +420,7 @@ async fn handle_https_proxy(
)
.await??;

send_connect_request(req, &mut tls_stream, addr, &proxy).await?;
send_connect_request(req, &mut tls_stream, addr, proxy).await?;
Ok(())
}

Expand Down Expand Up @@ -517,7 +517,7 @@ impl Proxy {
&self.server,
&self.port.to_string(),
])
.expect(&format!("Failed to set {proxy_type}"));
.unwrap_or_else(|_| panic!("Failed to set {proxy_type}"));
}
}

Expand All @@ -533,7 +533,7 @@ impl Proxy {

let _ = self
.execute_command(&[&command, &self.interface, proxy_state])
.expect(&format!("Failed to set {proxy_type} state"));
.unwrap_or_else(|_| panic!("Failed to set {proxy_type} state"));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};

let config = fs::read_to_string(&config_file)
.expect(format!("Failed to read config file: {config_file}").as_str());
.unwrap_or_else(|_| panic!("Failed to read config file: {config_file}"));
let parsed_config: Vec<ProxyConfig> = json5::from_str(&config)
.expect(format!("Failed to parse config file: {config_file}").as_str());
.unwrap_or_else(|_| panic!("Failed to parse config file: {config_file}"));
let shared_config = Arc::new(parsed_config);

// Run ping proxy in loop
Expand Down Expand Up @@ -76,12 +76,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let system_proxy_arc = Arc::new(system_proxy);

// Set up signal handling
let mut signals = Signals::new(&[SIGINT, SIGTERM, SIGQUIT])?;
let mut signals = Signals::new([SIGINT, SIGTERM, SIGQUIT])?;
let handle = signals.handle();

// Start signal handler in a separate task
let signals_task = tokio::spawn(async move {
while let Some(signal) = signals.next().await {
if let Some(signal) = signals.next().await {
match signal {
SIGINT | SIGTERM | SIGQUIT => {
system_proxy_arc.set_state(ProxyState::Off);
Expand Down

0 comments on commit 97b8db2

Please sign in to comment.