From 8ff732dc691b48e2e9a27634c9cb4335c766cccd Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Thu, 15 Jun 2023 21:24:17 +0800 Subject: [PATCH 1/3] How to create customed WebtransportSession #195 --- h3-webtransport/src/server.rs | 54 +++++++++++++++++++++++++++++++++++ h3-webtransport/src/stream.rs | 5 ++-- h3/src/server.rs | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/h3-webtransport/src/server.rs b/h3-webtransport/src/server.rs index fd24ed4d..4e103efd 100644 --- a/h3-webtransport/src/server.rs +++ b/h3-webtransport/src/server.rs @@ -269,6 +269,22 @@ pin_project! { } } +impl<'a, C: quic::Connection, B: Buf> OpenBi<'a, C, B> { + #[allow(missing_docs)] + pub fn new(opener: &'a Mutex, session_id: SessionId) -> Self { + Self { + opener, + stream: None, + session_id, + } + } + #[allow(missing_docs)] + pub fn set_stream(mut self, stream: impl Into>>) -> Self { + self.stream = stream.into(); + self + } +} + impl<'a, B, C> Future for OpenBi<'a, C, B> where C: quic::Connection, @@ -312,6 +328,21 @@ pin_project! { session_id: SessionId, } } +impl<'a, C: quic::Connection, B: Buf> OpenUni<'a, C, B> { + #[allow(missing_docs)] + pub fn new(opener: &'a Mutex, session_id: SessionId) -> Self { + Self { + opener, + stream: None, + session_id, + } + } + #[allow(missing_docs)] + pub fn set_stream(mut self, stream: impl Into>>) -> Self { + self.stream = stream.into(); + self + } +} impl<'a, C, B> Future for OpenUni<'a, C, B> where @@ -368,6 +399,19 @@ where conn: &'a Mutex>, _marker: PhantomData, } +impl<'a, C, B> ReadDatagram<'a, C, B> +where + C: quic::Connection, + B: Buf, +{ + #[allow(missing_docs)] + pub fn new(conn: &'a Mutex>) -> Self { + Self { + conn, + _marker: PhantomData, + } + } +} impl<'a, C, B> Future for ReadDatagram<'a, C, B> where @@ -400,6 +444,16 @@ where conn: &'a Mutex>, } +impl<'a, C, B> AcceptUni<'a, C, B> +where + C: quic::Connection, + B: Buf, +{ + #[allow(missing_docs)] + pub fn new(conn: &'a Mutex>) -> Self { + Self { conn } + } +} impl<'a, C, B> Future for AcceptUni<'a, C, B> where C: quic::Connection, diff --git a/h3-webtransport/src/stream.rs b/h3-webtransport/src/stream.rs index 4f29f6f5..b0ace0e1 100644 --- a/h3-webtransport/src/stream.rs +++ b/h3-webtransport/src/stream.rs @@ -91,7 +91,7 @@ impl std::fmt::Debug for SendStream { impl SendStream { #[allow(missing_docs)] - pub(crate) fn new(stream: BufRecvStream) -> Self { + pub fn new(stream: BufRecvStream) -> Self { Self { stream } } } @@ -210,7 +210,8 @@ pin_project! { } impl BidiStream { - pub(crate) fn new(stream: BufRecvStream) -> Self { + #[allow(missing_docs)] + pub fn new(stream: BufRecvStream) -> Self { Self { stream } } } diff --git a/h3/src/server.rs b/h3/src/server.rs index 3e220f1e..42ee7b86 100644 --- a/h3/src/server.rs +++ b/h3/src/server.rs @@ -820,6 +820,19 @@ pin_project! { } } +impl<'a, C, B> ReadDatagram<'a, C, B> +where + C: quic::Connection, + B: Buf,{ + #[allow(missing_docs)] + pub fn new(conn: &'a mut Connection) -> Self { + Self { + conn, + _marker: PhantomData, + } + } + } + impl<'a, C, B> Future for ReadDatagram<'a, C, B> where C: quic::Connection + RecvDatagramExt, From 049622d1d27d659eaf66b427446fef99b02707ba Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Thu, 15 Jun 2023 21:26:32 +0800 Subject: [PATCH 2/3] Rename set_stream to with_stream --- h3-webtransport/src/server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h3-webtransport/src/server.rs b/h3-webtransport/src/server.rs index 4e103efd..ce64d34f 100644 --- a/h3-webtransport/src/server.rs +++ b/h3-webtransport/src/server.rs @@ -279,7 +279,7 @@ impl<'a, C: quic::Connection, B: Buf> OpenBi<'a, C, B> { } } #[allow(missing_docs)] - pub fn set_stream(mut self, stream: impl Into>>) -> Self { + pub fn with_stream(mut self, stream: impl Into>>) -> Self { self.stream = stream.into(); self } @@ -338,7 +338,7 @@ impl<'a, C: quic::Connection, B: Buf> OpenUni<'a, C, B> { } } #[allow(missing_docs)] - pub fn set_stream(mut self, stream: impl Into>>) -> Self { + pub fn with_stream(mut self, stream: impl Into>>) -> Self { self.stream = stream.into(); self } From 84559466b56ee63fa28a7f006dfe0457ba692811 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Thu, 15 Jun 2023 21:31:00 +0800 Subject: [PATCH 3/3] cargo fmt --- h3-webtransport/src/server.rs | 4 ++-- h3/src/server.rs | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/h3-webtransport/src/server.rs b/h3-webtransport/src/server.rs index ce64d34f..6a2cf780 100644 --- a/h3-webtransport/src/server.rs +++ b/h3-webtransport/src/server.rs @@ -279,7 +279,7 @@ impl<'a, C: quic::Connection, B: Buf> OpenBi<'a, C, B> { } } #[allow(missing_docs)] - pub fn with_stream(mut self, stream: impl Into>>) -> Self { + pub fn with_stream(mut self, stream: impl Into>>) -> Self { self.stream = stream.into(); self } @@ -338,7 +338,7 @@ impl<'a, C: quic::Connection, B: Buf> OpenUni<'a, C, B> { } } #[allow(missing_docs)] - pub fn with_stream(mut self, stream: impl Into>>) -> Self { + pub fn with_stream(mut self, stream: impl Into>>) -> Self { self.stream = stream.into(); self } diff --git a/h3/src/server.rs b/h3/src/server.rs index 42ee7b86..d64a3d9b 100644 --- a/h3/src/server.rs +++ b/h3/src/server.rs @@ -822,16 +822,17 @@ pin_project! { impl<'a, C, B> ReadDatagram<'a, C, B> where - C: quic::Connection, - B: Buf,{ - #[allow(missing_docs)] - pub fn new(conn: &'a mut Connection) -> Self { - Self { - conn, - _marker: PhantomData, - } - } + C: quic::Connection, + B: Buf, +{ + #[allow(missing_docs)] + pub fn new(conn: &'a mut Connection) -> Self { + Self { + conn, + _marker: PhantomData, } + } +} impl<'a, C, B> Future for ReadDatagram<'a, C, B> where