From 3e58d9b9d283a28f2ca69b19763a915ac004613a Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 9 Feb 2017 16:03:16 +0200 Subject: [PATCH] mcclient: net findPeers command for /net/find api --- src/client/api/RestClient.js | 5 +++++ src/client/cli/commands/net/findPeers.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/client/cli/commands/net/findPeers.js diff --git a/src/client/api/RestClient.js b/src/client/api/RestClient.js index 95d77f0..d361925 100644 --- a/src/client/api/RestClient.js +++ b/src/client/api/RestClient.js @@ -336,6 +336,11 @@ class RestClient { .then(r => r.json()) } + netFindPeers (): Promise> { + return this.getRequest('net/find') + .then(parseStringArrayResponse) + } + getSelfManifest (): Promise { return this.getRequest('manifest/self') .then(trimTextResponse) diff --git a/src/client/cli/commands/net/findPeers.js b/src/client/cli/commands/net/findPeers.js new file mode 100644 index 0000000..5ea78eb --- /dev/null +++ b/src/client/cli/commands/net/findPeers.js @@ -0,0 +1,23 @@ +// @flow + +const RestClient = require('../../../api/RestClient') +const { subcommand, println } = require('../../util') + +module.exports = { + command: 'findPeers', + description: `find all public peers registerd in the DHT.\n`, + handler: subcommand((opts: {client: RestClient}) => { + const {client} = opts + + return client.netFindPeers() + .then( + peers => { + peers.forEach(peer => { + println(peer) + }) + }) + .catch( + err => { throw new Error(`Error finding peers: ${err.message}`) } + ) + }) +}