mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-21 13:51:33 +00:00
feat(swarm): remove deprecated items
Related: https://github.com/libp2p/rust-libp2p/issues/3647. Pull-Request: #3956.
This commit is contained in:
@ -180,7 +180,7 @@
|
|||||||
//! [`Transport`] to the [`NetworkBehaviour`].
|
//! [`Transport`] to the [`NetworkBehaviour`].
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, Swarm};
|
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder};
|
||||||
//! use libp2p::{identity, ping, PeerId};
|
//! use libp2p::{identity, ping, PeerId};
|
||||||
//! use std::error::Error;
|
//! use std::error::Error;
|
||||||
//!
|
//!
|
||||||
@ -194,7 +194,7 @@
|
|||||||
//!
|
//!
|
||||||
//! let behaviour = Behaviour::default();
|
//! let behaviour = Behaviour::default();
|
||||||
//!
|
//!
|
||||||
//! let mut swarm = Swarm::with_async_std_executor(transport, behaviour, local_peer_id);
|
//! let mut swarm = SwarmBuilder::with_async_std_executor(transport, behaviour, local_peer_id).build();
|
||||||
//!
|
//!
|
||||||
//! Ok(())
|
//! Ok(())
|
||||||
//! }
|
//! }
|
||||||
@ -237,7 +237,7 @@
|
|||||||
//! remote peer.
|
//! remote peer.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, Swarm};
|
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder};
|
||||||
//! use libp2p::{identity, ping, Multiaddr, PeerId};
|
//! use libp2p::{identity, ping, Multiaddr, PeerId};
|
||||||
//! use std::error::Error;
|
//! use std::error::Error;
|
||||||
//!
|
//!
|
||||||
@ -251,7 +251,7 @@
|
|||||||
//!
|
//!
|
||||||
//! let behaviour = Behaviour::default();
|
//! let behaviour = Behaviour::default();
|
||||||
//!
|
//!
|
||||||
//! let mut swarm = Swarm::with_async_std_executor(transport, behaviour, local_peer_id);
|
//! let mut swarm = SwarmBuilder::with_async_std_executor(transport, behaviour, local_peer_id).build();
|
||||||
//!
|
//!
|
||||||
//! // Tell the swarm to listen on all interfaces and a random, OS-assigned
|
//! // Tell the swarm to listen on all interfaces and a random, OS-assigned
|
||||||
//! // port.
|
//! // port.
|
||||||
@ -287,7 +287,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use futures::prelude::*;
|
//! use futures::prelude::*;
|
||||||
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent};
|
//! use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmEvent, SwarmBuilder};
|
||||||
//! use libp2p::{identity, ping, Multiaddr, PeerId};
|
//! use libp2p::{identity, ping, Multiaddr, PeerId};
|
||||||
//! use std::error::Error;
|
//! use std::error::Error;
|
||||||
//!
|
//!
|
||||||
@ -301,7 +301,7 @@
|
|||||||
//!
|
//!
|
||||||
//! let behaviour = Behaviour::default();
|
//! let behaviour = Behaviour::default();
|
||||||
//!
|
//!
|
||||||
//! let mut swarm = Swarm::with_async_std_executor(transport, behaviour, local_peer_id);
|
//! let mut swarm = SwarmBuilder::with_async_std_executor(transport, behaviour, local_peer_id).build();
|
||||||
//!
|
//!
|
||||||
//! // Tell the swarm to listen on all interfaces and a random, OS-assigned
|
//! // Tell the swarm to listen on all interfaces and a random, OS-assigned
|
||||||
//! // port.
|
//! // port.
|
||||||
|
@ -56,6 +56,8 @@
|
|||||||
|
|
||||||
- Rename `ConnectionHandlerEvent::Custom` to `ConnectionHandlerEvent::NotifyBehaviour`. See [PR 3955].
|
- Rename `ConnectionHandlerEvent::Custom` to `ConnectionHandlerEvent::NotifyBehaviour`. See [PR 3955].
|
||||||
|
|
||||||
|
- Remove deprecated items. See [PR 3956].
|
||||||
|
|
||||||
[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605
|
[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605
|
||||||
[PR 3651]: https://github.com/libp2p/rust-libp2p/pull/3651
|
[PR 3651]: https://github.com/libp2p/rust-libp2p/pull/3651
|
||||||
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
|
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
|
||||||
@ -70,6 +72,7 @@
|
|||||||
[PR 3919]: https://github.com/libp2p/rust-libp2p/pull/3919
|
[PR 3919]: https://github.com/libp2p/rust-libp2p/pull/3919
|
||||||
[PR 3927]: https://github.com/libp2p/rust-libp2p/pull/3927
|
[PR 3927]: https://github.com/libp2p/rust-libp2p/pull/3927
|
||||||
[PR 3955]: https://github.com/libp2p/rust-libp2p/pull/3955
|
[PR 3955]: https://github.com/libp2p/rust-libp2p/pull/3955
|
||||||
|
[PR 3956]: https://github.com/libp2p/rust-libp2p/pull/3956
|
||||||
|
|
||||||
## 0.42.2
|
## 0.42.2
|
||||||
|
|
||||||
|
@ -219,8 +219,6 @@ pub trait NetworkBehaviour: 'static {
|
|||||||
pub trait PollParameters {
|
pub trait PollParameters {
|
||||||
/// Iterator returned by [`supported_protocols`](PollParameters::supported_protocols).
|
/// Iterator returned by [`supported_protocols`](PollParameters::supported_protocols).
|
||||||
type SupportedProtocolsIter: ExactSizeIterator<Item = Vec<u8>>;
|
type SupportedProtocolsIter: ExactSizeIterator<Item = Vec<u8>>;
|
||||||
/// Iterator returned by [`listened_addresses`](PollParameters::listened_addresses).
|
|
||||||
type ListenedAddressesIter: ExactSizeIterator<Item = Multiaddr>;
|
|
||||||
|
|
||||||
/// Returns the list of protocol the behaviour supports when a remote negotiates a protocol on
|
/// Returns the list of protocol the behaviour supports when a remote negotiates a protocol on
|
||||||
/// an inbound substream.
|
/// an inbound substream.
|
||||||
@ -232,20 +230,6 @@ pub trait PollParameters {
|
|||||||
note = "Use `libp2p_swarm::SupportedProtocols` in your `ConnectionHandler` instead."
|
note = "Use `libp2p_swarm::SupportedProtocols` in your `ConnectionHandler` instead."
|
||||||
)]
|
)]
|
||||||
fn supported_protocols(&self) -> Self::SupportedProtocolsIter;
|
fn supported_protocols(&self) -> Self::SupportedProtocolsIter;
|
||||||
|
|
||||||
/// Returns the list of the addresses we're listening on.
|
|
||||||
#[deprecated(
|
|
||||||
since = "0.42.0",
|
|
||||||
note = "Use `libp2p_swarm::ListenAddresses` instead."
|
|
||||||
)]
|
|
||||||
fn listened_addresses(&self) -> Self::ListenedAddressesIter;
|
|
||||||
|
|
||||||
/// Returns the peer id of the local node.
|
|
||||||
#[deprecated(
|
|
||||||
since = "0.42.0",
|
|
||||||
note = "Pass the node's `PeerId` into the behaviour instead."
|
|
||||||
)]
|
|
||||||
fn local_peer_id(&self) -> &PeerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A command issued from a [`NetworkBehaviour`] for the [`Swarm`].
|
/// A command issued from a [`NetworkBehaviour`] for the [`Swarm`].
|
||||||
@ -413,7 +397,6 @@ pub enum CloseConnection {
|
|||||||
|
|
||||||
/// Enumeration with the list of the possible events
|
/// Enumeration with the list of the possible events
|
||||||
/// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event).
|
/// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event).
|
||||||
#[allow(deprecated)]
|
|
||||||
pub enum FromSwarm<'a, Handler> {
|
pub enum FromSwarm<'a, Handler> {
|
||||||
/// Informs the behaviour about a newly established connection to a peer.
|
/// Informs the behaviour about a newly established connection to a peer.
|
||||||
ConnectionEstablished(ConnectionEstablished<'a>),
|
ConnectionEstablished(ConnectionEstablished<'a>),
|
||||||
@ -470,7 +453,6 @@ pub struct ConnectionEstablished<'a> {
|
|||||||
/// This event is always paired with an earlier
|
/// This event is always paired with an earlier
|
||||||
/// [`FromSwarm::ConnectionEstablished`] with the same peer ID, connection ID
|
/// [`FromSwarm::ConnectionEstablished`] with the same peer ID, connection ID
|
||||||
/// and endpoint.
|
/// and endpoint.
|
||||||
#[allow(deprecated)]
|
|
||||||
pub struct ConnectionClosed<'a, Handler> {
|
pub struct ConnectionClosed<'a, Handler> {
|
||||||
pub peer_id: PeerId,
|
pub peer_id: PeerId,
|
||||||
pub connection_id: ConnectionId,
|
pub connection_id: ConnectionId,
|
||||||
|
@ -66,15 +66,6 @@ static NEXT_CONNECTION_ID: AtomicUsize = AtomicUsize::new(1);
|
|||||||
pub struct ConnectionId(usize);
|
pub struct ConnectionId(usize);
|
||||||
|
|
||||||
impl ConnectionId {
|
impl ConnectionId {
|
||||||
/// A "dummy" [`ConnectionId`].
|
|
||||||
///
|
|
||||||
/// Really, you should not use this, not even for testing but it is here if you need it.
|
|
||||||
#[deprecated(
|
|
||||||
since = "0.42.0",
|
|
||||||
note = "Don't use this, it will be removed at a later stage again."
|
|
||||||
)]
|
|
||||||
pub const DUMMY: ConnectionId = ConnectionId(0);
|
|
||||||
|
|
||||||
/// Creates an _unchecked_ [`ConnectionId`].
|
/// Creates an _unchecked_ [`ConnectionId`].
|
||||||
///
|
///
|
||||||
/// [`Swarm`](crate::Swarm) enforces that [`ConnectionId`]s are unique and not reused.
|
/// [`Swarm`](crate::Swarm) enforces that [`ConnectionId`]s are unique and not reused.
|
||||||
|
@ -406,7 +406,6 @@ where
|
|||||||
|
|
||||||
/// Adds a pending outgoing connection to the pool in the form of a `Future`
|
/// Adds a pending outgoing connection to the pool in the form of a `Future`
|
||||||
/// that establishes and negotiates the connection.
|
/// that establishes and negotiates the connection.
|
||||||
#[allow(deprecated)]
|
|
||||||
pub(crate) fn add_outgoing(
|
pub(crate) fn add_outgoing(
|
||||||
&mut self,
|
&mut self,
|
||||||
dials: Vec<
|
dials: Vec<
|
||||||
@ -486,7 +485,6 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
pub(crate) fn spawn_connection(
|
pub(crate) fn spawn_connection(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: ConnectionId,
|
id: ConnectionId,
|
||||||
|
127
swarm/src/lib.rs
127
swarm/src/lib.rs
@ -132,7 +132,7 @@ use connection::{
|
|||||||
PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError,
|
PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError,
|
||||||
};
|
};
|
||||||
use dial_opts::{DialOpts, PeerCondition};
|
use dial_opts::{DialOpts, PeerCondition};
|
||||||
use futures::{executor::ThreadPoolBuilder, prelude::*, stream::FusedStream};
|
use futures::{prelude::*, stream::FusedStream};
|
||||||
use libp2p_core::{
|
use libp2p_core::{
|
||||||
connection::ConnectedPoint,
|
connection::ConnectedPoint,
|
||||||
multiaddr,
|
multiaddr,
|
||||||
@ -164,7 +164,6 @@ type TBehaviourOutEvent<TBehaviour> = <TBehaviour as NetworkBehaviour>::ToSwarm;
|
|||||||
|
|
||||||
/// [`ConnectionHandler`] of the [`NetworkBehaviour`] for all the protocols the [`NetworkBehaviour`]
|
/// [`ConnectionHandler`] of the [`NetworkBehaviour`] for all the protocols the [`NetworkBehaviour`]
|
||||||
/// supports.
|
/// supports.
|
||||||
#[allow(deprecated)]
|
|
||||||
pub type THandler<TBehaviour> = <TBehaviour as NetworkBehaviour>::ConnectionHandler;
|
pub type THandler<TBehaviour> = <TBehaviour as NetworkBehaviour>::ConnectionHandler;
|
||||||
|
|
||||||
/// Custom event that can be received by the [`ConnectionHandler`] of the
|
/// Custom event that can be received by the [`ConnectionHandler`] of the
|
||||||
@ -352,121 +351,10 @@ where
|
|||||||
|
|
||||||
impl<TBehaviour> Unpin for Swarm<TBehaviour> where TBehaviour: NetworkBehaviour {}
|
impl<TBehaviour> Unpin for Swarm<TBehaviour> where TBehaviour: NetworkBehaviour {}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl<TBehaviour> Swarm<TBehaviour>
|
impl<TBehaviour> Swarm<TBehaviour>
|
||||||
where
|
where
|
||||||
TBehaviour: NetworkBehaviour,
|
TBehaviour: NetworkBehaviour,
|
||||||
{
|
{
|
||||||
/// Builds a new `Swarm` with a provided executor.
|
|
||||||
#[deprecated(note = "Use `SwarmBuilder::with_executor` instead.")]
|
|
||||||
pub fn with_executor(
|
|
||||||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
|
|
||||||
behaviour: TBehaviour,
|
|
||||||
local_peer_id: PeerId,
|
|
||||||
executor: impl Executor + Send + 'static,
|
|
||||||
) -> Self {
|
|
||||||
SwarmBuilder::with_executor(transport, behaviour, local_peer_id, executor).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds a new `Swarm` with a tokio executor.
|
|
||||||
#[cfg(all(
|
|
||||||
feature = "tokio",
|
|
||||||
not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))
|
|
||||||
))]
|
|
||||||
#[deprecated(note = "Use `SwarmBuilder::with_tokio_executor` instead.")]
|
|
||||||
pub fn with_tokio_executor(
|
|
||||||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
|
|
||||||
behaviour: TBehaviour,
|
|
||||||
local_peer_id: PeerId,
|
|
||||||
) -> Self {
|
|
||||||
Self::with_executor(
|
|
||||||
transport,
|
|
||||||
behaviour,
|
|
||||||
local_peer_id,
|
|
||||||
crate::executor::TokioExecutor,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds a new `Swarm` with an async-std executor.
|
|
||||||
#[cfg(all(
|
|
||||||
feature = "async-std",
|
|
||||||
not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))
|
|
||||||
))]
|
|
||||||
#[deprecated(note = "Use `SwarmBuilder::with_async_std_executor` instead.")]
|
|
||||||
pub fn with_async_std_executor(
|
|
||||||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
|
|
||||||
behaviour: TBehaviour,
|
|
||||||
local_peer_id: PeerId,
|
|
||||||
) -> Self {
|
|
||||||
Self::with_executor(
|
|
||||||
transport,
|
|
||||||
behaviour,
|
|
||||||
local_peer_id,
|
|
||||||
crate::executor::AsyncStdExecutor,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds a new `Swarm` with a threadpool executor.
|
|
||||||
#[deprecated(
|
|
||||||
note = "The `futures::executor::ThreadPool` executor is deprecated. See https://github.com/libp2p/rust-libp2p/issues/3107."
|
|
||||||
)]
|
|
||||||
pub fn with_threadpool_executor(
|
|
||||||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
|
|
||||||
behaviour: TBehaviour,
|
|
||||||
local_peer_id: PeerId,
|
|
||||||
) -> Self {
|
|
||||||
let builder = match ThreadPoolBuilder::new()
|
|
||||||
.name_prefix("libp2p-swarm-task-")
|
|
||||||
.create()
|
|
||||||
{
|
|
||||||
Ok(tp) => SwarmBuilder::with_executor(transport, behaviour, local_peer_id, tp),
|
|
||||||
Err(err) => {
|
|
||||||
log::warn!("Failed to create executor thread pool: {:?}", err);
|
|
||||||
SwarmBuilder::without_executor(transport, behaviour, local_peer_id)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
builder.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds a new `Swarm` with a wasm executor.
|
|
||||||
/// Background tasks will be executed by the browser on the next micro-tick.
|
|
||||||
///
|
|
||||||
/// Spawning a task is similar too:
|
|
||||||
/// ```typescript
|
|
||||||
/// function spawn(task: () => Promise<void>) {
|
|
||||||
/// task()
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[cfg(feature = "wasm-bindgen")]
|
|
||||||
#[deprecated(note = "Use `SwarmBuilder::with_wasm_executor` instead.")]
|
|
||||||
pub fn with_wasm_executor(
|
|
||||||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
|
|
||||||
behaviour: TBehaviour,
|
|
||||||
local_peer_id: PeerId,
|
|
||||||
) -> Self {
|
|
||||||
Self::with_executor(
|
|
||||||
transport,
|
|
||||||
behaviour,
|
|
||||||
local_peer_id,
|
|
||||||
crate::executor::WasmBindgenExecutor,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds a new `Swarm` without an executor, instead using the current task.
|
|
||||||
///
|
|
||||||
/// ## ⚠️ Performance warning
|
|
||||||
/// All connections will be polled on the current task, thus quite bad performance
|
|
||||||
/// characteristics should be expected. Whenever possible use an executor and
|
|
||||||
/// [`Swarm::with_executor`].
|
|
||||||
#[deprecated(note = "Use `SwarmBuilder::without_executor` instead.")]
|
|
||||||
pub fn without_executor(
|
|
||||||
transport: transport::Boxed<(PeerId, StreamMuxerBox)>,
|
|
||||||
behaviour: TBehaviour,
|
|
||||||
local_peer_id: PeerId,
|
|
||||||
) -> Self {
|
|
||||||
SwarmBuilder::without_executor(transport, behaviour, local_peer_id).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns information about the connections underlying the [`Swarm`].
|
/// Returns information about the connections underlying the [`Swarm`].
|
||||||
pub fn network_info(&self) -> NetworkInfo {
|
pub fn network_info(&self) -> NetworkInfo {
|
||||||
let num_peers = self.pool.num_peers();
|
let num_peers = self.pool.num_peers();
|
||||||
@ -1250,9 +1138,7 @@ where
|
|||||||
None => {
|
None => {
|
||||||
let behaviour_poll = {
|
let behaviour_poll = {
|
||||||
let mut parameters = SwarmPollParameters {
|
let mut parameters = SwarmPollParameters {
|
||||||
local_peer_id: &this.local_peer_id,
|
|
||||||
supported_protocols: &this.supported_protocols,
|
supported_protocols: &this.supported_protocols,
|
||||||
listened_addrs: this.listened_addrs.values().flatten().collect(),
|
|
||||||
};
|
};
|
||||||
this.behaviour.poll(cx, &mut parameters)
|
this.behaviour.poll(cx, &mut parameters)
|
||||||
};
|
};
|
||||||
@ -1417,26 +1303,15 @@ where
|
|||||||
/// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to.
|
/// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to.
|
||||||
// TODO: #[derive(Debug)]
|
// TODO: #[derive(Debug)]
|
||||||
pub struct SwarmPollParameters<'a> {
|
pub struct SwarmPollParameters<'a> {
|
||||||
local_peer_id: &'a PeerId,
|
|
||||||
supported_protocols: &'a [Vec<u8>],
|
supported_protocols: &'a [Vec<u8>],
|
||||||
listened_addrs: Vec<&'a Multiaddr>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PollParameters for SwarmPollParameters<'a> {
|
impl<'a> PollParameters for SwarmPollParameters<'a> {
|
||||||
type SupportedProtocolsIter = std::iter::Cloned<std::slice::Iter<'a, std::vec::Vec<u8>>>;
|
type SupportedProtocolsIter = std::iter::Cloned<std::slice::Iter<'a, std::vec::Vec<u8>>>;
|
||||||
type ListenedAddressesIter = std::iter::Cloned<std::vec::IntoIter<&'a Multiaddr>>;
|
|
||||||
|
|
||||||
fn supported_protocols(&self) -> Self::SupportedProtocolsIter {
|
fn supported_protocols(&self) -> Self::SupportedProtocolsIter {
|
||||||
self.supported_protocols.iter().cloned()
|
self.supported_protocols.iter().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn listened_addresses(&self) -> Self::ListenedAddressesIter {
|
|
||||||
self.listened_addrs.clone().into_iter().cloned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn local_peer_id(&self) -> &PeerId {
|
|
||||||
self.local_peer_id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`SwarmBuilder`] provides an API for configuring and constructing a [`Swarm`].
|
/// A [`SwarmBuilder`] provides an API for configuring and constructing a [`Swarm`].
|
||||||
|
Reference in New Issue
Block a user