add `--debug-echo` option for P4 end servers to run a simulated P5 TCP echo server
This makes it possible to debug with only 4 processes instead of 5.main
parent
d9949f3f68
commit
e1da97a517
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
- Open 3 terminals in `prototypes/quic_demo`
|
- Open 3 terminals in `prototypes/quic_demo`
|
||||||
- Use `export RUST_LOG=quic_demo_relay_server=debug` to enable debug logging
|
- Use `export RUST_LOG=quic_demo_relay_server=debug` to enable debug logging
|
||||||
for the terminal that will run the relay server
|
for the terminal that will run the relay server (P3)
|
||||||
- Use `export RUST_LOG=quic_demo_end_server=debug` for the terminal that
|
- Use `export RUST_LOG=quic_demo_end_server=debug` for the terminal that
|
||||||
will run the end server
|
will run the end server (P4)
|
||||||
|
- Use `export RUST_LOG=quic_demo_client=debug` for the terminal that
|
||||||
|
will run the client (P2)
|
||||||
|
|
||||||
When the relay server is running, use curl to get the list of connected
|
When the relay server is running, use curl to get the list of connected
|
||||||
end servers: `curl 127.0.0.1:4004`
|
end servers: `curl 127.0.0.1:4004`
|
||||||
|
@ -15,6 +17,8 @@ end servers: `curl 127.0.0.1:4004`
|
||||||
|
|
||||||
- Start a relay `cargo run --bin quic_demo_relay_server`
|
- Start a relay `cargo run --bin quic_demo_relay_server`
|
||||||
- Verify that the relay has no end servers connected
|
- Verify that the relay has no end servers connected
|
||||||
- Start an end server `cargo run --bin quic_demo_end_server`
|
- Start an end server `cargo run --bin quic_demo_end_server -- --debug-echo`
|
||||||
- Verify that the end server connected
|
- Verify that the end server connected
|
||||||
|
- Start a client `cargo run --bin quic_demo_client`
|
||||||
|
- Connect to the client and verify that the debug echo server is running
|
||||||
|
`nc 127.0.0.1 30381`
|
||||||
|
|
|
@ -10,21 +10,23 @@ struct Opt {
|
||||||
relay_addr: Option <String>,
|
relay_addr: Option <String>,
|
||||||
#[structopt (long)]
|
#[structopt (long)]
|
||||||
server_id: Option <PeerId>,
|
server_id: Option <PeerId>,
|
||||||
|
#[structopt (long)]
|
||||||
|
debug_echo: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main () -> anyhow::Result <()> {
|
async fn main () -> anyhow::Result <()> {
|
||||||
tracing_subscriber::fmt::init ();
|
tracing_subscriber::fmt::init ();
|
||||||
|
|
||||||
let opt = Opt::from_args ();
|
let opt = Arc::new (Opt::from_args ());
|
||||||
|
|
||||||
let server_cert = tokio::fs::read ("quic_server.crt").await?;
|
let server_cert = tokio::fs::read ("quic_server.crt").await?;
|
||||||
let relay_addr = opt.relay_addr.unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?;
|
let relay_addr = opt.relay_addr.clone ().unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?;
|
||||||
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
|
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
|
||||||
|
|
||||||
trace! ("Connecting to relay server");
|
trace! ("Connecting to relay server");
|
||||||
|
|
||||||
let server_id = opt.server_id.unwrap_or_else (|| "bogus_server".to_string ());
|
let server_id = opt.server_id.clone ().unwrap_or_else (|| "bogus_server".to_string ());
|
||||||
|
|
||||||
let quinn::NewConnection {
|
let quinn::NewConnection {
|
||||||
mut bi_streams,
|
mut bi_streams,
|
||||||
|
@ -37,11 +39,12 @@ async fn main () -> anyhow::Result <()> {
|
||||||
loop {
|
loop {
|
||||||
let (relay_send, relay_recv) = bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("Relay server didn't open a bi stream"))??;
|
let (relay_send, relay_recv) = bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("Relay server didn't open a bi stream"))??;
|
||||||
|
|
||||||
tokio::spawn (handle_bi_stream (relay_send, relay_recv));
|
tokio::spawn (handle_bi_stream (Arc::clone (&opt), relay_send, relay_recv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_bi_stream (
|
async fn handle_bi_stream (
|
||||||
|
opt: Arc <Opt>,
|
||||||
relay_send: quinn::SendStream,
|
relay_send: quinn::SendStream,
|
||||||
mut relay_recv: quinn::RecvStream,
|
mut relay_recv: quinn::RecvStream,
|
||||||
) -> anyhow::Result <()>
|
) -> anyhow::Result <()>
|
||||||
|
@ -50,13 +53,14 @@ async fn handle_bi_stream (
|
||||||
protocol::P3ToP4Stream::NewPtthConnection {
|
protocol::P3ToP4Stream::NewPtthConnection {
|
||||||
client_id,
|
client_id,
|
||||||
..
|
..
|
||||||
} => handle_new_ptth_connection (relay_send, relay_recv, client_id).await?,
|
} => handle_new_ptth_connection (opt, relay_send, relay_recv, client_id).await?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_new_ptth_connection (
|
async fn handle_new_ptth_connection (
|
||||||
|
opt: Arc <Opt>,
|
||||||
mut relay_send: quinn::SendStream,
|
mut relay_send: quinn::SendStream,
|
||||||
mut relay_recv: quinn::RecvStream,
|
mut relay_recv: quinn::RecvStream,
|
||||||
_client_id: String,
|
_client_id: String,
|
||||||
|
@ -73,19 +77,26 @@ async fn handle_new_ptth_connection (
|
||||||
|
|
||||||
debug! ("Started PTTH connection");
|
debug! ("Started PTTH connection");
|
||||||
|
|
||||||
let stream = TcpStream::connect (("127.0.0.1", p4_to_p5_req.port)).await?;
|
if opt.debug_echo {
|
||||||
let (local_recv, local_send) = stream.into_split ();
|
relay_send.write (b"Connected to P4=P5 debug echo server\n").await?;
|
||||||
|
debug! ("Relaying bytes using internal debug echo server (P4=P5)");
|
||||||
trace! ("Relaying bytes...");
|
tokio::io::copy (&mut relay_recv, &mut relay_send).await?;
|
||||||
|
}
|
||||||
let ptth_conn = quic_demo::connection::NewConnection {
|
else {
|
||||||
local_send,
|
let stream = TcpStream::connect (("127.0.0.1", p4_to_p5_req.port)).await?;
|
||||||
local_recv,
|
let (local_recv, local_send) = stream.into_split ();
|
||||||
relay_send,
|
|
||||||
relay_recv,
|
trace! ("Relaying bytes...");
|
||||||
}.build ();
|
|
||||||
|
let ptth_conn = quic_demo::connection::NewConnection {
|
||||||
ptth_conn.wait_for_close ().await?;
|
local_send,
|
||||||
|
local_recv,
|
||||||
|
relay_send,
|
||||||
|
relay_recv,
|
||||||
|
}.build ();
|
||||||
|
|
||||||
|
ptth_conn.wait_for_close ().await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue