Skip to content

Commit

Permalink
Unbounded stream receive window
Browse files Browse the repository at this point in the history
Depend on connection window only.
  • Loading branch information
mxinden committed Nov 23, 2023
1 parent 23c1e74 commit e6fb5f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion test-harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ impl Arbitrary for TestConfig {
fn arbitrary(g: &mut Gen) -> Self {
let mut c = Config::default();
c.set_read_after_close(Arbitrary::arbitrary(g));
c.set_receive_window(256 * 1024 + usize::arbitrary(g) % (768 * 1024));
if bool::arbitrary(g) {
c.set_receive_window(Some(256 * 1024 + usize::arbitrary(g) % (768 * 1024)));
} else {
c.set_receive_window(None);
}
TestConfig(c)
}
}
4 changes: 2 additions & 2 deletions yamux/src/connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use futures::{
ready, SinkExt,
};
use parking_lot::{Mutex, MutexGuard};
use std::convert::TryInto;
use std::time::Instant;
use std::{
fmt, io,
Expand Down Expand Up @@ -546,6 +545,7 @@ impl Shared {
self.window_max,
self.window
);

let bytes_received = self.window_max.saturating_sub(self.window);
let buffer_len = self.buffer.len();
let mut new_credit = bytes_received.saturating_sub(buffer_len);
Expand All @@ -571,7 +571,7 @@ impl Shared {
self.window_max = std::cmp::min(
std::cmp::min(
self.window_max.saturating_mul(2),
self.config.receive_window,
self.config.receive_window.unwrap_or(usize::MAX),
),
self.window_max
+ ((self.config.connection_window
Expand Down
12 changes: 7 additions & 5 deletions yamux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const DEFAULT_SPLIT_SEND_SIZE: usize = 16 * 1024;
#[derive(Debug, Clone)]
pub struct Config {
// TODO: Rename to max_stream_receive_window
receive_window: usize,
receive_window: Option<usize>,
// TODO: Rename to max_connection_receive_window
connection_window: usize,
max_buffer_size: usize,
Expand All @@ -89,7 +89,8 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Config {
receive_window: 16 * 1024 * 1024,
// TODO: Add rational: given that we have a connection window, ...
receive_window: None,
// TODO: reevaluate default.
// TODO: Add setter.
connection_window: 1 * 1024 * 1024 * 1024,
Expand All @@ -108,12 +109,12 @@ impl Config {
/// # Panics
///
/// If the given receive window is < 256 KiB.
pub fn set_receive_window(&mut self, n: usize) -> &mut Self {
pub fn set_receive_window(&mut self, n: Option<usize>) -> &mut Self {
self.receive_window = n;
self.check();
self
}

pub fn set_connection_window(&mut self, n: usize) -> &mut Self {
self.connection_window = n;
self.check();
Expand Down Expand Up @@ -150,8 +151,9 @@ impl Config {
self
}

// TODO: Consider doing the check on creation, not on each builder method call.
fn check(&self) {
assert!(self.receive_window >= DEFAULT_CREDIT);
assert!(self.receive_window.unwrap_or(usize::MAX) >= DEFAULT_CREDIT);
assert!(self.connection_window >= self.max_num_streams * DEFAULT_CREDIT);
}
}
Expand Down

0 comments on commit e6fb5f8

Please sign in to comment.