summaryrefslogtreecommitdiffstats
path: root/ipfs-api/examples/dns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipfs-api/examples/dns.rs')
-rw-r--r--ipfs-api/examples/dns.rs44
1 files changed, 24 insertions, 20 deletions
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);
}