diff --git a/gm-quic/examples/client.rs b/gm-quic/examples/client.rs index d9c3a197..acbdb462 100644 --- a/gm-quic/examples/client.rs +++ b/gm-quic/examples/client.rs @@ -27,11 +27,12 @@ struct Arguments { fn main() { let args = Arguments::parse(); let code = { - if let Err(e) = run(args) { - eprintln!("ERROR: {e}"); - 1 - } else { - 0 + match run(args) { + Err(e) => { + eprintln!("ERROR: {e}"); + 1 + } + _ => 0, } }; ::std::process::exit(code); diff --git a/gm-quic/examples/server.rs b/gm-quic/examples/server.rs index c346a71a..07eef1ed 100644 --- a/gm-quic/examples/server.rs +++ b/gm-quic/examples/server.rs @@ -21,11 +21,12 @@ struct Opt { fn main() { let opt = Opt::parse(); let code = { - if let Err(e) = run(opt) { - eprintln!("ERROR: {e}"); - 1 - } else { - 0 + match run(opt) { + Err(e) => { + eprintln!("ERROR: {e}"); + 1 + } + _ => 0, } }; ::std::process::exit(code); @@ -44,7 +45,7 @@ async fn run(options: Opt) -> Result<(), Box> { .with_supported_versions([0x00000001u32]) .without_cert_verifier() // .keep_alive() - .with_single_cert(options.cert, options.key) + .with_single_cert(options.cert.as_path(), options.key.as_path()) .listen(options.bind)?; while let Ok((_conn, pathway)) = server.accept().await { diff --git a/gm-quic/src/util.rs b/gm-quic/src/util.rs index 1c86f530..dd0cd0c9 100644 --- a/gm-quic/src/util.rs +++ b/gm-quic/src/util.rs @@ -2,38 +2,36 @@ use std::path::Path; use rustls::pki_types::{pem::PemObject, CertificateDer, PrivateKeyDer}; -pub struct Certificate(Vec>); - -impl From>> for Certificate { - fn from(cert: Vec>) -> Self { - Self(cert) - } -} - pub trait ToCertificate { fn to_certificate(self) -> Vec>; } -impl ToCertificate for Certificate { +impl ToCertificate for Vec> { fn to_certificate(self) -> Vec> { - self.0 + self } } -impl> ToCertificate for P { +impl ToCertificate for &Path { fn to_certificate(self) -> Vec> { - CertificateDer::pem_file_iter(self.as_ref()) + CertificateDer::pem_file_iter(self) .expect("failed to open cert file") .collect::, _>>() .expect("failed to parse cert file") } } -pub struct PrivateKey(PrivateKeyDer<'static>); +impl ToCertificate for &[u8] { + fn to_certificate(self) -> Vec> { + CertificateDer::pem_slice_iter(self) + .collect::, _>>() + .expect("failed to parse cert file") + } +} -impl From> for PrivateKey { - fn from(key: PrivateKeyDer<'static>) -> Self { - Self(key) +impl ToCertificate for &[u8; N] { + fn to_certificate(self) -> Vec> { + <&[u8]>::to_certificate(self) } } @@ -41,14 +39,26 @@ pub trait ToPrivateKey { fn to_private_key(self) -> PrivateKeyDer<'static>; } -impl ToPrivateKey for PrivateKey { +impl ToPrivateKey for PrivateKeyDer<'static> { + fn to_private_key(self) -> PrivateKeyDer<'static> { + self + } +} + +impl ToPrivateKey for &Path { + fn to_private_key(self) -> PrivateKeyDer<'static> { + PrivateKeyDer::from_pem_file(self).expect("failed to parse private key file") + } +} + +impl ToPrivateKey for &[u8] { fn to_private_key(self) -> PrivateKeyDer<'static> { - self.0 + PrivateKeyDer::from_pem_slice(self).expect("failed to parse private key file") } } -impl> ToPrivateKey for P { +impl ToPrivateKey for &[u8; N] { fn to_private_key(self) -> PrivateKeyDer<'static> { - PrivateKeyDer::from_pem_file(self.as_ref()).expect("failed to parse private key file") + <&[u8]>::to_private_key(self) } } diff --git a/h3-shim/examples/h3-server.rs b/h3-shim/examples/h3-server.rs index fb4b4382..14021225 100644 --- a/h3-shim/examples/h3-server.rs +++ b/h3-shim/examples/h3-server.rs @@ -95,7 +95,7 @@ pub async fn run(opt: Opt) -> Result<(), Box futures::Stream for Receiver { if queue.capacity() == 0 { return Poll::Ready(None); } - if let Some(item) = queue.pop_front() { - self.inner.write_waker.wake(); - Poll::Ready(Some(item)) - } else { - self.inner.read_waker.register(cx.waker()); - Poll::Pending + match queue.pop_front() { + Some(item) => { + self.inner.write_waker.wake(); + Poll::Ready(Some(item)) + } + _ => { + self.inner.read_waker.register(cx.waker()); + Poll::Pending + } } } } diff --git a/qconnection/src/builder.rs b/qconnection/src/builder.rs index e9f43f4e..9022b34c 100644 --- a/qconnection/src/builder.rs +++ b/qconnection/src/builder.rs @@ -419,7 +419,7 @@ impl ComponentsReady { } } -fn accpet_transport_parameters(components: &Components) -> impl Future + Send { +fn accpet_transport_parameters(components: &Components) -> impl Future + Send + use<> { let params = components.parameters.clone(); let streams = components.spaces.data().streams().clone(); let cid_registry = components.cid_registry.clone(); diff --git a/qconnection/src/lib.rs b/qconnection/src/lib.rs index 580fa5cf..24a946b3 100644 --- a/qconnection/src/lib.rs +++ b/qconnection/src/lib.rs @@ -175,7 +175,7 @@ pub struct Components { impl Components { pub fn open_bi_stream( &self, - ) -> impl Future>> + Send + ) -> impl Future>> + Send + use<> { let params = self.parameters.clone(); let streams = self.spaces.data().streams().clone(); @@ -193,7 +193,7 @@ impl Components { pub fn open_uni_stream( &self, - ) -> impl Future>> + Send { + ) -> impl Future>> + Send + use<> { let params = self.parameters.clone(); let streams = self.spaces.data().streams().clone(); let send_notify = self.send_notify.clone(); @@ -209,7 +209,7 @@ impl Components { pub fn accept_bi_stream( &self, - ) -> impl Future>> + Send + ) -> impl Future>> + Send + use<> { let params = self.parameters.clone(); let streams = self.spaces.data().streams().clone(); @@ -227,7 +227,7 @@ impl Components { pub fn accept_uni_stream( &self, - ) -> impl Future>> + Send { + ) -> impl Future>> + Send + use<> { let streams = self.spaces.data().streams().clone(); async move { Ok(Some(streams.accept_uni().await?)) } } @@ -236,7 +236,9 @@ impl Components { self.spaces.data().datagrams().reader() } - pub fn unreliable_writer(&self) -> impl Future> + Send { + pub fn unreliable_writer( + &self, + ) -> impl Future> + Send + use<> { let params = self.parameters.clone(); let datagrams = self.spaces.data().datagrams().clone(); async move { diff --git a/qconnection/src/path/burst.rs b/qconnection/src/path/burst.rs index b8dbebf1..b56a365f 100644 --- a/qconnection/src/path/burst.rs +++ b/qconnection/src/path/burst.rs @@ -48,7 +48,7 @@ impl Burst { fn prepare_buffers<'b>( &self, buffers: &'b mut Vec>, - ) -> io::Result> { + ) -> io::Result + use<'b>> { let max_segments = self.path.interface.max_segments()?; let max_segment_size = self.path.interface.max_segment_size()?; diff --git a/qconnection/src/path/idle.rs b/qconnection/src/path/idle.rs index 644c3967..1580297b 100644 --- a/qconnection/src/path/idle.rs +++ b/qconnection/src/path/idle.rs @@ -19,7 +19,10 @@ impl super::Path { } } - pub fn idle_timeout(self: &Arc, components: &Components) -> impl Future { + pub fn idle_timeout( + self: &Arc, + components: &Components, + ) -> impl Future + use<> { let parameters = components.parameters.clone(); let this = self.clone(); async move { diff --git a/qconnection/src/tls.rs b/qconnection/src/tls.rs index 1264bc74..6434e41e 100644 --- a/qconnection/src/tls.rs +++ b/qconnection/src/tls.rs @@ -215,7 +215,7 @@ impl ArcTlsSession { /// Start the TLS handshake, automatically upgrade the keys, and transmit tls data. #[tracing::instrument(level = "trace", skip(components))] -pub fn keys_upgrade(components: &Components) -> impl Future + Send { +pub fn keys_upgrade(components: &Components) -> impl Future + Send + use<> { let crypto_streams: [&CryptoStream; 3] = [ components.spaces.initial().crypto_stream(), components.spaces.handshake().crypto_stream(), diff --git a/qrecovery/src/journal/sent.rs b/qrecovery/src/journal/sent.rs index 7394f793..ec4e9ef9 100644 --- a/qrecovery/src/journal/sent.rs +++ b/qrecovery/src/journal/sent.rs @@ -212,12 +212,12 @@ impl RotateGuard<'_, T> { } /// Called when the packet sent is acked by peer, return the frames in that packet. - pub fn on_pkt_acked(&mut self, pn: u64) -> impl Iterator + '_ { + pub fn on_pkt_acked(&mut self, pn: u64) -> impl Iterator + '_ + use<'_, T> { self.inner.on_pkt_acked(pn) } /// Called when the packet sent may lost, reutrn the frames in that packet. - pub fn may_loss_pkt(&mut self, pn: u64) -> impl Iterator + '_ { + pub fn may_loss_pkt(&mut self, pn: u64) -> impl Iterator + '_ + use<'_, T> { self.inner.may_loss_pkt(pn) }