wip: refactor, compiles
This commit is contained in:
@@ -291,104 +291,3 @@ impl PeerState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO track reserved streams
|
||||
// TODO constrain the size of `reset`
|
||||
#[derive(Debug, Default)]
|
||||
pub struct StreamMap<P> {
|
||||
/// Holds active streams initiated by the local endpoint.
|
||||
local_active: OrderMap<StreamId, StreamState, BuildHasherDefault<FnvHasher>>,
|
||||
|
||||
/// Holds active streams initiated by the remote endpoint.
|
||||
remote_active: OrderMap<StreamId, StreamState, BuildHasherDefault<FnvHasher>>,
|
||||
|
||||
/// Holds active streams initiated by the remote.
|
||||
reset: OrderMap<StreamId, Reason, BuildHasherDefault<FnvHasher>>,
|
||||
|
||||
_phantom: PhantomData<P>,
|
||||
}
|
||||
|
||||
impl<P: Peer> StreamMap<P> {
|
||||
pub fn active(&mut self, id: StreamId) -> Option<&StreamState> {
|
||||
assert!(!id.is_zero());
|
||||
if P::is_valid_local_stream_id(id) {
|
||||
self.local_active.get(id)
|
||||
} else {
|
||||
self.remote_active.get(id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn active_mut(&mut self, id: StreamId) -> Option<&mut StreamState> {
|
||||
assert!(!id.is_zero());
|
||||
if P::is_valid_local_stream_id(id) {
|
||||
self.local_active.get_mut(id)
|
||||
} else {
|
||||
self.remote_active.get_mut(id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn local_active(&self, id: StreamId) -> Option<&StreamState> {
|
||||
self.local_active.get(&id)
|
||||
}
|
||||
|
||||
pub fn local_active_mut(&mut self, id: StreamId) -> Option<&mut StreamState> {
|
||||
self.local_active.get_mut(&id)
|
||||
}
|
||||
|
||||
pub fn local_flow_controller(&mut self, id: StreamId) -> Option<&mut FlowControlState> {
|
||||
self.get_active_mut(id).and_then(|s| s.local_flow_controller())
|
||||
}
|
||||
|
||||
pub fn remote_flow_controller(&mut self, id: StreamId) -> Option<&mut FlowControlState> {
|
||||
self.get_active_mut(id).and_then(|s| s.remote_flow_controller())
|
||||
}
|
||||
|
||||
pub fn localis_active(&mut self, id: StreamId) -> bool {
|
||||
self.active.contains_key(&id)
|
||||
}
|
||||
|
||||
pub fn active_count(&self) -> usize {
|
||||
self.active.len()
|
||||
}
|
||||
|
||||
pub fn reset(&mut self, id: StreamId, cause: Reason) {
|
||||
self.reset.insert(id, cause);
|
||||
self.active.remove(&id);
|
||||
}
|
||||
|
||||
pub fn get_reset(&mut self, id: StreamId) -> Option<Reason> {
|
||||
self.reset.get(&id).map(|r| *r)
|
||||
}
|
||||
|
||||
pub fn shrink_all_local_windows(&mut self, decr: u32) {
|
||||
for (_, mut s) in &mut self.active {
|
||||
if let Some(fc) = s.local_flow_controller() {
|
||||
fc.shrink_window(decr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expand_all_local_windows(&mut self, incr: u32) {
|
||||
for (_, mut s) in &mut self.active {
|
||||
if let Some(fc) = s.local_flow_controller() {
|
||||
fc.expand_window(incr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shrink_all_remote_windows(&mut self, decr: u32) {
|
||||
for (_, mut s) in &mut self.active {
|
||||
if let Some(fc) = s.remote_flow_controller() {
|
||||
fc.shrink_window(decr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expand_all_remote_windows(&mut self, incr: u32) {
|
||||
for (_, mut s) in &mut self.active {
|
||||
if let Some(fc) = s.remote_flow_controller() {
|
||||
fc.expand_window(incr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user