Skip to content

Commit

Permalink
add clap args
Browse files Browse the repository at this point in the history
  • Loading branch information
maxomatic458 committed Aug 21, 2024
1 parent c723ee8 commit 347184b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qs-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions qs-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions qs-roundezvous/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
30 changes: 26 additions & 4 deletions qs-roundezvous/src/main.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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<HashMap<[u8; CODE_LEN], (Connection, SocketAddr, u64)>>,
/// Counter for the connections
counter: Arc<AtomicU64>,
}

#[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 {
Expand Down

0 comments on commit 347184b

Please sign in to comment.