🐛 bug: P2 no longer exits when P1 closes the connection

main
_ 2021-07-17 20:07:26 +00:00
parent fe25ff3d34
commit c8e44bb740
1 changed files with 33 additions and 26 deletions

View File

@ -27,35 +27,42 @@ 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 local TCP client to connect to us");
let listener = TcpListener::bind ("127.0.0.1:30381").await?; let listener = TcpListener::bind ("127.0.0.1:30381").await?;
let (tcp_socket, _) = listener.accept ().await?;
let (local_recv, local_send) = tcp_socket.into_split ();
debug! ("Connecting to end server"); debug! ("Accepting local TCP connections");
let (mut relay_send, mut relay_recv) = connection.open_bi ().await?; loop {
let (tcp_socket, _) = listener.accept ().await?;
let connection = connection.clone ();
let req_buf = [1, 43, 0, 0, 1, 0, 0, 0]; tokio::spawn (async move {
relay_send.write_all (&req_buf).await?; let (local_recv, local_send) = tcp_socket.into_split ();
let mut resp_buf = [0; 8]; debug! ("Connecting to end server");
relay_recv.read_exact (&mut resp_buf).await?;
debug! ("Relaying bytes..."); let (mut relay_send, mut relay_recv) = connection.open_bi ().await?;
let ptth_conn = PtthNewConnection { let req_buf = [1, 43, 0, 0, 1, 0, 0, 0];
local_send, relay_send.write_all (&req_buf).await?;
local_recv,
relay_send,
relay_recv,
}.build ();
ptth_conn.uplink_task.await??; let mut resp_buf = [0; 8];
ptth_conn.downlink_task.await??; relay_recv.read_exact (&mut resp_buf).await?;
Ok (()) 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 { struct PtthNewConnection {