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

@ -28,7 +28,8 @@ use libp2p_core::{
use libp2p_identity::PeerId;
use libp2p_plaintext::PlainText2Config;
use libp2p_swarm::{
dial_opts::DialOpts, AddressScore, NetworkBehaviour, Swarm, SwarmEvent, THandlerErr,
dial_opts::DialOpts, AddressScore, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent,
THandlerErr,
};
use libp2p_yamux::YamuxConfig;
use std::fmt::Debug;
@ -218,7 +219,7 @@ where
.timeout(Duration::from_secs(20))
.boxed();
Swarm::without_executor(transport, behaviour_fn(identity), peer_id)
SwarmBuilder::without_executor(transport, behaviour_fn(identity), peer_id).build()
}
async fn connect<T>(&mut self, other: &mut Swarm<T>)