rust-ipfs/README.md

55 lines
2.3 KiB
Markdown
Raw Normal View History

2020-02-26 20:03:28 +03:00
<h1>
<img src="https://ipfs.io/ipfs/QmRcFsCvTgGrB52UGpp9P2bSDmnYNTAATdRf4NBj8SKf77/rust-ipfs-logo-256w.png" width="128" /><br />
Rust IPFS
</h1>
2019-03-01 18:59:35 +03:00
[![Build Status](https://travis-ci.org/dvc94ch/rust-ipfs.svg?branch=master)](https://travis-ci.org/dvc94ch/rust-ipfs)
2020-02-21 16:50:09 +03:00
[![Back on OpenCollective](https://img.shields.io/badge/open%20collective-donate-yellow.svg)](https://opencollective.com/ipfs-rust) [![Matrix](https://img.shields.io/badge/matrix-%23rust_ipfs%3Amatrix.org-blue.svg)](https://riot.im/app/#/room/#rust-ipfs:matrix.org) [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/9E5SFvW)
2019-03-01 18:59:35 +03:00
2019-02-14 03:26:35 +03:00
Currently implements an altruistic bitswap strategy over mdns.
## Getting started
```rust,no-run
use ipfs::{UninitializedIpfs, IpfsOptions, Ipld, Types};
2019-02-27 21:18:58 +03:00
use futures::join;
use futures::{FutureExt, TryFutureExt};
2019-02-14 03:26:35 +03:00
fn main() {
let options = IpfsOptions::<Types>::default();
env_logger::Builder::new().parse_filters(&options.ipfs_log).init();
2019-02-22 17:58:19 +03:00
tokio::runtime::current_thread::block_on_all(async move {
2019-02-27 21:18:58 +03:00
// Start daemon and initialize repo
2020-01-09 01:30:46 +03:00
let (ipfs, fut) = UninitializedIpfs::new(options).await.start().await.unwrap();
tokio::spawn(fut.unit_error().boxed().compat());
2019-02-22 17:58:19 +03:00
2019-02-27 21:18:58 +03:00
// Create a DAG
let block1: Ipld = "block1".to_string().into();
let block2: Ipld = "block2".to_string().into();
let f1 = ipfs.put_dag(block1);
let f2 = ipfs.put_dag(block2);
let (res1, res2) = join!(f1, f2);
let root: Ipld = vec![res1.unwrap(), res2.unwrap()].into();
let path = ipfs.put_dag(root).await.unwrap();
2019-02-27 21:18:58 +03:00
// Query the DAG
let path1 = path.sub_path("0").unwrap();
let path2 = path.sub_path("1").unwrap();
2019-02-27 21:18:58 +03:00
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
2019-02-25 19:15:12 +03:00
ipfs.exit_daemon();
}.unit_error().boxed().compat()).unwrap();
2019-02-14 03:26:35 +03:00
}
```
Note: `rust-ipfs` currently requires nightly, see `rust-toolchain` and `.travis.yml` for the tested version.
2019-02-14 03:26:35 +03:00
## License
2020-02-20 16:15:10 +03:00
Dual licensed under MIT or Apache License (Version 2.0). See [LICENSE-MIT](./LICENSE-MIT) and [LICENSE-APACHE](./LICENSE-APACHE) for more details.