diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 3a27d63b9..611377270 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -2121,23 +2121,8 @@ where self.streams.increase_max_data(bytes); } Frame::MaxStreamData { id, offset } => { - if id.initiator() != self.side && id.dir() == Dir::Uni { - debug!("got MAX_STREAM_DATA on recv-only {}", id); - return Err(TransportError::STREAM_STATE_ERROR( - "MAX_STREAM_DATA on recv-only stream", - )); - } - if let Some(ss) = self.streams.send_mut(id) { - if ss.increase_max_data(offset) { - // Unblocked - self.streams.events.push_back(StreamEvent::Writable { id }); - } - } else if id.initiator() == self.side() && self.streams.is_local_unopened(id) { - debug!("got MAX_STREAM_DATA on unopened {}", id); - return Err(TransportError::STREAM_STATE_ERROR( - "MAX_STREAM_DATA on unopened stream", - )); - } + self.streams + .received_max_stream_data(id, offset, self.side)?; self.on_stream_frame(false, id); } Frame::MaxStreams { dir, count } => { diff --git a/quinn-proto/src/connection/streams.rs b/quinn-proto/src/connection/streams.rs index c37b880b6..c86e42d7b 100644 --- a/quinn-proto/src/connection/streams.rs +++ b/quinn-proto/src/connection/streams.rs @@ -371,6 +371,34 @@ impl Streams { self.max_data = self.max_data.max(n); } + pub fn received_max_stream_data( + &mut self, + id: StreamId, + offset: u64, + side: Side, + ) -> Result<(), TransportError> { + if id.initiator() != side && id.dir() == Dir::Uni { + debug!("got MAX_STREAM_DATA on recv-only {}", id); + return Err(TransportError::STREAM_STATE_ERROR( + "MAX_STREAM_DATA on recv-only stream", + )); + } + + if let Some(ss) = self.send_mut(id) { + if ss.increase_max_data(offset) { + self.events.push_back(StreamEvent::Writable { id }); + } + Ok(()) + } else if id.initiator() == side && self.is_local_unopened(id) { + debug!("got MAX_STREAM_DATA on unopened {}", id); + Err(TransportError::STREAM_STATE_ERROR( + "MAX_STREAM_DATA on unopened stream", + )) + } else { + Ok(()) + } + } + /// Yield stream events pub fn poll(&mut self) -> Option { if let Some(dir) = Dir::iter().find(|&i| mem::replace(&mut self.opened[i as usize], false))