Compare commits

..

No commits in common. "b71d4c16a1411572b0fd41a2dc2cb8699dd68416" and "1a775622cfd0606cf0684199167236431b88ca21" have entirely different histories.

4 changed files with 138 additions and 109 deletions

57
Cargo.lock generated
View File

@ -345,22 +345,36 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fltk"
version = "1.2.7"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0953c34fd5b0c6ac1b615fdcda8845c81ed364165b115ddac46ae8953d456640"
checksum = "471fefc1fc3e019d314d542637f5bf48bd72a678f5e9052167b9ac7bea7b0a38"
dependencies = [
"bitflags",
"fltk-derive",
"fltk-sys",
"paste",
"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",
]
[[package]]
name = "fltk-sys"
version = "1.2.7"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2df700440c014123cc1644fbef7d33dcdda18cdd80373a7552a9d5cec47ca63"
checksum = "5cc5eabad4839df806d102049c44586233743cf6607e2d2829155bb9fe45775e"
dependencies = [
"cmake",
"libc",
]
[[package]]
@ -760,6 +774,15 @@ 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"
@ -901,6 +924,15 @@ 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"
@ -977,12 +1009,6 @@ 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"
@ -1446,6 +1472,15 @@ 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"

View File

@ -9,7 +9,7 @@ license = "AGPL-3.0"
[dependencies]
anyhow = "1.0.38"
fltk = "1.2.7"
fltk = "1.1.1"
quic_demo = { path = "../quic_demo" }
quinn = "0.7.2"
reqwest = "0.11.4"

View File

@ -1,13 +1,10 @@
use std::{
str::FromStr,
};
use std::str::FromStr;
use fltk::{
app,
button::Button,
enums::CallbackTrigger,
frame::Frame,
group::Flex,
input::*,
prelude::*,
window::Window
@ -37,27 +34,13 @@ struct Opt {
enum Message {
OpenPort (usize),
ClosePort (usize),
AddPort,
}
struct GuiClient <'a> {
rt: &'a Runtime,
frame_status: Frame,
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,
forwarding_instances: Vec <Option <ForwardingInstance>>,
gui_ports: Vec <GuiPort>,
}
impl GuiClient <'_> {
@ -67,7 +50,7 @@ impl GuiClient <'_> {
port_idx: usize,
) -> anyhow::Result <()>
{
let params = self.ports [port_idx].gui.get_params ()?;
let params = self.gui_ports [port_idx].get_params ()?;
let _guard = self.rt.enter ();
let forwarding_instance = self.rt.block_on (ForwardingInstance::new (
@ -75,16 +58,16 @@ impl GuiClient <'_> {
params,
))?;
self.ports [port_idx].forwarding_instance.replace (forwarding_instance);
self.forwarding_instances [port_idx].replace (forwarding_instance);
self.ports [port_idx].gui.set_forwarding (true);
self.gui_ports [port_idx].set_forwarding (true);
self.sync_status ();
Ok (())
}
pub fn close_port (&mut self, port_idx: usize) -> anyhow::Result <()> {
if let Some (old_instance) = self.ports [port_idx].forwarding_instance.take () {
if let Some (old_instance) = self.forwarding_instances [port_idx].take () {
self.rt.block_on (async {
old_instance.close ()
.await
@ -94,40 +77,23 @@ impl GuiClient <'_> {
})?;
}
self.ports [port_idx].gui.set_forwarding (false);
self.gui_ports [port_idx].set_forwarding (false);
self.sync_status ();
Ok (())
}
fn open_ports (&self) -> usize {
self.ports.iter ()
.map (|x| if x.forwarding_instance.is_some () { 1 } else { 0 })
self.forwarding_instances.iter ()
.map (|x| if x.is_some () { 1 } else { 0 })
.sum ()
}
pub fn sync_status (&mut self) {
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 <()> {
@ -142,47 +108,66 @@ 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 mut col = Flex::default ().column ().size_of_parent ();
let margin = 10;
let h = 30;
let mut x = margin;
let mut y = margin;
let mut frame_status = Frame::default ();
col.set_size (&mut frame_status, 30);
let frame_status = Frame::new (x, y, 800 - 20, h, "Forwarding 0 ports");
y += h + margin;
x = margin;
{
let mut row = Flex::default ().row ();
let w = 80;
Frame::new (x, y, w, h, "Local port");
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 = 120;
Frame::new (x, y, w, h, "Server ID");
x += w + margin;
col.set_size (&mut row, 30);
let w = 80;
Frame::new (x, y, w, h, "Server port");
// x += w + margin;
}
let mut ports_col = Flex::default ().column ();
ports_col.end ();
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_0 = GuiPort::new (fltk_tx, &mut x, y, 0);
y += h + margin;
x = margin;
col.end ();
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,
];
let mut gui_client = GuiClient {
rt: &rt,
frame_status,
ports: Default::default (),
forwarding_instances,
gui_ports,
};
gui_client.add_port (&mut ports_col, fltk_tx);
ports_col.recalc ();
gui_client.sync_status ();
// y += h + margin;
wind.end ();
wind.show ();
@ -215,19 +200,14 @@ fn main () -> anyhow::Result <()> {
while app.wait () {
match fltk_rx.recv () {
Some (Message::OpenPort (port_idx)) => {
if let Err (e) = gui_client.open_port (connection_p2_p3.clone (), port_idx)
{
error! ("{:?}", e);
}
match gui_client.open_port (connection_p2_p3.clone (), port_idx) {
Err (e) => 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 => (),
}
}
@ -244,22 +224,38 @@ 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>, port_idx: usize) -> Self {
fn new (fltk_tx: fltk::app::Sender <Message>, x: &mut i32, y: i32, port_idx: usize) -> Self {
let margin = 10;
let h = 30;
let mut row = Flex::default ().row ();
let w = 80;
let mut input_client_port = 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 = 120;
let mut input_server_id = Input::new (*x, y, w, h, "");
*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);
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;
input_client_port.set_value ("5901");
input_server_id.set_value ("bogus_server");
@ -273,10 +269,7 @@ 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,

View File

@ -36,8 +36,9 @@ impl ForwardingInstance {
}
pub async fn close (self) -> anyhow::Result <()> {
if self.shutdown_flag.send (false).is_err () {
warn! ("Trying to gracefully shutdown forwarding task but it appears to already be shut down");
match self.shutdown_flag.send (false) {
Err (_) => warn! ("Trying to gracefully shutdown forwarding task but it appears to already be shut down"),
_ => (),
}
self.task.await
.context ("awaiting ForwardingInstance task")?
@ -63,9 +64,9 @@ pub async fn forward_port (
) -> anyhow::Result <()>
{
let ForwardingParams {
client_tcp_port,
server_id,
server_tcp_port,
..
} = params;
while *shutdown_flag_rx.borrow () {