Compare commits

..

No commits in common. "6c5dff4685e01beede0b5375ce34485ff0187195" and "e6cf9e2b72066a029d10f979bd5acea1308a3334" have entirely different histories.

1 changed files with 15 additions and 30 deletions

View File

@ -48,7 +48,6 @@ 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 {
@ -57,11 +56,8 @@ struct Port {
} }
impl Port { impl Port {
pub fn open_port ( pub fn open_port (&mut self, rt: &Runtime, connection_p2_p3: quinn::Connection)
&mut self, -> anyhow::Result <()>
rt: &Runtime,
connection_p2_p3: quinn::Connection,
) -> anyhow::Result <()>
{ {
let params = self.gui.get_params ()?; let params = self.gui.get_params ()?;
@ -136,10 +132,6 @@ 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);
@ -150,10 +142,6 @@ impl GuiClient <'_> {
}; };
self.ports.push (port); self.ports.push (port);
if self.ports.len () >= 5 {
self.but_add_port.deactivate ();
}
} }
} }
@ -200,17 +188,10 @@ 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);
@ -227,6 +208,10 @@ 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");
@ -276,6 +261,7 @@ 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 ();
@ -322,6 +308,7 @@ 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 ();
@ -351,7 +338,7 @@ impl GuiPort {
#[derive (serde::Serialize)] #[derive (serde::Serialize)]
struct PortInfo <'a> { struct PortInfo <'a> {
// relay_addr: SocketAddr, relay_addr: &'a str,
server_id: &'a str, server_id: &'a str,
server_tcp_port: u16 server_tcp_port: u16
} }
@ -388,16 +375,14 @@ mod test {
assert_eq! (port, 49408); assert_eq! (port, 49408);
for (input, expected) in vec! [ for (input, expected) in vec! [
(("127.0.0.1:4000", "bogus_server", 22), 51168), (("bogus_relay", "bogus_server", 22), 62350),
// The relay address is explicitly excluded from the eph port (("real_relay", "bogus_server", 22), 61081),
// computation in case I want to support connecting to a server (("bogus_relay", "real_server", 22), 50513),
// across multiple relays (("bogus_relay", "bogus_server", 5900), 60730),
(("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 { let input = PortInfo {
relay_addr,
server_id, server_id,
server_tcp_port, server_tcp_port,
}; };