Skip to content

Commit 1e9fcf9

Browse files
authored
core/: Remove DisconnectedPeer::set_connected and Pool::add (#2195)
This logic seems to be a leftover of #889 and unused today.
1 parent f2905c0 commit 1e9fcf9

File tree

5 files changed

+11
-129
lines changed

5 files changed

+11
-129
lines changed

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
- Require `ConnectionHandler::{InEvent,OutEvent,Error}` to implement `Debug`
2121
(see [PR 2183]).
2222

23+
- Remove `DisconnectedPeer::set_connected` and `Pool::add` (see [PR 2195]).
24+
25+
2326
[PR 2145]: https://github.com/libp2p/rust-libp2p/pull/2145
2427
[PR 2142]: https://github.com/libp2p/rust-libp2p/pull/2142
2528
[PR 2137]: https://github.com/libp2p/rust-libp2p/pull/2137
2629
[PR 2183]: https://github.com/libp2p/rust-libp2p/pull/2183
30+
[PR 2195]: https://github.com/libp2p/rust-libp2p/pull/2195
2731

2832
# 0.29.0 [2021-07-12]
2933

core/src/connection/manager.rs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
use super::{
2222
handler::{THandlerError, THandlerInEvent, THandlerOutEvent},
23-
Connected, ConnectedPoint, Connection, ConnectionError, ConnectionHandler,
24-
IntoConnectionHandler, PendingConnectionError, Substream,
23+
Connected, ConnectedPoint, ConnectionError, ConnectionHandler, IntoConnectionHandler,
24+
PendingConnectionError, Substream,
2525
};
2626
use crate::{muxing::StreamMuxer, Executor};
2727
use fnv::FnvHashMap;
@@ -276,40 +276,6 @@ impl<H: IntoConnectionHandler, TE> Manager<H, TE> {
276276
ConnectionId(task_id)
277277
}
278278

279-
/// Adds an existing connection to the manager.
280-
pub fn add<M>(&mut self, conn: Connection<M, H::Handler>, info: Connected) -> ConnectionId
281-
where
282-
H: IntoConnectionHandler + Send + 'static,
283-
H::Handler: ConnectionHandler<Substream = Substream<M>> + Send + 'static,
284-
<H::Handler as ConnectionHandler>::OutboundOpenInfo: Send + 'static,
285-
TE: error::Error + Send + 'static,
286-
M: StreamMuxer + Send + Sync + 'static,
287-
M::OutboundSubstream: Send + 'static,
288-
{
289-
let task_id = self.next_task_id;
290-
self.next_task_id.0 += 1;
291-
292-
let (tx, rx) = mpsc::channel(self.task_command_buffer_size);
293-
self.tasks.insert(
294-
task_id,
295-
TaskInfo {
296-
sender: tx,
297-
state: TaskState::Established(info),
298-
},
299-
);
300-
301-
let task: Pin<Box<Task<Pin<Box<future::Pending<_>>>, _, _, _>>> =
302-
Box::pin(Task::established(task_id, self.events_tx.clone(), rx, conn));
303-
304-
if let Some(executor) = &mut self.executor {
305-
executor.exec(task);
306-
} else {
307-
self.local_spawns.push(task);
308-
}
309-
310-
ConnectionId(task_id)
311-
}
312-
313279
/// Gets an entry for a managed connection, if it exists.
314280
pub fn entry(&mut self, id: ConnectionId) -> Option<Entry<'_, THandlerInEvent<H>>> {
315281
if let hash_map::Entry::Occupied(task) = self.tasks.entry(id.0) {

core/src/connection/manager/task.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,6 @@ where
130130
},
131131
}
132132
}
133-
134-
/// Create a task for an existing node we are already connected to.
135-
pub fn established(
136-
id: TaskId,
137-
events: mpsc::Sender<Event<H, E>>,
138-
commands: mpsc::Receiver<Command<THandlerInEvent<H>>>,
139-
connection: Connection<M, H::Handler>,
140-
) -> Self {
141-
Task {
142-
id,
143-
events,
144-
commands: commands.fuse(),
145-
state: State::Established {
146-
connection,
147-
event: None,
148-
},
149-
}
150-
}
151133
}
152134

153135
/// The state associated with the `Task` of a connection.

core/src/connection/pool.rs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020

