mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
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:
@ -37,8 +37,8 @@ use libp2p_swarm::handler::{
|
||||
ListenUpgradeError,
|
||||
};
|
||||
use libp2p_swarm::{
|
||||
ConnectionHandler, ConnectionHandlerEvent, ConnectionId, KeepAlive, NegotiatedSubstream,
|
||||
StreamUpgradeError, SubstreamProtocol,
|
||||
ConnectionHandler, ConnectionHandlerEvent, ConnectionId, KeepAlive, Stream, StreamUpgradeError,
|
||||
SubstreamProtocol,
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
@ -77,7 +77,7 @@ pub enum In {
|
||||
dst_peer_id: PeerId,
|
||||
inbound_circuit_req: inbound_hop::CircuitReq,
|
||||
dst_handler_notifier: oneshot::Sender<()>,
|
||||
dst_stream: NegotiatedSubstream,
|
||||
dst_stream: Stream,
|
||||
dst_pending_data: Bytes,
|
||||
},
|
||||
}
|
||||
@ -193,7 +193,7 @@ pub enum Event {
|
||||
src_connection_id: ConnectionId,
|
||||
inbound_circuit_req: inbound_hop::CircuitReq,
|
||||
dst_handler_notifier: oneshot::Sender<()>,
|
||||
dst_stream: NegotiatedSubstream,
|
||||
dst_stream: Stream,
|
||||
dst_pending_data: Bytes,
|
||||
},
|
||||
/// Negotiating an outbound substream for an inbound circuit request failed.
|
||||
@ -914,10 +914,10 @@ pub struct OutboundOpenInfo {
|
||||
|
||||
pub(crate) struct CircuitParts {
|
||||
circuit_id: CircuitId,
|
||||
src_stream: NegotiatedSubstream,
|
||||
src_stream: Stream,
|
||||
src_pending_data: Bytes,
|
||||
dst_peer_id: PeerId,
|
||||
dst_handler_notifier: oneshot::Sender<()>,
|
||||
dst_stream: NegotiatedSubstream,
|
||||
dst_stream: Stream,
|
||||
dst_pending_data: Bytes,
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ use libp2p_identity::PeerId;
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm};
|
||||
use libp2p_swarm::dial_opts::DialOpts;
|
||||
use libp2p_swarm::{
|
||||
dummy, ConnectionDenied, ConnectionHandler, ConnectionId, DialFailure, NegotiatedSubstream,
|
||||
NetworkBehaviour, NotifyHandler, PollParameters, StreamUpgradeError, THandler, THandlerInEvent,
|
||||
dummy, ConnectionDenied, ConnectionHandler, ConnectionId, DialFailure, NetworkBehaviour,
|
||||
NotifyHandler, PollParameters, Stream, StreamUpgradeError, THandler, THandlerInEvent,
|
||||
THandlerOutEvent, ToSwarm,
|
||||
};
|
||||
use std::collections::{hash_map, HashMap, VecDeque};
|
||||
@ -391,7 +391,7 @@ enum ConnectionState {
|
||||
},
|
||||
Operational {
|
||||
read_buffer: Bytes,
|
||||
substream: NegotiatedSubstream,
|
||||
substream: Stream,
|
||||
/// "Drop notifier" pattern to signal to the transport that the connection has been dropped.
|
||||
///
|
||||
/// This is flagged as "dead-code" by the compiler because we never read from it here.
|
||||
@ -425,7 +425,7 @@ impl ConnectionState {
|
||||
}
|
||||
|
||||
pub(crate) fn new_outbound(
|
||||
substream: NegotiatedSubstream,
|
||||
substream: Stream,
|
||||
read_buffer: Bytes,
|
||||
drop_notifier: oneshot::Sender<void::Void>,
|
||||
) -> Self {
|
||||
|
@ -26,7 +26,7 @@ use futures::{future::BoxFuture, prelude::*};
|
||||
use instant::{Duration, SystemTime};
|
||||
use libp2p_core::{upgrade, Multiaddr};
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_swarm::{NegotiatedSubstream, StreamProtocol};
|
||||
use libp2p_swarm::{Stream, StreamProtocol};
|
||||
use std::convert::TryInto;
|
||||
use std::iter;
|
||||
use thiserror::Error;
|
||||
@ -46,12 +46,12 @@ impl upgrade::UpgradeInfo for Upgrade {
|
||||
}
|
||||
}
|
||||
|
||||
impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
|
||||
impl upgrade::InboundUpgrade<Stream> for Upgrade {
|
||||
type Output = Req;
|
||||
type Error = UpgradeError;
|
||||
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_inbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, substream: Stream, _: Self::Info) -> Self::Future {
|
||||
let mut substream = Framed::new(
|
||||
substream,
|
||||
quick_protobuf_codec::Codec::new(MAX_MESSAGE_SIZE),
|
||||
@ -126,7 +126,7 @@ pub enum Req {
|
||||
}
|
||||
|
||||
pub struct ReservationReq {
|
||||
substream: Framed<NegotiatedSubstream, quick_protobuf_codec::Codec<proto::HopMessage>>,
|
||||
substream: Framed<Stream, quick_protobuf_codec::Codec<proto::HopMessage>>,
|
||||
reservation_duration: Duration,
|
||||
max_circuit_duration: Duration,
|
||||
max_circuit_bytes: u64,
|
||||
@ -183,7 +183,7 @@ impl ReservationReq {
|
||||
|
||||
pub struct CircuitReq {
|
||||
dst: PeerId,
|
||||
substream: Framed<NegotiatedSubstream, quick_protobuf_codec::Codec<proto::HopMessage>>,
|
||||
substream: Framed<Stream, quick_protobuf_codec::Codec<proto::HopMessage>>,
|
||||
}
|
||||
|
||||
impl CircuitReq {
|
||||
@ -191,7 +191,7 @@ impl CircuitReq {
|
||||
self.dst
|
||||
}
|
||||
|
||||
pub async fn accept(mut self) -> Result<(NegotiatedSubstream, Bytes), UpgradeError> {
|
||||
pub async fn accept(mut self) -> Result<(Stream, Bytes), UpgradeError> {
|
||||
let msg = proto::HopMessage {
|
||||
type_pb: proto::HopMessageType::STATUS,
|
||||
peer: None,
|
||||
|
@ -25,7 +25,7 @@ use bytes::Bytes;
|
||||
use futures::{future::BoxFuture, prelude::*};
|
||||
use libp2p_core::upgrade;
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_swarm::{NegotiatedSubstream, StreamProtocol};
|
||||
use libp2p_swarm::{Stream, StreamProtocol};
|
||||
use std::iter;
|
||||
use thiserror::Error;
|
||||
|
||||
@ -40,12 +40,12 @@ impl upgrade::UpgradeInfo for Upgrade {
|
||||
}
|
||||
}
|
||||
|
||||
impl upgrade::InboundUpgrade<NegotiatedSubstream> for Upgrade {
|
||||
impl upgrade::InboundUpgrade<Stream> for Upgrade {
|
||||
type Output = Circuit;
|
||||
type Error = UpgradeError;
|
||||
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_inbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, substream: Stream, _: Self::Info) -> Self::Future {
|
||||
let mut substream = Framed::new(
|
||||
substream,
|
||||
quick_protobuf_codec::Codec::new(MAX_MESSAGE_SIZE),
|
||||
@ -111,7 +111,7 @@ pub enum FatalUpgradeError {
|
||||
}
|
||||
|
||||
pub struct Circuit {
|
||||
substream: Framed<NegotiatedSubstream, quick_protobuf_codec::Codec<proto::StopMessage>>,
|
||||
substream: Framed<Stream, quick_protobuf_codec::Codec<proto::StopMessage>>,
|
||||
src_peer_id: PeerId,
|
||||
limit: Option<protocol::Limit>,
|
||||
}
|
||||
@ -125,7 +125,7 @@ impl Circuit {
|
||||
self.limit
|
||||
}
|
||||
|
||||
pub async fn accept(mut self) -> Result<(NegotiatedSubstream, Bytes), UpgradeError> {
|
||||
pub async fn accept(mut self) -> Result<(Stream, Bytes), UpgradeError> {
|
||||
let msg = proto::StopMessage {
|
||||
type_pb: proto::StopMessageType::STATUS,
|
||||
peer: None,
|
||||
|
@ -27,7 +27,7 @@ use futures_timer::Delay;
|
||||
use instant::{Duration, SystemTime};
|
||||
use libp2p_core::{upgrade, Multiaddr};
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_swarm::{NegotiatedSubstream, StreamProtocol};
|
||||
use libp2p_swarm::{Stream, StreamProtocol};
|
||||
use std::convert::TryFrom;
|
||||
use std::iter;
|
||||
use thiserror::Error;
|
||||
@ -46,12 +46,12 @@ impl upgrade::UpgradeInfo for Upgrade {
|
||||
}
|
||||
}
|
||||
|
||||
impl upgrade::OutboundUpgrade<NegotiatedSubstream> for Upgrade {
|
||||
impl upgrade::OutboundUpgrade<Stream> for Upgrade {
|
||||
type Output = Output;
|
||||
type Error = UpgradeError;
|
||||
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_outbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, substream: Stream, _: Self::Info) -> Self::Future {
|
||||
let msg = match self {
|
||||
Upgrade::Reserve => proto::HopMessage {
|
||||
type_pb: proto::HopMessageType::RESERVE,
|
||||
@ -269,7 +269,7 @@ pub enum Output {
|
||||
limit: Option<Limit>,
|
||||
},
|
||||
Circuit {
|
||||
substream: NegotiatedSubstream,
|
||||
substream: Stream,
|
||||
read_buffer: Bytes,
|
||||
limit: Option<Limit>,
|
||||
},
|
||||
|
@ -25,7 +25,7 @@ use bytes::Bytes;
|
||||
use futures::{future::BoxFuture, prelude::*};
|
||||
use libp2p_core::upgrade;
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_swarm::{NegotiatedSubstream, StreamProtocol};
|
||||
use libp2p_swarm::{Stream, StreamProtocol};
|
||||
use std::convert::TryInto;
|
||||
use std::iter;
|
||||
use std::time::Duration;
|
||||
@ -46,12 +46,12 @@ impl upgrade::UpgradeInfo for Upgrade {
|
||||
}
|
||||
}
|
||||
|
||||
impl upgrade::OutboundUpgrade<NegotiatedSubstream> for Upgrade {
|
||||
type Output = (NegotiatedSubstream, Bytes);
|
||||
impl upgrade::OutboundUpgrade<Stream> for Upgrade {
|
||||
type Output = (Stream, Bytes);
|
||||
type Error = UpgradeError;
|
||||
type Future = BoxFuture<'static, Result<Self::Output, Self::Error>>;
|
||||
|
||||
fn upgrade_outbound(self, substream: NegotiatedSubstream, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, substream: Stream, _: Self::Info) -> Self::Future {
|
||||
let msg = proto::StopMessage {
|
||||
type_pb: proto::StopMessageType::CONNECT,
|
||||
peer: Some(proto::Peer {
|
||||
|
Reference in New Issue
Block a user