Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(examples): change file-sharing from async-std to tokio #5191

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/file-sharing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions examples/file-sharing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

mod network;

use async_std::task::spawn;
use clap::Parser;
use tokio::task::spawn;

use futures::prelude::*;
use futures::StreamExt;
Expand All @@ -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<dyn Error>> {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand Down
7 changes: 4 additions & 3 deletions examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use futures::channel::{mpsc, oneshot};
use futures::prelude::*;
use futures::StreamExt;

use libp2p::{
core::Multiaddr,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
Loading