♻️ refactor
parent
88fab23871
commit
6fbe35379b
|
@ -25,14 +25,37 @@ async fn main () -> anyhow::Result <()> {
|
|||
let opt = Opt::from_args ();
|
||||
let conf = opt.into_config ().await?;
|
||||
|
||||
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
|
||||
let client = P2Client::connect (conf)?;
|
||||
client.run ().await?;
|
||||
|
||||
debug! ("Connecting to relay server");
|
||||
Ok (())
|
||||
}
|
||||
|
||||
pub struct P2Client {
|
||||
endpoint: quinn::Endpoint,
|
||||
conf: Arc <Config>,
|
||||
}
|
||||
|
||||
impl P2Client {
|
||||
pub fn connect (conf: Config) -> anyhow::Result <Self> {
|
||||
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
|
||||
let conf = Arc::new (conf);
|
||||
|
||||
Ok (Self {
|
||||
endpoint,
|
||||
conf,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn run (&self) -> anyhow::Result <()> {
|
||||
debug! ("P2 client connecting to P3 relay server");
|
||||
|
||||
let conf = Arc::clone (&self.conf);
|
||||
|
||||
let quinn::NewConnection {
|
||||
connection,
|
||||
..
|
||||
} = protocol::p2_connect_to_p3 (&endpoint, &conf.relay_addr, &conf.client_id).await?;
|
||||
} = protocol::p2_connect_to_p3 (&self.endpoint, &conf.relay_addr, &conf.client_id).await?;
|
||||
|
||||
let listener = TcpListener::bind (("127.0.0.1", conf.client_tcp_port)).await?;
|
||||
|
||||
|
@ -80,6 +103,7 @@ async fn main () -> anyhow::Result <()> {
|
|||
|
||||
Ok (())
|
||||
}
|
||||
}
|
||||
|
||||
/// A filled-out config for constructing a P2 client
|
||||
#[derive (Clone)]
|
||||
|
|
|
@ -25,7 +25,7 @@ pub async fn main (args: &[OsString], shutdown_rx: Option <watch::Receiver <bool
|
|||
let opt = Opt::from_iter (args);
|
||||
let conf = opt.into_config ().await?;
|
||||
|
||||
let end_server = Arc::new (P4EndServer::connect (conf).await?);
|
||||
let end_server = Arc::new (P4EndServer::connect (conf)?);
|
||||
|
||||
let run_task = {
|
||||
let end_server = Arc::clone (&end_server);
|
||||
|
@ -86,7 +86,6 @@ impl Opt {
|
|||
}
|
||||
}
|
||||
|
||||
/// An end server that is connected to its relay server
|
||||
pub struct P4EndServer {
|
||||
endpoint: quinn::Endpoint,
|
||||
conf: Arc <Config>,
|
||||
|
@ -95,7 +94,7 @@ pub struct P4EndServer {
|
|||
}
|
||||
|
||||
impl P4EndServer {
|
||||
pub async fn connect (conf: Config) -> anyhow::Result <Self> {
|
||||
pub fn connect (conf: Config) -> anyhow::Result <Self> {
|
||||
trace! ("P4 end server making its QUIC endpoint");
|
||||
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue