mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 08:11:39 +00:00
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:
@ -26,7 +26,7 @@ use libp2p_identity as identity;
|
||||
use libp2p_identity::PeerId;
|
||||
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 libp2p_swarm_test::SwarmExt as _;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -123,15 +123,15 @@ fn build_client() -> Swarm<Client> {
|
||||
.multiplex(libp2p_yamux::Config::default())
|
||||
.boxed();
|
||||
|
||||
SwarmBuilder::without_executor(
|
||||
Swarm::new(
|
||||
transport,
|
||||
Client {
|
||||
relay: behaviour,
|
||||
dcutr: dcutr::Behaviour::new(local_peer_id),
|
||||
},
|
||||
local_peer_id,
|
||||
Config::with_async_std_executor(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
#[derive(NetworkBehaviour)]
|
||||
|
@ -37,7 +37,7 @@ use libp2p_core::{
|
||||
use libp2p_identity as identity;
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_noise as noise;
|
||||
use libp2p_swarm::{ConnectionId, Swarm, SwarmBuilder, SwarmEvent};
|
||||
use libp2p_swarm::{self as swarm, ConnectionId, Swarm, SwarmEvent};
|
||||
use libp2p_yamux as yamux;
|
||||
use quickcheck::*;
|
||||
use rand::{random, rngs::StdRng, thread_rng, Rng, SeedableRng};
|
||||
@ -67,7 +67,12 @@ fn build_node_with_config(cfg: Config) -> (Multiaddr, TestSwarm) {
|
||||
let store = MemoryStore::new(local_id);
|
||||
let behaviour = Behaviour::with_config(local_id, store, cfg);
|
||||
|
||||
let mut swarm = SwarmBuilder::without_executor(transport, behaviour, local_id).build();
|
||||
let mut swarm = Swarm::new(
|
||||
transport,
|
||||
behaviour,
|
||||
local_id,
|
||||
swarm::Config::with_async_std_executor(),
|
||||
);
|
||||
|
||||
let address: Multiaddr = Protocol::Memory(random::<u64>()).into();
|
||||
swarm.listen_on(address.clone()).unwrap();
|
||||
|
@ -31,7 +31,7 @@ use libp2p_core::{
|
||||
};
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_perf::{Run, RunDuration, RunParams};
|
||||
use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
|
||||
use libp2p_swarm::{Config, NetworkBehaviour, Swarm, SwarmEvent};
|
||||
use log::{error, info};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -414,11 +414,15 @@ async fn swarm<B: NetworkBehaviour + Default>() -> Result<Swarm<B>> {
|
||||
.boxed()
|
||||
};
|
||||
|
||||
Ok(
|
||||
SwarmBuilder::with_tokio_executor(transport, Default::default(), local_peer_id)
|
||||
.substream_upgrade_protocol_override(upgrade::Version::V1Lazy)
|
||||
.build(),
|
||||
)
|
||||
let swarm = Swarm::new(
|
||||
transport,
|
||||
Default::default(),
|
||||
local_peer_id,
|
||||
Config::with_tokio_executor()
|
||||
.with_substream_upgrade_protocol_override(upgrade::Version::V1Lazy),
|
||||
);
|
||||
|
||||
Ok(swarm)
|
||||
}
|
||||
|
||||
async fn connect(
|
||||
|
@ -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>(
|
||||
|
Reference in New Issue
Block a user