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