Change stream ID handling to consider flags. (#436)

Replaces the former odd/even distinction of IDs. However we still increment stream IDs by 2
for backwards compatibility.
This commit is contained in:
Toralf Wittner
2018-09-06 13:59:14 +02:00
committed by Pierre Krieger
parent ea1f172397
commit 5c35047ee3
3 changed files with 50 additions and 19 deletions

View File

@ -20,10 +20,10 @@
use bytes::Bytes;
use futures::future::Future;
use std::io::Error as IoError;
use std::{io::Error as IoError, ops::Not};
/// Type of connection for the upgrade.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Endpoint {
/// The socket comes from a dialer.
Dialer,
@ -31,6 +31,18 @@ pub enum Endpoint {
Listener,
}
impl Not for Endpoint {
type Output = Endpoint;
fn not(self) -> Self::Output {
match self {
Endpoint::Dialer => Endpoint::Listener,
Endpoint::Listener => Endpoint::Dialer
}
}
}
/// Implemented on structs that describe a possible upgrade to a connection between two peers.
///
/// The generic `C` is the type of the incoming connection before it is upgraded.