From bf0dd08024475755259b3e2a88d4e3f7cdaefb51 Mon Sep 17 00:00:00 2001 From: stammw Date: Wed, 26 Feb 2020 13:23:50 +0100 Subject: [PATCH] H3: make connection constructors infaillible --- quinn-h3/src/client.rs | 5 ++--- quinn-h3/src/connection.rs | 8 ++++---- quinn-h3/src/proto/connection.rs | 16 ++++++++++------ quinn-h3/src/server.rs | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/quinn-h3/src/client.rs b/quinn-h3/src/client.rs index 6603f9cbb..4f2254a30 100644 --- a/quinn-h3/src/client.rs +++ b/quinn-h3/src/client.rs @@ -207,8 +207,7 @@ impl Connecting { .. } = new_conn; let conn_ref = - ConnectionRef::new(connection, Side::Client, uni_streams, bi_streams, settings) - .expect("error in h3 settings"); // FIXME return an error type + ConnectionRef::new(connection, Side::Client, uni_streams, bi_streams, settings); tokio::spawn(ConnectionDriver(conn_ref.clone())); Ok((Connection(conn_ref), ZeroRttAccepted(zero_rtt))) } @@ -232,7 +231,7 @@ impl Future for Connecting { uni_streams, bi_streams, self.settings.clone(), - )?; + ); tokio::spawn(ConnectionDriver(conn_ref.clone())); Poll::Ready(Ok(Connection(conn_ref))) } diff --git a/quinn-h3/src/connection.rs b/quinn-h3/src/connection.rs index b97fe9095..1a256b778 100644 --- a/quinn-h3/src/connection.rs +++ b/quinn-h3/src/connection.rs @@ -76,8 +76,8 @@ impl ConnectionRef { uni_streams: IncomingUniStreams, bi_streams: IncomingBiStreams, settings: Settings, - ) -> Result { - Ok(Self { + ) -> Self { + Self { quic: quic.clone(), h3: Arc::new(Mutex::new(ConnectionInner { side, @@ -85,7 +85,7 @@ impl ConnectionRef { incoming_bi: bi_streams, incoming_uni: uni_streams, pending_uni: VecDeque::with_capacity(3), - inner: Connection::with_settings(settings)?, + inner: Connection::with_settings(settings), requests: VecDeque::with_capacity(16), requests_task: None, recv_control: None, @@ -99,7 +99,7 @@ impl ConnectionRef { ], closed: false, })), - }) + } } } diff --git a/quinn-h3/src/proto/connection.rs b/quinn-h3/src/proto/connection.rs index 94c23abb6..5e18d1f28 100644 --- a/quinn-h3/src/proto/connection.rs +++ b/quinn-h3/src/proto/connection.rs @@ -50,10 +50,14 @@ pub struct Connection { } impl Connection { - pub fn with_settings(settings: Settings) -> Result { + pub fn with_settings(settings: Settings) -> Self { let mut decoder_table = DynamicTable::new(); - decoder_table.set_max_blocked(settings.qpack_max_blocked_streams() as usize)?; - decoder_table.set_max_size(settings.qpack_max_table_capacity() as usize)?; + decoder_table + .set_max_blocked(settings.qpack_max_blocked_streams() as usize) + .expect("set max blocked streams"); + decoder_table + .set_max_size(settings.qpack_max_table_capacity() as usize) + .expect("set max table size"); let mut pending_control = BytesMut::with_capacity(128); settings.to_frame().encode(&mut pending_control); @@ -63,14 +67,14 @@ impl Connection { BytesMut::with_capacity(2048), ]; - Ok(Self { + Self { decoder_table, pending_streams, remote_settings: None, encoder_table: DynamicTable::new(), requests_in_flight: VecDeque::with_capacity(32), go_away: false, - }) + } } pub fn encode_header(&mut self, stream_id: StreamId, headers: Header) -> Result { @@ -375,7 +379,7 @@ mod tests { let mut settings = Settings::new(); settings.set_qpack_max_blocked_streams(42).unwrap(); settings.set_qpack_max_table_capacity(2048).unwrap(); - let mut server = Connection::with_settings(settings).expect("create server"); + let mut server = Connection::with_settings(settings); assert_matches!( server.decode_header(StreamId(1), &encoded), diff --git a/quinn-h3/src/server.rs b/quinn-h3/src/server.rs index 3fca1ca8b..552f59e7a 100644 --- a/quinn-h3/src/server.rs +++ b/quinn-h3/src/server.rs @@ -158,7 +158,7 @@ impl Future for Connecting { uni_streams, bi_streams, self.settings.clone(), - )?; + ); tokio::spawn(ConnectionDriver(conn_ref.clone())); Poll::Ready(Ok(IncomingRequest(conn_ref))) }