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

@ -40,7 +40,7 @@ use futures::prelude::*;
use libp2p::{
core::{multiaddr::Multiaddr, upgrade::Version},
identify, identity, noise,
swarm::{Swarm, SwarmEvent},
swarm::{SwarmBuilder, SwarmEvent},
tcp, yamux, PeerId, Transport,
};
use std::error::Error;
@ -63,7 +63,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
local_key.public(),
));
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
// port.