mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +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:
@ -18,7 +18,7 @@ futures = "0.3.27"
|
||||
futures-timer = "3"
|
||||
instant = "0.1.11"
|
||||
libp2p-core = { version = "0.39.0", path = "../../core" }
|
||||
libp2p-swarm = { version = "0.42.0", path = "../../swarm" }
|
||||
libp2p-swarm = { version = "0.42.0", path = "../../swarm", features = ["async-std"] }
|
||||
libp2p-identity = { version = "0.1.0", path = "../../identity" }
|
||||
log = "0.4"
|
||||
quick-protobuf = "0.8"
|
||||
|
@ -31,7 +31,7 @@ use libp2p_identity::PeerId;
|
||||
use libp2p_noise as noise;
|
||||
use libp2p_ping as ping;
|
||||
use libp2p_relay as relay;
|
||||
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent};
|
||||
use libp2p_swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
|
||||
use libp2p_tcp as tcp;
|
||||
use std::error::Error;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
@ -67,7 +67,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
)),
|
||||
};
|
||||
|
||||
let mut swarm = Swarm::without_executor(transport, behaviour, local_peer_id);
|
||||
let mut swarm = SwarmBuilder::without_executor(transport, behaviour, local_peer_id).build();
|
||||
|
||||
// Listen on all interfaces
|
||||
let listen_addr = Multiaddr::empty()
|
||||
|
@ -34,7 +34,7 @@ use libp2p_identity::PublicKey;
|
||||
use libp2p_ping as ping;
|
||||
use libp2p_plaintext::PlainText2Config;
|
||||
use libp2p_relay as relay;
|
||||
use libp2p_swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmEvent};
|
||||
use libp2p_swarm::{AddressScore, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
@ -292,7 +292,7 @@ fn build_relay() -> Swarm<Relay> {
|
||||
|
||||
let transport = upgrade_transport(MemoryTransport::default().boxed(), local_public_key);
|
||||
|
||||
Swarm::with_threadpool_executor(
|
||||
SwarmBuilder::with_async_std_executor(
|
||||
transport,
|
||||
Relay {
|
||||
ping: ping::Behaviour::new(ping::Config::new()),
|
||||
@ -306,6 +306,7 @@ fn build_relay() -> Swarm<Relay> {
|
||||
},
|
||||
local_peer_id,
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn build_client() -> Swarm<Client> {
|
||||
@ -319,7 +320,7 @@ fn build_client() -> Swarm<Client> {
|
||||
local_public_key,
|
||||
);
|
||||
|
||||
Swarm::with_threadpool_executor(
|
||||
SwarmBuilder::with_async_std_executor(
|
||||
transport,
|
||||
Client {
|
||||
ping: ping::Behaviour::new(ping::Config::new()),
|
||||
@ -327,6 +328,7 @@ fn build_client() -> Swarm<Client> {
|
||||
},
|
||||
local_peer_id,
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn upgrade_transport<StreamSink>(
|
||||
|
Reference in New Issue
Block a user