🚧 working on a few things
parent
27106de4e4
commit
97ef6d7fce
|
@ -45,7 +45,9 @@ fn main () -> anyhow::Result <()> {
|
||||||
let mut x = margin;
|
let mut x = margin;
|
||||||
let mut y = margin;
|
let mut y = margin;
|
||||||
|
|
||||||
let frame_status;
|
let mut frame_status;
|
||||||
|
|
||||||
|
|
||||||
let mut input_client_port;
|
let mut input_client_port;
|
||||||
let mut input_server_id;
|
let mut input_server_id;
|
||||||
let mut input_server_port;
|
let mut input_server_port;
|
||||||
|
@ -53,7 +55,7 @@ fn main () -> anyhow::Result <()> {
|
||||||
let mut but_close;
|
let mut but_close;
|
||||||
|
|
||||||
{
|
{
|
||||||
frame_status = Frame::new (10, 10, 800 - 20, 30, "0 ports forwarded");
|
frame_status = Frame::new (10, 10, 800 - 20, 30, "Forwarding 0 ports");
|
||||||
}
|
}
|
||||||
|
|
||||||
y += h + margin;
|
y += h + margin;
|
||||||
|
@ -110,6 +112,14 @@ fn main () -> anyhow::Result <()> {
|
||||||
set_active (&mut but_close, false);
|
set_active (&mut but_close, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut gui_port = GuiPort {
|
||||||
|
input_client_port,
|
||||||
|
input_server_id,
|
||||||
|
input_server_port,
|
||||||
|
but_open,
|
||||||
|
but_close,
|
||||||
|
};
|
||||||
|
|
||||||
// y += h + margin;
|
// y += h + margin;
|
||||||
|
|
||||||
wind.end ();
|
wind.end ();
|
||||||
|
@ -137,31 +147,25 @@ fn main () -> anyhow::Result <()> {
|
||||||
while app.wait () {
|
while app.wait () {
|
||||||
match fltk_rx.recv () {
|
match fltk_rx.recv () {
|
||||||
Some (Message::OpenPort) => {
|
Some (Message::OpenPort) => {
|
||||||
let connection_p2_p3 = connection_p2_p3.clone ();
|
if let Ok (params) = gui_port.get_params () {
|
||||||
let client_tcp_port = u16::from_str (&input_client_port.value ())?;
|
let connection_p2_p3 = connection_p2_p3.clone ();
|
||||||
let server_id = input_server_id.value ();
|
let (shutdown_flag, shutdown_flag_rx) = tokio::sync::watch::channel (true);
|
||||||
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 {
|
let task = rt.spawn (forward_port (
|
||||||
forward_port (
|
|
||||||
connection_p2_p3,
|
connection_p2_p3,
|
||||||
client_tcp_port,
|
params,
|
||||||
server_id,
|
|
||||||
server_tcp_port,
|
|
||||||
shutdown_flag_rx
|
shutdown_flag_rx
|
||||||
).await
|
));
|
||||||
});
|
|
||||||
|
|
||||||
forwarding_instance.replace (ForwardingInstance {
|
forwarding_instance.replace (ForwardingInstance {
|
||||||
task,
|
task,
|
||||||
shutdown_flag,
|
shutdown_flag,
|
||||||
});
|
});
|
||||||
|
|
||||||
set_active (&mut but_open, false);
|
gui_port.set_forwarding (true);
|
||||||
set_active (&mut but_close, true);
|
|
||||||
but_open.set (true);
|
frame_status.set_label ("Forwarding 1 port");
|
||||||
but_close.set (false);
|
}
|
||||||
},
|
},
|
||||||
Some (Message::ClosePort) => {
|
Some (Message::ClosePort) => {
|
||||||
if let Some (mut old_instance) = forwarding_instance.take () {
|
if let Some (mut old_instance) = forwarding_instance.take () {
|
||||||
|
@ -172,10 +176,8 @@ fn main () -> anyhow::Result <()> {
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_active (&mut but_open, true);
|
gui_port.set_forwarding (false);
|
||||||
set_active (&mut but_close, false);
|
frame_status.set_label ("Forwarding 0 ports");
|
||||||
but_open.set (false);
|
|
||||||
but_close.set (true);
|
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
|
@ -200,12 +202,16 @@ struct ForwardingInstance {
|
||||||
|
|
||||||
async fn forward_port (
|
async fn forward_port (
|
||||||
connection_p2_p3: quinn::Connection,
|
connection_p2_p3: quinn::Connection,
|
||||||
client_tcp_port: u16,
|
params: ForwardingParams,
|
||||||
server_id: String,
|
|
||||||
server_tcp_port: u16,
|
|
||||||
shutdown_flag_rx: tokio::sync::watch::Receiver <bool>,
|
shutdown_flag_rx: tokio::sync::watch::Receiver <bool>,
|
||||||
) -> anyhow::Result <()>
|
) -> anyhow::Result <()>
|
||||||
{
|
{
|
||||||
|
let ForwardingParams {
|
||||||
|
client_tcp_port,
|
||||||
|
server_id,
|
||||||
|
server_tcp_port,
|
||||||
|
} = params;
|
||||||
|
|
||||||
let listener = TcpListener::bind (("127.0.0.1", client_tcp_port)).await?;
|
let listener = TcpListener::bind (("127.0.0.1", client_tcp_port)).await?;
|
||||||
|
|
||||||
trace! ("Accepting local TCP connections from P1 on {}", client_tcp_port);
|
trace! ("Accepting local TCP connections from P1 on {}", client_tcp_port);
|
||||||
|
@ -307,3 +313,43 @@ async fn handle_p1 (
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct GuiPort {
|
||||||
|
input_client_port: Input,
|
||||||
|
input_server_id: Input,
|
||||||
|
input_server_port: Input,
|
||||||
|
but_open: Button,
|
||||||
|
but_close: Button,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ForwardingParams {
|
||||||
|
client_tcp_port: u16,
|
||||||
|
server_id: String,
|
||||||
|
server_tcp_port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GuiPort {
|
||||||
|
fn get_params (&self) -> anyhow::Result <ForwardingParams>
|
||||||
|
{
|
||||||
|
let client_tcp_port = u16::from_str (&self.input_client_port.value ())?;
|
||||||
|
let server_id = self.input_server_id.value ();
|
||||||
|
let server_tcp_port = u16::from_str (&self.input_server_port.value ())?;
|
||||||
|
|
||||||
|
Ok (ForwardingParams {
|
||||||
|
client_tcp_port,
|
||||||
|
server_id,
|
||||||
|
server_tcp_port,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_forwarding (&mut self, x: bool) {
|
||||||
|
set_active (&mut self.input_client_port, !x);
|
||||||
|
set_active (&mut self.input_server_id, !x);
|
||||||
|
set_active (&mut self.input_server_port, !x);
|
||||||
|
set_active (&mut self.but_open, !x);
|
||||||
|
set_active (&mut self.but_close, x);
|
||||||
|
|
||||||
|
self.but_open.set (x);
|
||||||
|
self.but_close.set (!x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue