Allow configuring Yamux window size (#7916)

This commit is contained in:
Pierre Krieger
2021-01-18 11:10:47 +01:00
committed by GitHub
parent 13cb98522b
commit c58a2d9a74
4 changed files with 38 additions and 1 deletions
@@ -35,12 +35,16 @@ pub use self::bandwidth::BandwidthSinks;
/// If `memory_only` is true, then only communication within the same process are allowed. Only
/// addresses with the format `/memory/...` are allowed.
///
/// `yamux_window_size` consists in the size of the Yamux windows. `None` to leave the default
/// (256kiB).
///
/// Returns a `BandwidthSinks` object that allows querying the average bandwidth produced by all
/// the connections spawned with this transport.
pub fn build_transport(
keypair: identity::Keypair,
memory_only: bool,
wasm_external_transport: Option<wasm_ext::ExtTransport>,
yamux_window_size: Option<u32>,
) -> (Boxed<(PeerId, StreamMuxerBox)>, Arc<BandwidthSinks>) {
// Build the base layer of the transport.
let transport = if let Some(t) = wasm_external_transport {
@@ -98,6 +102,10 @@ pub fn build_transport(
// buffered data has been consumed.
yamux_config.set_window_update_mode(libp2p::yamux::WindowUpdateMode::on_read());
if let Some(yamux_window_size) = yamux_window_size {
yamux_config.set_receive_window_size(yamux_window_size);
}
core::upgrade::SelectUpgrade::new(yamux_config, mplex_config)
};