Wrap multistream-select streams under a Negotiated (#1001)

This commit is contained in:
Pierre Krieger
2019-03-19 17:27:30 +01:00
committed by GitHub
parent 63e9e39538
commit 96e559b503
24 changed files with 162 additions and 111 deletions

View File

@ -53,10 +53,10 @@ where
{
type Output = FloodsubRpc;
type Error = FloodsubDecodeError;
type Future = upgrade::ReadOneThen<TSocket, (), fn(Vec<u8>, ()) -> Result<FloodsubRpc, FloodsubDecodeError>>;
type Future = upgrade::ReadOneThen<upgrade::Negotiated<TSocket>, (), fn(Vec<u8>, ()) -> Result<FloodsubRpc, FloodsubDecodeError>>;
#[inline]
fn upgrade_inbound(self, socket: TSocket, _: Self::Info) -> Self::Future {
fn upgrade_inbound(self, socket: upgrade::Negotiated<TSocket>, _: Self::Info) -> Self::Future {
upgrade::read_one_then(socket, 2048, (), |packet, ()| {
let mut rpc: rpc_proto::RPC = protobuf::parse_from_bytes(&packet)?;
@ -168,10 +168,10 @@ where
{
type Output = ();
type Error = io::Error;
type Future = upgrade::WriteOne<TSocket>;
type Future = upgrade::WriteOne<upgrade::Negotiated<TSocket>>;
#[inline]
fn upgrade_outbound(self, socket: TSocket, _: Self::Info) -> Self::Future {
fn upgrade_outbound(self, socket: upgrade::Negotiated<TSocket>, _: Self::Info) -> Self::Future {
let bytes = self.into_bytes();
upgrade::write_one(socket, bytes)
}