♻️ 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 <()> { pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
let opt = Arc::new (Opt::from_iter (args)); let opt = Arc::new (Opt::from_iter (args));
let server_cert = match opt.cert_url.as_ref () { let server_cert: Vec <u8> = match opt.cert_url.as_ref () {
Some (url) => reqwest::get (url).await?.bytes ().await?, Some (url) => reqwest::get (url).await?.bytes ().await?.into_iter ().collect (),
None => tokio::fs::read ("quic_server.crt").await?.into (), 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 relay_addr: SocketAddr = 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 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"); trace! ("Connecting to relay server");
@ -33,7 +39,7 @@ pub async fn main (args: &[OsString]) -> anyhow::Result <()> {
let quinn::NewConnection { let quinn::NewConnection {
mut bi_streams, 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"); debug! ("Connected to relay server");
trace! ("Accepting bi streams from P3"); 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 ( async fn handle_bi_stream (
opt: Arc <Opt>, opt: Arc <Opt>,
relay_send: quinn::SendStream, relay_send: quinn::SendStream,