♻️ refactor

main
_ 2021-10-10 16:58:12 +00:00
parent a3b62b012d
commit c2caeb405c
1 changed files with 6 additions and 23 deletions

View File

@ -89,30 +89,13 @@ impl P2Client {
) -> anyhow::Result <()> { ) -> anyhow::Result <()> {
let running = true; let running = true;
while running { while running {
let (tcp_socket, _) = listener.accept ().await?; let (tcp_stream, _) = listener.accept ().await?;
let connection = connection.clone (); let connection = connection.clone ();
let server_id = conf.server_id.clone (); let server_id = conf.server_id.clone ();
let server_tcp_port = conf.server_tcp_port; let server_tcp_port = conf.server_tcp_port;
tokio::spawn (async move { tokio::spawn (async move {
let (local_recv, local_send) = tcp_socket.into_split (); Self::run_tcp_stream (&connection, tcp_stream, &server_id, server_tcp_port).await?;
debug! ("Starting PTTH connection");
let (relay_send, relay_recv) = protocol::p2_connect_to_p5 (&connection, &server_id, server_tcp_port).await?;
trace! ("Relaying bytes...");
let ptth_conn = quic_demo::connection::NewConnection {
local_send,
local_recv,
relay_send,
relay_recv,
}.build ();
ptth_conn.wait_for_close ().await?;
debug! ("Ended PTTH connection");
Ok::<_, anyhow::Error> (()) Ok::<_, anyhow::Error> (())
}); });
@ -124,16 +107,16 @@ impl P2Client {
/// Forwards a single TCP stream /// Forwards a single TCP stream
async fn run_tcp_stream ( async fn run_tcp_stream (
connection: quinn::Connection, connection: &quinn::Connection,
tcp_socket: TcpStream, tcp_stream: TcpStream,
server_id: &str, server_id: &str,
server_tcp_port: u16, server_tcp_port: u16,
) -> anyhow::Result <()> { ) -> anyhow::Result <()> {
let (local_recv, local_send) = tcp_socket.into_split (); let (local_recv, local_send) = tcp_stream.into_split ();
debug! ("Starting PTTH connection"); debug! ("Starting PTTH connection");
let (relay_send, relay_recv) = protocol::p2_connect_to_p5 (&connection, server_id, server_tcp_port).await?; let (relay_send, relay_recv) = protocol::p2_connect_to_p5 (connection, server_id, server_tcp_port).await?;
trace! ("Relaying bytes..."); trace! ("Relaying bytes...");