From 6b729f9bd22ec36eefd23f071b3b1880377582a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Sat, 21 Jan 2023 17:55:22 +0000 Subject: [PATCH] examples: update ping example to use And instead of a custom structure that derives `NetworkBehaviour`. --- examples/ping.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/examples/ping.rs b/examples/ping.rs index 5deb8544ccb8..fc17ee313635 100644 --- a/examples/ping.rs +++ b/examples/ping.rs @@ -41,9 +41,9 @@ //! and begin pinging each other. use futures::prelude::*; -use libp2p::swarm::{NetworkBehaviour, Swarm, SwarmEvent}; +use libp2p::swarm::{Swarm, SwarmEvent}; use libp2p::{identity, ping, Multiaddr, PeerId}; -use libp2p_swarm::keep_alive; +use libp2p_swarm::{behaviour::And, keep_alive}; use std::error::Error; #[async_std::main] @@ -54,7 +54,12 @@ async fn main() -> Result<(), Box> { let transport = libp2p::development_transport(local_key).await?; - let mut swarm = Swarm::with_async_std_executor(transport, Behaviour::default(), local_peer_id); + // Our network behaviour. + // + // For illustrative purposes, this includes the [`KeepAlive`](behaviour::KeepAlive) behaviour so a continuous sequence of + // pings can be observed. + let behaviour = And::::default(); + let mut swarm = Swarm::with_async_std_executor(transport, behaviour, local_peer_id); // Tell the swarm to listen on all interfaces and a random, OS-assigned // port. @@ -76,13 +81,3 @@ async fn main() -> Result<(), Box> { } } } - -/// Our network behaviour. -/// -/// For illustrative purposes, this includes the [`KeepAlive`](behaviour::KeepAlive) behaviour so a continuous sequence of -/// pings can be observed. -#[derive(NetworkBehaviour, Default)] -struct Behaviour { - keep_alive: keep_alive::Behaviour, - ping: ping::Behaviour, -}