diff --git a/Cargo.lock b/Cargo.lock index b9a3df8cd5b..9d708273a34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2263,12 +2263,12 @@ dependencies = [ name = "ipfs-private-example" version = "0.1.0" dependencies = [ - "async-std", "async-trait", "either", "env_logger 0.10.0", "futures", "libp2p", + "tokio", ] [[package]] diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index 278611e6aa1..ba8e8e12232 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -6,9 +6,9 @@ publish = false license = "MIT" [dependencies] -async-std = { version = "1.12", features = ["attributes"] } +tokio = { version = "1.32", features = ["rt-multi-thread", "macros", "io-std"] } async-trait = "0.1" either = "1.9" env_logger = "0.10" futures = "0.3.28" -libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } +libp2p = { path = "../../libp2p", features = ["tokio", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 172131751d7..fe83e891cfc 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -20,9 +20,8 @@ #![doc = include_str!("../README.md")] -use async_std::io; use either::Either; -use futures::{prelude::*, select}; +use futures::prelude::*; use libp2p::{ core::{muxing::StreamMuxerBox, transport, transport::upgrade::Version}, gossipsub, identify, identity, @@ -33,6 +32,7 @@ use libp2p::{ tcp, yamux, Multiaddr, PeerId, Transport, }; use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration}; +use tokio::{io, io::AsyncBufReadExt, select}; /// Builds the transport that serves as a common ground for all connections. pub fn build_transport( @@ -42,7 +42,7 @@ pub fn build_transport( let noise_config = noise::Config::new(&key_pair).unwrap(); let yamux_config = yamux::Config::default(); - let base_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)); + let base_transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true)); let maybe_encrypted = match psk { Some(psk) => Either::Left( base_transport.and_then(move |socket, _| PnetConfig::new(psk).handshake(socket)), @@ -108,7 +108,7 @@ fn parse_legacy_multiaddr(text: &str) -> Result> { Ok(res) } -#[async_std::main] +#[tokio::main] async fn main() -> Result<(), Box> { env_logger::init(); @@ -186,7 +186,7 @@ async fn main() -> Result<(), Box> { println!("Subscribing to {gossipsub_topic:?}"); behaviour.gossipsub.subscribe(&gossipsub_topic).unwrap(); - SwarmBuilder::with_async_std_executor(transport, behaviour, local_peer_id).build() + SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build() }; // Reach out to other nodes if specified @@ -197,7 +197,7 @@ async fn main() -> Result<(), Box> { } // 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()?)?; @@ -205,11 +205,11 @@ async fn main() -> Result<(), Box> { // Kick it off loop { select! { - line = stdin.select_next_some() => { + Ok(Some(line)) = stdin.next_line() => { if let Err(e) = swarm .behaviour_mut() .gossipsub - .publish(gossipsub_topic.clone(), line.expect("Stdin not to close").as_bytes()) + .publish(gossipsub_topic.clone(), line.as_bytes()) { println!("Publish error: {e:?}"); }