From 27106de4e4ce09ba309cb48dcb13ce910465462e Mon Sep 17 00:00:00 2001 From: _ <> Date: Mon, 19 Jul 2021 01:56:42 +0000 Subject: [PATCH] read client and server ports from GUI --- prototypes/quic_demo/src/bin/client_gui.rs | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/prototypes/quic_demo/src/bin/client_gui.rs b/prototypes/quic_demo/src/bin/client_gui.rs index ca6d6b9..4abafda 100644 --- a/prototypes/quic_demo/src/bin/client_gui.rs +++ b/prototypes/quic_demo/src/bin/client_gui.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use fltk::{ app, button::Button, @@ -44,7 +46,9 @@ fn main () -> anyhow::Result <()> { let mut y = margin; let frame_status; + let mut input_client_port; let mut input_server_id; + let mut input_server_port; let mut but_open; let mut but_close; @@ -74,7 +78,7 @@ fn main () -> anyhow::Result <()> { { let w = 80; - let mut input_client_port = Input::new (x, y, w, h, ""); + input_client_port = Input::new (x, y, w, h, ""); x += w + margin; let w = 120; @@ -82,7 +86,7 @@ fn main () -> anyhow::Result <()> { x += w + margin; let w = 80; - let mut input_server_port = Input::new (x, y, w, h, ""); + input_server_port = Input::new (x, y, w, h, ""); x += w + margin; let w = 80; @@ -134,11 +138,19 @@ fn main () -> anyhow::Result <()> { match fltk_rx.recv () { Some (Message::OpenPort) => { let connection_p2_p3 = connection_p2_p3.clone (); - let server_id = input_server_id.value ().to_string (); + let client_tcp_port = u16::from_str (&input_client_port.value ())?; + let server_id = input_server_id.value (); + let server_tcp_port = u16::from_str (&input_server_port.value ())?; let (shutdown_flag, shutdown_flag_rx) = tokio::sync::watch::channel (true); let task = rt.spawn (async move { - forward_port (connection_p2_p3, server_id, shutdown_flag_rx).await + forward_port ( + connection_p2_p3, + client_tcp_port, + server_id, + server_tcp_port, + shutdown_flag_rx + ).await }); forwarding_instance.replace (ForwardingInstance { @@ -188,12 +200,12 @@ struct ForwardingInstance { async fn forward_port ( connection_p2_p3: quinn::Connection, + client_tcp_port: u16, server_id: String, + server_tcp_port: u16, shutdown_flag_rx: tokio::sync::watch::Receiver , ) -> anyhow::Result <()> { - let client_tcp_port = 30381; - let server_tcp_port = 30382; let listener = TcpListener::bind (("127.0.0.1", client_tcp_port)).await?; trace! ("Accepting local TCP connections from P1 on {}", client_tcp_port);