2019-01-29 19:52:22 +01:00
|
|
|
// Copyright 2019 Parity Technologies (UK) Ltd.
|
2018-11-26 14:01:08 +01:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
use crate::handler::{
|
|
|
|
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, IntoConnectionHandler,
|
|
|
|
KeepAlive, SubstreamProtocol,
|
2018-11-26 14:01:08 +01:00
|
|
|
};
|
2020-02-07 16:29:30 +01:00
|
|
|
use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper};
|
|
|
|
|
2019-07-04 14:47:59 +02:00
|
|
|
use libp2p_core::{
|
|
|
|
either::{EitherError, EitherOutput},
|
2020-08-18 16:27:02 +02:00
|
|
|
upgrade::{EitherUpgrade, NegotiationError, ProtocolError, SelectUpgrade, UpgradeError},
|
2019-05-10 11:05:22 +02:00
|
|
|
ConnectedPoint, Multiaddr, PeerId,
|
2019-07-04 14:47:59 +02:00
|
|
|
};
|
2019-09-16 11:08:44 +02:00
|
|
|
use std::{cmp, task::Context, task::Poll};
|
2018-11-26 14:01:08 +01:00
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
/// Implementation of `IntoConnectionHandler` that combines two protocols into one.
|
2019-01-14 14:22:25 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2022-02-21 13:32:24 +01:00
|
|
|
pub struct IntoConnectionHandlerSelect<TProto1, TProto2> {
|
2019-01-29 19:52:22 +01:00
|
|
|
/// The first protocol.
|
2019-01-14 14:22:25 +01:00
|
|
|
proto1: TProto1,
|
2019-01-29 19:52:22 +01:00
|
|
|
/// The second protocol.
|
2019-01-14 14:22:25 +01:00
|
|
|
proto2: TProto2,
|
|
|
|
}
|
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
impl<TProto1, TProto2> IntoConnectionHandlerSelect<TProto1, TProto2> {
|
|
|
|
/// Builds a `IntoConnectionHandlerSelect`.
|
2019-01-14 14:22:25 +01:00
|
|
|
pub(crate) fn new(proto1: TProto1, proto2: TProto2) -> Self {
|
2022-02-21 13:32:24 +01:00
|
|
|
IntoConnectionHandlerSelect { proto1, proto2 }
|
2019-01-14 14:22:25 +01:00
|
|
|
}
|
2021-08-31 17:00:51 +02:00
|
|
|
|
|
|
|
pub fn into_inner(self) -> (TProto1, TProto2) {
|
|
|
|
(self.proto1, self.proto2)
|
|
|
|
}
|
2019-01-14 14:22:25 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
impl<TProto1, TProto2> IntoConnectionHandler for IntoConnectionHandlerSelect<TProto1, TProto2>
|
2019-01-14 14:22:25 +01:00
|
|
|
where
|
2022-02-21 13:32:24 +01:00
|
|
|
TProto1: IntoConnectionHandler,
|
|
|
|
TProto2: IntoConnectionHandler,
|
2019-01-14 14:22:25 +01:00
|
|
|
{
|
2022-02-21 13:32:24 +01:00
|
|
|
type Handler = ConnectionHandlerSelect<TProto1::Handler, TProto2::Handler>;
|
2019-01-14 14:22:25 +01:00
|
|
|
|
2019-05-10 11:05:22 +02:00
|
|
|
fn into_handler(
|
|
|
|
self,
|
|
|
|
remote_peer_id: &PeerId,
|
|
|
|
connected_point: &ConnectedPoint,
|
|
|
|
) -> Self::Handler {
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerSelect {
|
2019-05-10 11:05:22 +02:00
|
|
|
proto1: self.proto1.into_handler(remote_peer_id, connected_point),
|
|
|
|
proto2: self.proto2.into_handler(remote_peer_id, connected_point),
|
2019-01-14 14:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-08 20:23:28 +02:00
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
fn inbound_protocol(&self) -> <Self::Handler as ConnectionHandler>::InboundProtocol {
|
2020-02-07 16:29:30 +01:00
|
|
|
SelectUpgrade::new(
|
|
|
|
SendWrapper(self.proto1.inbound_protocol()),
|
|
|
|
SendWrapper(self.proto2.inbound_protocol()),
|
|
|
|
)
|
2019-05-08 20:23:28 +02:00
|
|
|
}
|
2019-01-14 14:22:25 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
/// Implementation of [`ConnectionHandler`] that combines two protocols into one.
|
2018-11-26 14:01:08 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2022-02-21 13:32:24 +01:00
|
|
|
pub struct ConnectionHandlerSelect<TProto1, TProto2> {
|
2019-01-29 19:52:22 +01:00
|
|
|
/// The first protocol.
|
2019-03-11 17:19:50 +01:00
|
|
|
proto1: TProto1,
|
2019-01-29 19:52:22 +01:00
|
|
|
/// The second protocol.
|
2019-03-11 17:19:50 +01:00
|
|
|
proto2: TProto2,
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
impl<TProto1, TProto2> ConnectionHandlerSelect<TProto1, TProto2> {
|
|
|
|
/// Builds a [`ConnectionHandlerSelect`].
|
2018-11-26 14:01:08 +01:00
|
|
|
pub(crate) fn new(proto1: TProto1, proto2: TProto2) -> Self {
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerSelect { proto1, proto2 }
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
2021-08-31 17:00:51 +02:00
|
|
|
|
|
|
|
pub fn into_inner(self) -> (TProto1, TProto2) {
|
|
|
|
(self.proto1, self.proto2)
|
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 13:32:24 +01:00
|
|
|
impl<TProto1, TProto2> ConnectionHandler for ConnectionHandlerSelect<TProto1, TProto2>
|
2018-11-26 14:01:08 +01:00
|
|
|
where
|
2022-02-21 13:32:24 +01:00
|
|
|
TProto1: ConnectionHandler,
|
|
|
|
TProto2: ConnectionHandler,
|
2018-11-26 14:01:08 +01:00
|
|
|
{
|
|
|
|
type InEvent = EitherOutput<TProto1::InEvent, TProto2::InEvent>;
|
|
|
|
type OutEvent = EitherOutput<TProto1::OutEvent, TProto2::OutEvent>;
|
2018-12-28 15:11:35 +01:00
|
|
|
type Error = EitherError<TProto1::Error, TProto2::Error>;
|
2020-02-07 16:29:30 +01:00
|
|
|
type InboundProtocol = SelectUpgrade<
|
2022-02-21 13:32:24 +01:00
|
|
|
SendWrapper<<TProto1 as ConnectionHandler>::InboundProtocol>,
|
|
|
|
SendWrapper<<TProto2 as ConnectionHandler>::InboundProtocol>,
|
2020-02-07 16:29:30 +01:00
|
|
|
>;
|
|
|
|
type OutboundProtocol = EitherUpgrade<
|
|
|
|
SendWrapper<TProto1::OutboundProtocol>,
|
|
|
|
SendWrapper<TProto2::OutboundProtocol>,
|
|
|
|
>;
|
2018-11-26 14:01:08 +01:00
|
|
|
type OutboundOpenInfo = EitherOutput<TProto1::OutboundOpenInfo, TProto2::OutboundOpenInfo>;
|
2020-08-23 16:57:20 +02:00
|
|
|
type InboundOpenInfo = (TProto1::InboundOpenInfo, TProto2::InboundOpenInfo);
|
2018-11-26 14:01:08 +01:00
|
|
|
|
2020-08-23 16:57:20 +02:00
|
|
|
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
|
2018-11-26 14:01:08 +01:00
|
|
|
let proto1 = self.proto1.listen_protocol();
|
|
|
|
let proto2 = self.proto2.listen_protocol();
|
2021-02-15 11:59:51 +01:00
|
|
|
let timeout = *std::cmp::max(proto1.timeout(), proto2.timeout());
|
2021-02-25 11:35:52 +01:00
|
|
|
let (u1, i1) = proto1.into_upgrade();
|
|
|
|
let (u2, i2) = proto2.into_upgrade();
|
2020-08-23 16:57:20 +02:00
|
|
|
let choice = SelectUpgrade::new(SendWrapper(u1), SendWrapper(u2));
|
|
|
|
SubstreamProtocol::new(choice, (i1, i2)).with_timeout(timeout)
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
|
2020-02-07 16:29:30 +01:00
|
|
|
fn inject_fully_negotiated_outbound(
|
|
|
|
&mut self,
|
|
|
|
protocol: <Self::OutboundProtocol as OutboundUpgradeSend>::Output,
|
|
|
|
endpoint: Self::OutboundOpenInfo,
|
|
|
|
) {
|
2018-11-26 14:01:08 +01:00
|
|
|
match (protocol, endpoint) {
|
|
|
|
(EitherOutput::First(protocol), EitherOutput::First(info)) => {
|
|
|
|
self.proto1.inject_fully_negotiated_outbound(protocol, info)
|
2021-08-11 13:12:12 +02:00
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
(EitherOutput::Second(protocol), EitherOutput::Second(info)) => {
|
|
|
|
self.proto2.inject_fully_negotiated_outbound(protocol, info)
|
2021-08-11 13:12:12 +02:00
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
(EitherOutput::First(_), EitherOutput::Second(_)) => {
|
|
|
|
panic!("wrong API usage: the protocol doesn't match the upgrade info")
|
2021-08-11 13:12:12 +02:00
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
(EitherOutput::Second(_), EitherOutput::First(_)) => {
|
|
|
|
panic!("wrong API usage: the protocol doesn't match the upgrade info")
|
2021-08-11 13:12:12 +02:00
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 16:57:20 +02:00
|
|
|
fn inject_fully_negotiated_inbound(
|
|
|
|
&mut self,
|
|
|
|
protocol: <Self::InboundProtocol as InboundUpgradeSend>::Output,
|
|
|
|
(i1, i2): Self::InboundOpenInfo,
|
|
|
|
) {
|
2018-11-26 14:01:08 +01:00
|
|
|
match protocol {
|
|
|
|
EitherOutput::First(protocol) => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto1.inject_fully_negotiated_inbound(protocol, i1)
|
2021-08-11 13:12:12 +02:00
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
EitherOutput::Second(protocol) => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto2.inject_fully_negotiated_inbound(protocol, i2)
|
2021-08-11 13:12:12 +02:00
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn inject_event(&mut self, event: Self::InEvent) {
|
|
|
|
match event {
|
|
|
|
EitherOutput::First(event) => self.proto1.inject_event(event),
|
|
|
|
EitherOutput::Second(event) => self.proto2.inject_event(event),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 16:57:20 +02:00
|
|
|
fn inject_address_change(&mut self, new_address: &Multiaddr) {
|
|
|
|
self.proto1.inject_address_change(new_address);
|
|
|
|
self.proto2.inject_address_change(new_address)
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
|
|
|
|
2020-02-07 16:29:30 +01:00
|
|
|
fn inject_dial_upgrade_error(
|
|
|
|
&mut self,
|
|
|
|
info: Self::OutboundOpenInfo,
|
2022-02-21 13:32:24 +01:00
|
|
|
error: ConnectionHandlerUpgrErr<<Self::OutboundProtocol as OutboundUpgradeSend>::Error>,
|
2020-02-07 16:29:30 +01:00
|
|
|
) {
|
2018-12-18 11:23:13 +01:00
|
|
|
match (info, error) {
|
2022-02-21 13:32:24 +01:00
|
|
|
(EitherOutput::First(info), ConnectionHandlerUpgrErr::Timer) => self
|
2018-12-18 11:23:13 +01:00
|
|
|
.proto1
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_dial_upgrade_error(info, ConnectionHandlerUpgrErr::Timer),
|
|
|
|
(EitherOutput::First(info), ConnectionHandlerUpgrErr::Timeout) => self
|
2018-12-18 11:23:13 +01:00
|
|
|
.proto1
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_dial_upgrade_error(info, ConnectionHandlerUpgrErr::Timeout),
|
2018-12-18 11:23:13 +01:00
|
|
|
(
|
|
|
|
EitherOutput::First(info),
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(err)),
|
2018-12-18 11:23:13 +01:00
|
|
|
) => self.proto1.inject_dial_upgrade_error(
|
2021-08-11 13:12:12 +02:00
|
|
|
info,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(err)),
|
2018-12-18 11:23:13 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
EitherOutput::First(info),
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(err))),
|
2018-12-18 11:23:13 +01:00
|
|
|
) => self.proto1.inject_dial_upgrade_error(
|
|
|
|
info,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)),
|
2018-12-18 11:23:13 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
EitherOutput::First(_),
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(_))),
|
2018-12-18 11:23:13 +01:00
|
|
|
) => {
|
|
|
|
panic!("Wrong API usage; the upgrade error doesn't match the outbound open info");
|
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
(EitherOutput::Second(info), ConnectionHandlerUpgrErr::Timeout) => self
|
2018-12-18 11:23:13 +01:00
|
|
|
.proto2
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_dial_upgrade_error(info, ConnectionHandlerUpgrErr::Timeout),
|
|
|
|
(EitherOutput::Second(info), ConnectionHandlerUpgrErr::Timer) => self
|
2018-12-18 11:23:13 +01:00
|
|
|
.proto2
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_dial_upgrade_error(info, ConnectionHandlerUpgrErr::Timer),
|
2018-12-18 11:23:13 +01:00
|
|
|
(
|
|
|
|
EitherOutput::Second(info),
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(err)),
|
2018-12-18 11:23:13 +01:00
|
|
|
) => self.proto2.inject_dial_upgrade_error(
|
2021-08-11 13:12:12 +02:00
|
|
|
info,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(err)),
|
2018-12-18 11:23:13 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
EitherOutput::Second(info),
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(err))),
|
2018-12-18 11:23:13 +01:00
|
|
|
) => self.proto2.inject_dial_upgrade_error(
|
|
|
|
info,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)),
|
2018-12-18 11:23:13 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
EitherOutput::Second(_),
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(_))),
|
2018-12-18 11:23:13 +01:00
|
|
|
) => {
|
|
|
|
panic!("Wrong API usage; the upgrade error doesn't match the outbound open info");
|
|
|
|
}
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 16:57:20 +02:00
|
|
|
fn inject_listen_upgrade_error(
|
|
|
|
&mut self,
|
|
|
|
(i1, i2): Self::InboundOpenInfo,
|
2022-02-21 13:32:24 +01:00
|
|
|
error: ConnectionHandlerUpgrErr<<Self::InboundProtocol as InboundUpgradeSend>::Error>,
|
2020-08-23 16:57:20 +02:00
|
|
|
) {
|
2020-08-18 16:27:02 +02:00
|
|
|
match error {
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Timer => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto1
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_listen_upgrade_error(i1, ConnectionHandlerUpgrErr::Timer);
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto2
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_listen_upgrade_error(i2, ConnectionHandlerUpgrErr::Timer)
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Timeout => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto1
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_listen_upgrade_error(i1, ConnectionHandlerUpgrErr::Timeout);
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto2
|
2022-02-21 13:32:24 +01:00
|
|
|
.inject_listen_upgrade_error(i2, ConnectionHandlerUpgrErr::Timeout)
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto1.inject_listen_upgrade_error(
|
|
|
|
i1,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
2020-08-23 16:57:20 +02:00
|
|
|
NegotiationError::Failed,
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
self.proto2.inject_listen_upgrade_error(
|
|
|
|
i2,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
2020-08-23 16:57:20 +02:00
|
|
|
NegotiationError::Failed,
|
|
|
|
)),
|
2021-08-11 13:12:12 +02:00
|
|
|
);
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
2020-08-18 16:27:02 +02:00
|
|
|
NegotiationError::ProtocolError(e),
|
|
|
|
)) => {
|
|
|
|
let (e1, e2);
|
|
|
|
match e {
|
|
|
|
ProtocolError::IoError(e) => {
|
|
|
|
e1 = NegotiationError::ProtocolError(ProtocolError::IoError(
|
|
|
|
e.kind().into(),
|
|
|
|
));
|
|
|
|
e2 = NegotiationError::ProtocolError(ProtocolError::IoError(e))
|
|
|
|
}
|
|
|
|
ProtocolError::InvalidMessage => {
|
|
|
|
e1 = NegotiationError::ProtocolError(ProtocolError::InvalidMessage);
|
|
|
|
e2 = NegotiationError::ProtocolError(ProtocolError::InvalidMessage)
|
|
|
|
}
|
|
|
|
ProtocolError::InvalidProtocol => {
|
|
|
|
e1 = NegotiationError::ProtocolError(ProtocolError::InvalidProtocol);
|
|
|
|
e2 = NegotiationError::ProtocolError(ProtocolError::InvalidProtocol)
|
|
|
|
}
|
|
|
|
ProtocolError::TooManyProtocols => {
|
|
|
|
e1 = NegotiationError::ProtocolError(ProtocolError::TooManyProtocols);
|
|
|
|
e2 = NegotiationError::ProtocolError(ProtocolError::TooManyProtocols)
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto1.inject_listen_upgrade_error(
|
|
|
|
i1,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e1)),
|
2020-08-23 16:57:20 +02:00
|
|
|
);
|
|
|
|
self.proto2.inject_listen_upgrade_error(
|
|
|
|
i2,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e2)),
|
2020-08-23 16:57:20 +02:00
|
|
|
)
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(e))) => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto1.inject_listen_upgrade_error(
|
|
|
|
i1,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)),
|
2020-08-23 16:57:20 +02:00
|
|
|
)
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(e))) => {
|
2020-08-23 16:57:20 +02:00
|
|
|
self.proto2.inject_listen_upgrade_error(
|
|
|
|
i2,
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)),
|
2020-08-23 16:57:20 +02:00
|
|
|
)
|
2020-08-18 16:27:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:37:34 +01:00
|
|
|
fn connection_keep_alive(&self) -> KeepAlive {
|
2019-02-14 12:35:24 +02:00
|
|
|
cmp::max(
|
|
|
|
self.proto1.connection_keep_alive(),
|
|
|
|
self.proto2.connection_keep_alive(),
|
|
|
|
)
|
2019-01-04 12:02:39 +01:00
|
|
|
}
|
|
|
|
|
2020-07-27 20:27:33 +00:00
|
|
|
fn poll(
|
|
|
|
&mut self,
|
|
|
|
cx: &mut Context<'_>,
|
|
|
|
) -> Poll<
|
2022-02-21 13:32:24 +01:00
|
|
|
ConnectionHandlerEvent<
|
2020-07-27 20:27:33 +00:00
|
|
|
Self::OutboundProtocol,
|
|
|
|
Self::OutboundOpenInfo,
|
|
|
|
Self::OutEvent,
|
|
|
|
Self::Error,
|
2021-08-11 13:12:12 +02:00
|
|
|
>,
|
2020-07-27 20:27:33 +00:00
|
|
|
> {
|
2019-09-16 11:08:44 +02:00
|
|
|
match self.proto1.poll(cx) {
|
2022-02-21 13:32:24 +01:00
|
|
|
Poll::Ready(ConnectionHandlerEvent::Custom(event)) => {
|
|
|
|
return Poll::Ready(ConnectionHandlerEvent::Custom(EitherOutput::First(event)));
|
2019-06-18 18:42:40 +10:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
Poll::Ready(ConnectionHandlerEvent::Close(event)) => {
|
|
|
|
return Poll::Ready(ConnectionHandlerEvent::Close(EitherError::A(event)));
|
2019-09-16 11:08:44 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }) => {
|
|
|
|
return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {
|
2020-08-23 16:57:20 +02:00
|
|
|
protocol: protocol
|
|
|
|
.map_upgrade(|u| EitherUpgrade::A(SendWrapper(u)))
|
|
|
|
.map_info(EitherOutput::First),
|
2019-09-16 11:08:44 +02:00
|
|
|
});
|
2019-06-18 18:42:40 +10:00
|
|
|
}
|
2019-09-16 11:08:44 +02:00
|
|
|
Poll::Pending => (),
|
2019-06-18 18:42:40 +10:00
|
|
|
};
|
|
|
|
|
2019-09-16 11:08:44 +02:00
|
|
|
match self.proto2.poll(cx) {
|
2022-02-21 13:32:24 +01:00
|
|
|
Poll::Ready(ConnectionHandlerEvent::Custom(event)) => {
|
|
|
|
return Poll::Ready(ConnectionHandlerEvent::Custom(EitherOutput::Second(event)));
|
2019-09-16 11:08:44 +02:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
Poll::Ready(ConnectionHandlerEvent::Close(event)) => {
|
|
|
|
return Poll::Ready(ConnectionHandlerEvent::Close(EitherError::B(event)));
|
2019-06-18 18:42:40 +10:00
|
|
|
}
|
2022-02-21 13:32:24 +01:00
|
|
|
Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }) => {
|
|
|
|
return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {
|
2020-08-23 16:57:20 +02:00
|
|
|
protocol: protocol
|
|
|
|
.map_upgrade(|u| EitherUpgrade::B(SendWrapper(u)))
|
|
|
|
.map_info(EitherOutput::Second),
|
2019-09-16 11:08:44 +02:00
|
|
|
});
|
2019-06-18 18:42:40 +10:00
|
|
|
}
|
2019-09-16 11:08:44 +02:00
|
|
|
Poll::Pending => (),
|
2019-06-18 18:42:40 +10:00
|
|
|
};
|
2019-01-29 19:52:22 +01:00
|
|
|
|
2019-09-16 11:08:44 +02:00
|
|
|
Poll::Pending
|
2018-11-26 14:01:08 +01:00
|
|
|
}
|
|
|
|
}
|