2121
use crate::{
2222
connection::{
23-
self,
2423
handler::{THandlerError, THandlerInEvent, THandlerOutEvent},
2524
manager::{self, Manager, ManagerConfig},
26-
Connected, Connection, ConnectionError, ConnectionHandler, ConnectionId, ConnectionLimit,
27-
IncomingInfo, IntoConnectionHandler, OutgoingInfo, PendingConnectionError, Substream,
25+
Connected, ConnectionError, ConnectionHandler, ConnectionId, ConnectionLimit, IncomingInfo,
26+
IntoConnectionHandler, OutgoingInfo, PendingConnectionError, Substream,
2827
},
2928
muxing::StreamMuxer,
3029
ConnectedPoint, PeerId,
@@ -313,37 +312,6 @@ impl<THandler: IntoConnectionHandler, TTransErr> Pool<THandler, TTransErr> {
313312
id
314313
}
315314

316-
/// Adds an existing established connection to the pool.
317-
///
318-
/// Returns the assigned connection ID on success. An error is returned
319-
/// if the configured maximum number of established connections for the
320-
/// connected peer has been reached.
321-
pub fn add<TMuxer>(
322-
&mut self,
323-
c: Connection<TMuxer, THandler::Handler>,
324-
i: Connected,
325-
) -> Result<ConnectionId, ConnectionLimit>
326-
where
327-
THandler: IntoConnectionHandler + Send + 'static,
328-
THandler::Handler:
329-
ConnectionHandler<Substream = connection::Substream<TMuxer>> + Send + 'static,
330-
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send + 'static,
331-
TTransErr: error::Error + Send + 'static,
332-
TMuxer: StreamMuxer + Send + Sync + 'static,
333-
TMuxer::OutboundSubstream: Send + 'static,
334-
{
335-
self.counters.check_max_established(&i.endpoint)?;
336-
self.counters
337-
.check_max_established_per_peer(self.num_peer_established(&i.peer_id))?;
338-
let id = self.manager.add(c, i.clone());
339-
self.counters.inc_established(&i.endpoint);
340-
self.established
341-
.entry(i.peer_id)
342-
.or_default()
343-
.insert(id, i.endpoint);
344-
Ok(id)
345-
}
346-
347315
/// Gets an entry representing a connection in the pool.
348316
///
349317
/// Returns `None` if the pool has no connection with the given ID.

core/src/network/peer.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
use super::{DialError, DialingOpts, Network};
2222
use crate::{
2323
connection::{
24-
handler::THandlerInEvent, pool::Pool, Connected, ConnectedPoint, Connection,
25-
ConnectionHandler, ConnectionId, ConnectionLimit, EstablishedConnection,
26-
EstablishedConnectionIter, IntoConnectionHandler, PendingConnection, Substream,
24+
handler::THandlerInEvent, pool::Pool, ConnectedPoint, ConnectionHandler, ConnectionId,
25+
ConnectionLimit, EstablishedConnection, EstablishedConnectionIter, IntoConnectionHandler,
26+
PendingConnection, Substream,
2727
},
2828
Multiaddr, PeerId, StreamMuxer, Transport,
2929
};
@@ -472,44 +472,6 @@ where
472472
pub fn into_peer(self) -> Peer<'a, TTrans, THandler> {
473473
Peer::Disconnected(self)
474474
}
475-
476-
/// Moves the peer into a connected state by supplying an existing
477-
/// established connection.
478-
///
479-
/// No event is generated for this action.
480-
///
481-
/// # Panics
482-
///
483-
/// Panics if `connected.peer_id` does not identify the current peer.
484-
pub fn set_connected<TMuxer>(
485-
self,
486-
connected: Connected,
487-
connection: Connection<TMuxer, THandler::Handler>,
488-
) -> Result<ConnectedPeer<'a, TTrans, THandler>, ConnectionLimit>
489-
where
490-
THandler: Send + 'static,
491-
TTrans::Error: Send + 'static,
492-
THandler::Handler: ConnectionHandler<Substream = Substream<TMuxer>> + Send,
493-
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
494-
<THandler::Handler as ConnectionHandler>::Error: error::Error + Send + 'static,
495-
TMuxer: StreamMuxer + Send + Sync + 'static,
496-
TMuxer::OutboundSubstream: Send,
497-
{
498-
if connected.peer_id != self.peer_id {
499-
panic!(
500-
"Invalid peer ID given: {:?}. Expected: {:?}",
501-
connected.peer_id, self.peer_id
502-
)
503-
}
504-
505-
self.network
506-
.pool
507-
.add(connection, connected)
508-
.map(move |_id| ConnectedPeer {
509-
network: self.network,
510-
peer_id: self.peer_id,
511-
})
512-
}
513475
}
514476

515477
/// The (internal) state of a `DialingAttempt`, tracking the

0 commit comments

Comments
 (0)