Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Use tokio instead of async_std #307

Merged
merged 6 commits into from
Aug 13, 2020
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
73 changes: 4 additions & 69 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ nightly = []

[dependencies]
anyhow = { default-features = false, version = "1.0" }
async-std = { default-features = false, features = ["attributes", "std"], version = "1.6" }
async-stream = { default-features = false, version = "0.3" }
async-trait = { default-features = false, version = "0.1" }
base64 = { default-features = false, features = ["alloc"], version = "0.12" }
Expand All @@ -24,14 +23,15 @@ domain = { default-features = false, version = "0.5" }
domain-resolv = { default-features = false, version = "0.5" }
futures = { default-features = false, features = ["compat", "io-compat"], version = "0.3.5" }
ipfs-unixfs = { path = "unixfs" }
libp2p = { default-features = false, features = ["floodsub", "identify", "kad", "tcp-async-std", "mdns", "mplex", "noise", "ping", "yamux"], version = "0.23" }
libp2p = { default-features = false, features = ["floodsub", "identify", "kad", "tcp-tokio", "mdns", "mplex", "noise", "ping", "yamux"], version = "0.23" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: soon tokio-mdns as well, mdns might still use async-std by default.

Copy link
Member Author

@ljedrz ljedrz Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I was looking at the main features in search for other tokio ones and found none - mdns does use async-std right now; probably gonna change soon, like you're saying.

multibase = { default-features = false, version = "0.8" }
multihash = { default-features = false, version = "0.11" }
prost = { default-features = false, version = "0.6" }
rand = { default-features = false, features = ["getrandom"], version = "0.7" }
serde = { default-features = false, features = ["derive"], version = "1.0" }
serde_json = { default-features = false, features = ["std"], version = "1.0" }
thiserror = { default-features = false, version = "1.0" }
tokio = { default-features = false, features = ["fs", "rt-threaded", "stream"], version = "0.2" }
tracing = { default-features = false, features = ["log"], version = "0.1" }
tracing-futures = { default-features = false, features = ["std", "futures-03"], version = "0.2" }
void = { default-features = false, version = "1.0" }
Expand All @@ -42,6 +42,7 @@ prost-build = { default-features = false, version = "0.6" }
[dev-dependencies]
hex-literal = { default-features = false, version = "0.3" }
sha2 = { default-features = false, version = "0.9" }
tokio = { default-features = false, features = ["io-std"], version = "0.2" }
tracing-subscriber = { default-features = false, features = ["fmt", "tracing-log", "ansi", "env-filter"], version = "0.2" }

[workspace]
Expand Down
53 changes: 26 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,37 @@ _Note: binaries available via `cargo install` is coming soon._

## Getting started
```rust,no_run
use async_std::task;
use tokio::task;
use futures::join;
use ipfs::{make_ipld, Ipfs, IpfsPath, Ipld, Types, UninitializedIpfs};

fn main() {
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();

task::block_on(async move {
// Start daemon and initialize repo
let (ipfs, fut): (Ipfs<Types>, _) = UninitializedIpfs::default().await.start().await.unwrap();
task::spawn(fut);

// Create a DAG
let f1 = ipfs.put_dag(make_ipld!("block1"));
let f2 = ipfs.put_dag(make_ipld!("block2"));
let (res1, res2) = join!(f1, f2);
let root = make_ipld!([res1.unwrap(), res2.unwrap()]);
let cid = ipfs.put_dag(root).await.unwrap();
let path = IpfsPath::from(cid);

// Query the DAG
let path1 = path.sub_path("0").unwrap();
let path2 = path.sub_path("1").unwrap();
let f1 = ipfs.get_dag(path1);
let f2 = ipfs.get_dag(path2);
let (res1, res2) = join!(f1, f2);
println!("Received block with contents: {:?}", res1.unwrap());
println!("Received block with contents: {:?}", res2.unwrap());

// Exit
ipfs.exit_daemon();
});
// Start daemon and initialize repo
let (ipfs, fut): (Ipfs<Types>, _) = UninitializedIpfs::default().await.start().await.unwrap();
task::spawn(fut);

// Create a DAG
let f1 = ipfs.put_dag(make_ipld!("block1"));
let f2 = ipfs.put_dag(make_ipld!("block2"));
let (res1, res2) = join!(f1, f2);
let root = make_ipld!([res1.unwrap(), res2.unwrap()]);
let cid = ipfs.put_dag(root).await.unwrap();
let path = IpfsPath::from(cid);

// Query the DAG
let path1 = path.sub_path("0").unwrap();
let path2 = path.sub_path("1").unwrap();
let f1 = ipfs.get_dag(path1);
let f2 = ipfs.get_dag(path2);
let (res1, res2) = join!(f1, f2);
println!("Received block with contents: {:?}", res1.unwrap());
println!("Received block with contents: {:?}", res2.unwrap());

// Exit
ipfs.exit_daemon();
}
```

Expand Down
2 changes: 1 addition & 1 deletion bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ version = "0.1.0"
prost-build = { default-features = false, version = "0.6" }

[dependencies]
async-std = { default-features = false, version = "1.6" }
async-trait = { default-features = false, version = "0.1" }
cid = { default-features = false, version = "0.5" }
fnv = { default-features = false, version = "1.0" }
Expand All @@ -18,5 +17,6 @@ libp2p-swarm = { default-features = false, version = "0.20" }
multihash = { default-features = false, version = "0.11" }
prost = { default-features = false, version = "0.6" }
thiserror = { default-features = false, version = "1.0" }
tokio = { default-features = false, version = "0.2" }
tracing = { default-features = false, version = "0.1" }
unsigned-varint = { default-features = false, version = "0.3" }
25 changes: 12 additions & 13 deletions examples/client1.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use async_std::task;
use futures::join;
use ipfs::{make_ipld, Ipfs, TestTypes, UninitializedIpfs};
use tokio::task;

fn main() {
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();

task::block_on(async move {
let (ipfs, fut): (Ipfs<TestTypes>, _) =
UninitializedIpfs::default().await.start().await.unwrap();
task::spawn(fut);
let (ipfs, fut): (Ipfs<TestTypes>, _) =
UninitializedIpfs::default().await.start().await.unwrap();
task::spawn(fut);

let f1 = ipfs.put_dag(make_ipld!("block1"));
let f2 = ipfs.put_dag(make_ipld!("block2"));
let (res1, res2) = join!(f1, f2);
let f1 = ipfs.put_dag(make_ipld!("block1"));
let f2 = ipfs.put_dag(make_ipld!("block2"));
let (res1, res2) = join!(f1, f2);

let root = make_ipld!([res1.unwrap(), res2.unwrap()]);
ipfs.put_dag(root).await.unwrap();
let root = make_ipld!([res1.unwrap(), res2.unwrap()]);
ipfs.put_dag(root).await.unwrap();

ipfs.exit_daemon().await;
});
ipfs.exit_daemon().await;
}
25 changes: 12 additions & 13 deletions examples/client2.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use async_std::task;
use futures::join;
use ipfs::{Ipfs, IpfsPath, TestTypes, UninitializedIpfs};
use std::str::FromStr;
use tokio::task;

fn main() {
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();

let path =
IpfsPath::from_str("/ipfs/zdpuB1caPcm4QNXeegatVfLQ839Lmprd5zosXGwRUBJHwj66X").unwrap();

task::block_on(async move {
let (ipfs, fut): (Ipfs<TestTypes>, _) =
UninitializedIpfs::default().await.start().await.unwrap();
task::spawn(fut);
let (ipfs, fut): (Ipfs<TestTypes>, _) =
UninitializedIpfs::default().await.start().await.unwrap();
task::spawn(fut);

let f1 = ipfs.get_dag(path.sub_path("0").unwrap());
let f2 = ipfs.get_dag(path.sub_path("1").unwrap());
let (res1, res2) = join!(f1, f2);
println!("Received block with contents: {:?}", res1.unwrap());
println!("Received block with contents: {:?}", res2.unwrap());
let f1 = ipfs.get_dag(path.sub_path("0").unwrap());
let f2 = ipfs.get_dag(path.sub_path("1").unwrap());
let (res1, res2) = join!(f1, f2);
println!("Received block with contents: {:?}", res1.unwrap());
println!("Received block with contents: {:?}", res2.unwrap());

ipfs.exit_daemon().await;
});
ipfs.exit_daemon().await;
}
Loading