pub struct Config { /* private fields */ }
Expand description
Yamux configuration.
The default configuration values are as follows:
- max. for the total receive window size across all streams of a connection = 1 GiB
- max. number of streams = 512
- read after close = true
- split send size = 16 KiB
Implementations§
Source§impl Config
impl Config
Sourcepub fn set_max_connection_receive_window(
&mut self,
n: Option<usize>,
) -> &mut Self
pub fn set_max_connection_receive_window( &mut self, n: Option<usize>, ) -> &mut Self
Set the upper limit for the total receive window size across all streams of a connection.
Must be >= 256 KiB * max_num_streams
to allow each stream at least the Yamux default
window size.
The window of a stream starts at 256 KiB and is increased (auto-tuned) based on the connection’s round-trip time and the stream’s bandwidth (striving for the bandwidth-delay-product).
Set to None
to disable limit, i.e. allow each stream to grow receive window based on
connection’s round-trip time and stream’s bandwidth without limit.
§DOS attack mitigation
A remote node (attacker) might trick the local node (target) into allocating large stream receive windows, trying to make the local node run out of memory.
This attack is difficult, as the local node only increases the stream receive window up to 2x the bandwidth-delay-product, where bandwidth is the amount of bytes read, not just received. In other words, the attacker has to send (and have the local node read) significant amount of bytes on a stream over a long period of time to increase the stream receive window. E.g. on a 60ms 10Gbit/s connection the bandwidth-delay-product is ~75 MiB and thus the local node will at most allocate ~150 MiB (2x bandwidth-delay-product) per stream.
Despite the difficulty of the attack one should choose a reasonable
max_connection_receive_window
to protect against this attack, especially since an attacker
might use more than one stream per connection.
Sourcepub fn set_max_num_streams(&mut self, n: usize) -> &mut Self
pub fn set_max_num_streams(&mut self, n: usize) -> &mut Self
Set the max. number of streams per connection.
Sourcepub fn set_read_after_close(&mut self, b: bool) -> &mut Self
pub fn set_read_after_close(&mut self, b: bool) -> &mut Self
Allow or disallow streams to read from buffered data after the connection has been closed.
Sourcepub fn set_split_send_size(&mut self, n: usize) -> &mut Self
pub fn set_split_send_size(&mut self, n: usize) -> &mut Self
Set the max. payload size used when sending data frames. Payloads larger than the configured max. will be split.