diff --git a/Cargo.lock b/Cargo.lock index f0c36291839..d3e2fc9fa47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1361,10 +1361,10 @@ dependencies = [ name = "distributed-key-value-store-example" version = "0.1.0" dependencies = [ - "async-std", "async-trait", "futures", "libp2p", + "tokio", "tracing", "tracing-subscriber", ] diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index 9c2e2bce5c9..3846e54c8d3 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -9,10 +9,10 @@ license = "MIT" release = false [dependencies] -async-std = { version = "1.12", features = ["attributes"] } +tokio = { workspace = true, features = ["full"] } async-trait = "0.1" futures = { workspace = true } -libp2p = { path = "../../libp2p", features = [ "async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "yamux"] } +libp2p = { path = "../../libp2p", features = [ "tokio", "dns", "kad", "mdns", "noise", "macros", "tcp", "yamux"] } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 404333f3d20..6b7947b7eb3 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -20,8 +20,7 @@ #![doc = include_str!("../README.md")] -use async_std::io; -use futures::{prelude::*, select}; +use futures::stream::StreamExt; use libp2p::kad; use libp2p::kad::store::MemoryStore; use libp2p::kad::Mode; @@ -32,9 +31,13 @@ use libp2p::{ }; use std::error::Error; use std::time::Duration; +use tokio::{ + io::{self, AsyncBufReadExt}, + select, +}; use tracing_subscriber::EnvFilter; -#[async_std::main] +#[tokio::main] async fn main() -> Result<(), Box> { let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) @@ -44,11 +47,11 @@ async fn main() -> Result<(), Box> { #[derive(NetworkBehaviour)] struct Behaviour { kademlia: kad::Behaviour, - mdns: mdns::async_io::Behaviour, + mdns: mdns::tokio::Behaviour, } let mut swarm = libp2p::SwarmBuilder::with_new_identity() - .with_async_std() + .with_tokio() .with_tcp( tcp::Config::default(), noise::Config::new, @@ -60,7 +63,7 @@ async fn main() -> Result<(), Box> { key.public().to_peer_id(), MemoryStore::new(key.public().to_peer_id()), ), - mdns: mdns::async_io::Behaviour::new( + mdns: mdns::tokio::Behaviour::new( mdns::Config::default(), key.public().to_peer_id(), )?, @@ -72,7 +75,7 @@ async fn main() -> Result<(), Box> { swarm.behaviour_mut().kademlia.set_mode(Some(Mode::Server)); // Read full lines from stdin - let mut stdin = io::BufReader::new(io::stdin()).lines().fuse(); + let mut stdin = io::BufReader::new(io::stdin()).lines(); // Listen on all interfaces and whatever port the OS assigns. swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; @@ -80,7 +83,9 @@ async fn main() -> Result<(), Box> { // Kick it off. loop { select! { - line = stdin.select_next_some() => handle_input_line(&mut swarm.behaviour_mut().kademlia, line.expect("Stdin not to close")), + Ok(Some(line)) = stdin.next_line() => { + handle_input_line(&mut swarm.behaviour_mut().kademlia, line); + } event = swarm.select_next_some() => match event { SwarmEvent::NewListenAddr { address, .. } => { println!("Listening in {address:?}");