From 93cd4174f6e71d060adf07f3c463e9d24d0f8464 Mon Sep 17 00:00:00 2001 From: efarg Date: Wed, 23 Nov 2022 07:02:26 +0000 Subject: [PATCH] even more code #2831 --- swarm/src/handler/multi.rs | 11 +++++------ swarm/src/handler/pending.rs | 4 ++-- swarm/src/upgrade.rs | 29 +++++++++++------------------ 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 07c1168b132..51e24705dad 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -397,9 +397,9 @@ where /// Index and protocol name pair used as `UpgradeInfo::Info`. #[derive(Debug, Clone)] -pub struct IndexedProtoName(usize, H); +pub struct IndexedProtoName(usize, ProtocolName); -impl ProtocolName for IndexedProtoName { +impl IndexedProtoName { fn protocol_name(&self) -> &[u8] { self.1.protocol_name() } @@ -455,8 +455,7 @@ where H: UpgradeInfoSend, K: Send + 'static, { - type Info = IndexedProtoName; - type InfoIter = std::vec::IntoIter; + type InfoIter = std::vec::IntoIter; fn protocol_info(&self) -> Self::InfoIter { self.upgrades @@ -478,7 +477,7 @@ where type Error = (K, ::Error); type Future = BoxFuture<'static, Result>; - fn upgrade_inbound(mut self, resource: NegotiatedSubstream, info: Self::Info) -> Self::Future { + fn upgrade_inbound(mut self, resource: NegotiatedSubstream, info: IndexedProtoName) -> Self::Future { let IndexedProtoName(index, info) = info; let (key, upgrade) = self.upgrades.remove(index); upgrade @@ -500,7 +499,7 @@ where type Error = (K, ::Error); type Future = BoxFuture<'static, Result>; - fn upgrade_outbound(mut self, resource: NegotiatedSubstream, info: Self::Info) -> Self::Future { + fn upgrade_outbound(mut self, resource: NegotiatedSubstream, info: IndexedProtoName) -> Self::Future { let IndexedProtoName(index, info) = info; let (key, upgrade) = self.upgrades.remove(index); upgrade diff --git a/swarm/src/handler/pending.rs b/swarm/src/handler/pending.rs index 04c1696515c..003c6e552c8 100644 --- a/swarm/src/handler/pending.rs +++ b/swarm/src/handler/pending.rs @@ -47,8 +47,8 @@ impl ConnectionHandler for PendingConnectionHandler { type InEvent = Void; type OutEvent = Void; type Error = Void; - type InboundProtocol = PendingUpgrade; - type OutboundProtocol = PendingUpgrade; + type InboundProtocol = PendingUpgrade; + type OutboundProtocol = PendingUpgrade; type OutboundOpenInfo = Void; type InboundOpenInfo = (); diff --git a/swarm/src/upgrade.rs b/swarm/src/upgrade.rs index e544ac3f27f..edca1b3e886 100644 --- a/swarm/src/upgrade.rs +++ b/swarm/src/upgrade.rs @@ -29,10 +29,8 @@ use libp2p_core::upgrade; /// Do not implement this trait yourself. Instead, please implement /// [`UpgradeInfo`](upgrade::UpgradeInfo). pub trait UpgradeInfoSend: Send + 'static { - /// Equivalent to [`UpgradeInfo::Info`](upgrade::UpgradeInfo::Info). - type Info: upgrade::ProtocolName + Clone + Send + 'static; /// Equivalent to [`UpgradeInfo::InfoIter`](upgrade::UpgradeInfo::InfoIter). - type InfoIter: Iterator + Send + 'static; + type InfoIter; /// Equivalent to [`UpgradeInfo::protocol_info`](upgrade::UpgradeInfo::protocol_info). fn protocol_info(&self) -> Self::InfoIter; @@ -41,10 +39,8 @@ pub trait UpgradeInfoSend: Send + 'static { impl UpgradeInfoSend for T where T: upgrade::UpgradeInfo + Send + 'static, - T::Info: Send + 'static, ::IntoIter: Send + 'static, { - type Info = T::Info; type InfoIter = ::IntoIter; fn protocol_info(&self) -> Self::InfoIter { @@ -66,13 +62,12 @@ pub trait OutboundUpgradeSend: UpgradeInfoSend { type Future: Future> + Send + 'static; /// Equivalent to [`OutboundUpgrade::upgrade_outbound`](upgrade::OutboundUpgrade::upgrade_outbound). - fn upgrade_outbound(self, socket: NegotiatedSubstream, info: Self::Info) -> Self::Future; + fn upgrade_outbound(self, socket: NegotiatedSubstream, info: upgrade::ProtocolName) -> Self::Future; } -impl OutboundUpgradeSend for T +impl OutboundUpgradeSend for T where - T: upgrade::OutboundUpgrade + UpgradeInfoSend, - TInfo: upgrade::ProtocolName + Clone + Send + 'static, + T: upgrade::OutboundUpgrade + UpgradeInfoSend, T::Output: Send + 'static, T::Error: Send + 'static, T::Future: Send + 'static, @@ -81,7 +76,7 @@ where type Error = T::Error; type Future = T::Future; - fn upgrade_outbound(self, socket: NegotiatedSubstream, info: TInfo) -> Self::Future { + fn upgrade_outbound(self, socket: NegotiatedSubstream, info: upgrade::ProtocolName) -> Self::Future { upgrade::OutboundUpgrade::upgrade_outbound(self, socket, info) } } @@ -100,13 +95,12 @@ pub trait InboundUpgradeSend: UpgradeInfoSend { type Future: Future> + Send + 'static; /// Equivalent to [`InboundUpgrade::upgrade_inbound`](upgrade::InboundUpgrade::upgrade_inbound). - fn upgrade_inbound(self, socket: NegotiatedSubstream, info: Self::Info) -> Self::Future; + fn upgrade_inbound(self, socket: NegotiatedSubstream, info: upgrade::ProtocolName) -> Self::Future; } -impl InboundUpgradeSend for T +impl InboundUpgradeSend for T where - T: upgrade::InboundUpgrade + UpgradeInfoSend, - TInfo: upgrade::ProtocolName + Clone + Send + 'static, + T: upgrade::InboundUpgrade + UpgradeInfoSend, T::Output: Send + 'static, T::Error: Send + 'static, T::Future: Send + 'static, @@ -115,7 +109,7 @@ where type Error = T::Error; type Future = T::Future; - fn upgrade_inbound(self, socket: NegotiatedSubstream, info: TInfo) -> Self::Future { + fn upgrade_inbound(self, socket: NegotiatedSubstream, info: upgrade::ProtocolName) -> Self::Future { upgrade::InboundUpgrade::upgrade_inbound(self, socket, info) } } @@ -129,7 +123,6 @@ where pub struct SendWrapper(pub T); impl upgrade::UpgradeInfo for SendWrapper { - type Info = T::Info; type InfoIter = T::InfoIter; fn protocol_info(&self) -> Self::InfoIter { @@ -142,7 +135,7 @@ impl upgrade::OutboundUpgrade for S type Error = T::Error; type Future = T::Future; - fn upgrade_outbound(self, socket: NegotiatedSubstream, info: T::Info) -> Self::Future { + fn upgrade_outbound(self, socket: NegotiatedSubstream, info: upgrade::ProtocolName) -> Self::Future { OutboundUpgradeSend::upgrade_outbound(self.0, socket, info) } } @@ -152,7 +145,7 @@ impl upgrade::InboundUpgrade for Sen type Error = T::Error; type Future = T::Future; - fn upgrade_inbound(self, socket: NegotiatedSubstream, info: T::Info) -> Self::Future { + fn upgrade_inbound(self, socket: NegotiatedSubstream, info: upgrade::ProtocolName) -> Self::Future { InboundUpgradeSend::upgrade_inbound(self.0, socket, info) } }