diff --git a/Cargo.lock b/Cargo.lock index fde7a14..4466889 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -319,12 +319,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" -[[package]] -name = "drop_guard" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bb5d73478dbcb7c404cd86336e90c67425497ca94b6f7352c8ea7deb9098e2" - [[package]] name = "either" version = "1.6.1" @@ -1357,10 +1351,10 @@ name = "quic_demo" version = "0.1.0" dependencies = [ "anyhow", - "drop_guard", "futures-util", "quinn", "rcgen", + "structopt", "tokio", "tracing", "tracing-subscriber", diff --git a/prototypes/quic_demo/Cargo.toml b/prototypes/quic_demo/Cargo.toml index 0b2f25c..6a47464 100644 --- a/prototypes/quic_demo/Cargo.toml +++ b/prototypes/quic_demo/Cargo.toml @@ -8,10 +8,10 @@ edition = "2018" [dependencies] anyhow = "1.0.38" -drop_guard = "0.2.1" futures-util = "0.3.9" quinn = "0.7.2" rcgen = "0.8.11" +structopt = "0.3.20" tokio = { version = "1.4.0", features = ["full"] } tracing-subscriber = "0.2.16" tracing = "0.1.25" diff --git a/prototypes/quic_demo/src/bin/quic_demo_client.rs b/prototypes/quic_demo/src/bin/quic_demo_client.rs index e32bd92..a6bc14a 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_client.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_client.rs @@ -1,15 +1,29 @@ -use tokio::{ - net::TcpListener, -}; +use structopt::StructOpt; +use tokio::net::TcpListener; use quic_demo::prelude::*; +#[derive (Debug, StructOpt)] +struct Opt { + #[structopt (long)] + relay_addr: Option , + #[structopt (long)] + local_tcp_port: Option , + #[structopt (long)] + client_id: Option , + #[structopt (long)] + server_id: Option , +} + #[tokio::main] async fn main () -> anyhow::Result <()> { tracing_subscriber::fmt::init (); + let opt = Opt::from_args (); + let local_tcp_port = opt.local_tcp_port.unwrap_or (30381); + let server_cert = tokio::fs::read ("quic_server.crt").await?; - let server_addr = "127.0.0.1:30380".parse ()?; + let relay_addr = opt.relay_addr.unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?; let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?; trace! ("Connecting to relay server"); @@ -17,15 +31,16 @@ async fn main () -> anyhow::Result <()> { let quinn::NewConnection { connection, .. - } = endpoint.connect (&server_addr, "localhost")?.await?; + } = endpoint.connect (&relay_addr, "localhost")?.await?; let (mut send, mut recv) = connection.open_bi ().await?; - let our_id = 42; + let client_id = opt.client_id.unwrap_or (42); + let server_id = opt.server_id.unwrap_or (43); let req_buf = [ Command::CONNECT_P2_TO_P3.0, - our_id, + client_id, 0, 0, ]; @@ -40,7 +55,7 @@ async fn main () -> anyhow::Result <()> { 0, ]); - let listener = TcpListener::bind ("127.0.0.1:30381").await?; + let listener = TcpListener::bind (("127.0.0.1", local_tcp_port)).await?; trace! ("Accepting local TCP connections from P1"); @@ -57,7 +72,6 @@ async fn main () -> anyhow::Result <()> { // Ask P3 if we can connect to P4 - let server_id = 43; let req_buf = [ Command::CONNECT_P2_TO_P4.0, server_id, diff --git a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs index f598656..5f9bc9f 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs @@ -1,13 +1,27 @@ +use structopt::StructOpt; use tokio::net::TcpStream; use quic_demo::prelude::*; +#[derive (Debug, StructOpt)] +struct Opt { + #[structopt (long)] + relay_addr: Option , + #[structopt (long)] + local_tcp_port: Option , + #[structopt (long)] + server_id: Option , +} + #[tokio::main] async fn main () -> anyhow::Result <()> { tracing_subscriber::fmt::init (); + let opt = Opt::from_args (); + let local_tcp_port = opt.local_tcp_port.unwrap_or (30382); + let server_cert = tokio::fs::read ("quic_server.crt").await?; - let server_addr = "127.0.0.1:30380".parse ()?; + let relay_addr = opt.relay_addr.unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?; let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?; trace! ("Connecting to relay server"); @@ -16,11 +30,11 @@ async fn main () -> anyhow::Result <()> { connection, mut bi_streams, .. - } = endpoint.connect (&server_addr, "localhost")?.await?; + } = endpoint.connect (&relay_addr, "localhost")?.await?; let (mut send, mut recv) = connection.open_bi ().await?; - let our_id = 43; + let our_id = opt.server_id.unwrap_or (43); let req_buf = [ Command::CONNECT_P4_TO_P3.0, our_id, @@ -74,7 +88,7 @@ async fn main () -> anyhow::Result <()> { debug! ("Started PTTH connection"); - let stream = TcpStream::connect ("127.0.0.1:30382").await?; + let stream = TcpStream::connect (("127.0.0.1", local_tcp_port)).await?; let (local_recv, local_send) = stream.into_split (); trace! ("Relaying bytes..."); diff --git a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs index 1fa0411..8230553 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs @@ -1,11 +1,21 @@ +use structopt::StructOpt; + use quic_demo::prelude::*; +#[derive (Debug, StructOpt)] +struct Opt { + #[structopt (long)] + listen_addr: Option , +} + #[tokio::main] async fn main () -> anyhow::Result <()> { tracing_subscriber::fmt::init (); - let server_addr = "0.0.0.0:30380".parse ()?; - let (mut incoming, server_cert) = make_server_endpoint (server_addr)?; + let opt = Opt::from_args (); + + let listen_addr = opt.listen_addr.unwrap_or_else (|| String::from ("0.0.0.0:30380")).parse ()?; + let (mut incoming, server_cert) = make_server_endpoint (listen_addr)?; tokio::fs::write ("quic_server.crt", &server_cert).await?; let relay_state = RelayState::default ();