diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 3f9854d89d6..f0d7579d17d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -3,7 +3,11 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Remove deprecated symbols related to upgrades. + See [PR 3867]. + [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3867]: https://github.com/libp2p/rust-libp2p/pull/3867 ## 0.39.2 diff --git a/core/src/upgrade.rs b/core/src/upgrade.rs index 4c46418e7a7..b53ba5f1d5e 100644 --- a/core/src/upgrade.rs +++ b/core/src/upgrade.rs @@ -61,9 +61,6 @@ mod apply; mod denied; mod either; mod error; -mod from_fn; -mod map; -mod optional; mod pending; mod ready; mod select; @@ -71,8 +68,6 @@ mod transfer; use futures::future::Future; -#[allow(deprecated)] -pub use self::from_fn::{from_fn, FromFnUpgrade}; pub use self::{ apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, denied::DeniedUpgrade, @@ -83,11 +78,7 @@ pub use self::{ transfer::{read_length_prefixed, read_varint, write_length_prefixed, write_varint}, }; pub use crate::Negotiated; -#[allow(deprecated)] -pub use map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr}; pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError, Version}; -#[allow(deprecated)] -pub use optional::OptionalUpgrade; /// Types serving as protocol names. /// @@ -164,35 +155,6 @@ pub trait InboundUpgrade: UpgradeInfo { fn upgrade_inbound(self, socket: C, info: Self::Info) -> Self::Future; } -/// Extension trait for `InboundUpgrade`. Automatically implemented on all types that implement -/// `InboundUpgrade`. -#[deprecated( - note = "Will be removed without replacement because it is not used within rust-libp2p." -)] -#[allow(deprecated)] -pub trait InboundUpgradeExt: InboundUpgrade { - /// Returns a new object that wraps around `Self` and applies a closure to the `Output`. - fn map_inbound(self, f: F) -> MapInboundUpgrade - where - Self: Sized, - F: FnOnce(Self::Output) -> T, - { - MapInboundUpgrade::new(self, f) - } - - /// Returns a new object that wraps around `Self` and applies a closure to the `Error`. - fn map_inbound_err(self, f: F) -> MapInboundUpgradeErr - where - Self: Sized, - F: FnOnce(Self::Error) -> T, - { - MapInboundUpgradeErr::new(self, f) - } -} - -#[allow(deprecated)] -impl> InboundUpgradeExt for U {} - /// Possible upgrade on an outbound connection or substream. pub trait OutboundUpgrade: UpgradeInfo { /// Output after the upgrade has been successfully negotiated and the handshake performed. @@ -208,32 +170,3 @@ pub trait OutboundUpgrade: UpgradeInfo { /// The `info` is the identifier of the protocol, as produced by `protocol_info`. fn upgrade_outbound(self, socket: C, info: Self::Info) -> Self::Future; } - -/// Extention trait for `OutboundUpgrade`. Automatically implemented on all types that implement -/// `OutboundUpgrade`. -#[deprecated( - note = "Will be removed without replacement because it is not used within rust-libp2p." -)] -#[allow(deprecated)] -pub trait OutboundUpgradeExt: OutboundUpgrade { - /// Returns a new object that wraps around `Self` and applies a closure to the `Output`. - fn map_outbound(self, f: F) -> MapOutboundUpgrade - where - Self: Sized, - F: FnOnce(Self::Output) -> T, - { - MapOutboundUpgrade::new(self, f) - } - - /// Returns a new object that wraps around `Self` and applies a closure to the `Error`. - fn map_outbound_err(self, f: F) -> MapOutboundUpgradeErr - where - Self: Sized, - F: FnOnce(Self::Error) -> T, - { - MapOutboundUpgradeErr::new(self, f) - } -} - -#[allow(deprecated)] -impl> OutboundUpgradeExt for U {} diff --git a/core/src/upgrade/from_fn.rs b/core/src/upgrade/from_fn.rs deleted file mode 100644 index d6da7b6ed5a..00000000000 --- a/core/src/upgrade/from_fn.rs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2020 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::{ - upgrade::{InboundUpgrade, OutboundUpgrade, ProtocolName, UpgradeInfo}, - Endpoint, -}; - -use futures::prelude::*; -use std::iter; - -/// Initializes a new [`FromFnUpgrade`]. -/// -/// # Example -/// -/// ``` -/// # use libp2p_core::transport::{Transport, MemoryTransport, memory::Channel}; -/// # use libp2p_core::{upgrade, Negotiated}; -/// # use std::io; -/// # use futures::AsyncWriteExt; -/// # #[allow(deprecated)] -/// let _transport = MemoryTransport::default() -/// .and_then(move |out, cp| { -/// upgrade::apply(out, upgrade::from_fn("/foo/1", move |mut sock: Negotiated>>, endpoint| async move { -/// if endpoint.is_dialer() { -/// upgrade::write_length_prefixed(&mut sock, "some handshake data").await?; -/// sock.close().await?; -/// } else { -/// let handshake_data = upgrade::read_length_prefixed(&mut sock, 1024).await?; -/// if handshake_data != b"some handshake data" { -/// return Err(io::Error::new(io::ErrorKind::Other, "bad handshake")); -/// } -/// } -/// Ok(sock) -/// }), cp, upgrade::Version::V1) -/// }); -/// ``` -/// -#[deprecated( - note = "`from_fn` upgrade will be removed without replacement as it is not used within `rust-libp2p`." -)] -#[allow(deprecated)] -pub fn from_fn(protocol_name: P, fun: F) -> FromFnUpgrade -where - // Note: these bounds are there in order to help the compiler infer types - P: ProtocolName + Clone, - F: FnOnce(C, Endpoint) -> Fut, - Fut: Future>, -{ - FromFnUpgrade { protocol_name, fun } -} - -/// Implements the `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` traits. -/// -/// The upgrade consists in calling the function passed when creating this struct. -#[derive(Debug, Clone)] -#[deprecated( - note = "`from_fn` upgrade will be removed without replacement as it is not used within `rust-libp2p`." -)] -pub struct FromFnUpgrade { - protocol_name: P, - fun: F, -} - -#[allow(deprecated)] -impl UpgradeInfo for FromFnUpgrade -where - P: ProtocolName + Clone, -{ - type Info = P; - type InfoIter = iter::Once

