feat(swarm): enforce creation of Swarm via SwarmBuilder

Mark constructors `Swarm::with_X_executor` as deprecated.
Move the deprecated functionality to `SwarmBuilder::with_X_executor`
Use `SwarmBuilder` throughout.

Resolves #3186.
Resolves #3107.

Pull-Request: #3588.
This commit is contained in:
Victor Ermolaev
2023-03-13 20:53:14 +01:00
committed by GitHub
parent 9d05c619e8
commit 2ec5402474
28 changed files with 142 additions and 79 deletions

View File

@ -58,10 +58,7 @@ use libp2p_identity::PeerId;
use libp2p_metrics::{Metrics, Recorder};
use libp2p_noise as noise;
use libp2p_ping as ping;
use libp2p_swarm::keep_alive;
use libp2p_swarm::NetworkBehaviour;
use libp2p_swarm::Swarm;
use libp2p_swarm::SwarmEvent;
use libp2p_swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use libp2p_yamux as yamux;
use log::info;
@ -79,7 +76,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let local_pub_key = local_key.public();
info!("Local peer id: {local_peer_id:?}");
let mut swarm = Swarm::without_executor(
let mut swarm = SwarmBuilder::without_executor(
tcp::async_io::Transport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
@ -87,7 +84,8 @@ fn main() -> Result<(), Box<dyn Error>> {
.boxed(),
Behaviour::new(local_pub_key),
local_peer_id,
);
)
.build();
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;