Skip to content

Commit

Permalink
feat(swarm): enforce creation of Swarm via SwarmBuilder
Browse files Browse the repository at this point in the history
Mark constructors `Swarm::with_X_executor` as deprecated.
Move the deprecated functionality to `SwarmBuilder::with_X_executor`
Use `SwarmBuilder` throughout.

Resolves libp2p#3186.
Resolves libp2p#3107.

Pull-Request: libp2p#3588.
  • Loading branch information
vnermolaev authored Mar 13, 2023
1 parent 7ffd994 commit 4a38e4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions examples/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use libp2p_identify as identify;
use libp2p_identity as identity;
use libp2p_identity::PeerId;
use libp2p_noise as noise;
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use libp2p_yamux as yamux;
use std::error::Error;
Expand Down Expand Up @@ -76,7 +76,8 @@ async fn main() -> Result<(), Box<dyn Error>> {

let behaviour = Behaviour::new(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();
swarm.listen_on(
Multiaddr::empty()
.with(Protocol::Ip4(Ipv4Addr::UNSPECIFIED))
Expand Down
5 changes: 3 additions & 2 deletions examples/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use libp2p_identify as identify;
use libp2p_identity as identity;
use libp2p_identity::PeerId;
use libp2p_noise as noise;
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use libp2p_yamux as yamux;
use std::error::Error;
Expand Down Expand Up @@ -65,7 +65,8 @@ async fn main() -> Result<(), Box<dyn Error>> {

let behaviour = Behaviour::new(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();
swarm.listen_on(
Multiaddr::empty()
.with(Protocol::Ip4(Ipv4Addr::UNSPECIFIED))
Expand Down

0 comments on commit 4a38e4c

Please sign in to comment.