feat(libp2p): add SwarmBuilder

Introduce the new `libp2p::SwarmBuilder`. Users should use the new `libp2p::SwarmBuilder` instead of the now deprecated `libp2p::swarm::SwarmBuilder`. See `libp2p::SwarmBuilder` docs on how to use the new builder.

Fixes #3657.
Fixes #3563.
Fixes #3179.

Pull-Request: #4120.
This commit is contained in:
Max Inden
2023-10-10 08:55:14 +02:00
committed by GitHub
parent 3ae72557ab
commit d605255fec
62 changed files with 2970 additions and 940 deletions

View File

@ -33,7 +33,7 @@ use libp2p_identity::PeerId;
use libp2p_ping as ping;
use libp2p_plaintext as plaintext;
use libp2p_relay as relay;
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
use libp2p_swarm::{Config, NetworkBehaviour, Swarm, SwarmEvent};
use std::time::Duration;
#[test]
@ -310,7 +310,7 @@ fn build_relay() -> Swarm<Relay> {
let transport = upgrade_transport(MemoryTransport::default().boxed(), &local_key);
SwarmBuilder::with_async_std_executor(
Swarm::new(
transport,
Relay {
ping: ping::Behaviour::new(ping::Config::new()),
@ -323,8 +323,8 @@ fn build_relay() -> Swarm<Relay> {
),
},
local_peer_id,
Config::with_async_std_executor(),
)
.build()
}
fn build_client() -> Swarm<Client> {
@ -337,15 +337,15 @@ fn build_client() -> Swarm<Client> {
&local_key,
);
SwarmBuilder::with_async_std_executor(
Swarm::new(
transport,
Client {
ping: ping::Behaviour::new(ping::Config::new()),
relay: behaviour,
},
local_peer_id,
Config::with_async_std_executor(),
)
.build()
}
fn upgrade_transport<StreamSink>(