mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-19 17:55:37 +00:00
H3: make connection constructors infaillible
This commit is contained in:
@@ -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)))
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ impl ConnectionRef {
|
||||
uni_streams: IncomingUniStreams,
|
||||
bi_streams: IncomingBiStreams,
|
||||
settings: Settings,
|
||||
) -> Result<Self, ProtoError> {
|
||||
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,
|
||||
})),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,10 +50,14 @@ pub struct Connection {
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
pub fn with_settings(settings: Settings) -> Result<Self> {
|
||||
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<HeadersFrame> {
|
||||
@@ -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),
|
||||
|
||||
@@ -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)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user