diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 348da58c..b585513d 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -167,9 +167,6 @@ impl Config { } /// Configures the size of the LRU cache, caching addresses of discovered peers. - /// - /// The [`Swarm`](libp2p_swarm::Swarm) may extend the set of addresses of an outgoing connection attempt via - /// [`Behaviour::addresses_of_peer`]. pub fn with_cache_size(mut self, cache_size: usize) -> Self { self.cache_size = cache_size; self diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 324d352c..e6f842ae 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -47,7 +47,7 @@ pub struct Behaviour { /// Hold addresses of all peers that we have discovered so far. /// - /// Storing these internally allows us to assist the [`libp2p_swarm::Swarm`] in dialing by returning addresses from [`NetworkBehaviour::addresses_of_peer`]. + /// Storing these internally allows us to assist the [`libp2p_swarm::Swarm`] in dialing by returning addresses from [`NetworkBehaviour::handle_pending_outbound_connection`]. discovered_peers: HashMap<(PeerId, Namespace), Vec>, /// Tracks the expiry of registrations that we have discovered and stored in `discovered_peers` otherwise we have a memory leak. diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 37e114b0..4267f83d 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -417,7 +417,7 @@ where /// Adds a known address for a peer that can be used for /// dialing attempts by the `Swarm`, i.e. is returned - /// by [`NetworkBehaviour::addresses_of_peer`]. + /// by [`NetworkBehaviour::handle_pending_outbound_connection`]. /// /// Addresses added in this way are only removed by `remove_address`. pub fn add_address(&mut self, peer: &PeerId, address: Multiaddr) { diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 64de61ff..aeab2912 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -18,12 +18,18 @@ This variant was never constructed and thus dead code. See [PR 3605]. -[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 -[PR 3746]: https://github.com/libp2p/rust-libp2p/pull/3746 +- Remove deprecated `IntoConnectionHandler` and all its implementations. + This also removes the `NetworkBehaviour::new_handler` and `NetworkBehaviour::addresses_of_peer` methods. + See changelog for `0.42` on how to migrate. + See [PR 3884]. + [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 [PR 3746]: https://github.com/libp2p/rust-libp2p/pull/3746 [PR 3865]: https://github.com/libp2p/rust-libp2p/pull/3865 [PR 3886]: https://github.com/libp2p/rust-libp2p/pull/3886 +[PR 3884]: https://github.com/libp2p/rust-libp2p/pull/3884 +[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 +[PR 3746]: https://github.com/libp2p/rust-libp2p/pull/3746 ## 0.42.2 diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 9fd014bd..01a10688 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -28,11 +28,9 @@ pub use listen_addresses::ListenAddresses; use crate::connection::ConnectionId; use crate::dial_opts::DialOpts; -#[allow(deprecated)] -use crate::handler::IntoConnectionHandler; use crate::{ - AddressRecord, AddressScore, ConnectionDenied, DialError, ListenError, THandler, - THandlerInEvent, THandlerOutEvent, + AddressRecord, AddressScore, ConnectionDenied, ConnectionHandler, DialError, ListenError, + THandler, THandlerInEvent, THandlerOutEvent, }; use libp2p_core::{transport::ListenerId, ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; @@ -77,9 +75,7 @@ use std::{task::Context, task::Poll}; /// implementation for the custom `struct`. Each [`NetworkBehaviour`] trait method is simply /// delegated to each `struct` member in the order the `struct` is defined. For example for /// [`NetworkBehaviour::poll`] it will first poll the first `struct` member until it returns -/// [`Poll::Pending`] before moving on to later members. For [`NetworkBehaviour::addresses_of_peer`] -/// it will delegate to each `struct` member and return a concatenated array of all addresses -/// returned by the struct members. +/// [`Poll::Pending`] before moving on to later members. /// /// Events ([`NetworkBehaviour::OutEvent`]) returned by each `struct` member are wrapped in a new /// `enum` event, with an `enum` variant for each `struct` member. Users can define this event @@ -122,37 +118,11 @@ use std::{task::Context, task::Poll}; /// ``` pub trait NetworkBehaviour: 'static { /// Handler for all the protocols the network behaviour supports. - #[allow(deprecated)] - type ConnectionHandler: IntoConnectionHandler; + type ConnectionHandler: ConnectionHandler; /// Event generated by the `NetworkBehaviour` and that the swarm will report back. type OutEvent: Send + 'static; - /// Creates a new [`ConnectionHandler`](crate::ConnectionHandler) for a connection with a peer. - /// - /// Every time an incoming connection is opened, and every time another [`NetworkBehaviour`] - /// emitted a dial request, this method is called. - /// - /// The returned object is a handler for that specific connection, and will be moved to a - /// background task dedicated to that connection. - /// - /// The network behaviour (ie. the implementation of this trait) and the handlers it has spawned - /// (ie. the objects returned by `new_handler`) can communicate by passing messages. Messages - /// sent from the handler to the behaviour are invoked with - /// [`NetworkBehaviour::on_connection_handler_event`], - /// and the behaviour can send a message to the handler by making [`NetworkBehaviour::poll`] - /// return [`ToSwarm::NotifyHandler`]. - /// - /// Note that the handler is returned to the [`NetworkBehaviour`] on connection failure and - /// connection closing. - #[deprecated( - since = "0.42.0", - note = "Use one or more of `NetworkBehaviour::{handle_pending_inbound_connection,handle_established_inbound_connection,handle_pending_outbound_connection,handle_established_outbound_connection}` instead." - )] - fn new_handler(&mut self) -> Self::ConnectionHandler { - panic!("You must implement `handle_established_inbound_connection` and `handle_established_outbound_connection`.") - } - /// Callback that is invoked for every new inbound connection. /// /// At this point in the connection lifecycle, only the remote's and our local address are known. @@ -181,16 +151,7 @@ pub trait NetworkBehaviour: 'static { peer: PeerId, local_addr: &Multiaddr, remote_addr: &Multiaddr, - ) -> Result, ConnectionDenied> { - #[allow(deprecated)] - Ok(self.new_handler().into_handler( - &peer, - &ConnectedPoint::Listener { - local_addr: local_addr.clone(), - send_back_addr: remote_addr.clone(), - }, - )) - } + ) -> Result, ConnectionDenied>; /// Callback that is invoked for every outbound connection attempt. /// @@ -207,16 +168,11 @@ pub trait NetworkBehaviour: 'static { fn handle_pending_outbound_connection( &mut self, _connection_id: ConnectionId, - maybe_peer: Option, + _maybe_peer: Option, _addresses: &[Multiaddr], _effective_role: Endpoint, ) -> Result, ConnectionDenied> { - #[allow(deprecated)] - if let Some(peer_id) = maybe_peer { - Ok(self.addresses_of_peer(&peer_id)) - } else { - Ok(vec![]) - } + Ok(vec![]) } /// Callback that is invoked for every established outbound connection. @@ -231,27 +187,7 @@ pub trait NetworkBehaviour: 'static { peer: PeerId, addr: &Multiaddr, role_override: Endpoint, - ) -> Result, ConnectionDenied> { - #[allow(deprecated)] - Ok(self.new_handler().into_handler( - &peer, - &ConnectedPoint::Dialer { - address: addr.clone(), - role_override, - }, - )) - } - - /// Addresses that this behaviour is aware of for this specific peer, and that may allow - /// reaching the peer. - /// - /// The addresses will be tried in the order returned by this function, which means that they - /// should be ordered by decreasing likelihood of reachability. In other words, the first - /// address should be the most likely to be reachable. - #[deprecated(note = "Use `NetworkBehaviour::handle_pending_outbound_connection` instead.")] - fn addresses_of_peer(&mut self, _: &PeerId) -> Vec { - vec![] - } + ) -> Result, ConnectionDenied>; /// Informs the behaviour about an event from the [`Swarm`](crate::Swarm). fn on_swarm_event(&mut self, event: FromSwarm); @@ -480,7 +416,7 @@ pub enum CloseConnection { /// Enumeration with the list of the possible events /// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event). #[allow(deprecated)] -pub enum FromSwarm<'a, Handler: IntoConnectionHandler> { +pub enum FromSwarm<'a, Handler> { /// Informs the behaviour about a newly established connection to a peer. ConnectionEstablished(ConnectionEstablished<'a>), /// Informs the behaviour about a closed connection to a peer. @@ -535,11 +471,11 @@ pub struct ConnectionEstablished<'a> { /// [`FromSwarm::ConnectionEstablished`] with the same peer ID, connection ID /// and endpoint. #[allow(deprecated)] -pub struct ConnectionClosed<'a, Handler: IntoConnectionHandler> { +pub struct ConnectionClosed<'a, Handler> { pub peer_id: PeerId, pub connection_id: ConnectionId, pub endpoint: &'a ConnectedPoint, - pub handler: ::Handler, + pub handler: Handler, pub remaining_established: usize, } @@ -625,30 +561,19 @@ pub struct ExpiredExternalAddr<'a> { pub addr: &'a Multiaddr, } -#[allow(deprecated)] -impl<'a, Handler: IntoConnectionHandler> FromSwarm<'a, Handler> { +impl<'a, Handler> FromSwarm<'a, Handler> { fn map_handler( self, - map_handler: impl FnOnce( - ::Handler, - ) -> ::Handler, - ) -> FromSwarm<'a, NewHandler> - where - NewHandler: IntoConnectionHandler, - { + map_handler: impl FnOnce(Handler) -> NewHandler, + ) -> FromSwarm<'a, NewHandler> { self.maybe_map_handler(|h| Some(map_handler(h))) .expect("To return Some as all closures return Some.") } fn maybe_map_handler( self, - map_handler: impl FnOnce( - ::Handler, - ) -> Option<::Handler>, - ) -> Option> - where - NewHandler: IntoConnectionHandler, - { + map_handler: impl FnOnce(Handler) -> Option, + ) -> Option> { match self { FromSwarm::ConnectionClosed(ConnectionClosed { peer_id, diff --git a/swarm/src/behaviour/external_addresses.rs b/swarm/src/behaviour/external_addresses.rs index 6f1d523e..49f540f8 100644 --- a/swarm/src/behaviour/external_addresses.rs +++ b/swarm/src/behaviour/external_addresses.rs @@ -1,6 +1,4 @@ use crate::behaviour::{ExpiredExternalAddr, FromSwarm, NewExternalAddr}; -#[allow(deprecated)] -use crate::IntoConnectionHandler; use libp2p_core::Multiaddr; use std::collections::HashSet; @@ -34,11 +32,7 @@ impl ExternalAddresses { /// Feed a [`FromSwarm`] event to this struct. /// /// Returns whether the event changed our set of external addresses. - #[allow(deprecated)] - pub fn on_swarm_event(&mut self, event: &FromSwarm) -> bool - where - THandler: IntoConnectionHandler, - { + pub fn on_swarm_event(&mut self, event: &FromSwarm) -> bool { match event { FromSwarm::NewExternalAddr(NewExternalAddr { addr, .. }) => { if self.addresses.len() < self.limit { diff --git a/swarm/src/behaviour/listen_addresses.rs b/swarm/src/behaviour/listen_addresses.rs index f2b61582..2a8adb8f 100644 --- a/swarm/src/behaviour/listen_addresses.rs +++ b/swarm/src/behaviour/listen_addresses.rs @@ -1,6 +1,4 @@ use crate::behaviour::{ExpiredListenAddr, FromSwarm, NewListenAddr}; -#[allow(deprecated)] -use crate::IntoConnectionHandler; use libp2p_core::Multiaddr; use std::collections::HashSet; @@ -19,11 +17,7 @@ impl ListenAddresses { /// Feed a [`FromSwarm`] event to this struct. /// /// Returns whether the event changed our set of listen addresses. - #[allow(deprecated)] - pub fn on_swarm_event(&mut self, event: &FromSwarm) -> bool - where - THandler: IntoConnectionHandler, - { + pub fn on_swarm_event(&mut self, event: &FromSwarm) -> bool { match event { FromSwarm::NewListenAddr(NewListenAddr { addr, .. }) => { self.addresses.insert((*addr).clone()) diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 68ad16ad..fec91a18 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -20,8 +20,6 @@ // DEALINGS IN THE SOFTWARE. #[allow(deprecated)] use crate::connection::{Connection, ConnectionId, ConnectionLimit, PendingPoint}; -#[allow(deprecated)] -use crate::IntoConnectionHandler; use crate::{ connection::{ Connected, ConnectionError, IncomingInfo, PendingConnectionError, @@ -512,7 +510,7 @@ where obtained_peer_id: PeerId, endpoint: &ConnectedPoint, connection: NewConnection, - handler: ::Handler, + handler: THandler, ) { let connection = connection.extract(); diff --git a/swarm/src/dial_opts.rs b/swarm/src/dial_opts.rs index 6ee60831..dc3d94cb 100644 --- a/swarm/src/dial_opts.rs +++ b/swarm/src/dial_opts.rs @@ -207,9 +207,6 @@ impl WithPeerId { } /// Build the final [`DialOpts`]. - /// - /// Addresses to dial the peer are retrieved via - /// [`NetworkBehaviour::addresses_of_peer`](crate::behaviour::NetworkBehaviour::addresses_of_peer). pub fn build(self) -> DialOpts { DialOpts { peer_id: Some(self.peer_id), @@ -241,7 +238,7 @@ impl WithPeerIdWithAddresses { } /// In addition to the provided addresses, extend the set via - /// [`NetworkBehaviour::addresses_of_peer`](crate::behaviour::NetworkBehaviour::addresses_of_peer). + /// [`NetworkBehaviour::handle_pending_outbound_connection`](crate::behaviour::NetworkBehaviour::handle_pending_outbound_connection). pub fn extend_addresses_through_behaviour(mut self) -> Self { self.extend_addresses_through_behaviour = true; self diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index b3810b97..4ce02c34 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -49,15 +49,14 @@ mod select; pub use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper, UpgradeInfoSend}; use instant::Instant; -use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Multiaddr}; -use libp2p_identity::PeerId; +use libp2p_core::{upgrade::UpgradeError, Multiaddr}; use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration}; pub use map_in::MapInEvent; pub use map_out::MapOutEvent; pub use one_shot::{OneShotHandler, OneShotHandlerConfig}; pub use pending::PendingConnectionHandler; -pub use select::{ConnectionHandlerSelect, IntoConnectionHandlerSelect}; +pub use select::ConnectionHandlerSelect; /// A handler for a set of protocols used on a connection with a remote. /// @@ -510,52 +509,6 @@ where } } -/// Prototype for a [`ConnectionHandler`]. -#[deprecated( - note = "Implement `ConnectionHandler` directly and use `NetworkBehaviour::{handle_pending_inbound_connection,handle_pending_outbound_connection}` to handle pending connections." -)] -pub trait IntoConnectionHandler: Send + 'static { - /// The protocols handler. - type Handler: ConnectionHandler; - - /// Builds the protocols handler. - /// - /// The `PeerId` is the id of the node the handler is going to handle. - fn into_handler( - self, - remote_peer_id: &PeerId, - connected_point: &ConnectedPoint, - ) -> Self::Handler; - - /// Return the handler's inbound protocol. - fn inbound_protocol(&self) -> ::InboundProtocol; - - /// Builds an implementation of [`IntoConnectionHandler`] that handles both this protocol and the - /// other one together. - fn select(self, other: TProto2) -> IntoConnectionHandlerSelect - where - Self: Sized, - { - IntoConnectionHandlerSelect::new(self, other) - } -} - -#[allow(deprecated)] -impl IntoConnectionHandler for T -where - T: ConnectionHandler, -{ - type Handler = Self; - - fn into_handler(self, _: &PeerId, _: &ConnectedPoint) -> Self { - self - } - - fn inbound_protocol(&self) -> ::InboundProtocol { - self.listen_protocol().into_upgrade().0 - } -} - /// How long the connection should be kept alive. #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum KeepAlive { diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index ece9ac44..a6b2152a 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -18,8 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#[allow(deprecated)] -use crate::handler::IntoConnectionHandler; use crate::handler::{ ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, FullyNegotiatedInbound, InboundUpgradeSend, KeepAlive, ListenUpgradeError, SubstreamProtocol, @@ -27,71 +25,8 @@ use crate::handler::{ use crate::upgrade::SendWrapper; use either::Either; use futures::future; -use libp2p_core::ConnectedPoint; -use libp2p_identity::PeerId; use std::task::{Context, Poll}; -/// Auxiliary type to allow implementing [`IntoConnectionHandler`]. As [`IntoConnectionHandler`] is -/// already implemented for T, we cannot implement it for Either. -pub enum IntoEitherHandler { - Left(L), - Right(R), -} - -/// Implementation of a [`IntoConnectionHandler`] that represents either of two [`IntoConnectionHandler`] -/// implementations. -#[allow(deprecated)] -impl IntoConnectionHandler for IntoEitherHandler -where - L: IntoConnectionHandler, - R: IntoConnectionHandler, -{ - type Handler = Either; - - fn into_handler(self, p: &PeerId, c: &ConnectedPoint) -> Self::Handler { - match self { - IntoEitherHandler::Left(into_handler) => Either::Left(into_handler.into_handler(p, c)), - IntoEitherHandler::Right(into_handler) => { - Either::Right(into_handler.into_handler(p, c)) - } - } - } - - fn inbound_protocol(&self) -> ::InboundProtocol { - match self { - IntoEitherHandler::Left(into_handler) => { - Either::Left(SendWrapper(into_handler.inbound_protocol())) - } - IntoEitherHandler::Right(into_handler) => { - Either::Right(SendWrapper(into_handler.inbound_protocol())) - } - } - } -} - -// Taken from https://github.com/bluss/either. -impl IntoEitherHandler { - /// Returns the left value. - pub fn unwrap_left(self) -> L { - match self { - IntoEitherHandler::Left(l) => l, - IntoEitherHandler::Right(_) => { - panic!("called `IntoEitherHandler::unwrap_left()` on a `Right` value.",) - } - } - } - - /// Returns the right value. - pub fn unwrap_right(self) -> R { - match self { - IntoEitherHandler::Right(r) => r, - IntoEitherHandler::Left(_) => { - panic!("called `IntoEitherHandler::unwrap_right()` on a `Left` value.",) - } - } - } -} - impl FullyNegotiatedInbound, SendWrapper>, Either> where diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index a90dc528..a934ebb6 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -21,8 +21,6 @@ //! A [`ConnectionHandler`] implementation that combines multiple other [`ConnectionHandler`]s //! indexed by some key. -#[allow(deprecated)] -use crate::handler::IntoConnectionHandler; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, ListenUpgradeError, @@ -31,8 +29,6 @@ use crate::handler::{ use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, UpgradeInfoSend}; use crate::NegotiatedSubstream; use futures::{future::BoxFuture, prelude::*}; -use libp2p_core::ConnectedPoint; -use libp2p_identity::PeerId; use rand::Rng; use std::{ cmp, @@ -280,76 +276,6 @@ impl IntoIterator for MultiHandler { } } -/// A [`IntoConnectionHandler`] for multiple other `IntoConnectionHandler`s. -#[derive(Clone)] -#[deprecated(note = "Use `MultiHandler` directly.")] -pub struct IntoMultiHandler { - handlers: HashMap, -} - -#[allow(deprecated)] -impl fmt::Debug for IntoMultiHandler -where - K: fmt::Debug + Eq + Hash, - H: fmt::Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("IntoMultiHandler") - .field("handlers", &self.handlers) - .finish() - } -} - -#[allow(deprecated)] -impl IntoMultiHandler -where - K: Hash + Eq, - H: IntoConnectionHandler, -{ - /// Create and populate an `IntoMultiHandler` from the given iterator. - /// - /// It is an error for any two protocols handlers to share the same protocol name. - pub fn try_from_iter(iter: I) -> Result - where - I: IntoIterator, - { - let m = IntoMultiHandler { - handlers: HashMap::from_iter(iter), - }; - uniq_proto_names(m.handlers.values().map(|h| h.inbound_protocol()))?; - Ok(m) - } -} - -#[allow(deprecated)] -impl IntoConnectionHandler for IntoMultiHandler -where - K: Debug + Clone + Eq + Hash + Send + 'static, - H: IntoConnectionHandler, -{ - type Handler = MultiHandler; - - fn into_handler(self, p: &PeerId, c: &ConnectedPoint) -> Self::Handler { - MultiHandler { - handlers: self - .handlers - .into_iter() - .map(|(k, h)| (k, h.into_handler(p, c))) - .collect(), - } - } - - fn inbound_protocol(&self) -> ::InboundProtocol { - Upgrade { - upgrades: self - .handlers - .iter() - .map(|(k, h)| (k.clone(), h.inbound_protocol())) - .collect(), - } - } -} - /// Index and protocol name pair used as `UpgradeInfo::Info`. #[derive(Debug, Clone)] pub struct IndexedProtoName(usize, H); diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index 9be6428b..197c8a5a 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -18,8 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#[allow(deprecated)] -use crate::handler::IntoConnectionHandler; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -28,60 +26,9 @@ use crate::handler::{ use crate::upgrade::SendWrapper; use either::Either; use futures::future; -use libp2p_core::{ - upgrade::{SelectUpgrade, UpgradeError}, - ConnectedPoint, -}; -use libp2p_identity::PeerId; +use libp2p_core::upgrade::{SelectUpgrade, UpgradeError}; use std::{cmp, task::Context, task::Poll}; -/// Implementation of `IntoConnectionHandler` that combines two protocols into one. -#[derive(Debug, Clone)] -pub struct IntoConnectionHandlerSelect { - /// The first protocol. - proto1: TProto1, - /// The second protocol. - proto2: TProto2, -} - -impl IntoConnectionHandlerSelect { - /// Builds a `IntoConnectionHandlerSelect`. - pub(crate) fn new(proto1: TProto1, proto2: TProto2) -> Self { - IntoConnectionHandlerSelect { proto1, proto2 } - } - - pub fn into_inner(self) -> (TProto1, TProto2) { - (self.proto1, self.proto2) - } -} - -#[allow(deprecated)] -impl IntoConnectionHandler for IntoConnectionHandlerSelect -where - TProto1: IntoConnectionHandler, - TProto2: IntoConnectionHandler, -{ - type Handler = ConnectionHandlerSelect; - - fn into_handler( - self, - remote_peer_id: &PeerId, - connected_point: &ConnectedPoint, - ) -> Self::Handler { - ConnectionHandlerSelect { - proto1: self.proto1.into_handler(remote_peer_id, connected_point), - proto2: self.proto2.into_handler(remote_peer_id, connected_point), - } - } - - fn inbound_protocol(&self) -> ::InboundProtocol { - SelectUpgrade::new( - SendWrapper(self.proto1.inbound_protocol()), - SendWrapper(self.proto2.inbound_protocol()), - ) - } -} - /// Implementation of [`ConnectionHandler`] that combines two protocols into one. #[derive(Debug, Clone)] pub struct ConnectionHandlerSelect { diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 06504d18..5e7c44d9 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -121,12 +121,9 @@ pub use behaviour::{ pub use connection::pool::{ConnectionCounters, ConnectionLimits}; pub use connection::{ConnectionError, ConnectionId}; pub use executor::Executor; -#[allow(deprecated)] -pub use handler::IntoConnectionHandler; pub use handler::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerSelect, ConnectionHandlerUpgrErr, - IntoConnectionHandlerSelect, KeepAlive, OneShotHandler, OneShotHandlerConfig, - SubstreamProtocol, + KeepAlive, OneShotHandler, OneShotHandlerConfig, SubstreamProtocol, }; #[cfg(feature = "macros")] pub use libp2p_swarm_derive::NetworkBehaviour; @@ -174,8 +171,7 @@ type TBehaviourOutEvent = ::OutEvent /// [`ConnectionHandler`] of the [`NetworkBehaviour`] for all the protocols the [`NetworkBehaviour`] /// supports. #[allow(deprecated)] -pub type THandler = - <::ConnectionHandler as IntoConnectionHandler>::Handler; +pub type THandler = ::ConnectionHandler; /// Custom event that can be received by the [`ConnectionHandler`] of the /// [`NetworkBehaviour`]. @@ -1681,8 +1677,7 @@ pub enum DialError { LocalPeerId { endpoint: ConnectedPoint, }, - /// [`NetworkBehaviour::addresses_of_peer`] returned no addresses - /// for the peer to dial. + /// No addresses have been provided by [`NetworkBehaviour::handle_pending_outbound_connection`] and [`DialOpts`]. NoAddresses, /// The provided [`dial_opts::PeerCondition`] evaluated to false and thus /// the dial was aborted. diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 5d7bdcac..ccb282bd 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -41,9 +41,9 @@ where TOutEvent: Send + 'static, { /// The prototype protocols handler that is cloned for every - /// invocation of `new_handler`. + /// invocation of [`NetworkBehaviour::handle_established_inbound_connection`] and [`NetworkBehaviour::handle_established_outbound_connection`] pub(crate) handler_proto: THandler, - /// The addresses to return from `addresses_of_peer`. + /// The addresses to return from [`NetworkBehaviour::handle_established_outbound_connection`]. pub(crate) addresses: HashMap>, /// The next action to return from `poll`. ///