use futures::prelude::*;
use crate::muxing::StreamMuxer;
use std::io::Error as IoError;
#[derive(Debug)]
pub struct DummySubstream {}
#[derive(Debug)]
pub struct DummyOutboundSubstream {}
#[derive(Debug, PartialEq, Clone)]
pub enum DummyConnectionState {
Pending, Opened, }
#[derive(Debug, PartialEq, Clone)]
struct DummyConnection {
state: DummyConnectionState,
}
#[derive(Debug, PartialEq, Clone)]
pub struct DummyMuxer{
in_connection: DummyConnection,
out_connection: DummyConnection,
}
impl DummyMuxer {
pub fn new() -> Self {
DummyMuxer {
in_connection: DummyConnection {
state: DummyConnectionState::Pending,
},
out_connection: DummyConnection {
state: DummyConnectionState::Pending,
},
}
}
pub fn set_inbound_connection_state(&mut self, state: DummyConnectionState) {
self.in_connection.state = state
}
pub fn set_outbound_connection_state(&mut self, state: DummyConnectionState) {
self.out_connection.state = state
}
}
impl StreamMuxer for DummyMuxer {
type Substream = DummySubstream;
type OutboundSubstream = DummyOutboundSubstream;
type Error = IoError;
fn poll_inbound(&self) -> Poll<Self::Substream, IoError> {
match self.in_connection.state {
DummyConnectionState::Pending => Ok(Async::NotReady),
DummyConnectionState::Opened => Ok(Async::Ready(Self::Substream {})),
}
}
fn open_outbound(&self) -> Self::OutboundSubstream {
Self::OutboundSubstream {}
}
fn poll_outbound(
&self,
_substream: &mut Self::OutboundSubstream,
) -> Poll<Self::Substream, IoError> {
match self.out_connection.state {
DummyConnectionState::Pending => Ok(Async::NotReady),
DummyConnectionState::Opened => Ok(Async::Ready(Self::Substream {})),
}
}
fn destroy_outbound(&self, _: Self::OutboundSubstream) {}
fn read_substream(&self, _: &mut Self::Substream, _buf: &mut [u8]) -> Poll<usize, IoError> {
unreachable!()
}
fn write_substream(&self, _: &mut Self::Substream, _buf: &[u8]) -> Poll<usize, IoError> {
unreachable!()
}
fn flush_substream(&self, _: &mut Self::Substream) -> Poll<(), IoError> {
unreachable!()
}
fn shutdown_substream(&self, _: &mut Self::Substream) -> Poll<(), IoError> {
unreachable!()
}
fn destroy_substream(&self, _: Self::Substream) {}
fn is_remote_acknowledged(&self) -> bool { true }
fn close(&self) -> Poll<(), IoError> {
Ok(Async::Ready(()))
}
fn flush_all(&self) -> Poll<(), IoError> {
Ok(Async::Ready(()))
}
}