summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@gmail.com>2018-06-27 18:38:51 -0400
committerGitHub <noreply@github.com>2018-06-27 18:38:51 -0400
commit8ddbbd1854f86a15d522247993e6c6ce39db1781 (patch)
tree82b60aa1968a3e685b08e685efaa24ecaa99f768
parentbbaa488b09cf6b77416a65f8cae6da2aafeb88d5 (diff)
parentfedf875de04c8577a439bff9f62f1cb7d079459a (diff)
Merge pull request #16 from ferristseng/upgrade-hyper
Upgrade hyper to 0.12.0
-rw-r--r--README.md39
-rw-r--r--ipfs-api/Cargo.toml14
-rw-r--r--ipfs-api/examples/add_file.rs16
-rw-r--r--ipfs-api/examples/add_tar.rs34
-rw-r--r--ipfs-api/examples/bootstrap_default.rs76
-rw-r--r--ipfs-api/examples/dns.rs44
-rw-r--r--ipfs-api/examples/get_commands.rs15
-rw-r--r--ipfs-api/examples/get_stats.rs82
-rw-r--r--ipfs-api/examples/get_swarm.rs54
-rw-r--r--ipfs-api/examples/get_version.rs15
-rw-r--r--ipfs-api/examples/mfs.rs85
-rw-r--r--ipfs-api/examples/ping_peer.rs75
-rw-r--r--ipfs-api/examples/pubsub.rs52
-rw-r--r--ipfs-api/examples/replace_config.rs17
-rw-r--r--ipfs-api/examples/resolve_name.rs45
-rw-r--r--ipfs-api/src/client.rs523
-rw-r--r--ipfs-api/src/header.rs74
-rw-r--r--ipfs-api/src/lib.rs49
-rw-r--r--ipfs-api/src/read.rs26
-rw-r--r--ipfs-api/src/request/add.rs2
-rw-r--r--ipfs-api/src/request/block.rs2
-rw-r--r--ipfs-api/src/request/config.rs2
-rw-r--r--ipfs-api/src/request/dag.rs2
-rw-r--r--ipfs-api/src/request/files.rs2
-rw-r--r--ipfs-api/src/request/mod.rs2
-rw-r--r--ipfs-api/src/request/tar.rs2
-rw-r--r--ipfs-api/src/response/error.rs13
-rw-r--r--ipfs-cli/Cargo.toml2
-rw-r--r--ipfs-cli/src/command/add.rs50
-rw-r--r--ipfs-cli/src/command/bitswap.rs173
-rw-r--r--ipfs-cli/src/command/block.rs128
-rw-r--r--ipfs-cli/src/command/bootstrap.rs88
-rw-r--r--ipfs-cli/src/command/cat.rs41
-rw-r--r--ipfs-cli/src/command/commands.rs38
-rw-r--r--ipfs-cli/src/command/config.rs67
-rw-r--r--ipfs-cli/src/command/dag.rs64
-rw-r--r--ipfs-cli/src/command/dht.rs121
-rw-r--r--ipfs-cli/src/command/diag.rs117
-rw-r--r--ipfs-cli/src/command/dns.rs47
-rw-r--r--ipfs-cli/src/command/file.rs92
-rw-r--r--ipfs-cli/src/command/files.rs283
-rw-r--r--ipfs-cli/src/command/filestore.rs103
-rw-r--r--ipfs-cli/src/command/mod.rs118
-rw-r--r--ipfs-cli/src/command/shutdown.rs29
-rw-r--r--ipfs-cli/src/command/version.rs43
-rw-r--r--ipfs-cli/src/main.rs82
46 files changed, 1509 insertions, 1539 deletions
diff --git a/README.md b/README.md
index 3218b82..d5020ac 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Rust library for connecting to the IPFS HTTP API using tokio.
```toml
[dependencies]
-ipfs-api = "0.4.0-alpha.3"
+ipfs-api = "0.5.0-alpha1"
```
### Examples
@@ -19,38 +19,45 @@ Write a file to IPFS:
```rust
#
+use hyper::rt::Future;
use ipfs_api::IpfsClient;
use std::io::Cursor;
-use tokio_core::reactor::Core;
-let mut core = Core::new().unwrap();
-let client = IpfsClient::default(&core.handle());
+let client = IpfsClient::default();
let data = Cursor::new("Hello World!");
-let req = client.add(data);
-let res = core.run(req).unwrap();
+let req = client
+ .add(data)
+ .map(|res| {
+ println!("{}", res.hash);
+ })
+ .map_err(|e| eprintln!("{}", e));
-println!("{}", res.hash);
+hyper::rt::run(req);
```
Read a file from IPFS:
```rust
#
-use futures::stream::Stream;
+use futures::{Future, Stream};
use ipfs_api::IpfsClient;
use std::io::{self, Write};
-use tokio_core::reactor::Core;
-let mut core = Core::new().unwrap();
-let client = IpfsClient::default(&core.handle());
+let client = IpfsClient::default();
-let req = client.get("/test/file.json").concat2();
-let res = core.run(req).unwrap();
-let out = io::stdout();
-let mut out = out.lock();
+let req = client
+ .get("/test/file.json")
+ .concat2()
+ .map(|res| {
+ let out = io::stdout();
+ let mut out = out.lock();
-out.write_all(&res).unwrap();
+ out.write_all(&res).unwrap();
+ })
+ .map_err(|e| eprintln!("{}", e));
+
+hyper::rt::run(req);
```
There are also a bunch of examples included in the project, which
diff --git a/ipfs-api/Cargo.toml b/ipfs-api/Cargo.toml
index c01d5dd..597a42a 100644
--- a/ipfs-api/Cargo.toml
+++ b/ipfs-api/Cargo.toml
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/ipfs-api"
repository = "https://github.com/ferristseng/rust-ipfs-api"
keywords = ["ipfs"]
categories = ["filesystem", "web-programming"]
-version = "0.4.0-alpha.3"
+version = "0.5.0-alpha1"
readme = "../README.md"
license = "MIT OR Apache-2.0"
@@ -15,17 +15,19 @@ travis-ci = { repository = "ferristseng/rust-ipfs-api" }
[dependencies]
bytes = "0.4"
-error-chain = "0.11"
+error-chain = "0.12"
futures = "0.1"
-hyper = "0.11"
-hyper-multipart-rfc7578 = "0.1.0-alpha"
+http = "0.1"
+hyper = "0.12"
+hyper-multipart-rfc7578 = "0.2.0-alpha2"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.5"
-tokio-core = "0.1"
+tokio = "0.1"
+tokio-codec = "0.1"
tokio-io = "0.1"
[dev-dependencies]
-tokio-timer = "0.1"
+tokio-timer = "0.2"
tar = "0.4"
diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs
index 66775f4..7784c89 100644
--- a/ipfs-api/examples/add_file.rs
+++ b/ipfs-api/examples/add_file.rs
@@ -6,12 +6,13 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
use ipfs_api::IpfsClient;
+use futures::Future;
use std::fs::File;
-use tokio_core::reactor::Core;
// Creates an Ipfs client, and adds this source file to Ipfs.
//
@@ -19,11 +20,12 @@ fn main() {
println!("note: this must be run in the root of the project repository");
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
+ let client = IpfsClient::default();
let file = File::open(file!()).expect("could not read source file");
- let req = client.add(file);
- let add = core.run(req).expect("expected a valid response");
+ let req = client
+ .add(file)
+ .map(|add| println!("added file: {:?}", add))
+ .map_err(|e| eprintln!("{}", e));
- println!("added file: {:?}", add);
+ hyper::rt::run(req);
}
diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api/examples/add_tar.rs
index 401c61d..1880712 100644
--- a/ipfs-api/examples/add_tar.rs
+++ b/ipfs-api/examples/add_tar.rs
@@ -7,15 +7,14 @@
//
extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
extern crate tar;
-extern crate tokio_core;
-use futures::stream::Stream;
+use futures::{Future, Stream};
use ipfs_api::IpfsClient;
use std::io::Cursor;
use tar::Builder;
-use tokio_core::reactor::Core;
// Creates an Ipfs client, and adds this source file to Ipfs.
//
@@ -23,8 +22,7 @@ fn main() {
println!("note: this must be run in the root of the project repository");
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
+ let client = IpfsClient::default();
let mut buf = Vec::new();
@@ -40,15 +38,19 @@ fn main() {
}
let cursor = Cursor::new(buf);
- let req = client.tar_add(cursor);
- let add = core.run(req).expect("expected a valid response");
-
- println!("added tar file: {:?}", add);
- println!();
-
- let req = client.tar_cat(&add.hash[..]).concat2();
- let cat = core.run(req).expect("expected a valid response");
-
- println!("{}", String::from_utf8_lossy(&cat[..]));
- println!();
+ let req = client
+ .tar_add(cursor)
+ .and_then(move |add| {
+ println!("added tar file: {:?}", add);
+ println!();
+
+ client.tar_cat(&add.hash[..]).concat2()
+ })
+ .map(|cat| {
+ println!("{}", String::from_utf8_lossy(&cat[..]));
+ println!();
+ })
+ .map_err(|e| eprintln!("{}", e));
+
+ hyper::rt::run(req)
}
diff --git a/ipfs-api/examples/bootstrap_default.rs b/ipfs-api/examples/bootstrap_default.rs
index d236716..79c66ab 100644
--- a/ipfs-api/examples/bootstrap_default.rs
+++ b/ipfs-api/examples/bootstrap_default.rs
@@ -6,11 +6,12 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
use ipfs_api::IpfsClient;
-use tokio_core::reactor::Core;
+use futures::Future;
// Lists clients in bootstrap list, then adds the default list, then removes
// them, and readds them.
@@ -18,36 +19,43 @@ use tokio_core::reactor::Core;
fn main() {
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
-
- let bootstrap = client.bootstrap_list();
- let bootstrap = core.run(bootstrap).expect("expected a valid response");
-
- println!("current bootstrap peers:");
- for peer in bootstrap.peers {
- println!(" {}", peer);
- }
-
- println!();
- println!("dropping all bootstrap peers...");
-
- let drop = client.bootstrap_rm_all();
- let drop = core.run(drop).expect("expected a valid response");
-
- println!("dropped:");
- for peer in drop.peers {
- println!(" {}", peer);
- }
-
- println!();
- println!("adding default peers...");
-
- let add = client.bootstrap_add_default();
- let add = core.run(add).expect("expected a valid response");
-
- println!("added:");
- for peer in add.peers {
- println!(" {}", peer);
- }
+ let client = IpfsClient::default();
+
+ let bootstrap = client.bootstrap_list().map(|bootstrap| {
+ println!("current bootstrap peers:");
+ for peer in bootstrap.peers {
+ println!(" {}", peer);
+ }
+ });
+
+ let drop = client.bootstrap_rm_all().map(|drop| {
+ println!("dropped:");
+ for peer in drop.peers {
+ println!(" {}", peer);
+ }
+ });
+
+ let add = client.bootstrap_add_default().map(|add| {
+ println!("added:");
+ for peer in add.peers {
+ println!(" {}", peer);
+ }
+ });
+
+ hyper::rt::run(
+ bootstrap
+ .and_then(|_| {
+ println!();
+ println!("dropping all bootstrap peers...");
+
+ drop
+ })
+ .and_then(|_| {
+ println!();
+ println!("adding default peers...");
+
+ add
+ })
+ .map_err(|e| eprintln!("{}", e)),
+ );
}
diff --git a/ipfs-api/examples/dns.rs b/ipfs-api/examples/dns.rs
index ec574ab..78b4086 100644
--- a/ipfs-api/examples/dns.rs
+++ b/ipfs-api/examples/dns.rs
@@ -6,33 +6,37 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
+use futures::Future;
use ipfs_api::IpfsClient;
-use tokio_core::reactor::Core;
// Creates an Ipfs client, resolves ipfs.io, and lists the contents of it.
//
fn main() {
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
-
- let req = client.dns("ipfs.io", false);
- let dns = core.run(req).expect("dns should resolve");
-
- println!("dns resolves to ({})", &dns.path);
- println!();
-
- let req = client.file_ls(&dns.path[..]);
- let contents = core.run(req).expect("api should return path contents");
-
- println!("found contents:");
- for directory in contents.objects.values() {
- for file in directory.links.iter() {
- println!("[{}] ({} bytes)", file.name, file.size);
- }
- }
+ let client = IpfsClient::default();
+
+ let req = client
+ .dns("ipfs.io", false)
+ .and_then(move |dns| {
+ println!("dns resolves to ({})", &dns.path);
+ println!();
+
+ client.file_ls(&dns.path[..])
+ })
+ .map(|contents| {
+ println!("found contents:");
+ for directory in contents.objects.values() {
+ for file in directory.links.iter() {
+ println!("[{}] ({} bytes)", file.name, file.size);
+ }
+ }
+ })
+ .map_err(|e| eprintln!("{}", e));
+
+ hyper::rt::run(req);
}
diff --git a/ipfs-api/examples/get_commands.rs b/ipfs-api/examples/get_commands.rs
index d3f9852..b12ffa1 100644
--- a/ipfs-api/examples/get_commands.rs
+++ b/ipfs-api/examples/get_commands.rs
@@ -6,11 +6,12 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
+use futures::Future;
use ipfs_api::{response, IpfsClient};
-use tokio_core::reactor::Core;
fn print_recursive(indent: usize, cmd: &response::CommandsResponse) {
let cmd_indent = " ".repeat(indent * 4);
@@ -39,9 +40,11 @@ fn print_recursive(indent: usize, cmd: &response::CommandsResponse) {
fn main() {
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
- let req = client.commands();
+ let client = IpfsClient::default();
+ let req = client
+ .commands()
+ .map(|commands| print_recursive(0, &commands))
+ .map_err(|e| eprintln!("{}", e));
- print_recursive(0, &core.run(req).expect("expected a valid response"));
+ hyper::rt::run(req);
}
diff --git a/ipfs-api/examples/get_stats.rs b/ipfs-api/examples/get_stats.rs
index fe9f84f..41f2a5c 100644
--- a/ipfs-api/examples/get_stats.rs
+++ b/ipfs-api/examples/get_stats.rs
@@ -6,52 +6,58 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
+use futures::Future;
use ipfs_api::IpfsClient;
-use tokio_core::reactor::Core;
// Creates an Ipfs client, and gets some stats about the Ipfs server.
//
fn main() {
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
-
- let bitswap_stats = client.stats_bitswap();
- let bitswap_stats = core.run(bitswap_stats).expect("expected a valid response");
-
- let bw_stats = client.stats_bw();
- let bw_stats = core.run(bw_stats).expect("expected a valid response");
-
- let repo_stats = client.stats_repo();
- let repo_stats = core.run(repo_stats).expect("expected a valid response");
-
- println!("bitswap stats:");
- println!(" blocks recv: {}", bitswap_stats.blocks_received);
- println!(" data recv: {}", bitswap_stats.data_received);
- println!(" blocks sent: {}", bitswap_stats.blocks_sent);
- println!(" data sent: {}", bitswap_stats.data_sent);
- println!(
- " peers: {}",
- bitswap_stats.peers.join("\n ")
- );
- println!(
- " wantlist: {}",
- bitswap_stats.wantlist.join("\n ")
+ let client = IpfsClient::default();
+
+ let bitswap_stats = client.stats_bitswap().map(|bitswap_stats| {
+ println!("bitswap stats:");
+ println!(" blocks recv: {}", bitswap_stats.blocks_received);
+ println!(" data recv: {}", bitswap_stats.data_received);
+ println!(" blocks sent: {}", bitswap_stats.blocks_sent);
+ println!(" data sent: {}", bitswap_stats.data_sent);
+ println!(
+ " peers: {}",
+ bitswap_stats.peers.join("\n ")
+ );
+ println!(
+ " wantlist: {}",
+ bitswap_stats.wantlist.join("\n ")
+ );
+ println!();
+ });
+
+ let bw_stats = client.stats_bw().map(|bw_stats| {
+ println!("bandwidth stats:");
+ println!(" total in: {}", bw_stats.total_in);
+ println!(" total out: {}", bw_stats.total_out);
+ println!(" rate in: {}", bw_stats.rate_in);
+ println!(" rate out: {}", bw_stats.rate_out);
+ println!();
+ });
+
+ let repo_stats = client.stats_repo().map(|repo_stats| {
+ println!("repo stats:");
+ println!(" num objs: {}", repo_stats.num_objects);
+ println!(" repo size: {}", repo_stats.repo_size);
+ println!(" repo path: {}", repo_stats.repo_path);
+ println!(" version : {}", repo_stats.version);
+ });
+
+ hyper::rt::run(
+ bitswap_stats
+ .and_then(|_| bw_stats)
+ .and_then(|_| repo_stats)
+ .map_err(|e| eprintln!("{}", e)),
);
- println!();
- println!("bandwidth stats:");
- println!(" total in: {}", bw_stats.total_in);
- println!(" total out: {}", bw_stats.total_out);
- println!(" rate in: {}", bw_stats.rate_in);
- println!(" rate out: {}", bw_stats.rate_out);
- println!();
- println!("repo stats:");
- println!(" num objs: {}", repo_stats.num_objects);
- println!(" repo size: {}", repo_stats.repo_size);
- println!(" repo path: {}", repo_stats.repo_path);
- println!(" version : {}", repo_stats.version);
}
diff --git a/ipfs-api/examples/get_swarm.rs b/ipfs-api/examples/get_swarm.rs
index 52e547a..2b9fd73 100644
--- a/ipfs-api/examples/get_swarm.rs
+++ b/ipfs-api/examples/get_swarm.rs
@@ -6,11 +6,12 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
+use futures::Future;
use ipfs_api::IpfsClient;
-use tokio_core::reactor::Core;
// Creates an Ipfs client, and gets information about your local address, and
// connected peers.
@@ -18,30 +19,33 @@ use tokio_core::reactor::Core;
fn main() {
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
+ let client = IpfsClient::default();
- let local = client.swarm_addrs_local();
- let local = core.run(local).expect("expected a valid response");
-
- println!();
- println!("your addrs:");
- for addr in local.strings {
- println!(" {}", addr);
- }
-
- let connected = client.swarm_peers();
- let connected = core.run(connected).expect("expected a valid response");
+ let local = client.swarm_addrs_local().map(|local| {
+ println!();
+ println!("your addrs:");
+ for addr in local.strings {
+ println!(" {}", addr);
+ }
+ });
- println!();
- println!("connected:");
- for peer in connected.peers {
- let streams: Vec<&str> = peer.streams.iter().map(|s| &s.protocol[..]).collect();
- println!(" addr: {}", peer.addr);
- println!(" peer: {}", peer.peer);
- println!(" latency: {}", peer.latency);
- println!(" muxer: {}", peer.muxer);
- println!(" streams: {}", streams.join(", "));
+ let connected = client.swarm_peers().map(|connected| {
println!();
- }
+ println!("connected:");
+ for peer in connected.peers {
+ let streams: Vec<&str> = peer.streams.iter().map(|s| &s.protocol[..]).collect();
+ println!(" addr: {}", peer.addr);
+ println!(" peer: {}", peer.peer);
+ println!(" latency: {}", peer.latency);
+ println!(" muxer: {}", peer.muxer);
+ println!(" streams: {}", streams.join(", "));
+ println!();
+ }
+ });
+
+ hyper::rt::run(
+ local
+ .and_then(|_| connected)
+ .map_err(|e| eprintln!("{}", e)),
+ );
}
diff --git a/ipfs-api/examples/get_version.rs b/ipfs-api/examples/get_version.rs
index deea4e6..41a4ee5 100644
--- a/ipfs-api/examples/get_version.rs
+++ b/ipfs-api/examples/get_version.rs
@@ -6,21 +6,22 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
+use futures::Future;
use ipfs_api::IpfsClient;
-use tokio_core::reactor::Core;
// Creates an Ipfs client, and gets the version of the Ipfs server.
//
fn main() {
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
- let req = client.version();
- let version = core.run(req).expect("expected a valid response");
+ let client = IpfsClient::default();
+ let req = client
+ .version()
+ .map(|version| println!("version: {:?}", version.version));
- println!("version: {:?}", version.version);
+ hyper::rt::run(req.map_err(|e| eprintln!("{}", e)));
}
diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs
index c92e212..8bea192 100644
--- a/ipfs-api/examples/mfs.rs
+++ b/ipfs-api/examples/mfs.rs
@@ -6,12 +6,13 @@
// copied, modified, or distributed except according to those terms.
//
+extern crate futures;
+extern crate hyper;
extern crate ipfs_api;
-extern crate tokio_core;
+use futures::Future;
use ipfs_api::{response, IpfsClient};
use std::fs::File;
-use tokio_core::reactor::Core;
fn print_stat(stat: response::FilesStatResponse) {
println!(" type : {}", stat.typ);
@@ -28,47 +29,55 @@ fn main() {
println!("note: this must be run in the root of the project repository");
println!("connecting to localhost:5001...");
- let mut core = Core::new().expect("expected event loop");
- let client = IpfsClient::default(&core.handle());
+ let client = IpfsClient::default();
println!("making /test...");
println!();
- let req = client.files_mkdir("/test", false);
- core.run(req).expect("expected mkdir to succeed");
+ let mkdir = client.files_mkdir("/test", false);
+ let mkdir_recursive = client.files_mkdir("/test/does/not/exist/yet", true);
- println!("making dirs /test/does/not/exist/yet...");
- println!();
-
- let req = client.files_mkdir("/test/does/not/exist/yet", true);
- core.run(req).expect("expected mkdir -p to succeed");
-
- println!("getting status of /test/does...");
- println!();
-
- let req = client.files_stat("/test/does");
- let stat = core.run(req).expect("expected stat to succeed");
-
- print_stat(stat);
-
- println!("writing source file to /test/mfs.rs");
- println!();
+ let file_stat = client.files_stat("/test/does");
let src = File::open(file!()).expect("could not read source file");
- let req = client.files_write("/test/mfs.rs", true, true, src);
-
- core.run(req).expect("expected write to succed");
-
- let req = client.files_stat("/test/mfs.rs");
- let stat = core.run(req).expect("expected stat to succeed");
-
- print_stat(stat);
-