From 70c968f17e8c0f1def329ce055185a2ee75e42f8 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 7 Nov 2023 04:07:40 +0300 Subject: [PATCH] fix(core): add impl `{In,Out}boundConnectionUpgrade` for `SelectUpgrade` Fixes https://github.com/libp2p/rust-libp2p/issues/4810. Pull-Request: #4812. --- Cargo.lock | 2 +- Cargo.toml | 2 +- core/CHANGELOG.md | 5 +++++ core/Cargo.toml | 2 +- core/src/upgrade/select.rs | 39 +++++++++++++++++++++++++++++++++++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1825b15ed4..4f1630f4810 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2530,7 +2530,7 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.41.0" +version = "0.41.1" dependencies = [ "async-std", "either", diff --git a/Cargo.toml b/Cargo.toml index d676d69a57a..89790baf82e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 6dda895c70a..034524b46dd 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -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`. diff --git a/core/Cargo.toml b/core/Cargo.toml index b9ebb0ad851..3d3bad6eefa 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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 "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/core/src/upgrade/select.rs b/core/src/upgrade/select.rs index 19b8b7a93f7..037045a2f29 100644 --- a/core/src/upgrade/select.rs +++ b/core/src/upgrade/select.rs @@ -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}; @@ -84,6 +87,23 @@ where } } +impl InboundConnectionUpgrade for SelectUpgrade +where + A: InboundConnectionUpgrade, + B: InboundConnectionUpgrade, +{ + type Output = future::Either; + type Error = Either; + type Future = EitherFuture; + + 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 OutboundUpgrade for SelectUpgrade where A: OutboundUpgrade, @@ -100,3 +120,20 @@ where } } } + +impl OutboundConnectionUpgrade for SelectUpgrade +where + A: OutboundConnectionUpgrade, + B: OutboundConnectionUpgrade, +{ + type Output = future::Either; + type Error = Either; + type Future = EitherFuture; + + 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)), + } + } +}