add `--cert-url` to GUI client

main
Trisha 2021-10-01 12:19:23 -05:00
parent 3a4d7c934e
commit f7bd179bba
3 changed files with 17 additions and 5 deletions

5
Cargo.lock generated
View File

@ -1209,6 +1209,7 @@ dependencies = [
"fltk", "fltk",
"quic_demo", "quic_demo",
"quinn", "quinn",
"reqwest",
"structopt", "structopt",
"tokio", "tokio",
"tracing", "tracing",
@ -1500,9 +1501,9 @@ dependencies = [
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.2" version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22"
dependencies = [ dependencies = [
"base64", "base64",
"bytes", "bytes",

View File

@ -12,6 +12,7 @@ anyhow = "1.0.38"
fltk = "1.1.1" fltk = "1.1.1"
quic_demo = { path = "../quic_demo" } quic_demo = { path = "../quic_demo" }
quinn = "0.7.2" quinn = "0.7.2"
reqwest = "0.11.4"
structopt = "0.3.20" structopt = "0.3.20"
tokio = { version = "1.8.1", features = ["full"] } tokio = { version = "1.8.1", features = ["full"] }
tracing-subscriber = "0.2.16" tracing-subscriber = "0.2.16"

View File

@ -25,6 +25,8 @@ struct Opt {
relay_addr: Option <String>, relay_addr: Option <String>,
#[structopt (long)] #[structopt (long)]
client_id: Option <PeerId>, client_id: Option <PeerId>,
#[structopt (long)]
cert_url: Option <String>,
} }
#[derive (Clone, Copy)] #[derive (Clone, Copy)]
@ -103,8 +105,15 @@ fn main () -> anyhow::Result <()> {
wind.show (); wind.show ();
let connection_p2_p3 = rt.block_on (async move { let connection_p2_p3 = rt.block_on (async move {
let server_cert = tokio::fs::read ("quic_server.crt").await?; let server_cert = match opt.cert_url.as_ref () {
let relay_addr = opt.relay_addr.unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?; Some (url) => reqwest::get (url).await?.bytes ().await?,
None => tokio::fs::read ("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");
@ -114,7 +123,8 @@ fn main () -> anyhow::Result <()> {
let quinn::NewConnection { let quinn::NewConnection {
connection, connection,
.. ..
} = protocol::p2_connect_to_p3 (&endpoint, &relay_addr, &client_id).await?; } = protocol::p2_connect_to_p3 (&endpoint, &relay_addr, &client_id).await
.context ("P2 can't connect to P3")?;
Ok::<_, anyhow::Error> (connection) Ok::<_, anyhow::Error> (connection)
})?; })?;