♻️ refactor

main
_ 2021-07-18 18:52:51 +00:00
parent ca3145669d
commit 4ba35ee7d1
1 changed files with 56 additions and 49 deletions

View File

@ -37,9 +37,18 @@ async fn main () -> anyhow::Result <()> {
trace! ("Accepting bi streams from P3");
loop {
let (mut relay_send, mut 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 (async move {
tokio::spawn (handle_p2_connection (relay_send, relay_recv, local_tcp_port));
}
}
async fn handle_p2_connection (
mut relay_send: quinn::SendStream,
mut relay_recv: quinn::RecvStream,
local_tcp_port: u16,
) -> anyhow::Result <()>
{
let mut req_buf = [0, 0, 0, 0];
relay_recv.read_exact (&mut req_buf).await?;
assert_eq! (req_buf [0], Command::CONNECT_P2_TO_P4_STEP_2.0);
@ -85,9 +94,7 @@ async fn main () -> anyhow::Result <()> {
ptth_conn.uplink_task.await??;
ptth_conn.downlink_task.await??;
Ok::<_, anyhow::Error> (())
});
}
Ok (())
}
struct PtthNewConnection {