🐛 bug: P3 no longer closes when the PTTH connection closes
parent
c8e44bb740
commit
3442bf220b
|
@ -29,7 +29,7 @@ async fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
let listener = TcpListener::bind ("127.0.0.1:30381").await?;
|
let listener = TcpListener::bind ("127.0.0.1:30381").await?;
|
||||||
|
|
||||||
debug! ("Accepting local TCP connections");
|
debug! ("Accepting local TCP connections from P1");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (tcp_socket, _) = listener.accept ().await?;
|
let (tcp_socket, _) = listener.accept ().await?;
|
||||||
|
|
|
@ -26,10 +26,12 @@ async fn main () -> anyhow::Result <()> {
|
||||||
let mut resp_buf = [0u8, 0, 0, 0];
|
let mut resp_buf = [0u8, 0, 0, 0];
|
||||||
recv.read_exact (&mut resp_buf).await?;
|
recv.read_exact (&mut resp_buf).await?;
|
||||||
|
|
||||||
debug! ("Waiting for relay server to forward a bi stream");
|
debug! ("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 (mut relay_send, mut relay_recv) = bi_streams.next ().await.ok_or_else (|| anyhow::anyhow! ("Relay server didn't open a bi stream"))??;
|
||||||
|
|
||||||
|
tokio::spawn (async move {
|
||||||
let mut req_buf = [0, 0, 0, 0];
|
let mut req_buf = [0, 0, 0, 0];
|
||||||
relay_recv.read_exact (&mut req_buf).await?;
|
relay_recv.read_exact (&mut req_buf).await?;
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ async fn main () -> anyhow::Result <()> {
|
||||||
debug! ("Connecting to TCP end server");
|
debug! ("Connecting to TCP end server");
|
||||||
|
|
||||||
let stream = TcpStream::connect ("127.0.0.1:30382").await?;
|
let stream = TcpStream::connect ("127.0.0.1:30382").await?;
|
||||||
let (mut local_recv, mut local_send) = stream.into_split ();
|
let (local_recv, local_send) = stream.into_split ();
|
||||||
|
|
||||||
let resp_buf = [20, 0, 0, 0];
|
let resp_buf = [20, 0, 0, 0];
|
||||||
relay_send.write_all (&resp_buf).await?;
|
relay_send.write_all (&resp_buf).await?;
|
||||||
|
@ -46,6 +48,42 @@ async fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
debug! ("Relaying bytes...");
|
debug! ("Relaying bytes...");
|
||||||
|
|
||||||
|
let ptth_conn = PtthNewConnection {
|
||||||
|
local_send,
|
||||||
|
local_recv,
|
||||||
|
relay_send,
|
||||||
|
relay_recv,
|
||||||
|
}.build ();
|
||||||
|
|
||||||
|
ptth_conn.uplink_task.await??;
|
||||||
|
ptth_conn.downlink_task.await??;
|
||||||
|
|
||||||
|
Ok::<_, anyhow::Error> (())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PtthNewConnection {
|
||||||
|
local_send: tokio::net::tcp::OwnedWriteHalf,
|
||||||
|
local_recv: tokio::net::tcp::OwnedReadHalf,
|
||||||
|
relay_send: quinn::SendStream,
|
||||||
|
relay_recv: quinn::RecvStream,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PtthConnection {
|
||||||
|
uplink_task: JoinHandle <anyhow::Result <()>>,
|
||||||
|
downlink_task: JoinHandle <anyhow::Result <()>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PtthNewConnection {
|
||||||
|
fn build (self) -> PtthConnection {
|
||||||
|
let Self {
|
||||||
|
mut local_send,
|
||||||
|
mut local_recv,
|
||||||
|
mut relay_send,
|
||||||
|
mut relay_recv,
|
||||||
|
} = self;
|
||||||
|
|
||||||
let uplink_task = tokio::spawn (async move {
|
let uplink_task = tokio::spawn (async move {
|
||||||
// Downlink - Relay server to local client
|
// Downlink - Relay server to local client
|
||||||
|
|
||||||
|
@ -80,8 +118,9 @@ async fn main () -> anyhow::Result <()> {
|
||||||
Ok::<_, anyhow::Error> (())
|
Ok::<_, anyhow::Error> (())
|
||||||
});
|
});
|
||||||
|
|
||||||
uplink_task.await??;
|
PtthConnection {
|
||||||
downlink_task.await??;
|
uplink_task,
|
||||||
|
downlink_task,
|
||||||
Ok (())
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue