diff --git a/Cargo.lock b/Cargo.lock index 6b50bf74d57..7ca3795ff3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1555,12 +1555,11 @@ checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" name = "file-sharing-example" version = "0.1.0" dependencies = [ - "async-std", "clap", - "either", "futures", "libp2p", "serde", + "tokio", "tracing", "tracing-subscriber", "void", diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index e38039a11bb..8d20a702718 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -10,11 +10,10 @@ release = false [dependencies] serde = { version = "1.0", features = ["derive"] } -async-std = { version = "1.12", features = ["attributes"] } +tokio = { version = "1.36.0", features = ["full"] } clap = { version = "4.4.16", features = ["derive"] } -either = "1.9" futures = "0.3.30" -libp2p = { path = "../../libp2p", features = [ "async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } +libp2p = { path = "../../libp2p", features = [ "tokio", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3", features = ["env-filter"] } void = "1.0.2" diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index a834ee0600e..5f6be83dc11 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -22,8 +22,8 @@ mod network; -use async_std::task::spawn; use clap::Parser; +use tokio::task::spawn; use futures::prelude::*; use futures::StreamExt; @@ -33,7 +33,7 @@ use std::io::Write; use std::path::PathBuf; 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()) diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index 59625fc39ea..a74afd1c0da 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -1,5 +1,6 @@ use futures::channel::{mpsc, oneshot}; use futures::prelude::*; +use futures::StreamExt; use libp2p::{ core::Multiaddr, @@ -40,7 +41,7 @@ pub(crate) async fn new( let peer_id = id_keys.public().to_peer_id(); let mut swarm = libp2p::SwarmBuilder::with_existing_identity(id_keys) - .with_async_std() + .with_tokio() .with_tcp( tcp::Config::default(), noise::Config::new, @@ -197,8 +198,8 @@ impl EventLoop { pub(crate) async fn run(mut self) { loop { - futures::select! { - event = self.swarm.next() => self.handle_event(event.expect("Swarm stream to be infinite.")).await , + tokio::select! { + event = self.swarm.select_next_some() => self.handle_event(event).await, command = self.command_receiver.next() => match command { Some(c) => self.handle_command(c).await, // Command channel closed, thus shutting down the network event loop.