diff --git a/prototypes/quic_demo/src/bin/quic_demo_client.rs b/prototypes/quic_demo/src/bin/quic_demo_client.rs index 67006c9..03e2ec8 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_client.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_client.rs @@ -19,49 +19,59 @@ async fn main () -> anyhow::Result <()> { .. } = endpoint.connect (&server_addr, "localhost")?.await?; - debug! ("Waiting for local TCP client to connect to us"); + let (mut send, mut recv) = connection.open_bi ().await?; - let listener = TcpListener::bind ("127.0.0.1:30381").await?; - let (tcp_socket, _) = listener.accept ().await?; - let (mut local_recv, mut local_send) = tcp_socket.into_split (); + let req_buf = [2u8, 42, 0, 0]; + send.write_all (&req_buf).await?; - debug! ("Connecting to end server"); + let mut resp_buf = [0u8, 0, 0, 0]; + recv.read_exact (&mut resp_buf).await?; - let (mut relay_send, mut relay_recv) = connection.open_bi ().await?; - - debug! ("Relaying bytes..."); - - let uplink_task = tokio::spawn (async move { - // Uplink - local client to relay server + if false { + debug! ("Waiting for local TCP client to connect to us"); - let mut buf = vec! [0u8; 65_536]; - loop { - let bytes_read = local_recv.read (&mut buf).await?; - let buf_slice = &buf [0..bytes_read]; - relay_send.write_all (buf_slice).await?; - } + let listener = TcpListener::bind ("127.0.0.1:30381").await?; + let (tcp_socket, _) = listener.accept ().await?; + let (mut local_recv, mut local_send) = tcp_socket.into_split (); - debug! ("Uplink closed"); + debug! ("Connecting to end server"); - Ok::<_, anyhow::Error> (()) - }); - - let downlink_task = tokio::spawn (async move { - // Downlink - Relay server to local client + let (mut relay_send, mut relay_recv) = connection.open_bi ().await?; - let mut buf = vec! [0u8; 65_536]; - while let Some (bytes_read) = relay_recv.read (&mut buf).await? { - let buf_slice = &buf [0..bytes_read]; - local_send.write_all (buf_slice).await?; - } + debug! ("Relaying bytes..."); - debug! ("Downlink closed"); + let uplink_task = tokio::spawn (async move { + // Uplink - local client to relay server + + let mut buf = vec! [0u8; 65_536]; + loop { + let bytes_read = local_recv.read (&mut buf).await?; + let buf_slice = &buf [0..bytes_read]; + relay_send.write_all (buf_slice).await?; + } + + debug! ("Uplink closed"); + + Ok::<_, anyhow::Error> (()) + }); - Ok::<_, anyhow::Error> (()) - }); - - uplink_task.await??; - downlink_task.await??; + let downlink_task = tokio::spawn (async move { + // Downlink - Relay server to local client + + let mut buf = vec! [0u8; 65_536]; + while let Some (bytes_read) = relay_recv.read (&mut buf).await? { + let buf_slice = &buf [0..bytes_read]; + local_send.write_all (buf_slice).await?; + } + + debug! ("Downlink closed"); + + Ok::<_, anyhow::Error> (()) + }); + + uplink_task.await??; + downlink_task.await??; + } Ok (()) } 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 f30b717..4977c3b 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs @@ -20,7 +20,7 @@ async fn main () -> anyhow::Result <()> { let (mut send, mut recv) = connection.open_bi ().await?; - let req_buf = [4u8, 0, 0, 0]; + let req_buf = [4u8, 43, 0, 0]; send.write_all (&req_buf).await?; let mut resp_buf = [0u8, 0, 0, 0]; 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 a7d4a10..13886cc 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs @@ -14,7 +14,7 @@ async fn main () -> anyhow::Result <()> { while let Some (conn) = incoming.next ().await { let relay_state = Arc::clone (&relay_state); - // Each new connection gets its own task + // Each new peer QUIC connection gets its own task tokio::spawn (async move { let quinn::NewConnection { connection, @@ -31,15 +31,28 @@ async fn main () -> anyhow::Result <()> { let mut req_buf = [0u8; 4]; recv.read_exact (&mut req_buf).await?; - match req_buf [0] { - 4 => debug! ("Server-side proxy (P4) connected"), - 2 => debug! ("Client-side proxy (P2) connected"), + let peer_type = req_buf [0]; + let peer_id = req_buf [1]; + + match peer_type { + 4 => debug! ("Server-side proxy (P4) connected, ID {}", peer_id), + 2 => debug! ("Client-side proxy (P2) connected, ID {}", peer_id), _ => bail! ("Unknown QUIC client type"), } let resp_buf = [20u8, 0, 0, 0]; send.write_all (&resp_buf).await?; + match peer_type { + 2 => while let Some (bi_stream) = bi_streams.next ().await { + let (mut send, mut recv) = bi_stream?; + + // Each new + }, + 4 => (), + _ => bail! ("Unknown QUIC client type"), + } + Ok::<_, anyhow::Error> (()) }); }