mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 17:51:35 +00:00
refactor(core)!: remove EitherUpgrade
(#3339)
We don't need to define our own type here, we can simply implement `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` on `either::Either`.
This commit is contained in:
@ -21,7 +21,7 @@
|
||||
use crate::protocol;
|
||||
use either::Either;
|
||||
use libp2p_core::connection::ConnectionId;
|
||||
use libp2p_core::upgrade::{self, DeniedUpgrade};
|
||||
use libp2p_core::upgrade::DeniedUpgrade;
|
||||
use libp2p_core::{ConnectedPoint, PeerId};
|
||||
use libp2p_swarm::dummy;
|
||||
use libp2p_swarm::handler::SendWrapper;
|
||||
@ -70,11 +70,11 @@ impl IntoConnectionHandler for Prototype {
|
||||
|
||||
fn inbound_protocol(&self) -> <Self::Handler as ConnectionHandler>::InboundProtocol {
|
||||
match self {
|
||||
Prototype::UnknownConnection => upgrade::EitherUpgrade::A(SendWrapper(
|
||||
upgrade::EitherUpgrade::A(protocol::inbound::Upgrade {}),
|
||||
)),
|
||||
Prototype::UnknownConnection => {
|
||||
Either::Left(SendWrapper(Either::Left(protocol::inbound::Upgrade {})))
|
||||
}
|
||||
Prototype::DirectConnection { .. } => {
|
||||
upgrade::EitherUpgrade::A(SendWrapper(upgrade::EitherUpgrade::B(DeniedUpgrade)))
|
||||
Either::Left(SendWrapper(Either::Right(DeniedUpgrade)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ use futures::future::{BoxFuture, FutureExt};
|
||||
use instant::Instant;
|
||||
use libp2p_core::either::EitherOutput;
|
||||
use libp2p_core::multiaddr::Multiaddr;
|
||||
use libp2p_core::upgrade::{self, DeniedUpgrade, NegotiationError, UpgradeError};
|
||||
use libp2p_core::upgrade::{DeniedUpgrade, NegotiationError, UpgradeError};
|
||||
use libp2p_core::ConnectedPoint;
|
||||
use libp2p_swarm::handler::{
|
||||
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
|
||||
@ -305,7 +305,7 @@ impl ConnectionHandler for Handler {
|
||||
type Error = ConnectionHandlerUpgrErr<
|
||||
Either<protocol::inbound::UpgradeError, protocol::outbound::UpgradeError>,
|
||||
>;
|
||||
type InboundProtocol = upgrade::EitherUpgrade<protocol::inbound::Upgrade, DeniedUpgrade>;
|
||||
type InboundProtocol = Either<protocol::inbound::Upgrade, DeniedUpgrade>;
|
||||
type OutboundProtocol = protocol::outbound::Upgrade;
|
||||
type OutboundOpenInfo = u8; // Number of upgrade attempts.
|
||||
type InboundOpenInfo = ();
|
||||
@ -313,7 +313,7 @@ impl ConnectionHandler for Handler {
|
||||
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
||||
match self.endpoint {
|
||||
ConnectedPoint::Dialer { .. } => {
|
||||
SubstreamProtocol::new(upgrade::EitherUpgrade::A(protocol::inbound::Upgrade {}), ())
|
||||
SubstreamProtocol::new(Either::Left(protocol::inbound::Upgrade {}), ())
|
||||
}
|
||||
ConnectedPoint::Listener { .. } => {
|
||||
// By the protocol specification the listening side of a relayed connection
|
||||
@ -321,7 +321,7 @@ impl ConnectionHandler for Handler {
|
||||
// the relayed connection opens a substream to the dialing side. (Connection roles
|
||||
// and substream roles are reversed.) The listening side on a relayed connection
|
||||
// never expects incoming substreams, hence the denied upgrade below.
|
||||
SubstreamProtocol::new(upgrade::EitherUpgrade::B(DeniedUpgrade), ())
|
||||
SubstreamProtocol::new(Either::Right(DeniedUpgrade), ())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user