diff --git a/Cargo.lock b/Cargo.lock index e60ec55..18ca418 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -744,6 +744,7 @@ version = "0.2.1" dependencies = [ "async-compression", "bincode", + "clap", "pretty_assertions", "quinn", "rcgen", @@ -759,6 +760,7 @@ name = "qs-roundezvous" version = "0.2.1" dependencies = [ "bincode", + "clap", "qs-core", "quinn", "rand", diff --git a/Cargo.toml b/Cargo.toml index fe7ce9c..faba954 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ tracing-subscriber = "0.3.18" thiserror = "1.0.63" pretty_assertions = "1.4.0" rand = "0.8.5" +clap = { version = "4.5.16", features = ["derive"] } [profile.release] lto = true diff --git a/qs-cli/Cargo.toml b/qs-cli/Cargo.toml index 802af14..1bfc8b0 100644 --- a/qs-cli/Cargo.toml +++ b/qs-cli/Cargo.toml @@ -9,9 +9,9 @@ tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } quinn = { workspace = true } +clap = { workspace = true } qs-core = { path = "../qs-core" } async-compression = { version = "0.4.12", features = ["tokio", "gzip"] } -clap = { version = "4.5.16", features = ["derive"] } indicatif = "0.17.8" dialoguer = "0.11.0" diff --git a/qs-core/Cargo.toml b/qs-core/Cargo.toml index 9faf363..1d88780 100644 --- a/qs-core/Cargo.toml +++ b/qs-core/Cargo.toml @@ -11,6 +11,7 @@ quinn = { workspace = true } rustls = { workspace = true } rcgen = { workspace = true } bincode = { workspace = true } +clap = { workspace = true } async-compression = { version = "0.4.12", features = ["tokio", "gzip"] } stunclient = "0.4.0" diff --git a/qs-roundezvous/Cargo.toml b/qs-roundezvous/Cargo.toml index a6edc74..74448ac 100644 --- a/qs-roundezvous/Cargo.toml +++ b/qs-roundezvous/Cargo.toml @@ -12,6 +12,7 @@ thiserror = { workspace = true } bincode = { workspace = true } rand = { workspace = true } qs-core = { path = "../qs-core" } +clap = { version = "4.5.16", features = ["derive"] } # rustls = { workspace = true } # rcgen = { workspace = true } diff --git a/qs-roundezvous/src/main.rs b/qs-roundezvous/src/main.rs index e5415cd..388fdc9 100644 --- a/qs-roundezvous/src/main.rs +++ b/qs-roundezvous/src/main.rs @@ -1,10 +1,11 @@ use std::{ collections::HashMap, - net::{IpAddr, Ipv4Addr, SocketAddr}, + net::SocketAddr, sync::{atomic::AtomicU64, Arc}, time, }; +use clap::Parser; use qs_core::{ common::{receive_packet, send_packet}, packets::{RoundezvousFromServer, RoundezvousToServer}, @@ -29,21 +30,42 @@ enum AppError { } const BIND_PORT: u16 = 9090; -const BIND_IP: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED); const CODE_CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const MAX_CONNECTION_AGE: u64 = 60; +#[derive(Parser, Debug)] +#[clap(version = VERSION, author = env!("CARGO_PKG_AUTHORS"))] +struct Args { + /// Log level + #[clap(long, short, default_value = "info")] + log_level: tracing::Level, + /// Port + #[clap(long, short, default_value_t = BIND_PORT)] + port: u16, + /// bind ip + #[clap(long, short, default_value = "0.0.0.0")] + bind_ip: String, + /// Max connection age + #[clap(long, short, default_value_t = MAX_CONNECTION_AGE)] + max_connection_age: u64, +} + struct AppState { /// Keep track of the connections awaiting exchange awaiting_exchange: RwLock>, + /// Counter for the connections counter: Arc, } #[tokio::main] async fn main() -> Result<(), AppError> { - tracing_subscriber::fmt::init(); + let args: Args = Args::parse(); + + tracing_subscriber::fmt() + .with_max_level(args.log_level) + .init(); - let addr = SocketAddr::new(BIND_IP, BIND_PORT); + let addr = SocketAddr::new(args.bind_ip.parse().unwrap(), args.port); let endpoint = quinn::Endpoint::server(server_config(), addr)?; let state = Arc::new(AppState {