Skip to content

Commit

Permalink
refactor(examples): change ping from async-std to tokio
Browse files Browse the repository at this point in the history
Related: #4449.

Pull-Request: #4570.
  • Loading branch information
arpankapoor committed Oct 3, 2023
1 parent 980bda0 commit 399eaa3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions examples/ping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ publish = false
license = "MIT"

[dependencies]
async-std = { version = "1.12", features = ["attributes"] }
async-trait = "0.1"
env_logger = "0.10.0"
futures = "0.3.28"
libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] }
libp2p = { path = "../../libp2p", features = ["noise", "ping", "tcp", "tokio", "yamux"] }
tokio = { version = "1.32.0", features = ["full"] }
6 changes: 3 additions & 3 deletions examples/ping/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ use libp2p::{
use std::error::Error;
use std::time::Duration;

#[async_std::main]
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

let transport = tcp::async_io::Transport::default()
let transport = tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::Config::new(&local_key)?)
.multiplex(yamux::Config::default())
.boxed();

let mut swarm =
SwarmBuilder::with_async_std_executor(transport, ping::Behaviour::default(), local_peer_id)
SwarmBuilder::with_tokio_executor(transport, ping::Behaviour::default(), local_peer_id)
.idle_connection_timeout(Duration::from_secs(60)) // For illustrative purposes, keep idle connections alive for a minute so we can observe a few pings.
.build();

Expand Down

0 comments on commit 399eaa3

Please sign in to comment.