Compare commits
7 Commits
1a775622cf
...
b71d4c16a1
Author | SHA1 | Date |
---|---|---|
_ | b71d4c16a1 | |
_ | 17ed6cc4c5 | |
_ | 227c9f7ba4 | |
_ | bfb96e2475 | |
_ | 63f9dcef97 | |
_ | de248f2382 | |
_ | 4ffcca8559 |
|
@ -345,36 +345,22 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
|||
|
||||
[[package]]
|
||||
name = "fltk"
|
||||
version = "1.1.11"
|
||||
version = "1.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "471fefc1fc3e019d314d542637f5bf48bd72a678f5e9052167b9ac7bea7b0a38"
|
||||
checksum = "0953c34fd5b0c6ac1b615fdcda8845c81ed364165b115ddac46ae8953d456640"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"fltk-derive",
|
||||
"fltk-sys",
|
||||
"lazy_static",
|
||||
"objc",
|
||||
"raw-window-handle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fltk-derive"
|
||||
version = "1.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712f09c29760a17e14a2f0d08a36b78bab82d5fbb3b2c3e17f3420f239351364"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fltk-sys"
|
||||
version = "1.1.11"
|
||||
version = "1.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cc5eabad4839df806d102049c44586233743cf6607e2d2829155bb9fe45775e"
|
||||
checksum = "e2df700440c014123cc1644fbef7d33dcdda18cdd80373a7552a9d5cec47ca63"
|
||||
dependencies = [
|
||||
"cmake",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -774,15 +760,6 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
|
@ -924,15 +901,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
|
||||
dependencies = [
|
||||
"malloc_buf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.8.0"
|
||||
|
@ -1009,6 +977,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58"
|
||||
|
||||
[[package]]
|
||||
name = "pem"
|
||||
version = "0.8.3"
|
||||
|
@ -1472,15 +1446,6 @@ dependencies = [
|
|||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rcgen"
|
||||
version = "0.8.13"
|
||||
|
|
|
@ -9,7 +9,7 @@ license = "AGPL-3.0"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.38"
|
||||
fltk = "1.1.1"
|
||||
fltk = "1.2.7"
|
||||
quic_demo = { path = "../quic_demo" }
|
||||
quinn = "0.7.2"
|
||||
reqwest = "0.11.4"
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
use std::str::FromStr;
|
||||
use std::{
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use fltk::{
|
||||
app,
|
||||
button::Button,
|
||||
enums::CallbackTrigger,
|
||||
frame::Frame,
|
||||
group::Flex,
|
||||
input::*,
|
||||
prelude::*,
|
||||
window::Window
|
||||
|
@ -34,13 +37,27 @@ struct Opt {
|
|||
enum Message {
|
||||
OpenPort (usize),
|
||||
ClosePort (usize),
|
||||
AddPort,
|
||||
}
|
||||
|
||||
struct GuiClient <'a> {
|
||||
rt: &'a Runtime,
|
||||
frame_status: Frame,
|
||||
forwarding_instances: Vec <Option <ForwardingInstance>>,
|
||||
gui_ports: Vec <GuiPort>,
|
||||
ports: Vec <Port>,
|
||||
}
|
||||
|
||||
struct Port {
|
||||
gui: GuiPort,
|
||||
forwarding_instance: Option <ForwardingInstance>,
|
||||
}
|
||||
|
||||
struct GuiPort {
|
||||
row: fltk::group::Flex,
|
||||
input_client_port: Input,
|
||||
input_server_id: Input,
|
||||
input_server_port: Input,
|
||||
but_open: Button,
|
||||
but_close: Button,
|
||||
}
|
||||
|
||||
impl GuiClient <'_> {
|
||||
|
@ -50,7 +67,7 @@ impl GuiClient <'_> {
|
|||
port_idx: usize,
|
||||
) -> anyhow::Result <()>
|
||||
{
|
||||
let params = self.gui_ports [port_idx].get_params ()?;
|
||||
let params = self.ports [port_idx].gui.get_params ()?;
|
||||
|
||||
let _guard = self.rt.enter ();
|
||||
let forwarding_instance = self.rt.block_on (ForwardingInstance::new (
|
||||
|
@ -58,16 +75,16 @@ impl GuiClient <'_> {
|
|||
params,
|
||||
))?;
|
||||
|
||||
self.forwarding_instances [port_idx].replace (forwarding_instance);
|
||||
self.ports [port_idx].forwarding_instance.replace (forwarding_instance);
|
||||
|
||||
self.gui_ports [port_idx].set_forwarding (true);
|
||||
self.ports [port_idx].gui.set_forwarding (true);
|
||||
self.sync_status ();
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
pub fn close_port (&mut self, port_idx: usize) -> anyhow::Result <()> {
|
||||
if let Some (old_instance) = self.forwarding_instances [port_idx].take () {
|
||||
if let Some (old_instance) = self.ports [port_idx].forwarding_instance.take () {
|
||||
self.rt.block_on (async {
|
||||
old_instance.close ()
|
||||
.await
|
||||
|
@ -77,23 +94,40 @@ impl GuiClient <'_> {
|
|||
})?;
|
||||
}
|
||||
|
||||
self.gui_ports [port_idx].set_forwarding (false);
|
||||
self.ports [port_idx].gui.set_forwarding (false);
|
||||
self.sync_status ();
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
fn open_ports (&self) -> usize {
|
||||
self.forwarding_instances.iter ()
|
||||
.map (|x| if x.is_some () { 1 } else { 0 })
|
||||
self.ports.iter ()
|
||||
.map (|x| if x.forwarding_instance.is_some () { 1 } else { 0 })
|
||||
.sum ()
|
||||
}
|
||||
|
||||
fn sync_status (&mut self) {
|
||||
pub fn sync_status (&mut self) {
|
||||
let open_ports = self.open_ports ();
|
||||
|
||||
self.frame_status.set_label (&format! ("Forwarding {} ports", open_ports));
|
||||
}
|
||||
|
||||
pub fn add_port (
|
||||
&mut self,
|
||||
ports_col: &mut Flex,
|
||||
fltk_tx: fltk::app::Sender <Message>
|
||||
) {
|
||||
let mut gui = GuiPort::new (fltk_tx, self.ports.len ());
|
||||
ports_col.add (&gui.row);
|
||||
ports_col.set_size (&mut gui.row, 30);
|
||||
|
||||
let port = Port {
|
||||
gui,
|
||||
forwarding_instance: None,
|
||||
};
|
||||
|
||||
self.ports.push (port);
|
||||
}
|
||||
}
|
||||
|
||||
fn main () -> anyhow::Result <()> {
|
||||
|
@ -108,66 +142,47 @@ fn main () -> anyhow::Result <()> {
|
|||
let window_title = opt.window_title.clone ().unwrap_or_else (|| "PTTH client proxy".to_string ());
|
||||
let mut wind = Window::new (100, 100, 800, 600, None)
|
||||
.with_label (&window_title);
|
||||
wind.make_resizable (true);
|
||||
|
||||
let margin = 10;
|
||||
let h = 30;
|
||||
let mut x = margin;
|
||||
let mut y = margin;
|
||||
let mut col = Flex::default ().column ().size_of_parent ();
|
||||
|
||||
let frame_status = Frame::new (x, y, 800 - 20, h, "Forwarding 0 ports");
|
||||
|
||||
y += h + margin;
|
||||
x = margin;
|
||||
let mut frame_status = Frame::default ();
|
||||
col.set_size (&mut frame_status, 30);
|
||||
|
||||
{
|
||||
let w = 80;
|
||||
Frame::new (x, y, w, h, "Local port");
|
||||
x += w + margin;
|
||||
let mut row = Flex::default ().row ();
|
||||
|
||||
let w = 120;
|
||||
Frame::new (x, y, w, h, "Server ID");
|
||||
x += w + margin;
|
||||
let mut l = Frame::default ().with_label ("Local port");
|
||||
row.set_size (&mut l, 80);
|
||||
let mut l = Frame::default ().with_label ("Server ID");
|
||||
row.set_size (&mut l, 120);
|
||||
let mut l = Frame::default ().with_label ("Server port");
|
||||
row.set_size (&mut l, 80);
|
||||
row.end ();
|
||||
|
||||
let w = 80;
|
||||
Frame::new (x, y, w, h, "Server port");
|
||||
// x += w + margin;
|
||||
col.set_size (&mut row, 30);
|
||||
}
|
||||
|
||||
y += h + margin;
|
||||
x = margin;
|
||||
let mut ports_col = Flex::default ().column ();
|
||||
ports_col.end ();
|
||||
|
||||
let gui_port_0 = GuiPort::new (fltk_tx, &mut x, y, 0);
|
||||
y += h + margin;
|
||||
x = margin;
|
||||
let mut but_add_port = Button::default ().with_label ("+");
|
||||
but_add_port.set_trigger (CallbackTrigger::Release);
|
||||
but_add_port.emit (fltk_tx, Message::AddPort);
|
||||
col.set_size (&mut but_add_port, 30);
|
||||
|
||||
let gui_port_1 = GuiPort::new (fltk_tx, &mut x, y, 1);
|
||||
y += h + margin;
|
||||
x = margin;
|
||||
|
||||
let gui_port_2 = GuiPort::new (fltk_tx, &mut x, y, 2);
|
||||
// y += h + margin;
|
||||
// x = margin;
|
||||
|
||||
let gui_ports = vec! [
|
||||
gui_port_0,
|
||||
gui_port_1,
|
||||
gui_port_2,
|
||||
];
|
||||
|
||||
let forwarding_instances = vec! [
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
];
|
||||
col.end ();
|
||||
|
||||
let mut gui_client = GuiClient {
|
||||
rt: &rt,
|
||||
frame_status,
|
||||
forwarding_instances,
|
||||
gui_ports,
|
||||
ports: Default::default (),
|
||||
};
|
||||
|
||||
// y += h + margin;
|
||||
gui_client.add_port (&mut ports_col, fltk_tx);
|
||||
ports_col.recalc ();
|
||||
|
||||
gui_client.sync_status ();
|
||||
|
||||
wind.end ();
|
||||
wind.show ();
|
||||
|
@ -200,14 +215,19 @@ fn main () -> anyhow::Result <()> {
|
|||
while app.wait () {
|
||||
match fltk_rx.recv () {
|
||||
Some (Message::OpenPort (port_idx)) => {
|
||||
match gui_client.open_port (connection_p2_p3.clone (), port_idx) {
|
||||
Err (e) => error! ("{:?}", e),
|
||||
_ => (),
|
||||
};
|
||||
if let Err (e) = gui_client.open_port (connection_p2_p3.clone (), port_idx)
|
||||
{
|
||||
error! ("{:?}", e);
|
||||
}
|
||||
},
|
||||
Some (Message::ClosePort (port_idx)) => {
|
||||
gui_client.close_port (port_idx)?;
|
||||
},
|
||||
Some (Message::AddPort) => {
|
||||
gui_client.add_port (&mut ports_col, fltk_tx);
|
||||
ports_col.recalc ();
|
||||
ports_col.redraw ();
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
|
@ -224,38 +244,22 @@ fn set_active <W: WidgetExt> (w: &mut W, b: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
struct GuiPort {
|
||||
input_client_port: Input,
|
||||
input_server_id: Input,
|
||||
input_server_port: Input,
|
||||
but_open: Button,
|
||||
but_close: Button,
|
||||
}
|
||||
|
||||
impl GuiPort {
|
||||
fn new (fltk_tx: fltk::app::Sender <Message>, x: &mut i32, y: i32, port_idx: usize) -> Self {
|
||||
let margin = 10;
|
||||
let h = 30;
|
||||
fn new (fltk_tx: fltk::app::Sender <Message>, port_idx: usize) -> Self {
|
||||
|
||||
let w = 80;
|
||||
let mut input_client_port = Input::new (*x, y, w, h, "");
|
||||
*x += w + margin;
|
||||
let mut row = Flex::default ().row ();
|
||||
|
||||
let w = 120;
|
||||
let mut input_server_id = Input::new (*x, y, w, h, "");
|
||||
*x += w + margin;
|
||||
let mut input_client_port = Input::default ();
|
||||
let mut input_server_id = Input::default ();
|
||||
let mut input_server_port = Input::default ();
|
||||
let mut but_open = Button::default ().with_label ("Open");
|
||||
let mut but_close = Button::default ().with_label ("Close");
|
||||
|
||||
let w = 80;
|
||||
let mut input_server_port = Input::new (*x, y, w, h, "");
|
||||
*x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
let mut but_open = Button::new (*x, y, w, h, "Open");
|
||||
*x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
let mut but_close = Button::new (*x, y, w, h, "Close");
|
||||
// *x += w + margin;
|
||||
row.set_size (&mut input_client_port, 80);
|
||||
row.set_size (&mut input_server_id, 120);
|
||||
row.set_size (&mut input_server_port, 80);
|
||||
row.set_size (&mut but_open, 80);
|
||||
row.set_size (&mut but_close, 80);
|
||||
|
||||
input_client_port.set_value ("5901");
|
||||
input_server_id.set_value ("bogus_server");
|
||||
|
@ -269,7 +273,10 @@ impl GuiPort {
|
|||
set_active (&mut but_open, true);
|
||||
set_active (&mut but_close, false);
|
||||
|
||||
row.end ();
|
||||
|
||||
Self {
|
||||
row,
|
||||
input_client_port,
|
||||
input_server_id,
|
||||
input_server_port,
|
||||
|
|
|
@ -36,9 +36,8 @@ impl ForwardingInstance {
|
|||
}
|
||||
|
||||
pub async fn close (self) -> anyhow::Result <()> {
|
||||
match self.shutdown_flag.send (false) {
|
||||
Err (_) => warn! ("Trying to gracefully shutdown forwarding task but it appears to already be shut down"),
|
||||
_ => (),
|
||||
if self.shutdown_flag.send (false).is_err () {
|
||||
warn! ("Trying to gracefully shutdown forwarding task but it appears to already be shut down");
|
||||
}
|
||||
self.task.await
|
||||
.context ("awaiting ForwardingInstance task")?
|
||||
|
@ -64,9 +63,9 @@ pub async fn forward_port (
|
|||
) -> anyhow::Result <()>
|
||||
{
|
||||
let ForwardingParams {
|
||||
client_tcp_port,
|
||||
server_id,
|
||||
server_tcp_port,
|
||||
..
|
||||
} = params;
|
||||
|
||||
while *shutdown_flag_rx.borrow () {
|
||||
|
|
Loading…
Reference in New Issue