feat(swarm): deprecate NegotiatedSubstream in favor of Stream

This patch tackles two things at once that are fairly intertwined:

1. There is no such thing as a "substream" in libp2p, the spec and other implementations only talk about "streams". We fix this by deprecating `NegotiatedSubstream`.
2. Previously, `NegotiatedSubstream` was a type alias that pointed to a type from `multistream-select`, effectively leaking the version of `multistream-select` to all dependencies of `libp2p-swarm`. We fix this by introducing a `Stream` newtype.

Resolves: #3759.
Related: #3748.

Pull-Request: #3912.
This commit is contained in:
Thomas Eizinger
2023-05-12 08:19:23 +02:00
committed by GitHub
parent 234a0d24db
commit 9e625881d5
24 changed files with 234 additions and 169 deletions

View File

@ -28,7 +28,7 @@ use crate::RequestId;
use futures::{channel::oneshot, future::BoxFuture, prelude::*};
use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use libp2p_swarm::NegotiatedSubstream;
use libp2p_swarm::Stream;
use smallvec::SmallVec;
use std::{fmt, io};
@ -88,7 +88,7 @@ where
}
}
impl<TCodec> InboundUpgrade<NegotiatedSubstream> for ResponseProtocol<TCodec>
impl<TCodec> InboundUpgrade<Stream> for ResponseProtocol<TCodec>
where
TCodec: Codec + Send + 'static,
{
@ -96,11 +96,7 @@ where
type Error = io::Error;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
fn upgrade_inbound(
mut self,
mut io: NegotiatedSubstream,
protocol: Self::Info,
) -> Self::Future {
fn upgrade_inbound(mut self, mut io: Stream, protocol: Self::Info) -> Self::Future {
async move {
let read = self.codec.read_request(&protocol, &mut io);
let request = read.await?;
@ -163,7 +159,7 @@ where
}
}
impl<TCodec> OutboundUpgrade<NegotiatedSubstream> for RequestProtocol<TCodec>
impl<TCodec> OutboundUpgrade<Stream> for RequestProtocol<TCodec>
where
TCodec: Codec + Send + 'static,
{
@ -171,11 +167,7 @@ where
type Error = io::Error;
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
fn upgrade_outbound(
mut self,
mut io: NegotiatedSubstream,
protocol: Self::Info,
) -> Self::Future {
fn upgrade_outbound(mut self, mut io: Stream, protocol: Self::Info) -> Self::Future {
async move {
let write = self.codec.write_request(&protocol, &mut io, self.request);
write.await?;