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

Bitswap endpoint #126

Closed
wants to merge 26 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:

- name: Install dependencies ubuntu
if: matrix.platform.host == 'ubuntu-latest'
run: sudo apt-get install llvm-dev libssl-dev pkg-config
run: sudo apt-get update && sudo apt-get install llvm-dev libssl-dev pkg-config

- name: Install dependencies macos
if: matrix.platform.host == 'macos-latest'
Expand Down
773 changes: 240 additions & 533 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ nightly = []
all = ["rocksdb"]

[dependencies]
anyhow = "1.0.26"
async-std = { version = "1.5.0", features = ["attributes", "std"] }
async-trait = "0.1.24"
async-trait = "0.1.26"
bitswap = { path = "bitswap" }
byteorder = "1.3.4"
dirs = "2.0.2"
domain = { git = "https://github.com/nlnetlabs/domain", features = ["resolv"] }
#domain = { git = "https://github.com/nlnetlabs/domain", features = ["resolv"] }
futures = { version = "0.3.4", features = ["compat", "io-compat"] }
libipld = { version = "0.1.0", features = ["dag-pb"] }
libp2p = "0.16.2"
Expand All @@ -27,9 +26,9 @@ multihash = "0.10.1"
prost = "0.6.1"
rand = "0.7.3"
rocksdb = { version = "0.13.0", optional = true }
serde = { version = "1.0.104", features = ["derive"] }
serde = { version = "1.0.105", features = ["derive"] }
serde_json = "1.0.48"
thiserror = "1.0.11"
thiserror = "1.0.13"
void = "1.0.2"

[build-dependencies]
Expand Down
59 changes: 28 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,37 @@ _Note: binaries available via `cargo install` is coming soon._

## Getting started
```rust,no_run
use async_std::task;
use futures::join;
use ipfs::{IpfsOptions, IpfsPath, Ipld, Types, UninitializedIpfs};
use libipld::ipld;
use ipfs::{IpfsOptions, Ipfs, Types};
use libipld::dag::{DagPath, StoreDagExt};
use libipld::hash::Sha2_256;
use libipld::store::StoreCborExt;

fn main() {
#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let options = IpfsOptions::<Types>::default();

task::block_on(async move {
// Start daemon and initialize repo
let (ipfs, fut) = UninitializedIpfs::new(options).await.start().await.unwrap();
task::spawn(fut);

// Create a DAG
let f1 = ipfs.put_dag(ipld!("block1"));
let f2 = ipfs.put_dag(ipld!("block2"));
let (res1, res2) = join!(f1, f2);
let root = 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();
});
let options = IpfsOptions::from_env()?;

// Start daemon and initialize repo
let ipfs = Ipfs::new::<Types>(options).await?;

// Create a DAG
let f1 = ipfs.write_cbor::<Sha2_256, _>(&1000);
let f2 = ipfs.write_cbor::<Sha2_256, _>(&2000);
let (res1, res2) = join!(f1, f2);
let root = vec![res1?, res2?];
let cid = ipfs.write_cbor::<Sha2_256, _>(&root).await?;

// Query the DAG
let path1 = DagPath::new(&cid, "0");
let path2 = DagPath::new(&cid, "1");
let f1 = ipfs.get(&path1);
let f2 = ipfs.get(&path2);
let (res1, res2) = join!(f1, f2);
println!("Received block with contents: {:?}", res1?);
println!("Received block with contents: {:?}", res2?);

Ok(())
}
```

Expand Down
7 changes: 6 additions & 1 deletion bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ prost-build = "0.6.1"

[dependencies]
anyhow = "1.0.26"
async-std = "1.5.0"
async-std = { version = "1.5.0", features = ["attributes"] }
async-trait = "0.1.24"
fnv = "1.0.6"
futures = "0.3.4"
Expand All @@ -19,3 +19,8 @@ libp2p-swarm = "0.16.1"
log = "0.4.8"
prost = "0.6.1"
thiserror = "1.0.11"

[dev-dependencies]
env_logger = "0.7.1"
libp2p = "0.16.2"
multihash = "0.10.1"
Loading