Skip to content

Commit e6fb5f8

Browse files
committed
Unbounded stream receive window
Depend on connection window only.
1 parent 23c1e74 commit e6fb5f8

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

test-harness/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,11 @@ impl Arbitrary for TestConfig {
449449
fn arbitrary(g: &mut Gen) -> Self {
450450
let mut c = Config::default();
451451
c.set_read_after_close(Arbitrary::arbitrary(g));
452-
c.set_receive_window(256 * 1024 + usize::arbitrary(g) % (768 * 1024));
452+
if bool::arbitrary(g) {
453+
c.set_receive_window(Some(256 * 1024 + usize::arbitrary(g) % (768 * 1024)));
454+
} else {
455+
c.set_receive_window(None);
456+
}
453457
TestConfig(c)
454458
}
455459
}

yamux/src/connection/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use futures::{
2525
ready, SinkExt,
2626
};
2727
use parking_lot::{Mutex, MutexGuard};
28-
use std::convert::TryInto;
2928
use std::time::Instant;
3029
use std::{
3130
fmt, io,
@@ -546,6 +545,7 @@ impl Shared {
546545
self.window_max,
547546
self.window
548547
);
548+
549549
let bytes_received = self.window_max.saturating_sub(self.window);
550550
let buffer_len = self.buffer.len();
551551
let mut new_credit = bytes_received.saturating_sub(buffer_len);
@@ -571,7 +571,7 @@ impl Shared {
571571
self.window_max = std::cmp::min(
572572
std::cmp::min(
573573
self.window_max.saturating_mul(2),
574-
self.config.receive_window,
574+
self.config.receive_window.unwrap_or(usize::MAX),
575575
),
576576
self.window_max
577577
+ ((self.config.connection_window

yamux/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const DEFAULT_SPLIT_SEND_SIZE: usize = 16 * 1024;
7777
#[derive(Debug, Clone)]
7878
pub struct Config {
7979
// TODO: Rename to max_stream_receive_window
80-
receive_window: usize,
80+
receive_window: Option<usize>,
8181
// TODO: Rename to max_connection_receive_window
8282
connection_window: usize,
8383
max_buffer_size: usize,
@@ -89,7 +89,8 @@ pub struct Config {
8989
impl Default for Config {
9090
fn default() -> Self {
9191
Config {
92-
receive_window: 16 * 1024 * 1024,
92+
// TODO: Add rational: given that we have a connection window, ...
93+
receive_window: None,
9394
// TODO: reevaluate default.
9495
// TODO: Add setter.
9596
connection_window: 1 * 1024 * 1024 * 1024,
@@ -108,12 +109,12 @@ impl Config {
108109
/// # Panics
109110
///
110111
/// If the given receive window is < 256 KiB.
111-
pub fn set_receive_window(&mut self, n: usize) -> &mut Self {
112+
pub fn set_receive_window(&mut self, n: Option<usize>) -> &mut Self {
112113
self.receive_window = n;
113114
self.check();
114115
self
115116
}
116-
117+
117118
pub fn set_connection_window(&mut self, n: usize) -> &mut Self {
118119
self.connection_window = n;
119120
self.check();
@@ -150,8 +151,9 @@ impl Config {
150151
self
151152
}
152153

154+
// TODO: Consider doing the check on creation, not on each builder method call.
153155
fn check(&self) {
154-
assert!(self.receive_window >= DEFAULT_CREDIT);
156+
assert!(self.receive_window.unwrap_or(usize::MAX) >= DEFAULT_CREDIT);
155157
assert!(self.connection_window >= self.max_num_streams * DEFAULT_CREDIT);
156158
}
157159
}

0 commit comments

Comments
 (0)