From 1e9fcf90ea52612025baee7f24c808e08bfdb6ec Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 19 Aug 2021 20:17:18 +0200 Subject: [PATCH] core/: Remove DisconnectedPeer::set_connected and Pool::add (#2195) This logic seems to be a leftover of https://github.com/libp2p/rust-libp2p/pull/889 and unused today. --- core/CHANGELOG.md | 4 +++ core/src/connection/manager.rs | 38 ++----------------------- core/src/connection/manager/task.rs | 18 ------------ core/src/connection/pool.rs | 36 ++--------------------- core/src/network/peer.rs | 44 ++--------------------------- 5 files changed, 11 insertions(+), 129 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 695d1522..e252497f 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -20,10 +20,14 @@ - Require `ConnectionHandler::{InEvent,OutEvent,Error}` to implement `Debug` (see [PR 2183]). +- Remove `DisconnectedPeer::set_connected` and `Pool::add` (see [PR 2195]). + + [PR 2145]: https://github.com/libp2p/rust-libp2p/pull/2145 [PR 2142]: https://github.com/libp2p/rust-libp2p/pull/2142 [PR 2137]: https://github.com/libp2p/rust-libp2p/pull/2137 [PR 2183]: https://github.com/libp2p/rust-libp2p/pull/2183 +[PR 2195]: https://github.com/libp2p/rust-libp2p/pull/2195 # 0.29.0 [2021-07-12] diff --git a/core/src/connection/manager.rs b/core/src/connection/manager.rs index 1d7acb92..2d99bd18 100644 --- a/core/src/connection/manager.rs +++ b/core/src/connection/manager.rs @@ -20,8 +20,8 @@ use super::{ handler::{THandlerError, THandlerInEvent, THandlerOutEvent}, - Connected, ConnectedPoint, Connection, ConnectionError, ConnectionHandler, - IntoConnectionHandler, PendingConnectionError, Substream, + Connected, ConnectedPoint, ConnectionError, ConnectionHandler, IntoConnectionHandler, + PendingConnectionError, Substream, }; use crate::{muxing::StreamMuxer, Executor}; use fnv::FnvHashMap; @@ -276,40 +276,6 @@ impl Manager { ConnectionId(task_id) } - /// Adds an existing connection to the manager. - pub fn add(&mut self, conn: Connection, info: Connected) -> ConnectionId - where - H: IntoConnectionHandler + Send + 'static, - H::Handler: ConnectionHandler> + Send + 'static, - ::OutboundOpenInfo: Send + 'static, - TE: error::Error + Send + 'static, - M: StreamMuxer + Send + Sync + 'static, - M::OutboundSubstream: Send + 'static, - { - let task_id = self.next_task_id; - self.next_task_id.0 += 1; - - let (tx, rx) = mpsc::channel(self.task_command_buffer_size); - self.tasks.insert( - task_id, - TaskInfo { - sender: tx, - state: TaskState::Established(info), - }, - ); - - let task: Pin>>, _, _, _>>> = - Box::pin(Task::established(task_id, self.events_tx.clone(), rx, conn)); - - if let Some(executor) = &mut self.executor { - executor.exec(task); - } else { - self.local_spawns.push(task); - } - - ConnectionId(task_id) - } - /// Gets an entry for a managed connection, if it exists. pub fn entry(&mut self, id: ConnectionId) -> Option>> { if let hash_map::Entry::Occupied(task) = self.tasks.entry(id.0) { diff --git a/core/src/connection/manager/task.rs b/core/src/connection/manager/task.rs index db8fb43a..cf217cc8 100644 --- a/core/src/connection/manager/task.rs +++ b/core/src/connection/manager/task.rs @@ -130,24 +130,6 @@ where }, } } - - /// Create a task for an existing node we are already connected to. - pub fn established( - id: TaskId, - events: mpsc::Sender>, - commands: mpsc::Receiver>>, - connection: Connection, - ) -> Self { - Task { - id, - events, - commands: commands.fuse(), - state: State::Established { - connection, - event: None, - }, - } - } } /// The state associated with the `Task` of a connection. diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index 9925dd52..9fcbba32 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -20,11 +20,10 @@ use crate::{ connection::{ - self, handler::{THandlerError, THandlerInEvent, THandlerOutEvent}, manager::{self, Manager, ManagerConfig}, - Connected, Connection, ConnectionError, ConnectionHandler, ConnectionId, ConnectionLimit, - IncomingInfo, IntoConnectionHandler, OutgoingInfo, PendingConnectionError, Substream, + Connected, ConnectionError, ConnectionHandler, ConnectionId, ConnectionLimit, IncomingInfo, + IntoConnectionHandler, OutgoingInfo, PendingConnectionError, Substream, }, muxing::StreamMuxer, ConnectedPoint, PeerId, @@ -313,37 +312,6 @@ impl Pool { id } - /// Adds an existing established connection to the pool. - /// - /// Returns the assigned connection ID on success. An error is returned - /// if the configured maximum number of established connections for the - /// connected peer has been reached. - pub fn add( - &mut self, - c: Connection, - i: Connected, - ) -> Result - where - THandler: IntoConnectionHandler + Send + 'static, - THandler::Handler: - ConnectionHandler> + Send + 'static, - ::OutboundOpenInfo: Send + 'static, - TTransErr: error::Error + Send + 'static, - TMuxer: StreamMuxer + Send + Sync + 'static, - TMuxer::OutboundSubstream: Send + 'static, - { - self.counters.check_max_established(&i.endpoint)?; - self.counters - .check_max_established_per_peer(self.num_peer_established(&i.peer_id))?; - let id = self.manager.add(c, i.clone()); - self.counters.inc_established(&i.endpoint); - self.established - .entry(i.peer_id) - .or_default() - .insert(id, i.endpoint); - Ok(id) - } - /// Gets an entry representing a connection in the pool. /// /// Returns `None` if the pool has no connection with the given ID. diff --git a/core/src/network/peer.rs b/core/src/network/peer.rs index ca1b9be7..7e904ce2 100644 --- a/core/src/network/peer.rs +++ b/core/src/network/peer.rs @@ -21,9 +21,9 @@ use super::{DialError, DialingOpts, Network}; use crate::{ connection::{ - handler::THandlerInEvent, pool::Pool, Connected, ConnectedPoint, Connection, - ConnectionHandler, ConnectionId, ConnectionLimit, EstablishedConnection, - EstablishedConnectionIter, IntoConnectionHandler, PendingConnection, Substream, + handler::THandlerInEvent, pool::Pool, ConnectedPoint, ConnectionHandler, ConnectionId, + ConnectionLimit, EstablishedConnection, EstablishedConnectionIter, IntoConnectionHandler, + PendingConnection, Substream, }, Multiaddr, PeerId, StreamMuxer, Transport, }; @@ -472,44 +472,6 @@ where pub fn into_peer(self) -> Peer<'a, TTrans, THandler> { Peer::Disconnected(self) } - - /// Moves the peer into a connected state by supplying an existing - /// established connection. - /// - /// No event is generated for this action. - /// - /// # Panics - /// - /// Panics if `connected.peer_id` does not identify the current peer. - pub fn set_connected( - self, - connected: Connected, - connection: Connection, - ) -> Result, ConnectionLimit> - where - THandler: Send + 'static, - TTrans::Error: Send + 'static, - THandler::Handler: ConnectionHandler> + Send, - ::OutboundOpenInfo: Send, - ::Error: error::Error + Send + 'static, - TMuxer: StreamMuxer + Send + Sync + 'static, - TMuxer::OutboundSubstream: Send, - { - if connected.peer_id != self.peer_id { - panic!( - "Invalid peer ID given: {:?}. Expected: {:?}", - connected.peer_id, self.peer_id - ) - } - - self.network - .pool - .add(connection, connected) - .map(move |_id| ConnectedPeer { - network: self.network, - peer_id: self.peer_id, - }) - } } /// The (internal) state of a `DialingAttempt`, tracking the