rust-ipfs/README.md

63 lines
2.3 KiB
Markdown
Raw Normal View History

2019-02-14 03:26:35 +03:00
# Rust IPFS implementation
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)
2019-02-14 03:26:35 +03:00
Currently implements an altruistic bitswap strategy over mdns.
## Getting started
```rust
2019-02-22 17:58:19 +03:00
#![feature(async_await, await_macro, futures_api)]
2019-02-27 21:18:58 +03:00
use ipfs::{Ipfs, IpfsOptions, Ipld, IpldPath, Types};
use futures::join;
2019-02-14 03:26:35 +03:00
fn main() {
2019-02-18 20:57:52 +03:00
let options = IpfsOptions::new();
env_logger::Builder::new().parse(&options.ipfs_log).init();
2019-02-22 17:58:19 +03:00
let mut ipfs = Ipfs::<Types>::new(options);
2019-02-25 19:15:12 +03:00
tokio::run_async(async move {
2019-02-27 21:18:58 +03:00
// Start daemon and initialize repo
2019-02-25 19:15:12 +03:00
tokio::spawn_async(ipfs.start_daemon());
2019-02-22 17:58:19 +03:00
await!(ipfs.init_repo()).unwrap();
await!(ipfs.open_repo()).unwrap();
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 root_cid = await!(ipfs.put_dag(root)).unwrap();
// Query the DAG
let path1 = IpldPath::from(root_cid.clone(), "0").unwrap();
let path2 = IpldPath::from(root_cid, "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
2019-02-25 19:15:12 +03:00
ipfs.exit_daemon();
});
2019-02-14 03:26:35 +03:00
}
```
## License
ISC License
2019-02-25 17:42:05 +03:00
Copyright (c) 2019, David Craven and others
2019-02-14 03:26:35 +03:00
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.