♻️ refactor

main
_ 2021-10-10 16:36:06 +00:00
parent a906472add
commit 88fab23871
1 changed files with 7 additions and 18 deletions

View File

@ -23,30 +23,20 @@ async fn main () -> anyhow::Result <()> {
tracing_subscriber::fmt::init ();
let opt = Opt::from_args ();
let conf = opt.into_config ().await?;
//let conf = opt.into_config ();
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 endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
debug! ("Connecting to relay server");
let client_id = opt.client_id.unwrap_or_else (|| "bogus_client".to_string ());
let quinn::NewConnection {
connection,
..
} = protocol::p2_connect_to_p3 (&endpoint, &relay_addr, &client_id).await?;
} = protocol::p2_connect_to_p3 (&endpoint, &conf.relay_addr, &conf.client_id).await?;
// End of per-client stuff
// Beginning of per-port stuff
let listener = TcpListener::bind (("127.0.0.1", conf.client_tcp_port)).await?;
let server_id = opt.server_id.unwrap_or_else (|| "bogus_server".to_string ());
let client_tcp_port = opt.client_tcp_port.unwrap_or (30381);
let server_tcp_port = opt.server_tcp_port.unwrap_or (30382);
let listener = TcpListener::bind (("127.0.0.1", client_tcp_port)).await?;
debug! ("Accepting local TCP connections from P1 at {}", conf.client_tcp_port);
// End of per-port stuff
// Beginning of per-connection stuff
@ -56,7 +46,8 @@ async fn main () -> anyhow::Result <()> {
while running {
let (tcp_socket, _) = listener.accept ().await?;
let connection = connection.clone ();
let server_id = server_id.clone ();
let server_id = conf.server_id.clone ();
let server_tcp_port = conf.server_tcp_port;
tokio::spawn (async move {
let (local_recv, local_send) = tcp_socket.into_split ();
@ -85,8 +76,6 @@ async fn main () -> anyhow::Result <()> {
Ok::<_, anyhow::Error> (())
});
debug! ("Accepting local TCP connections from P1 at {}", client_tcp_port);
task_tcp_server.await??;
Ok (())