♻️ refactor: clean up client to match the end server style

main
_ 2021-10-10 16:33:14 +00:00
parent fc6a9c9e1e
commit a906472add
1 changed files with 36 additions and 0 deletions

View File

@ -24,6 +24,8 @@ async fn main () -> anyhow::Result <()> {
let opt = Opt::from_args (); let opt = Opt::from_args ();
//let conf = opt.into_config ();
let server_cert = tokio::fs::read ("ptth_quic_output/quic_server.crt").await?; let server_cert = tokio::fs::read ("ptth_quic_output/quic_server.crt").await?;
let relay_addr = opt.relay_addr.unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?; let relay_addr = opt.relay_addr.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 endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
@ -89,3 +91,37 @@ async fn main () -> anyhow::Result <()> {
Ok (()) Ok (())
} }
/// A filled-out config for constructing a P2 client
#[derive (Clone)]
pub struct Config {
client_tcp_port: u16,
server_tcp_port: u16,
client_id: String,
server_id: String,
relay_addr: SocketAddr,
relay_cert: Vec <u8>,
}
impl Opt {
pub async fn into_config (self) -> anyhow::Result <Config> {
let client_tcp_port = self.client_tcp_port.unwrap_or (30381);
let server_tcp_port = self.server_tcp_port.unwrap_or (30382);
let client_id = self.client_id.unwrap_or_else (|| "bogus_client".to_string ());
let server_id = self.server_id.unwrap_or_else (|| "bogus_server".to_string ());
let relay_addr = self.relay_addr.unwrap_or_else (|| String::from ("127.0.0.1:30380")).parse ()?;
// Begin I/O
let relay_cert = tokio::fs::read ("ptth_quic_output/quic_server.crt").await?;
Ok (Config {
client_tcp_port,
server_tcp_port,
client_id,
server_id,
relay_addr,
relay_cert,
})
}
}