Skip to content

Commit

Permalink
fix(core): add impl {In,Out}boundConnectionUpgrade for SelectUpgrade
Browse files Browse the repository at this point in the history
Fixes #4810.

Pull-Request: #4812.
  • Loading branch information
gurinderu authored Nov 7, 2023
1 parent 4e1ad09 commit 70c968f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ libp2p = { version = "0.53.0", path = "libp2p" }
libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" }
libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" }
libp2p-connection-limits = { version = "0.3.0", path = "misc/connection-limits" }
libp2p-core = { version = "0.41.0", path = "core" }
libp2p-core = { version = "0.41.1", path = "core" }
libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" }
libp2p-dns = { version = "0.41.0", path = "transports/dns" }
libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" }
Expand Down
5 changes: 5 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.41.1 - unreleased

- Implement `{In,Out}boundConnectionUpgrade` for `SelectUpgrade`.
See [PR 4812](https://github.com/libp2p/rust-libp2p/pull/4812).

## 0.41.0

- Remove blanket-impl of `{In,Out}boundUpgrade` for `{In,Out}boundConnectionUpgrade`.
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-core"
edition = "2021"
rust-version = { workspace = true }
description = "Core traits and structs of libp2p"
version = "0.41.0"
version = "0.41.1"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
39 changes: 38 additions & 1 deletion core/src/upgrade/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
// DEALINGS IN THE SOFTWARE.

use crate::either::EitherFuture;
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use crate::upgrade::{
InboundConnectionUpgrade, InboundUpgrade, OutboundConnectionUpgrade, OutboundUpgrade,
UpgradeInfo,
};
use either::Either;
use futures::future;
use std::iter::{Chain, Map};
Expand Down Expand Up @@ -84,6 +87,23 @@ where
}
}

impl<C, A, B, TA, TB, EA, EB> InboundConnectionUpgrade<C> for SelectUpgrade<A, B>
where
A: InboundConnectionUpgrade<C, Output = TA, Error = EA>,
B: InboundConnectionUpgrade<C, Output = TB, Error = EB>,
{
type Output = future::Either<TA, TB>;
type Error = Either<EA, EB>;
type Future = EitherFuture<A::Future, B::Future>;

fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
match info {
Either::Left(info) => EitherFuture::First(self.0.upgrade_inbound(sock, info)),
Either::Right(info) => EitherFuture::Second(self.1.upgrade_inbound(sock, info)),
}
}
}

impl<C, A, B, TA, TB, EA, EB> OutboundUpgrade<C> for SelectUpgrade<A, B>
where
A: OutboundUpgrade<C, Output = TA, Error = EA>,
Expand All @@ -100,3 +120,20 @@ where
}
}
}

impl<C, A, B, TA, TB, EA, EB> OutboundConnectionUpgrade<C> for SelectUpgrade<A, B>
where
A: OutboundConnectionUpgrade<C, Output = TA, Error = EA>,
B: OutboundConnectionUpgrade<C, Output = TB, Error = EB>,
{
type Output = future::Either<TA, TB>;
type Error = Either<EA, EB>;
type Future = EitherFuture<A::Future, B::Future>;

fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
match info {
Either::Left(info) => EitherFuture::First(self.0.upgrade_outbound(sock, info)),
Either::Right(info) => EitherFuture::Second(self.1.upgrade_outbound(sock, info)),
}
}
}

0 comments on commit 70c968f

Please sign in to comment.