diff options
author | Ferris Tseng <ferristseng@fastmail.fm> | 2021-02-23 23:26:48 -0500 |
---|---|---|
committer | Ferris Tseng <ferristseng@fastmail.fm> | 2021-02-23 23:26:48 -0500 |
commit | 1dbab207ece88a47f92b951a83ef8d95dc40fe1c (patch) | |
tree | e93fe962328364bde9e5ac2bbdb80c62746ff28a /ipfs-api | |
parent | fd4a1e309d565d88c5e394e9e8411f4968499d18 (diff) |
migrate examples to separate crate
Diffstat (limited to 'ipfs-api')
-rw-r--r-- | ipfs-api/examples/add_file.rs | 29 | ||||
-rw-r--r-- | ipfs-api/examples/add_tar.rs | 70 | ||||
-rw-r--r-- | ipfs-api/examples/bootstrap_default.rs | 63 | ||||
-rw-r--r-- | ipfs-api/examples/config.rs | 70 | ||||
-rw-r--r-- | ipfs-api/examples/dag.rs | 47 | ||||
-rw-r--r-- | ipfs-api/examples/default_config.json | 121 | ||||
-rw-r--r-- | ipfs-api/examples/dns.rs | 44 | ||||
-rw-r--r-- | ipfs-api/examples/get_commands.rs | 48 | ||||
-rw-r--r-- | ipfs-api/examples/get_stats.rs | 64 | ||||
-rw-r--r-- | ipfs-api/examples/get_swarm.rs | 49 | ||||
-rw-r--r-- | ipfs-api/examples/get_version.rs | 26 | ||||
-rw-r--r-- | ipfs-api/examples/log_tail.rs | 34 | ||||
-rw-r--r-- | ipfs-api/examples/mfs.rs | 89 | ||||
-rw-r--r-- | ipfs-api/examples/ping_peer.rs | 71 | ||||
-rw-r--r-- | ipfs-api/examples/pubsub.rs | 86 | ||||
-rw-r--r-- | ipfs-api/examples/replace_config.rs | 29 | ||||
-rw-r--r-- | ipfs-api/examples/resolve_name.rs | 52 |
17 files changed, 0 insertions, 992 deletions
diff --git a/ipfs-api/examples/add_file.rs b/ipfs-api/examples/add_file.rs deleted file mode 100644 index a19e4a2..0000000 --- a/ipfs-api/examples/add_file.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; -use std::fs::File; - -// Creates an Ipfs client, and adds this source file to Ipfs. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("note: this must be run in the root of the project repository"); - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - let file = File::open(file!()).expect("could not read source file"); - - match client.add(file).await { - Ok(file) => eprintln!("added file: {:?}", file), - Err(e) => eprintln!("error adding file: {}", e), - } -} diff --git a/ipfs-api/examples/add_tar.rs b/ipfs-api/examples/add_tar.rs deleted file mode 100644 index e20cb1e..0000000 --- a/ipfs-api/examples/add_tar.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use futures::TryStreamExt; -use ipfs_api::IpfsClient; -use std::io::Cursor; -use tar::Builder; - -// Creates an Ipfs client, and adds this source file to Ipfs. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("note: this must be run in the root of the project repository"); - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - // Create a in-memory tar file with this source file as its contents. - // - let mut buf = Vec::new(); - { - let mut builder = Builder::new(&mut buf); - - builder - .append_path(file!()) - .expect("failed to create tar file"); - builder.finish().expect("failed to create tar file"); - } - let cursor = Cursor::new(buf); - - // Write in-memory tar file to IPFS. - // - let file = match client.tar_add(cursor).await { - Ok(file) => { - eprintln!("added tar file: {:?}", file); - eprintln!(); - - file - } - Err(e) => { - eprintln!("error writing tar file: {}", e); - - return; - } - }; - - // Read tar file from IPFS. - // - match client - .tar_cat(&file.hash[..]) - .map_ok(|chunk| chunk.to_vec()) - .try_concat() - .await - { - Ok(tar) => { - println!("{}", String::from_utf8_lossy(&tar[..])); - } - Err(e) => { - eprintln!("error reading tar file: {}", e); - } - } -} diff --git a/ipfs-api/examples/bootstrap_default.rs b/ipfs-api/examples/bootstrap_default.rs deleted file mode 100644 index f693341..0000000 --- a/ipfs-api/examples/bootstrap_default.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; - -// Lists clients in bootstrap list, then adds the default list, then removes -// them, and readds them. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - match client.bootstrap_list().await { - Ok(bootstrap) => { - eprintln!("current bootstrap peers:"); - for peer in bootstrap.peers { - eprintln!(" {}", peer); - } - eprintln!(); - } - Err(e) => { - eprintln!("error getting list of bootstrap peers: {}", e); - return; - } - } - - match client.bootstrap_rm_all().await { - Ok(drop) => { - eprintln!("dropped:"); - for peer in drop.peers { - eprintln!(" {}", peer); - } - eprintln!(); - } - Err(e) => { - eprintln!("error dropping bootstrap peers: {}", e); - return; - } - } - - match client.bootstrap_add_default().await { - Ok(add) => { - eprintln!("added:"); - for peer in add.peers { - eprintln!(" {}", peer); - } - eprintln!(); - } - Err(e) => { - eprintln!("error adding default peers: {}", e); - } - } -} diff --git a/ipfs-api/examples/config.rs b/ipfs-api/examples/config.rs deleted file mode 100644 index 1e0a3c3..0000000 --- a/ipfs-api/examples/config.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; - -// Creates an Ipfs client, read & set config values. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("note: this must be run in the root of the project repository"); - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - //read a string - let response = client - .config_get_string("Identity.PeerID") - .await - .expect("Config read failed"); - - println!("Config: {}={}", response.key, response.value); - - //read a bool - let response = client - .config_get_bool("Datastore.HashOnRead") - .await - .expect("Config read failed"); - - println!("Config: {}={}", response.key, response.value); - - //read a stringified json - let response = client - .config_get_json("Mounts") - .await - .expect("Config read failed"); - - println!("Config: {}={}", response.key, response.value); - - //set a string value - let response = client - .config_set_string("Routing.Type", "dht") - .await - .expect("Config write failed"); - - println!("Config: {}={}", response.key, response.value); - - //set a boolean value - let response = client - .config_set_bool("Pubsub.DisableSigning", false) - .await - .expect("Config write failed"); - - println!("Config: {}={}", response.key, response.value); - - //set a json value - let response = client - .config_set_json("Discovery", r#"{"MDNS":{"Enabled":true,"Interval":10}}"#) - .await - .expect("Config write failed"); - - println!("Config: {}={}", response.key, response.value); -} diff --git a/ipfs-api/examples/dag.rs b/ipfs-api/examples/dag.rs deleted file mode 100644 index 5632021..0000000 --- a/ipfs-api/examples/dag.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use futures::TryStreamExt; -use ipfs_api::IpfsClient; -use std::io::Cursor; - -// Creates an Ipfs client, and adds this dag object to Ipfs then fetch it back. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("note: this must be run in the root of the project repository"); - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - let dag_node = Cursor::new(r#"{"hello":"world"}"#); - - let response = client - .dag_put(dag_node) - .await - .expect("error adding dag node"); - - let cid = response.cid.cid_string; - - match client - .dag_get(&cid) - .map_ok(|chunk| chunk.to_vec()) - .try_concat() - .await - { - Ok(bytes) => { - println!("{}", String::from_utf8_lossy(&bytes[..])); - } - Err(e) => { - eprintln!("error reading dag node: {}", e); - } - } -} diff --git a/ipfs-api/examples/default_config.json b/ipfs-api/examples/default_config.json deleted file mode 100644 index 89a87f4..0000000 --- a/ipfs-api/examples/default_config.json +++ /dev/null @@ -1,121 +0,0 @@ -{ - "Identity": { - "PeerID": "QmVRF8ZnT1ootg5vSrzS4ws8W8NwzF5q5MUCzfNK6ZmYeH" - }, - "Datastore": { - "StorageMax": "10GB", - "StorageGCWatermark": 90, - "GCPeriod": "1h", - "Spec": { - "mounts": [ - { - "child": { - "path": "blocks", - "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2", - "sync": true, - "type": "flatfs" - }, - "mountpoint": "/blocks", - "prefix": "flatfs.datastore", - "type": "measure" - }, - { - "child": { - "compression": "none", - "path": "datastore", - "type": "levelds" - }, - "mountpoint": "/", - "prefix": "leveldb.datastore", - "type": "measure" - } - ], - "type": "mount" - }, - "HashOnRead": false, - "BloomFilterSize": 0 - }, - "Addresses": { - "Swarm": [ - "/ip4/0.0.0.0/tcp/4001", - "/ip6/::/tcp/4001" - ], - "Announce": [], - "NoAnnounce": [], - "API": "/ip4/127.0.0.1/tcp/5001", - "Gateway": "/ip4/127.0.0.1/tcp/8080" - }, - "Mounts": { - "IPFS": "/ipfs", - "IPNS": "/ipns", - "FuseAllowOther": false - }, - "Discovery": { - "MDNS": { - "Enabled": true, - "Interval": 10 - } - }, - "Ipns": { - "RepublishPeriod": "", - "RecordLifetime": "", - "ResolveCacheSize": 128 - }, - "Bootstrap": [ - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb", - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt", - "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", - "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", - "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", - "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", - "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", - "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", - "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", - "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", - "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd" - ], - "Gateway": { - "HTTPHeaders": { - "Access-Control-Allow-Headers": [ - "X-Requested-With", - "Range" - ], - "Access-Control-Allow-Methods": [ - "GET" - ], - "Access-Control-Allow-Origin": [ - "*" - ] - }, - "RootRedirect": "", - "Writable": false, - "PathPrefixes": [] - }, - "API": { - "HTTPHeaders": null - }, - "Swarm": { - "AddrFilters": null, - "DisableBandwidthMetrics": false, - "DisableNatPortMap": false, - "DisableRelay": false, - "EnableRelayHop": false, - "ConnMgr": { - "Type": "basic", - "LowWater": 600, - "HighWater": 900, - "GracePeriod": "20s" - } - }, - "Reprovider": { - "Interval": "12h", - "Strategy": "all" - }, - "Experimental": { - "FilestoreEnabled": false, - "ShardingEnabled": false, - "Libp2pStreamMounting": false - } -} diff --git a/ipfs-api/examples/dns.rs b/ipfs-api/examples/dns.rs deleted file mode 100644 index 4a262c9..0000000 --- a/ipfs-api/examples/dns.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; - -// Creates an Ipfs client, resolves ipfs.io, and lists the contents of it. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - let dns = match client.dns("ipfs.io", true).await { - Ok(dns) => { - eprintln!("dns resolves to ({})", &dns.path); - eprintln!(); - - dns - } - Err(e) => { - eprintln!("error resolving dns: {}", e); - return; - } - }; - - match client.object_get(&dns.path[..]).await { - Ok(contents) => { - eprintln!("found contents:"); - for link in contents.links.iter() { - eprintln!("[{}] ({} bytes)", link.name, link.size); - } - } - Err(e) => eprintln!("error listing path: {}", e), - } -} diff --git a/ipfs-api/examples/get_commands.rs b/ipfs-api/examples/get_commands.rs deleted file mode 100644 index fb019b6..0000000 --- a/ipfs-api/examples/get_commands.rs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::{response, IpfsClient}; - -fn print_recursive(indent: usize, cmd: &response::CommandsResponse) { - let cmd_indent = " ".repeat(indent * 4); - let opt_indent = " ".repeat((indent + 1) * 4); - - eprintln!("{}[{}]", cmd_indent, cmd.name); - - if cmd.options.len() > 0 { - eprintln!("{}* options:", cmd_indent); - for options in cmd.options.iter() { - eprintln!("{}{}", opt_indent, &options.names[..].join(", ")); - } - } - - if cmd.subcommands.len() > 0 { - eprintln!("{}- subcommands:", cmd_indent); - for subcommand in cmd.subcommands.iter() { - print_recursive(indent + 1, subcommand); - } - } -} - -// Creates an Ipfs client, and gets a list of available commands from the -// Ipfs server. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - match client.commands().await { - Ok(commands) => print_recursive(0, &commands), - Err(e) => eprintln!("error getting commands: {}", e), - } -} diff --git a/ipfs-api/examples/get_stats.rs b/ipfs-api/examples/get_stats.rs deleted file mode 100644 index f51a9da..0000000 --- a/ipfs-api/examples/get_stats.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; - -// Creates an Ipfs client, and gets some stats about the Ipfs server. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - match client.stats_bitswap().await { - Ok(bitswap_stats) => { - eprintln!("bitswap stats:"); - eprintln!(" blocks recv: {}", bitswap_stats.blocks_received); - eprintln!(" data recv: {}", bitswap_stats.data_received); - eprintln!(" blocks sent: {}", bitswap_stats.blocks_sent); - eprintln!(" data sent: {}", bitswap_stats.data_sent); - eprintln!( - " peers: {}", - bitswap_stats.peers.join("\n ") - ); - eprintln!( - " wantlist: {}", - bitswap_stats.wantlist.join("\n ") - ); - eprintln!(); - } - Err(e) => eprintln!("error getting bitswap stats: {}", e), - } - - match client.stats_bw().await { - Ok(bw_stats) => { - eprintln!("bandwidth stats:"); - eprintln!(" total in: {}", bw_stats.total_in); - eprintln!(" total out: {}", bw_stats.total_out); - eprintln!(" rate in: {}", bw_stats.rate_in); - eprintln!(" rate out: {}", bw_stats.rate_out); - eprintln!(); - } - Err(e) => eprintln!("error getting bandwidth stats: {}", e), - } - - match client.stats_repo().await { - Ok(repo_stats) => { - eprintln!("repo stats:"); - eprintln!(" num objs: {}", repo_stats.num_objects); - eprintln!(" repo size: {}", repo_stats.repo_size); - eprintln!(" repo path: {}", repo_stats.repo_path); - eprintln!(" version : {}", repo_stats.version); - } - Err(e) => eprintln!("error getting repo stats: {}", e), - } -} diff --git a/ipfs-api/examples/get_swarm.rs b/ipfs-api/examples/get_swarm.rs deleted file mode 100644 index 9f30b12..0000000 --- a/ipfs-api/examples/get_swarm.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; - -// Creates an Ipfs client, and gets information about your local address, and -// connected peers. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - match client.swarm_addrs_local().await { - Ok(local) => { - eprintln!("your addrs:"); - for addr in local.strings { - eprintln!(" {}", addr); - } - eprintln!(); - } - Err(e) => eprintln!("error getting local swarm addresses: {}", e), - } - - match client.swarm_peers().await { - Ok(connected) => { - eprintln!("connected:"); - for peer in connected.peers { - let streams: Vec<&str> = peer.streams.iter().map(|s| &s.protocol[..]).collect(); - eprintln!(" addr: {}", peer.addr); - eprintln!(" peer: {}", peer.peer); - eprintln!(" latency: {}", peer.latency); - eprintln!(" muxer: {}", peer.muxer); - eprintln!(" streams: {}", streams.join(", ")); - eprintln!(); - } - } - Err(e) => eprintln!("error getting swarm peers: {}", e), - } -} diff --git a/ipfs-api/examples/get_version.rs b/ipfs-api/examples/get_version.rs deleted file mode 100644 index 83c3f90..0000000 --- a/ipfs-api/examples/get_version.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::IpfsClient; - -// Creates an Ipfs client, and gets the version of the Ipfs server. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - match client.version().await { - Ok(version) => eprintln!("version: {:?}", version.version), - Err(e) => eprintln!("error getting version: {}", e), - } -} diff --git a/ipfs-api/examples/log_tail.rs b/ipfs-api/examples/log_tail.rs deleted file mode 100644 index e590a61..0000000 --- a/ipfs-api/examples/log_tail.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use futures::{future, TryStreamExt}; -use ipfs_api::IpfsClient; - -// Tails the log of IPFS. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - if let Err(e) = client - .log_tail() - .try_for_each(|line| { - println!("{}", line); - - future::ok(()) - }) - .await - { - eprintln!("error getting tail of log: {}", e); - } -} diff --git a/ipfs-api/examples/mfs.rs b/ipfs-api/examples/mfs.rs deleted file mode 100644 index 836e238..0000000 --- a/ipfs-api/examples/mfs.rs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use ipfs_api::{response, IpfsClient}; -use std::fs::File; - -fn print_stat(stat: response::FilesStatResponse) { - eprintln!(" type : {}", stat.typ); - eprintln!(" hash : {}", stat.hash); - eprintln!(" size : {}", stat.size); - eprintln!(" cum. size: {}", stat.cumulative_size); - eprintln!(" blocks : {}", stat.blocks); - eprintln!(); -} - -// Creates an Ipfs client, and makes some calls to the Mfs Api. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("note: this must be run in the root of the project repository"); - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - eprintln!("making /test..."); - eprintln!(); - - if let Err(e) = client.files_mkdir("/test", false).await { - eprintln!("error making /test: {}", e); - return; - } - - eprintln!("making dirs /test/does/not/exist/yet..."); - eprintln!(); - - if let Err(e) = client.files_mkdir("/test/does/not/exist/yet", true).await { - eprintln!("error making /test/does/not/exist/yet: {}", e); - return; - } - - eprintln!("getting status of /test/does..."); - eprintln!(); - - match client.files_stat("/test/does").await { - Ok(stat) => print_stat(stat), - Err(e) => { - eprintln!("error getting status of /test/does: {}", e); - return; - } - } - - eprintln!("writing source file to /test/mfs.rs"); - eprintln!(); - - let src = File::open(file!()).expect("could not read source file"); - - if let Err(e) = client.files_write("/test/mfs.rs", true, true, src).await { - eprintln!("error writing source file /test/mfs.rs: {}", e); - return; - } - - eprintln!("getting status of /test/mfs.rs..."); - eprintln!(); - - match client.files_stat("/test/mfs.rs").await { - Ok(stat) => print_stat(stat), - Err(e) => { - eprintln!("error getting status of /test/mfs.rs: {}", e); - return; - } - } - - eprintln!("removing /test..."); - eprintln!(); - - if let Err(e) = client.files_rm("/test", true).await { - eprintln!("error removing /test: {}", e); - } - - eprintln!("done!"); -} diff --git a/ipfs-api/examples/ping_peer.rs b/ipfs-api/examples/ping_peer.rs deleted file mode 100644 index eddc3ba..0000000 --- a/ipfs-api/examples/ping_peer.rs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -use futures::{future, TryStreamExt}; -use ipfs_api::{response::PingResponse, IpfsClient}; - -// Creates an Ipfs client, discovers a connected peer, and pings it using the -// streaming Api, and by collecting it into a collection. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("connecting to localhost:5001..."); - - let client = IpfsClient::default(); - - eprintln!(); - eprintln!("discovering connected peers..."); - - let peer = match client.swarm_peers().await { - Ok(connected) => connected - .peers - .into_iter() - .next() - .expect("expected at least one peer"), - Err(e) => { - eprintln!("error getting connected peers: {}", e); - return; - } - }; - - eprintln!(); - eprintln!("discovered peer ({})", peer.peer); - eprintln!(); - eprintln!("streaming 10 pings..."); - - if let Err(e) = client - .ping(&peer.peer[..], Some(10)) - .try_for_each(|ping| { - eprintln!("{:?}", ping); - - future::ok(()) - }) - .await - { - eprintln!("error streaming pings: {}", e); - } - - eprintln!(); - eprintln!("gathering 15 pings..."); - - match client - .ping(&peer.peer[..], Some(15)) - .try_collect::<Vec<PingResponse>>() - .await - { - Ok(pings) => { - for ping in pings.iter() { - eprintln!("got response ({:?}) at ({})...", ping.text, ping.time); - } - } - Err(e) => eprintln!("error collecting pings: {}", e), - } -} diff --git a/ipfs-api/examples/pubsub.rs b/ipfs-api/examples/pubsub.rs deleted file mode 100644 index 1c6a34c..0000000 --- a/ipfs-api/examples/pubsub.rs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2017 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or -// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or -// http://opensource.org/licenses/MIT>, at your option. This file may not be -// copied, modified, or distributed except according to those terms. -// - -#[macro_use] -extern crate futures; - -use futures::{future, FutureExt, StreamExt, TryStreamExt}; -use ipfs_api::IpfsClient; -use std::time::Duration; -use tokio::time; -use tokio_stream::wrappers::IntervalStream; - -static TOPIC: &'static str = "test"; - -fn get_client() -> IpfsClient { - eprintln!("connecting to localhost:5001..."); - - IpfsClient::default() -} - -// Creates an Ipfs client, and simultaneously publishes and reads from a pubsub -// topic. -// -#[cfg_attr(feature = "with-actix", actix_rt::main)] -#[cfg_attr(feature = "with-hyper", tokio::main)] -async fn main() { - tracing_subscriber::fmt::init(); - - eprintln!("note: ipfs must be run with the --enable-pubsub-experiment flag"); - - let publish_client = get_client(); - - // This block will execute a repeating function that sends - // a message to the "test" topic. - // - let interval = time::interval(Duration::from_secs(1)); - let mut publish = IntervalStream::new(interval) - .then(|_| future::ok(())) // Coerce the stream into a TryStream - .try_for_each(|_| { - eprintln!(); - eprintln!("publishing message..."); - - |