; - - fn protocol_info(&self) -> Self::InfoIter { - iter::once(self.protocol_name.clone()) - } -} - -#[allow(deprecated)] -impl InboundUpgrade for FromFnUpgrade -where - P: ProtocolName + Clone, - F: FnOnce(C, Endpoint) -> Fut, - Fut: Future>, -{ - type Output = Out; - type Error = Err; - type Future = Fut; - - fn upgrade_inbound(self, sock: C, _: Self::Info) -> Self::Future { - (self.fun)(sock, Endpoint::Listener) - } -} - -#[allow(deprecated)] -impl OutboundUpgrade for FromFnUpgrade -where - P: ProtocolName + Clone, - F: FnOnce(C, Endpoint) -> Fut, - Fut: Future>, -{ - type Output = Out; - type Error = Err; - type Future = Fut; - - fn upgrade_outbound(self, sock: C, _: Self::Info) -> Self::Future { - (self.fun)(sock, Endpoint::Dialer) - } -} diff --git a/core/src/upgrade/map.rs b/core/src/upgrade/map.rs deleted file mode 100644 index 4287665c88f..00000000000 --- a/core/src/upgrade/map.rs +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2018 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. - -#![allow(deprecated)] - -use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use futures::prelude::*; -use std::{pin::Pin, task::Context, task::Poll}; - -/// Wraps around an upgrade and applies a closure to the output. -#[derive(Debug, Clone)] -#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] -pub struct MapInboundUpgrade { - upgrade: U, - fun: F, -} - -impl MapInboundUpgrade { - pub fn new(upgrade: U, fun: F) -> Self { - MapInboundUpgrade { upgrade, fun } - } -} - -impl UpgradeInfo for MapInboundUpgrade -where - U: UpgradeInfo, -{ - type Info = U::Info; - type InfoIter = U::InfoIter; - - fn protocol_info(&self) -> Self::InfoIter { - self.upgrade.protocol_info() - } -} - -impl InboundUpgrade for MapInboundUpgrade -where - U: InboundUpgrade, - F: FnOnce(U::Output) -> T, -{ - type Output = T; - type Error = U::Error; - type Future = MapFuture; - - fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future { - MapFuture { - inner: self.upgrade.upgrade_inbound(sock, info), - map: Some(self.fun), - } - } -} - -impl OutboundUpgrade for MapInboundUpgrade -where - U: OutboundUpgrade, -{ - type Output = U::Output; - type Error = U::Error; - type Future = U::Future; - - fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future { - self.upgrade.upgrade_outbound(sock, info) - } -} - -/// Wraps around an upgrade and applies a closure to the output. -#[derive(Debug, Clone)] -#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] -pub struct MapOutboundUpgrade { - upgrade: U, - fun: F, -} - -impl MapOutboundUpgrade { - pub fn new(upgrade: U, fun: F) -> Self { - MapOutboundUpgrade { upgrade, fun } - } -} - -impl UpgradeInfo for MapOutboundUpgrade -where - U: UpgradeInfo, -{ - type Info = U::Info; - type InfoIter = U::InfoIter; - - fn protocol_info(&self) -> Self::InfoIter { - self.upgrade.protocol_info() - } -} - -impl InboundUpgrade for MapOutboundUpgrade -where - U: InboundUpgrade, -{ - type Output = U::Output; - type Error = U::Error; - type Future = U::Future; - - fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future { - self.upgrade.upgrade_inbound(sock, info) - } -} - -impl OutboundUpgrade for MapOutboundUpgrade -where - U: OutboundUpgrade, - F: FnOnce(U::Output) -> T, -{ - type Output = T; - type Error = U::Error; - type Future = MapFuture; - - fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future { - MapFuture { - inner: self.upgrade.upgrade_outbound(sock, info), - map: Some(self.fun), - } - } -} - -/// Wraps around an upgrade and applies a closure to the error. -#[derive(Debug, Clone)] -#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] -pub struct MapInboundUpgradeErr { - upgrade: U, - fun: F, -} - -impl MapInboundUpgradeErr { - pub fn new(upgrade: U, fun: F) -> Self { - MapInboundUpgradeErr { upgrade, fun } - } -} - -impl UpgradeInfo for MapInboundUpgradeErr -where - U: UpgradeInfo, -{ - type Info = U::Info; - type InfoIter = U::InfoIter; - - fn protocol_info(&self) -> Self::InfoIter { - self.upgrade.protocol_info() - } -} - -impl InboundUpgrade for MapInboundUpgradeErr -where - U: InboundUpgrade, - F: FnOnce(U::Error) -> T, -{ - type Output = U::Output; - type Error = T; - type Future = MapErrFuture; - - fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future { - MapErrFuture { - fut: self.upgrade.upgrade_inbound(sock, info), - fun: Some(self.fun), - } - } -} - -impl OutboundUpgrade for MapInboundUpgradeErr -where - U: OutboundUpgrade, -{ - type Output = U::Output; - type Error = U::Error; - type Future = U::Future; - - fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future { - self.upgrade.upgrade_outbound(sock, info) - } -} - -/// Wraps around an upgrade and applies a closure to the error. -#[derive(Debug, Clone)] -#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] -pub struct MapOutboundUpgradeErr { - upgrade: U, - fun: F, -} - -impl MapOutboundUpgradeErr { - pub fn new(upgrade: U, fun: F) -> Self { - MapOutboundUpgradeErr { upgrade, fun } - } -} - -impl UpgradeInfo for MapOutboundUpgradeErr -where - U: UpgradeInfo, -{ - type Info = U::Info; - type InfoIter = U::InfoIter; - - fn protocol_info(&self) -> Self::InfoIter { - self.upgrade.protocol_info() - } -} - -impl OutboundUpgrade for MapOutboundUpgradeErr -where - U: OutboundUpgrade, - F: FnOnce(U::Error) -> T, -{ - type Output = U::Output; - type Error = T; - type Future = MapErrFuture; - - fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future { - MapErrFuture { - fut: self.upgrade.upgrade_outbound(sock, info), - fun: Some(self.fun), - } - } -} - -impl InboundUpgrade for MapOutboundUpgradeErr -where - U: InboundUpgrade, -{ - type Output = U::Output; - type Error = U::Error; - type Future = U::Future; - - fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future { - self.upgrade.upgrade_inbound(sock, info) - } -} - -#[pin_project::pin_project] -pub struct MapFuture { - #[pin] - inner: TInnerFut, - map: Option, -} - -impl Future for MapFuture -where - TInnerFut: TryFuture, - TMap: FnOnce(TIn) -> TOut, -{ - type Output = Result; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - let item = match TryFuture::try_poll(this.inner, cx) { - Poll::Ready(Ok(v)) => v, - Poll::Ready(Err(err)) => return Poll::Ready(Err(err)), - Poll::Pending => return Poll::Pending, - }; - - let map = this.map.take().expect("Future has already finished"); - Poll::Ready(Ok(map(item))) - } -} - -#[pin_project::pin_project] -pub struct MapErrFuture { - #[pin] - fut: T, - fun: Option, -} - -impl Future for MapErrFuture -where - T: TryFuture, - F: FnOnce(E) -> A, -{ - type Output = Result; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - match TryFuture::try_poll(this.fut, cx) { - Poll::Pending => Poll::Pending, - Poll::Ready(Ok(x)) => Poll::Ready(Ok(x)), - Poll::Ready(Err(e)) => { - let f = this.fun.take().expect("Future has not resolved yet"); - Poll::Ready(Err(f(e))) - } - } - } -} diff --git a/core/src/upgrade/optional.rs b/core/src/upgrade/optional.rs deleted file mode 100644 index 40303db2bdf..00000000000 --- a/core/src/upgrade/optional.rs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2018 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. - -#![allow(deprecated)] - -use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; - -/// Upgrade that can be disabled at runtime. -/// -/// Wraps around an `Option` and makes it available or not depending on whether it contains or -/// not an upgrade. -#[derive(Debug, Clone)] -#[deprecated( - note = "Will be removed without replacement because it is not used within rust-libp2p." -)] -pub struct OptionalUpgrade(Option); - -impl OptionalUpgrade { - /// Creates an enabled `OptionalUpgrade`. - pub fn some(inner: T) -> Self { - OptionalUpgrade(Some(inner)) - } - - /// Creates a disabled `OptionalUpgrade`. - pub fn none() -> Self { - OptionalUpgrade(None) - } -} - -impl UpgradeInfo for OptionalUpgrade -where - T: UpgradeInfo, -{ - type Info = T::Info; - type InfoIter = Iter<::IntoIter>; - - fn protocol_info(&self) -> Self::InfoIter { - Iter(self.0.as_ref().map(|p| p.protocol_info().into_iter())) - } -} - -impl InboundUpgrade for OptionalUpgrade -where - T: InboundUpgrade, -{ - type Output = T::Output; - type Error = T::Error; - type Future = T::Future; - - fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future { - if let Some(inner) = self.0 { - inner.upgrade_inbound(sock, info) - } else { - panic!("Bad API usage; a protocol has been negotiated while this struct contains None") - } - } -} - -impl OutboundUpgrade for OptionalUpgrade -where - T: OutboundUpgrade, -{ - type Output = T::Output; - type Error = T::Error; - type Future = T::Future; - - fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future { - if let Some(inner) = self.0 { - inner.upgrade_outbound(sock, info) - } else { - panic!("Bad API usage; a protocol has been negotiated while this struct contains None") - } - } -} - -/// Iterator that flattens an `Option` where `T` is an iterator. -#[derive(Debug, Clone)] -pub struct Iter(Option); - -impl Iterator for Iter -where - T: Iterator, -{ - type Item = T::Item; - - fn next(&mut self) -> Option { - if let Some(iter) = self.0.as_mut() { - iter.next() - } else { - None - } - } - - fn size_hint(&self) -> (usize, Option) { - if let Some(iter) = self.0.as_ref() { - iter.size_hint() - } else { - (0, Some(0)) - } - } -} - -impl ExactSizeIterator for Iter where T: ExactSizeIterator {} diff --git a/libp2p/src/lib.rs b/libp2p/src/lib.rs index fad08b0128c..47db4ac4134 100644 --- a/libp2p/src/lib.rs +++ b/libp2p/src/lib.rs @@ -167,8 +167,6 @@ pub mod bandwidth; #[cfg(doc)] pub mod tutorials; -#[allow(deprecated)] -pub use self::core::upgrade::{InboundUpgradeExt, OutboundUpgradeExt}; pub use self::core::{ transport::TransportError, upgrade::{InboundUpgrade, OutboundUpgrade},