Skip to content

Commit

Permalink
mcclient: net findPeers command for /net/find api
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Feb 9, 2017
1 parent 090e44e commit 3e58d9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/client/api/RestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ class RestClient {
.then(r => r.json())
}

netFindPeers (): Promise<Array<string>> {
return this.getRequest('net/find')
.then(parseStringArrayResponse)
}

getSelfManifest (): Promise<string> {
return this.getRequest('manifest/self')
.then(trimTextResponse)
Expand Down
23 changes: 23 additions & 0 deletions src/client/cli/commands/net/findPeers.js
Original file line number Diff line number Diff line change
@@ -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}`) }
)
})
}

0 comments on commit 3e58d9b

Please sign in to comment.