From 4fe518de86ecb0805421cca6e291db168c10eac1 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 9 Dec 2022 18:56:30 +0100 Subject: [PATCH] feat!: Remove simple::SimpleProtocol (#3191) Due to lack of usage, remove the `simple::SimpleProtocol`. Users may look at `libp2p::core::upgrade` for alternatives. --- CHANGELOG.md | 4 +++ src/lib.rs | 2 -- src/simple.rs | 96 --------------------------------------------------- 3 files changed, 4 insertions(+), 98 deletions(-) delete mode 100644 src/simple.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index c9db1151f7cc..6ed797773194 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,9 +47,13 @@ # 0.51.0 [unreleased] +- Remove `SimpleProtocol` due to being unused. See [`libp2p::core::upgrade`](https://docs.rs/libp2p/0.50.0/libp2p/core/upgrade/index.html) for alternatives. See [PR 3191]. + - Update individual crates. - Update to [`libp2p-swarm` `v0.42.0`](swarm/CHANGELOG.md#0420). +[PR 3191]: https://github.com/libp2p/rust-libp2p/pull/3191 + # 0.50.0 This is a large release. After > 4 years, rust-libp2p ships with an [(alpha) QUIC diff --git a/src/lib.rs b/src/lib.rs index 1d80de1bd892..e87a5f746daf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,7 +140,6 @@ pub use libp2p_yamux as yamux; mod transport_ext; pub mod bandwidth; -pub mod simple; #[cfg(doc)] pub mod tutorials; @@ -152,7 +151,6 @@ pub use self::core::{ PeerId, Transport, }; pub use self::multiaddr::{multiaddr as build_multiaddr, Multiaddr}; -pub use self::simple::SimpleProtocol; pub use self::swarm::Swarm; pub use self::transport_ext::TransportExt; diff --git a/src/simple.rs b/src/simple.rs deleted file mode 100644 index fb4d3b735d25..000000000000 --- a/src/simple.rs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2017 Parity Technologies (UK) Ltd. -// -// 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. - -use crate::core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use bytes::Bytes; -use futures::prelude::*; -use std::{iter, sync::Arc}; - -/// Implementation of `ConnectionUpgrade`. Convenient to use with small protocols. -#[derive(Debug)] -pub struct SimpleProtocol { - info: Bytes, - // Note: we put the closure `F` in an `Arc` because Rust closures aren't automatically clonable - // yet. - upgrade: Arc, -} - -impl SimpleProtocol { - /// Builds a `SimpleProtocol`. - pub fn new(info: N, upgrade: F) -> SimpleProtocol - where - N: Into, - { - SimpleProtocol { - info: info.into(), - upgrade: Arc::new(upgrade), - } - } -} - -impl Clone for SimpleProtocol { - fn clone(&self) -> Self { - SimpleProtocol { - info: self.info.clone(), - upgrade: self.upgrade.clone(), - } - } -} - -impl UpgradeInfo for SimpleProtocol { - type Info = Bytes; - type InfoIter = iter::Once; - - fn protocol_info(&self) -> Self::InfoIter { - iter::once(self.info.clone()) - } -} - -impl InboundUpgrade for SimpleProtocol -where - C: AsyncRead + AsyncWrite, - F: Fn(C) -> O, - O: Future>, -{ - type Output = A; - type Error = E; - type Future = O; - - fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future { - let upgrade = &self.upgrade; - upgrade(socket) - } -} - -impl OutboundUpgrade for SimpleProtocol -where - C: AsyncRead + AsyncWrite, - F: Fn(C) -> O, - O: Future>, -{ - type Output = A; - type Error = E; - type Future = O; - - fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future { - let upgrade = &self.upgrade; - upgrade(socket) - } -}