🚧 sketching out the request-response control protocol
parent
b344e3f8ee
commit
ce817eab1a
|
@ -13,10 +13,20 @@ async fn main () -> anyhow::Result <()> {
|
|||
debug! ("Connecting to relay server");
|
||||
|
||||
let quinn::NewConnection {
|
||||
connection,
|
||||
mut bi_streams,
|
||||
..
|
||||
} = endpoint.connect (&server_addr, "localhost")?.await?;
|
||||
|
||||
let (mut send, mut recv) = connection.open_bi ().await?;
|
||||
|
||||
let req_buf = [4u8, 0, 0, 0];
|
||||
send.write_all (&req_buf).await?;
|
||||
|
||||
let mut resp_buf = [0u8, 0, 0, 0];
|
||||
recv.read_exact (&mut resp_buf).await?;
|
||||
|
||||
if false {
|
||||
debug! ("Waiting for relay server to forward a bi stream");
|
||||
|
||||
let (mut relay_send, mut relay_recv) = bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("Relay server didn't open a bi stream"))??;
|
||||
|
@ -59,6 +69,7 @@ async fn main () -> anyhow::Result <()> {
|
|||
|
||||
uplink_task.await??;
|
||||
downlink_task.await??;
|
||||
}
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use tokio::task::JoinHandle;
|
||||
|
||||
use quic_demo::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -10,6 +8,43 @@ async fn main () -> anyhow::Result <()> {
|
|||
let (mut incoming, server_cert) = make_server_endpoint (server_addr)?;
|
||||
tokio::fs::write ("quic_server.crt", &server_cert).await?;
|
||||
|
||||
let relay_state = RelayState::default ();
|
||||
let relay_state = Arc::new (Mutex::new (relay_state));
|
||||
|
||||
while let Some (conn) = incoming.next ().await {
|
||||
let relay_state = Arc::clone (&relay_state);
|
||||
|
||||
// Each new connection gets its own task
|
||||
tokio::spawn (async move {
|
||||
let quinn::NewConnection {
|
||||
connection,
|
||||
mut bi_streams,
|
||||
..
|
||||
} = conn.await?;
|
||||
|
||||
// Everyone who connects must identify themselves with the first
|
||||
// bi stream
|
||||
// TODO: Timeout
|
||||
|
||||
let (mut send, mut recv) = bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("QUIC client didn't identify itself"))??;
|
||||
|
||||
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"),
|
||||
_ => bail! ("Unknown QUIC client type"),
|
||||
}
|
||||
|
||||
let resp_buf = [20u8, 0, 0, 0];
|
||||
send.write_all (&resp_buf).await?;
|
||||
|
||||
Ok::<_, anyhow::Error> (())
|
||||
});
|
||||
}
|
||||
|
||||
if false {
|
||||
debug! ("Waiting for end server to connect");
|
||||
|
||||
let end_server_conn = incoming.next ().await.ok_or_else (|| anyhow::anyhow! ("No end server connection"))?;
|
||||
|
@ -52,10 +87,20 @@ async fn main () -> anyhow::Result <()> {
|
|||
|
||||
ptth_conn.uplink_task.await??;
|
||||
ptth_conn.downlink_task.await??;
|
||||
}
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
#[derive (Default)]
|
||||
struct RelayState {
|
||||
|
||||
}
|
||||
|
||||
impl RelayState {
|
||||
|
||||
}
|
||||
|
||||
struct PtthNewConnection {
|
||||
client_send: quinn::SendStream,
|
||||
client_recv: quinn::RecvStream,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
pub use std::{
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
|
@ -9,6 +10,8 @@ pub use tokio::{
|
|||
AsyncReadExt,
|
||||
AsyncWriteExt,
|
||||
},
|
||||
sync::Mutex,
|
||||
task::JoinHandle,
|
||||
};
|
||||
pub use tracing::{
|
||||
debug,
|
||||
|
|
Loading…
Reference in New Issue