Compare commits
2 Commits
e6cf9e2b72
...
6c5dff4685
Author | SHA1 | Date |
---|---|---|
_ | 6c5dff4685 | |
_ | 1226016150 |
|
@ -48,6 +48,7 @@ struct GuiClient <'a> {
|
|||
rt: &'a Runtime,
|
||||
frame_status: Frame,
|
||||
ports: Vec <Port>,
|
||||
but_add_port: Button,
|
||||
}
|
||||
|
||||
struct Port {
|
||||
|
@ -56,8 +57,11 @@ struct Port {
|
|||
}
|
||||
|
||||
impl Port {
|
||||
pub fn open_port (&mut self, rt: &Runtime, connection_p2_p3: quinn::Connection)
|
||||
-> anyhow::Result <()>
|
||||
pub fn open_port (
|
||||
&mut self,
|
||||
rt: &Runtime,
|
||||
connection_p2_p3: quinn::Connection,
|
||||
) -> anyhow::Result <()>
|
||||
{
|
||||
let params = self.gui.get_params ()?;
|
||||
|
||||
|
@ -132,6 +136,10 @@ impl GuiClient <'_> {
|
|||
ports_col: &mut Flex,
|
||||
fltk_tx: fltk::app::Sender <Message>
|
||||
) {
|
||||
if self.ports.len () >= 5 {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut gui = GuiPort::new (fltk_tx, self.ports.len ());
|
||||
ports_col.add (&gui.row);
|
||||
ports_col.set_size (&mut gui.row, 30);
|
||||
|
@ -142,6 +150,10 @@ impl GuiClient <'_> {
|
|||
};
|
||||
|
||||
self.ports.push (port);
|
||||
|
||||
if self.ports.len () >= 5 {
|
||||
self.but_add_port.deactivate ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,10 +200,17 @@ fn main () -> anyhow::Result <()> {
|
|||
|
||||
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 {
|
||||
rt: &rt,
|
||||
frame_status,
|
||||
ports: Default::default (),
|
||||
but_add_port,
|
||||
};
|
||||
|
||||
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 (),
|
||||
};
|
||||
|
||||
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])?;
|
||||
|
||||
trace! ("Connecting to relay server");
|
||||
|
@ -261,7 +276,6 @@ fn set_active <W: WidgetExt> (w: &mut W, b: bool) {
|
|||
|
||||
impl GuiPort {
|
||||
fn new (fltk_tx: fltk::app::Sender <Message>, port_idx: usize) -> Self {
|
||||
|
||||
let mut row = Flex::default ().row ();
|
||||
|
||||
let mut input_server_id = Input::default ();
|
||||
|
@ -308,7 +322,6 @@ impl GuiPort {
|
|||
let server_id = self.input_server_id.value ();
|
||||
|
||||
let client_tcp_port = PortInfo {
|
||||
relay_addr: "bogus_relay",
|
||||
server_id: &server_id,
|
||||
server_tcp_port,
|
||||
}.random_eph_port ();
|
||||
|
@ -338,7 +351,7 @@ impl GuiPort {
|
|||
|
||||
#[derive (serde::Serialize)]
|
||||
struct PortInfo <'a> {
|
||||
relay_addr: &'a str,
|
||||
// relay_addr: SocketAddr,
|
||||
server_id: &'a str,
|
||||
server_tcp_port: u16
|
||||
}
|
||||
|
@ -375,14 +388,16 @@ mod test {
|
|||
assert_eq! (port, 49408);
|
||||
|
||||
for (input, expected) in vec! [
|
||||
(("bogus_relay", "bogus_server", 22), 62350),
|
||||
(("real_relay", "bogus_server", 22), 61081),
|
||||
(("bogus_relay", "real_server", 22), 50513),
|
||||
(("bogus_relay", "bogus_server", 5900), 60730),
|
||||
(("127.0.0.1:4000", "bogus_server", 22), 51168),
|
||||
// The relay address is explicitly excluded from the eph port
|
||||
// computation in case I want to support connecting to a server
|
||||
// across multiple relays
|
||||
(("127.0.0.1:30380", "bogus_server", 22), 51168),
|
||||
(("127.0.0.1:4000", "real_server", 22), 53873),
|
||||
(("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 {
|
||||
relay_addr,
|
||||
server_id,
|
||||
server_tcp_port,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue