summaryrefslogtreecommitdiffstats
path: root/ipfs-cli
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-25 17:18:14 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-25 17:18:14 -0500
commit5c3c9b170f1415fcbb4c0de28339467bcbca5e29 (patch)
treec871a52c7611df78519c8673e2a1a7034bf337ba /ipfs-cli
parentbe4d9527b0ee4830d5434e6e70415d2f18af0180 (diff)
add dht and better serialization
Diffstat (limited to 'ipfs-cli')
-rw-r--r--ipfs-cli/src/command/dht.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/ipfs-cli/src/command/dht.rs b/ipfs-cli/src/command/dht.rs
index dc28188..7fd72e1 100644
--- a/ipfs-cli/src/command/dht.rs
+++ b/ipfs-cli/src/command/dht.rs
@@ -22,6 +22,18 @@ pub fn signature<'a, 'b>() -> App<'a, 'b> {
(about: "Query the DHT for all of the multiaddresses associated with a Peer ID")
(@arg PEER: +required "Peer to search for")
)
+ (@subcommand findprovs =>
+ (about: "Find peers in the DHT that can provide the given key")
+ (@arg KEY: +required "Key to search for")
+ )
+ (@subcommand get =>
+ (about: "Given a key, query the DHT for its best value")
+ (@arg KEY: +required "The key search for")
+ )
+ (@subcommand provide =>
+ (about: "Announce to the network that you are providing the given values")
+ (@arg KEY: +required "The key you are providing")
+ )
)
}
@@ -29,7 +41,7 @@ pub fn signature<'a, 'b>() -> App<'a, 'b> {
fn print_dht_response(res: DhtMessage) {
println!("");
println!(" id : {}", res.id);
- println!(" type : {}", res.typ);
+ println!(" type : {:?}", res.typ);
println!(" responses :");
for peer_res in res.responses {
println!(" id : {}", peer_res.id);
@@ -56,6 +68,36 @@ pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
core.run(req).expect(EXPECTED_API);
}
+ ("findprovs", Some(args)) => {
+ let key = args.value_of("KEY").unwrap();
+ let req = client.dht_findprovs(&key).for_each(|peer| {
+ print_dht_response(peer);
+
+ Ok(())
+ });
+
+ core.run(req).expect(EXPECTED_API);
+ }
+ ("get", Some(args)) => {
+ let key = args.value_of("KEY").unwrap();
+ let req = client.dht_get(&key).for_each(|peer| {
+ print_dht_response(peer);
+
+ Ok(())
+ });
+
+ core.run(req).expect(EXPECTED_API);
+ }
+ ("provide", Some(args)) => {
+ let key = args.value_of("KEY").unwrap();
+ let req = client.dht_provide(&key).for_each(|peer| {
+ print_dht_response(peer);
+
+ Ok(())
+ });
+
+ core.run(req).expect(EXPECTED_API);
+ }
_ => unreachable!(),
}
}