♻️ refactor
parent
b2fd8a8ede
commit
b344e3f8ee
|
@ -1,3 +1,5 @@
|
|||
use tokio::task::JoinHandle;
|
||||
|
||||
use quic_demo::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -33,15 +35,47 @@ async fn main () -> anyhow::Result <()> {
|
|||
|
||||
debug! ("Waiting for client to open bi stream");
|
||||
|
||||
let (mut client_send, mut client_recv) = client_incoming_bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("Client didn't open a bi stream"))??;
|
||||
let (client_send, client_recv) = client_incoming_bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("Client didn't open a bi stream"))??;
|
||||
|
||||
debug! ("Opening bi stream to the end server");
|
||||
|
||||
let (mut server_send, mut server_recv) = end_server_conn.open_bi ().await?;
|
||||
let (server_send, server_recv) = end_server_conn.open_bi ().await?;
|
||||
|
||||
debug! ("Relaying bytes...");
|
||||
|
||||
// Remember to swap tx and rx for patch cables
|
||||
let ptth_conn = PtthNewConnection {
|
||||
client_send,
|
||||
client_recv,
|
||||
server_send,
|
||||
server_recv,
|
||||
}.build ();
|
||||
|
||||
ptth_conn.uplink_task.await??;
|
||||
ptth_conn.downlink_task.await??;
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
struct PtthNewConnection {
|
||||
client_send: quinn::SendStream,
|
||||
client_recv: quinn::RecvStream,
|
||||
server_send: quinn::SendStream,
|
||||
server_recv: quinn::RecvStream,
|
||||
}
|
||||
|
||||
struct PtthConnection {
|
||||
uplink_task: JoinHandle <anyhow::Result <()>>,
|
||||
downlink_task: JoinHandle <anyhow::Result <()>>,
|
||||
}
|
||||
|
||||
impl PtthNewConnection {
|
||||
fn build (self) -> PtthConnection {
|
||||
let Self {
|
||||
mut client_send,
|
||||
mut client_recv,
|
||||
mut server_send,
|
||||
mut server_recv,
|
||||
} = self;
|
||||
|
||||
let uplink_task = tokio::spawn (async move {
|
||||
// Uplink - Client to end server
|
||||
|
@ -71,8 +105,9 @@ async fn main () -> anyhow::Result <()> {
|
|||
Ok::<_, anyhow::Error> (())
|
||||
});
|
||||
|
||||
uplink_task.await??;
|
||||
downlink_task.await??;
|
||||
|
||||
Ok (())
|
||||
PtthConnection {
|
||||
uplink_task,
|
||||
downlink_task,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue