🐛 bug: cap the number of forwarded ports at 5
If I want to access the same end server from multiple relays (like a LAN relay or a backup cloud relay) then the relay address should be explicitly _excluded_ from the eph port computationmain
parent
e6cf9e2b72
commit
1226016150
|
@ -48,6 +48,7 @@ struct GuiClient <'a> {
|
||||||
rt: &'a Runtime,
|
rt: &'a Runtime,
|
||||||
frame_status: Frame,
|
frame_status: Frame,
|
||||||
ports: Vec <Port>,
|
ports: Vec <Port>,
|
||||||
|
but_add_port: Button,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Port {
|
struct Port {
|
||||||
|
@ -56,8 +57,11 @@ struct Port {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Port {
|
impl Port {
|
||||||
pub fn open_port (&mut self, rt: &Runtime, connection_p2_p3: quinn::Connection)
|
pub fn open_port (
|
||||||
-> anyhow::Result <()>
|
&mut self,
|
||||||
|
rt: &Runtime,
|
||||||
|
connection_p2_p3: quinn::Connection,
|
||||||
|
) -> anyhow::Result <()>
|
||||||
{
|
{
|
||||||
let params = self.gui.get_params ()?;
|
let params = self.gui.get_params ()?;
|
||||||
|
|
||||||
|
@ -132,6 +136,10 @@ impl GuiClient <'_> {
|
||||||
ports_col: &mut Flex,
|
ports_col: &mut Flex,
|
||||||
fltk_tx: fltk::app::Sender <Message>
|
fltk_tx: fltk::app::Sender <Message>
|
||||||
) {
|
) {
|
||||||
|
if self.ports.len () >= 5 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut gui = GuiPort::new (fltk_tx, self.ports.len ());
|
let mut gui = GuiPort::new (fltk_tx, self.ports.len ());
|
||||||
ports_col.add (&gui.row);
|
ports_col.add (&gui.row);
|
||||||
ports_col.set_size (&mut gui.row, 30);
|
ports_col.set_size (&mut gui.row, 30);
|
||||||
|
@ -142,6 +150,10 @@ impl GuiClient <'_> {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.ports.push (port);
|
self.ports.push (port);
|
||||||
|
|
||||||
|
if self.ports.len () >= 5 {
|
||||||
|
self.but_add_port.deactivate ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,10 +200,17 @@ fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
col.end ();
|
col.end ();
|
||||||
|
|
||||||
|
let relay_addr = opt.relay_addr.as_ref ()
|
||||||
|
.map (|s| &s[..])
|
||||||
|
.unwrap_or ("127.0.0.1:30380")
|
||||||
|
.parse ()
|
||||||
|
.context ("relay_addr should be like 127.0.0.1:30380")?;
|
||||||
|
|
||||||
let mut gui_client = GuiClient {
|
let mut gui_client = GuiClient {
|
||||||
rt: &rt,
|
rt: &rt,
|
||||||
frame_status,
|
frame_status,
|
||||||
ports: Default::default (),
|
ports: Default::default (),
|
||||||
|
but_add_port,
|
||||||
};
|
};
|
||||||
|
|
||||||
gui_client.add_port (&mut ports_col, fltk_tx);
|
gui_client.add_port (&mut ports_col, fltk_tx);
|
||||||
|
@ -208,10 +227,6 @@ fn main () -> anyhow::Result <()> {
|
||||||
None => tokio::fs::read ("ptth_quic_output/quic_server.crt").await?.into (),
|
None => tokio::fs::read ("ptth_quic_output/quic_server.crt").await?.into (),
|
||||||
};
|
};
|
||||||
|
|
||||||
let relay_addr = opt.relay_addr
|
|
||||||
.unwrap_or_else (|| String::from ("127.0.0.1:30380"))
|
|
||||||
.parse ()
|
|
||||||
.context ("relay_addr should be like 127.0.0.1:30380")?;
|
|
||||||
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
|
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
|
||||||
|
|
||||||
trace! ("Connecting to relay server");
|
trace! ("Connecting to relay server");
|
||||||
|
@ -261,7 +276,6 @@ fn set_active <W: WidgetExt> (w: &mut W, b: bool) {
|
||||||
|
|
||||||
impl GuiPort {
|
impl GuiPort {
|
||||||
fn new (fltk_tx: fltk::app::Sender <Message>, port_idx: usize) -> Self {
|
fn new (fltk_tx: fltk::app::Sender <Message>, port_idx: usize) -> Self {
|
||||||
|
|
||||||
let mut row = Flex::default ().row ();
|
let mut row = Flex::default ().row ();
|
||||||
|
|
||||||
let mut input_server_id = Input::default ();
|
let mut input_server_id = Input::default ();
|
||||||
|
@ -308,7 +322,6 @@ impl GuiPort {
|
||||||
let server_id = self.input_server_id.value ();
|
let server_id = self.input_server_id.value ();
|
||||||
|
|
||||||
let client_tcp_port = PortInfo {
|
let client_tcp_port = PortInfo {
|
||||||
relay_addr: "bogus_relay",
|
|
||||||
server_id: &server_id,
|
server_id: &server_id,
|
||||||
server_tcp_port,
|
server_tcp_port,
|
||||||
}.random_eph_port ();
|
}.random_eph_port ();
|
||||||
|
@ -338,7 +351,7 @@ impl GuiPort {
|
||||||
|
|
||||||
#[derive (serde::Serialize)]
|
#[derive (serde::Serialize)]
|
||||||
struct PortInfo <'a> {
|
struct PortInfo <'a> {
|
||||||
relay_addr: &'a str,
|
// relay_addr: SocketAddr,
|
||||||
server_id: &'a str,
|
server_id: &'a str,
|
||||||
server_tcp_port: u16
|
server_tcp_port: u16
|
||||||
}
|
}
|
||||||
|
@ -375,14 +388,13 @@ mod test {
|
||||||
assert_eq! (port, 49408);
|
assert_eq! (port, 49408);
|
||||||
|
|
||||||
for (input, expected) in vec! [
|
for (input, expected) in vec! [
|
||||||
(("bogus_relay", "bogus_server", 22), 62350),
|
(("127.0.0.1:4000", "bogus_server", 22), 51168),
|
||||||
(("real_relay", "bogus_server", 22), 61081),
|
(("127.0.0.1:30380", "bogus_server", 22), 51168),
|
||||||
(("bogus_relay", "real_server", 22), 50513),
|
(("127.0.0.1:4000", "real_server", 22), 53873),
|
||||||
(("bogus_relay", "bogus_server", 5900), 60730),
|
(("127.0.0.1:4000", "bogus_server", 5900), 53844),
|
||||||
] {
|
] {
|
||||||
let (relay_addr, server_id, server_tcp_port) = input;
|
let (_relay_addr, server_id, server_tcp_port) = input;
|
||||||
let input = PortInfo {
|
let input = PortInfo {
|
||||||
relay_addr,
|
|
||||||
server_id,
|
server_id,
|
||||||
server_tcp_port,
|
server_tcp_port,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue