Skip to content

Commit

Permalink
quic config: add new with tls_context_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
yayanyang committed Apr 22, 2024
1 parent 46352c9 commit c810116
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
20 changes: 17 additions & 3 deletions crates/ext/src/net/quic/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{ops, time::Duration};

use boring::ssl::SslContextBuilder;

/// An wrapper for quiche [`Config`](quiche::Config).
pub struct Config {
quiche_config: quiche::Config,
Expand All @@ -26,15 +28,22 @@ impl ops::DerefMut for Config {
}

impl Config {
/// Create new quic config instance with default config.
pub fn new() -> Self {
pub fn new_with_ssl_cx_builder(ssl_cx_builder: SslContextBuilder) -> Self {
Config::with_quiche_config(
quiche::Config::with_boring_ssl_ctx_builder(quiche::PROTOCOL_VERSION, ssl_cx_builder)
.unwrap(),
)
}

pub fn with_quiche_config(quiche_config: quiche::Config) -> Self {
let mut config = Config {
quiche_config: quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap(),
quiche_config,
ping_packet_send_interval: None,
max_recv_udp_payload_size: 65527,
max_send_udp_payload_size: 1200,
};

config.set_initial_max_data(10_000_000);
config.set_initial_max_stream_data_bidi_local(1024 * 1024);
config.set_initial_max_stream_data_bidi_remote(1024 * 1024);
config.set_initial_max_streams_bidi(100);
Expand All @@ -43,6 +52,11 @@ impl Config {
config
}

/// Create new quic config instance with default config.
pub fn new() -> Self {
Config::with_quiche_config(quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap())
}

/// Sets the `max_idle_timeout` transport parameter, in milliseconds.
///
/// The default value is infinite, that is, no timeout is used.
Expand Down
17 changes: 16 additions & 1 deletion crates/ext/src/net/quic/rasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Drop for QuicConnFinalizer {

/// A builder for client side [`QuicConn`].
pub struct QuicConnector {
udp_group: UdpGroup,
pub udp_group: UdpGroup,
conn_state: QuicConnState,
max_send_udp_payload_size: usize,
}
Expand Down Expand Up @@ -200,6 +200,21 @@ impl QuicConn {
}
}

/// Closes the connection with the given error and reason.
///
/// The `app` parameter specifies whether an application close should be
/// sent to the peer. Otherwise a normal connection close is sent.
///
/// If `app` is true but the connection is not in a state that is safe to
/// send an application error (not established nor in early data), in
/// accordance with [RFC
/// 9000](https://www.rfc-editor.org/rfc/rfc9000.html#section-10.2.3-3), the
/// error code is changed to APPLICATION_ERROR and the reason phrase is
/// cleared.
pub async fn close(&self) -> io::Result<()> {
self.inner.0.close(false, 0, b"").await
}

/// Accepts a new incoming stream via this connection.
///
/// Returns None, if the connection is draining or has been closed.
Expand Down

0 comments on commit c810116

Please sign in to comment.