mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 16:51:34 +00:00
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.
This commit is contained in:
@ -20,10 +20,14 @@
|
|||||||
- Require `ConnectionHandler::{InEvent,OutEvent,Error}` to implement `Debug`
|
- Require `ConnectionHandler::{InEvent,OutEvent,Error}` to implement `Debug`
|
||||||
(see [PR 2183]).
|
(see [PR 2183]).
|
||||||
|
|
||||||
|
- Remove `DisconnectedPeer::set_connected` and `Pool::add` (see [PR 2195]).
|
||||||
|
|
||||||
|
|
||||||
[PR 2145]: https://github.com/libp2p/rust-libp2p/pull/2145
|
[PR 2145]: https://github.com/libp2p/rust-libp2p/pull/2145
|
||||||
[PR 2142]: https://github.com/libp2p/rust-libp2p/pull/2142
|
[PR 2142]: https://github.com/libp2p/rust-libp2p/pull/2142
|
||||||
[PR 2137]: https://github.com/libp2p/rust-libp2p/pull/2137
|
[PR 2137]: https://github.com/libp2p/rust-libp2p/pull/2137
|
||||||
[PR 2183]: https://github.com/libp2p/rust-libp2p/pull/2183
|
[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]
|
# 0.29.0 [2021-07-12]
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
handler::{THandlerError, THandlerInEvent, THandlerOutEvent},
|
handler::{THandlerError, THandlerInEvent, THandlerOutEvent},
|
||||||
Connected, ConnectedPoint, Connection, ConnectionError, ConnectionHandler,
|
Connected, ConnectedPoint, ConnectionError, ConnectionHandler, IntoConnectionHandler,
|
||||||
IntoConnectionHandler, PendingConnectionError, Substream,
|
PendingConnectionError, Substream,
|
||||||
};
|
};
|
||||||
use crate::{muxing::StreamMuxer, Executor};
|
use crate::{muxing::StreamMuxer, Executor};
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
@ -276,40 +276,6 @@ impl<H: IntoConnectionHandler, TE> Manager<H, TE> {
|
|||||||
ConnectionId(task_id)
|
ConnectionId(task_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds an existing connection to the manager.
|
|
||||||
pub fn add<M>(&mut self, conn: Connection<M, H::Handler>, info: Connected) -> ConnectionId
|
|
||||||
where
|
|
||||||
H: IntoConnectionHandler + Send + 'static,
|
|
||||||
H::Handler: ConnectionHandler<Substream = Substream<M>> + Send + 'static,
|
|
||||||
<H::Handler as ConnectionHandler>::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<Task<Pin<Box<future::Pending<_>>>, _, _, _>>> =
|
|
||||||
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.
|
/// Gets an entry for a managed connection, if it exists.
|
||||||
pub fn entry(&mut self, id: ConnectionId) -> Option<Entry<'_, THandlerInEvent<H>>> {
|
pub fn entry(&mut self, id: ConnectionId) -> Option<Entry<'_, THandlerInEvent<H>>> {
|
||||||
if let hash_map::Entry::Occupied(task) = self.tasks.entry(id.0) {
|
if let hash_map::Entry::Occupied(task) = self.tasks.entry(id.0) {
|
||||||
|
@ -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<Event<H, E>>,
|
|
||||||
commands: mpsc::Receiver<Command<THandlerInEvent<H>>>,
|
|
||||||
connection: Connection<M, H::Handler>,
|
|
||||||
) -> Self {
|
|
||||||
Task {
|
|
||||||
id,
|
|
||||||
events,
|
|
||||||
commands: commands.fuse(),
|
|
||||||
state: State::Established {
|
|
||||||
connection,
|
|
||||||
event: None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The state associated with the `Task` of a connection.
|
/// The state associated with the `Task` of a connection.
|
||||||
|
@ -20,11 +20,10 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connection::{
|
connection::{
|
||||||
self,
|
|
||||||
handler::{THandlerError, THandlerInEvent, THandlerOutEvent},
|
handler::{THandlerError, THandlerInEvent, THandlerOutEvent},
|
||||||
manager::{self, Manager, ManagerConfig},
|
manager::{self, Manager, ManagerConfig},
|
||||||
Connected, Connection, ConnectionError, ConnectionHandler, ConnectionId, ConnectionLimit,
|
Connected, ConnectionError, ConnectionHandler, ConnectionId, ConnectionLimit, IncomingInfo,
|
||||||
IncomingInfo, IntoConnectionHandler, OutgoingInfo, PendingConnectionError, Substream,
|
IntoConnectionHandler, OutgoingInfo, PendingConnectionError, Substream,
|
||||||
},
|
},
|
||||||
muxing::StreamMuxer,
|
muxing::StreamMuxer,
|
||||||
ConnectedPoint, PeerId,
|
ConnectedPoint, PeerId,
|
||||||
@ -313,37 +312,6 @@ impl<THandler: IntoConnectionHandler, TTransErr> Pool<THandler, TTransErr> {
|
|||||||
id
|
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<TMuxer>(
|
|
||||||
&mut self,
|
|
||||||
c: Connection<TMuxer, THandler::Handler>,
|
|
||||||
i: Connected,
|
|
||||||
) -> Result<ConnectionId, ConnectionLimit>
|
|
||||||
where
|
|
||||||
THandler: IntoConnectionHandler + Send + 'static,
|
|
||||||
THandler::Handler:
|
|
||||||
ConnectionHandler<Substream = connection::Substream<TMuxer>> + Send + 'static,
|
|
||||||
<THandler::Handler as ConnectionHandler>::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.
|
/// Gets an entry representing a connection in the pool.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the pool has no connection with the given ID.
|
/// Returns `None` if the pool has no connection with the given ID.
|
||||||
|
@ -21,9 +21,9 @@
|
|||||||
use super::{DialError, DialingOpts, Network};
|
use super::{DialError, DialingOpts, Network};
|
||||||
use crate::{
|
use crate::{
|
||||||
connection::{
|
connection::{
|
||||||
handler::THandlerInEvent, pool::Pool, Connected, ConnectedPoint, Connection,
|
handler::THandlerInEvent, pool::Pool, ConnectedPoint, ConnectionHandler, ConnectionId,
|
||||||
ConnectionHandler, ConnectionId, ConnectionLimit, EstablishedConnection,
|
ConnectionLimit, EstablishedConnection, EstablishedConnectionIter, IntoConnectionHandler,
|
||||||
EstablishedConnectionIter, IntoConnectionHandler, PendingConnection, Substream,
|
PendingConnection, Substream,
|
||||||
},
|
},
|
||||||
Multiaddr, PeerId, StreamMuxer, Transport,
|
Multiaddr, PeerId, StreamMuxer, Transport,
|
||||||
};
|
};
|
||||||
@ -472,44 +472,6 @@ where
|
|||||||
pub fn into_peer(self) -> Peer<'a, TTrans, THandler> {
|
pub fn into_peer(self) -> Peer<'a, TTrans, THandler> {
|
||||||
Peer::Disconnected(self)
|
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<TMuxer>(
|
|
||||||
self,
|
|
||||||
connected: Connected,
|
|
||||||
connection: Connection<TMuxer, THandler::Handler>,
|
|
||||||
) -> Result<ConnectedPeer<'a, TTrans, THandler>, ConnectionLimit>
|
|
||||||
where
|
|
||||||
THandler: Send + 'static,
|
|
||||||
TTrans::Error: Send + 'static,
|
|
||||||
THandler::Handler: ConnectionHandler<Substream = Substream<TMuxer>> + Send,
|
|
||||||
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
|
|
||||||
<THandler::Handler as ConnectionHandler>::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
|
/// The (internal) state of a `DialingAttempt`, tracking the
|
||||||
|
Reference in New Issue
Block a user