Misc protocol fixes

* Verify contiuation frame stream ID
* Fix sending RST_STREAM in certain cases.
This commit is contained in:
Carl Lerche
2017-08-25 10:21:47 -07:00
parent 0c8a94aa11
commit 91aa1db2ff
6 changed files with 83 additions and 28 deletions

View File

@@ -62,6 +62,10 @@ pub(super) struct VacantEntry<'a, B: 'a> {
slab: &'a mut slab::Slab<Stream<B>>,
}
pub(super) trait Resolve<B> {
fn resolve(&mut self, key: Key) -> Ptr<B>;
}
// ===== impl Store =====
impl<B> Store<B> {
@@ -72,13 +76,6 @@ impl<B> Store<B> {
}
}
pub fn resolve(&mut self, key: Key) -> Ptr<B> {
Ptr {
key: key,
slab: &mut self.slab,
}
}
pub fn find_mut(&mut self, id: &StreamId) -> Option<Ptr<B>> {
if let Some(&key) = self.ids.get(id) {
Some(Ptr {
@@ -132,6 +129,15 @@ impl<B> Store<B> {
}
}
impl<B> Resolve<B> for Store<B> {
fn resolve(&mut self, key: Key) -> Ptr<B> {
Ptr {
key: key,
slab: &mut self.slab,
}
}
}
impl<B> ops::Index<Key> for Store<B> {
type Output = Stream<B>;
@@ -209,7 +215,8 @@ impl<B, N> Queue<B, N>
true
}
pub fn pop<'a>(&mut self, store: &'a mut Store<B>) -> Option<store::Ptr<'a, B>>
pub fn pop<'a, R>(&mut self, store: &'a mut R) -> Option<store::Ptr<'a, B>>
where R: Resolve<B>
{
if let Some(mut idxs) = self.indices {
let mut stream = store.resolve(idxs.head);
@@ -238,8 +245,10 @@ impl<'a, B: 'a> Ptr<'a, B> {
pub fn key(&self) -> Key {
self.key
}
}
pub fn resolve(&mut self, key: Key) -> Ptr<B> {
impl<'a, B: 'a> Resolve<B> for Ptr<'a, B> {
fn resolve(&mut self, key: Key) -> Ptr<B> {
Ptr {
key: key,
slab: &mut *self.slab,