read client and server ports from GUI

main
_ 2021-07-19 01:56:42 +00:00
parent 34c9e5e7a1
commit 27106de4e4
1 changed files with 18 additions and 6 deletions

View File

@ -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 <bool>,
) -> 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);