refactor(core)!: remove EitherOutput (#3341)

The trick with this one is to use `futures::Either` everywhere where we may wrap something that implements any of the `futures` traits. This includes the output of `EitherFuture` itself. We also need to implement `StreamMuxer` on `future::Either` because `StreamMuxer`s may be the the `Output` of `InboundUpgrade`.
This commit is contained in:
Thomas Eizinger
2023-01-23 23:31:30 +11:00
committed by GitHub
parent 8d6a2fc4a9
commit 4b41f5a994
15 changed files with 123 additions and 329 deletions

View File

@ -26,7 +26,6 @@ use futures::future::BoxFuture;
use futures::prelude::*;
use futures::stream::FuturesUnordered;
use futures_timer::Delay;
use libp2p_core::either::EitherOutput;
use libp2p_core::upgrade::SelectUpgrade;
use libp2p_core::{ConnectedPoint, Multiaddr, PeerId, PublicKey};
use libp2p_swarm::handler::{
@ -201,7 +200,7 @@ impl Handler {
>,
) {
match output {
EitherOutput::First(substream) => {
future::Either::Left(substream) => {
self.events
.push(ConnectionHandlerEvent::Custom(Event::Identify));
if !self.reply_streams.is_empty() {
@ -213,7 +212,7 @@ impl Handler {
}
self.reply_streams.push_back(substream);
}
EitherOutput::Second(fut) => {
future::Either::Right(fut) => {
if self.inbound_identify_push.replace(fut).is_some() {
warn!(
"New inbound identify push stream from {} while still \
@ -235,14 +234,14 @@ impl Handler {
>,
) {
match output {
EitherOutput::First(remote_info) => {
future::Either::Left(remote_info) => {
self.events
.push(ConnectionHandlerEvent::Custom(Event::Identified(
remote_info,
)));
self.keep_alive = KeepAlive::No;
}
EitherOutput::Second(()) => self
future::Either::Right(()) => self
.events
.push(ConnectionHandlerEvent::Custom(Event::IdentificationPushed)),
}