Handle more H2 details

This commit is contained in:
Carl Lerche
2017-08-10 21:08:57 -07:00
parent e2fac3e823
commit c439232ed2
5 changed files with 64 additions and 4 deletions

View File

@@ -21,6 +21,9 @@ pub(super) struct Recv<B> {
/// Connection level flow control governing received data
flow_control: FlowControl,
/// The lowest stream ID that is still idle
next_stream_id: StreamId,
/// Streams that have pending window updates
/// TODO: don't use a VecDeque
pending_window_updates: VecDeque<StreamId>,
@@ -50,12 +53,19 @@ struct Indices {
}
impl<B> Recv<B> where B: Buf {
pub fn new(config: &Config) -> Self {
pub fn new<P: Peer>(config: &Config) -> Self {
let next_stream_id = if P::is_server() {
1
} else {
2
};
Recv {
max_streams: config.max_remote_initiated,
num_streams: 0,
init_window_sz: config.init_remote_window_sz,
flow_control: FlowControl::new(config.init_remote_window_sz),
next_stream_id: next_stream_id.into(),
pending_window_updates: VecDeque::new(),
pending_accept: store::List::new(),
buffer: Buffer::new(),
@@ -129,6 +139,13 @@ impl<B> Recv<B> where B: Buf {
unimplemented!();
}
if frame.stream_id() >= self.next_stream_id {
self.next_stream_id = frame.stream_id();
self.next_stream_id.increment();
} else {
return Err(ProtocolError.into());
}
// Increment the number of concurrent streams
self.inc_num_streams();
}
@@ -246,6 +263,14 @@ impl<B> Recv<B> where B: Buf {
Ok(())
}
pub fn ensure_not_idle(&self, id: StreamId) -> Result<(), ConnectionError> {
if id >= self.next_stream_id {
return Err(ProtocolError.into());
}
Ok(())
}
pub fn recv_reset(&mut self, frame: frame::Reset, stream: &mut Stream<B>)
-> Result<(), ConnectionError>
{