Skip to content

Commit

Permalink
Set additive flag in initial window update. (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
twittner authored Sep 8, 2020
1 parent 60b15bb commit 7ba9bb9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.6.0

Upgrade step 2 of 4. This version sets the non-standard flag, version 0.5.0
already recognises.

# 0.5.0

This version begins the upgrade process spawning multiple versions that
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yamux"
version = "0.5.0"
version = "0.6.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0 OR MIT"
description = "Multiplexer over reliable, ordered connections"
Expand Down
17 changes: 7 additions & 10 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,23 +463,20 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Connection<T> {
}
log::trace!("{}: creating new outbound stream", self.id);
let id = self.next_stream_id()?;
if !self.config.lazy_open {
let mut frame = Frame::window_update(id, self.config.receive_window);
let extra_credit = self.config.receive_window - DEFAULT_CREDIT;
if extra_credit > 0 {
let mut frame = Frame::window_update(id, extra_credit);
frame.header_mut().syn();
frame.header_mut().additive();
log::trace!("{}: sending initial {}", self.id, frame.header());
self.socket.get_mut().send(&frame).await.or(Err(ConnectionError::Closed))?
}
let stream = {
let config = self.config.clone();
let sender = self.stream_sender.clone();
let window =
if self.config.lazy_open {
DEFAULT_CREDIT
} else {
self.config.receive_window
};
let window = self.config.receive_window;
let mut stream = Stream::new(id, self.id, config, window, DEFAULT_CREDIT, sender);
if self.config.lazy_open {
if extra_credit == 0 {
stream.set_flag(stream::Flag::Syn)
}
stream
Expand All @@ -489,7 +486,7 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Connection<T> {
self.streams.insert(id, stream);
} else {
log::debug!("{}: open stream {} has been cancelled", self.id, id);
if !self.config.lazy_open {
if extra_credit > 0 {
let mut header = Header::data(id, 0);
header.rst();
let frame = Frame::new(header);
Expand Down
5 changes: 5 additions & 0 deletions src/frame/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ impl<T: HasSyn> Header<T> {
pub fn syn(&mut self) {
self.flags.0 |= SYN.0
}

/// Set the [`ADD`] flag.
pub fn additive(&mut self) {
self.flags.0 |= ADD.0
}
}

impl<T: HasAck> Header<T> {
Expand Down
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ pub enum WindowUpdateMode {
/// - max. number of streams = 8192
/// - window update mode = on receive
/// - read after close = true
/// - lazy open = false
#[derive(Debug, Clone)]
pub struct Config {
receive_window: u32,
max_buffer_size: usize,
max_num_streams: usize,
window_update_mode: WindowUpdateMode,
read_after_close: bool,
lazy_open: bool
read_after_close: bool
}

impl Default for Config {
Expand All @@ -94,8 +92,7 @@ impl Default for Config {
max_buffer_size: 1024 * 1024,
max_num_streams: 8192,
window_update_mode: WindowUpdateMode::OnReceive,
read_after_close: true,
lazy_open: false
read_after_close: true
}
}
}
Expand Down Expand Up @@ -149,8 +146,8 @@ impl Config {
/// to the remote. This allows opening a stream with a custom receive
/// window size (cf. [`Config::set_receive_window`]) which the remote
/// can directly make use of.
pub fn set_lazy_open(&mut self, b: bool) -> &mut Self {
self.lazy_open = b;
#[deprecated(since = "0.6.0")]
pub fn set_lazy_open(&mut self, _: bool) -> &mut Self {
self
}
}
Expand Down
1 change: 0 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ impl Arbitrary for TestConfig {
} else {
WindowUpdateMode::OnReceive
});
c.set_lazy_open(g.gen());
c.set_read_after_close(g.gen());
c.set_receive_window(g.gen_range(256 * 1024, 1024 * 1024));
TestConfig(c)
Expand Down

0 comments on commit 7ba9bb9

Please sign in to comment.