Skip to content

Commit 5443bf0

Browse files
committed
Update proxer-cli to version 0.3.4 and improve error logging
- Bump version of `proxer-cli` in `Cargo.toml` and `Cargo.lock` from 0.3.3 to 0.3.4. - Enhance error logging in `src/server/proxy.rs` by adding color formatting to error messages for better visibility. - Refactor connection limit handling in `src/server/mod.rs` to simplify the logic and improve clarity.
1 parent 223796c commit 5443bf0

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "proxer-cli"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
edition = "2021"
55
authors = ["doroved"]
66
description = "Proxy TCP traffic on macOS with domain filtering."

src/server/mod.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,15 @@ pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
4848
// Parse command-line options
4949
let options = Opt::parse();
5050

51+
// Set open connection limit
52+
let default_connection_limit = rlimit::Resource::NOFILE.get_soft()?;
53+
let _ = rlimit::setrlimit(rlimit::Resource::NOFILE, 999999, rlimit::INFINITY);
5154
tracing::info!(
52-
"Default open connection limit: {:?}",
53-
rlimit::Resource::NOFILE.get_soft()?
55+
"Setting open connection limit to {}, default limit is {}",
56+
rlimit::Resource::NOFILE.get_soft()?,
57+
default_connection_limit
5458
);
5559

56-
// Set open connection limit
57-
let connection_limit = match rlimit::Resource::NOFILE.get() {
58-
Ok(limit) if limit.0 < 1024 * 10 => {
59-
tracing::info!("Setting open connection limit to {}", limit.1);
60-
limit.1
61-
}
62-
Ok(limit) => limit.0,
63-
Err(err) => {
64-
tracing::error!("Failed to get open connection limit: {}", err);
65-
return Err(Box::new(err));
66-
}
67-
};
68-
69-
let _ = rlimit::setrlimit(rlimit::Resource::NOFILE, connection_limit, rlimit::INFINITY);
70-
7160
// Read the config file or use the default one
7261
let config_path = options.config.unwrap_or_else(|| {
7362
tracing::info!("Using default config file ~/.proxer-cli/config.json5");

src/server/proxy.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ pub async fn handle_request(
2929
if let Err(e) =
3030
tunnel_via_proxy(upgraded, &addr, proxy, &filter_name).await
3131
{
32-
tracing::error!("{addr} → PROXY connection error: {e}");
32+
tracing::error!(
33+
"\x1B[31m{addr} → PROXY connection error: {e}\x1B[0m"
34+
);
3335
};
3436
} else if let Err(e) = tunnel_direct(upgraded, &addr).await {
35-
tracing::error!("{addr} → DIRECT connection error: {e}");
37+
tracing::error!("\x1B[31m{addr} → DIRECT connection error: {e}\x1B[0m");
3638
}
3739
}
38-
Err(e) => tracing::error!("{addr} → UPGRADE error: {e}"),
40+
Err(e) => tracing::error!("\x1B[31m{addr} → UPGRADE error: {e}\x1B[0m"),
3941
}
4042
});
4143

@@ -66,15 +68,15 @@ pub async fn handle_request(
6668

6769
tokio::spawn(async move {
6870
if let Err(err) = conn.await {
69-
tracing::error!("Connection failed: {:?}", err);
71+
tracing::error!("\x1B[31mConnection failed: {:?}\x1B[0m", err);
7072
}
7173
});
7274

7375
let resp = sender.send_request(req).await?;
7476
Ok(resp.map(|b| b.boxed()))
7577
}
7678
Err(e) => {
77-
tracing::error!("{host}:{port} → Failed to connect: {:?}", e);
79+
tracing::error!("\x1B[31m{host}:{port} → Failed to connect: {:?}\x1B[0m", e);
7880
let mut resp = Response::new(full("Failed to connect to host"));
7981
*resp.status_mut() = http::StatusCode::BAD_GATEWAY;
8082

0 commit comments

Comments
 (0)