♻️ refactor: begin extacting a struct for the end server

main
_ 2021-10-10 14:36:01 +00:00
parent 61a74c29a6
commit 35cc1d49b7
1 changed files with 17 additions and 6 deletions

View File

@ -19,12 +19,18 @@ struct Opt {
pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
let opt = Arc::new (Opt::from_iter (args));
let server_cert = match opt.cert_url.as_ref () {
Some (url) => reqwest::get (url).await?.bytes ().await?,
None => tokio::fs::read ("quic_server.crt").await?.into (),
let server_cert: Vec <u8> = match opt.cert_url.as_ref () {
Some (url) => reqwest::get (url).await?.bytes ().await?.into_iter ().collect (),
None => tokio::fs::read ("quic_server.crt").await?,
};
let relay_addr = opt.relay_addr.clone ().unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?;
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
let relay_addr: SocketAddr = opt.relay_addr.clone ().unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?;
let end_server = P4EndServer {
relay_addr: relay_addr,
server_cert: server_cert,
};
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&end_server.server_cert])?;
trace! ("Connecting to relay server");
@ -33,7 +39,7 @@ pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
let quinn::NewConnection {
mut bi_streams,
..
} = protocol::p4_connect_to_p3 (&endpoint, &relay_addr, &server_id).await?;
} = protocol::p4_connect_to_p3 (&endpoint, &end_server.relay_addr, &server_id).await?;
debug! ("Connected to relay server");
trace! ("Accepting bi streams from P3");
@ -45,6 +51,11 @@ pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
}
}
struct P4EndServer {
relay_addr: SocketAddr,
server_cert: Vec <u8>,
}
async fn handle_bi_stream (
opt: Arc <Opt>,
relay_send: quinn::SendStream,