Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing use of clap::builder::PossibleValuesParser #2

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions socksx/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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); },
}
}

Expand Down
6 changes: 3 additions & 3 deletions socksx/examples/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)]
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions socksx/examples/redirector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand All @@ -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?;
Expand All @@ -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); },
};
}

Expand Down
4 changes: 2 additions & 2 deletions socksx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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)),
Expand Down
Loading