@@ -64,25 +64,55 @@ pub struct Config {
6464 /// Timeout for the initial handshake when establishing a connection.
6565 /// The actual timeout is the minimum of this and the [`Config::max_idle_timeout`].
6666 pub handshake_timeout : u32 ,
67+
6768 /// Maximum duration of inactivity in ms to accept before timing out the connection.
6869 pub max_idle_timeout : u32 ,
70+
6971 /// Period of inactivity before sending a keep-alive packet.
7072 /// Must be set lower than the idle_timeout of both
7173 /// peers to be effective.
7274 ///
7375 /// See [`quinn::TransportConfig::keep_alive_interval`] for more
7476 /// info.
7577 pub keep_alive_interval : u32 ,
78+
7679 /// Maximum number of incoming bidirectional streams that may be open
7780 /// concurrently by the remote peer.
7881 pub max_concurrent_stream_limit : u32 ,
7982
80- /// Max unacknowledged data in bytes that may be sent on a single stream.
83+ /// Maximum number of bytes the peer may transmit without acknowledgement on any one stream
84+ /// before becoming blocked.
85+ ///
86+ /// This should be set to at least the expected connection latency multiplied by the maximum
87+ /// desired throughput. Setting this smaller than `max_connection_data` helps ensure that a single
88+ /// stream doesn't monopolize receive buffers, which may otherwise occur if the application
89+ /// chooses not to read from a large stream for a time while still requiring data on other
90+ /// streams.
8191 pub max_stream_data : u32 ,
8292
83- /// Max unacknowledged data in bytes that may be sent in total on all streams
84- /// of a connection.
93+ /// Maximum number of bytes the peer may transmit across all streams of a connection before
94+ /// becoming blocked.
95+ ///
96+ /// This should be set to at least the expected connection latency multiplied by the maximum
97+ /// desired throughput. Larger values can be useful to allow maximum throughput within a
98+ /// stream while another is blocked.
8599 pub max_connection_data : u32 ,
100+
101+ /// OS socket receive buffer size.
102+ ///
103+ /// If this is set higher than the OS maximum, it will be clamped to the maximum allowed size.
104+ pub receive_buffer_size : u32 ,
105+
106+ /// OS socket send buffer size.
107+ ///
108+ /// If this is set higher than the OS maximum, it will be clamped to the maximum allowed size.
109+ pub send_buffer_size : u32 ,
110+ }
111+
112+ #[ derive( Clone , Copy ) ]
113+ pub struct SocketConfig {
114+ pub receive_buffer_size : u32 ,
115+ pub send_buffer_size : u32 ,
86116}
87117
88118/// Configuration used by the QUIC library
@@ -92,6 +122,7 @@ pub struct QuinnConfig {
92122 pub ( crate ) client_config : quinn:: ClientConfig ,
93123 pub ( crate ) server_config : quinn:: ServerConfig ,
94124 pub ( crate ) endpoint_config : quinn:: EndpointConfig ,
125+ pub ( crate ) socket_config : SocketConfig ,
95126}
96127
97128#[ napi]
@@ -113,20 +144,25 @@ impl TryFrom<Config> for QuinnConfig {
113144 max_connection_data,
114145 max_stream_data,
115146 handshake_timeout : _,
147+ receive_buffer_size,
148+ send_buffer_size,
116149 } = config;
117150
118151 let keypair = libp2p_identity:: Keypair :: from_protobuf_encoding ( & private_key_proto)
119152 . map_err ( |e| ConfigError :: InvalidPrivateKey ( e) ) ?;
120153
121154 let mut transport = quinn:: TransportConfig :: default ( ) ;
155+
156+ // Disable features we don't use/want
122157 // Disable uni-directional streams.
123158 transport. max_concurrent_uni_streams ( 0u32 . into ( ) ) ;
124- transport. max_concurrent_bidi_streams ( max_concurrent_stream_limit. into ( ) ) ;
125159 // Disable datagrams.
126160 transport. datagram_receive_buffer_size ( None ) ;
161+ transport. allow_spin ( false ) ;
162+
163+ transport. max_concurrent_bidi_streams ( max_concurrent_stream_limit. into ( ) ) ;
127164 transport. keep_alive_interval ( Some ( Duration :: from_millis ( keep_alive_interval. into ( ) ) ) ) ;
128165 transport. max_idle_timeout ( Some ( quinn:: VarInt :: from_u32 ( max_idle_timeout) . into ( ) ) ) ;
129- transport. allow_spin ( false ) ;
130166 transport. stream_receive_window ( max_stream_data. into ( ) ) ;
131167 transport. receive_window ( max_connection_data. into ( ) ) ;
132168 transport. mtu_discovery_config ( Default :: default ( ) ) ;
@@ -170,6 +206,10 @@ impl TryFrom<Config> for QuinnConfig {
170206 client_config,
171207 server_config,
172208 endpoint_config,
209+ socket_config : SocketConfig {
210+ receive_buffer_size,
211+ send_buffer_size,
212+ } ,
173213 } )
174214 }
175215}
0 commit comments