diff --git a/README.md b/README.md index 675629a..f7edd02 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Check out the `docker-compose-proxy.yml` or `docker-compose-extensive.yml` file ## TODO +- [ ] make socksx work for macOS - [ ] support chaining in socks 5 - [ ] add badge for coverage (coveralls) - [ ] add badge for crates link diff --git a/socksx/examples/client.rs b/socksx/examples/client.rs index eb8e79b..478e5e4 100644 --- a/socksx/examples/client.rs +++ b/socksx/examples/client.rs @@ -3,7 +3,6 @@ /// This also serves as a test to ensure that the crate works as expected. use anyhow::Result; use clap::Parser; -use clap::builder::PossibleValuesParser; use socksx::{Socks5Client, Socks6Client}; use tokio::io::AsyncWriteExt; @@ -12,7 +11,7 @@ use tokio::io::AsyncWriteExt; #[derive(Debug, Parser)] #[clap(name = "Client")] struct Arguments { - #[clap(name="VERSION", short='s', long="socks", value_parser=PossibleValuesParser::new(["5", "6"]), default_value="6", help="The SOCKS version to use")] + #[clap(name="VERSION", short='s', long="socks", default_value="6", help="The SOCKS version to use")] version : u8, #[clap(name="PROXY_HOST", long="host", default_value="127.0.0.1", help="The IP/hostname of the proxy")] proxy_host : String, @@ -38,11 +37,11 @@ async fn main() -> Result<()> { let proxy_addr = format!("{}:{}", args.proxy_host, args.proxy_port); let dest_addr = format!("{}:{}", args.dest_host, args.dest_port); - // Determine the SOCKS version specified in the arguments. + // Determine the appropriate SOCKS handler based on the specified version and restricting them to 5 and 6 match args.version { 5 => connect_v5(proxy_addr, dest_addr).await, 6 => connect_v6(proxy_addr, dest_addr).await, - version => panic!("Unsupported version: {}", version), + version => { eprintln!("ERROR: Unsupported SOCKS-version '{version}' (supported: `5`, `6`)"); std::process::exit(1); }, } } diff --git a/socksx/examples/functions.rs b/socksx/examples/functions.rs index 99dc341..15b02d3 100644 --- a/socksx/examples/functions.rs +++ b/socksx/examples/functions.rs @@ -10,7 +10,6 @@ use bytes::BytesMut; use chacha20::{ChaCha20, Key, Nonce}; use chacha20::cipher::{KeyIvInit as _, StreamCipher}; use clap::Parser; -use clap::builder::PossibleValuesParser; use dotenv::dotenv; use pin_project_lite::pin_project; use tokio::io::{self, AsyncBufRead, BufReader, BufWriter}; @@ -34,7 +33,7 @@ struct Args { port: u16, /// SOCKS version - #[clap(short, long, env = "SOCKS", default_value = "6", value_parser = PossibleValuesParser::new(["5", "6"]))] + #[clap(short, long, env = "SOCKS", default_value = "6")] socks: u8, #[clap(subcommand)] @@ -63,10 +62,11 @@ async fn main() -> Result<()> { // Create a TCP listener bound to the specified host and port. let listener = TcpListener::bind(format!("{}:{}", args.host, args.port)).await?; // Determine the appropriate SOCKS handler based on the specified version. + // Determine the appropriate SOCKS handler based on the specified version and restricting them to 5 and 6 let handler: Handler = match args.socks { 5 => Arc::new(Socks5Handler::default()), 6 => Arc::new(Socks6Handler::default()), - _ => unreachable!(), + version => { eprintln!("ERROR: Unsupported SOCKS-version '{version}' (supported: `5`, `6`)"); std::process::exit(1); }, }; // Main loop for accepting incoming connections and processing them. diff --git a/socksx/examples/redirector.rs b/socksx/examples/redirector.rs index 50f1af5..cffd518 100644 --- a/socksx/examples/redirector.rs +++ b/socksx/examples/redirector.rs @@ -3,7 +3,6 @@ /// through a proxy. use anyhow::Result; use clap::Parser; -use clap::builder::PossibleValuesParser; use tokio::net::{TcpListener, TcpStream}; use socksx::{self, Socks5Client, Socks6Client}; @@ -13,7 +12,7 @@ use socksx::{self, Socks5Client, Socks6Client}; #[derive(Debug, Parser)] #[clap(name = "Redirector")] struct Arguments { - #[clap(name="VERSION", short='s', long="socks", value_parser=PossibleValuesParser::new(["5", "6"]), default_value="6", help="The SOCKS version to use")] + #[clap(name="VERSION", short='s', long="socks", default_value="6", help="The SOCKS version to use")] version : u8, #[clap(name="PROXY_HOST", long="host", default_value="127.0.0.1", help="The IP/hostname of the proxy")] proxy_host : String, @@ -33,6 +32,7 @@ async fn main() -> Result<()> { let proxy_addr = format!("{}:{}", args.proxy_host, args.proxy_port); let listener = TcpListener::bind("127.0.0.1:42000").await?; + // Determine the appropriate SOCKS handler based on the specified version and restricting them to 5 and 6 match args.version { 5 => { let client = Socks5Client::new(proxy_addr, None).await?; @@ -50,7 +50,7 @@ async fn main() -> Result<()> { tokio::spawn(redirect_v6(stream, client.clone())); } } - version => panic!("Unsupported version: {}", version), + version => { eprintln!("ERROR: Unsupported SOCKS-version '{version}' (supported: `5`, `6`)"); std::process::exit(1); }, }; } diff --git a/socksx/src/main.rs b/socksx/src/main.rs index 15263e4..a212484 100644 --- a/socksx/src/main.rs +++ b/socksx/src/main.rs @@ -12,7 +12,6 @@ use std::{convert::TryInto, sync::Arc}; use anyhow::Result; use clap::Parser; -use clap::builder::PossibleValuesParser; use dotenv::dotenv; use itertools::Itertools; use log::LevelFilter; @@ -50,7 +49,7 @@ struct Args { port: u16, /// SOCKS version - #[clap(short, long, env = "SOCKS", default_value = "6", value_parser = PossibleValuesParser::new(["5", "6"]))] + #[clap(short, long, env = "SOCKS", default_value = "6")] socks: u8, } @@ -93,6 +92,7 @@ async fn main() -> Result<()> { // Bind TCP listener to the specified host and port let listener = TcpListener::bind(format!("{}:{}", args.host, args.port)).await?; + // Determine the appropriate SOCKS handler based on the specified version and restricting them to 5 and 6 let handler: Handler = match args.socks { 5 => Arc::new(Socks5Handler::new(chain)), 6 => Arc::new(Socks6Handler::new(chain)),