mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 02:21:21 +00:00
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:
@ -24,7 +24,7 @@ use libp2p::{
|
||||
identity,
|
||||
multiaddr::Protocol,
|
||||
noise, ping, rendezvous,
|
||||
swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent},
|
||||
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
|
||||
tcp, yamux, Multiaddr, PeerId, Transport,
|
||||
};
|
||||
use std::time::Duration;
|
||||
@ -41,7 +41,7 @@ async fn main() {
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let mut swarm = Swarm::with_tokio_executor(
|
||||
let mut swarm = SwarmBuilder::with_tokio_executor(
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
|
||||
@ -53,7 +53,8 @@ async fn main() {
|
||||
keep_alive: keep_alive::Behaviour,
|
||||
},
|
||||
PeerId::from(key_pair.public()),
|
||||
);
|
||||
)
|
||||
.build();
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
|
@ -22,7 +22,7 @@ use futures::StreamExt;
|
||||
use libp2p::{
|
||||
core::transport::upgrade::Version,
|
||||
identify, identity, noise, ping, rendezvous,
|
||||
swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent},
|
||||
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
|
||||
tcp, yamux, Multiaddr, PeerId, Transport,
|
||||
};
|
||||
use std::time::Duration;
|
||||
@ -37,7 +37,7 @@ async fn main() {
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let mut swarm = Swarm::with_tokio_executor(
|
||||
let mut swarm = SwarmBuilder::with_tokio_executor(
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
|
||||
@ -53,7 +53,8 @@ async fn main() {
|
||||
keep_alive: keep_alive::Behaviour,
|
||||
},
|
||||
PeerId::from(key_pair.public()),
|
||||
);
|
||||
)
|
||||
.build();
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
|
@ -22,7 +22,7 @@ use futures::StreamExt;
|
||||
use libp2p::{
|
||||
core::transport::upgrade::Version,
|
||||
identity, noise, ping, rendezvous,
|
||||
swarm::{keep_alive, AddressScore, NetworkBehaviour, Swarm, SwarmEvent},
|
||||
swarm::{keep_alive, AddressScore, NetworkBehaviour, SwarmBuilder, SwarmEvent},
|
||||
tcp, yamux, Multiaddr, PeerId, Transport,
|
||||
};
|
||||
use std::time::Duration;
|
||||
@ -37,7 +37,7 @@ async fn main() {
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let mut swarm = Swarm::with_tokio_executor(
|
||||
let mut swarm = SwarmBuilder::with_tokio_executor(
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
|
||||
@ -49,7 +49,8 @@ async fn main() {
|
||||
keep_alive: keep_alive::Behaviour,
|
||||
},
|
||||
PeerId::from(key_pair.public()),
|
||||
);
|
||||
)
|
||||
.build();
|
||||
|
||||
// In production the external address should be the publicly facing IP address of the rendezvous point.
|
||||
// This address is recorded in the registration entry by the rendezvous point.
|
||||
|
@ -40,7 +40,7 @@ use futures::StreamExt;
|
||||
use libp2p::{
|
||||
core::transport::upgrade::Version,
|
||||
identify, identity, noise, ping, rendezvous,
|
||||
swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmEvent},
|
||||
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
|
||||
tcp, yamux, PeerId, Transport,
|
||||
};
|
||||
use std::time::Duration;
|
||||
@ -51,7 +51,7 @@ async fn main() {
|
||||
|
||||
let key_pair = identity::Keypair::generate_ed25519();
|
||||
|
||||
let mut swarm = Swarm::with_tokio_executor(
|
||||
let mut swarm = SwarmBuilder::with_tokio_executor(
|
||||
tcp::tokio::Transport::default()
|
||||
.upgrade(Version::V1)
|
||||
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
|
||||
@ -67,7 +67,8 @@ async fn main() {
|
||||
keep_alive: keep_alive::Behaviour,
|
||||
},
|
||||
PeerId::from(key_pair.public()),
|
||||
);
|
||||
)
|
||||
.build();
|
||||
|
||||
log::info!("Local peer id: {}", swarm.local_peer_id());
|
||||
|
||||
|
Reference in New Issue
Block a user