diff --git a/package.json b/package.json index 2e885747d..40199b437 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,13 @@ "multiaddr": "^2.0.2", "multipart-stream": "^2.0.1", "ndjson": "^1.4.3", + "peer-id": "^0.7.0", + "peer-info": "^0.7.1", "promisify-es6": "^1.0.1", "qs": "^6.2.1", + "streamifier": "^0.1.1", "tar-stream": "^1.5.2", - "wreck": "^10.0.0", - "streamifier": "^0.1.1" + "wreck": "^10.0.0" }, "engines": { "node": ">=4.2.2" @@ -49,7 +51,7 @@ "chai": "^3.5.0", "gulp": "^3.9.1", "hapi": "^15.0.2", - "interface-ipfs-core": "^0.14.5", + "interface-ipfs-core": "^0.15.0", "ipfsd-ctl": "^0.14.0", "pre-commit": "^1.1.3", "socket.io": "^1.4.8", @@ -100,4 +102,4 @@ "url": "https://github.com/ipfs/js-ipfs-api/issues" }, "homepage": "https://github.com/ipfs/js-ipfs-api" -} \ No newline at end of file +} diff --git a/src/api/swarm.js b/src/api/swarm.js index 510b2d2a3..d068645b7 100644 --- a/src/api/swarm.js +++ b/src/api/swarm.js @@ -2,6 +2,8 @@ const promisify = require('promisify-es6') const multiaddr = require('multiaddr') +const PeerId = require('peer-id') +const PeerInfo = require('peer-info') module.exports = (send) => { return { @@ -56,11 +58,17 @@ module.exports = (send) => { if (err) { return callback(err) } - callback(null, Object.keys(result.Addrs).map((id) => { - return result.Addrs[id].map((maStr) => { - return multiaddr(maStr).encapsulate('/ipfs/' + id) + + const peers = Object.keys(result.Addrs).map((id) => { + const info = new PeerInfo(PeerId.createFromB58String(id)) + result.Addrs[id].forEach((addr) => { + info.multiaddr.add(multiaddr(addr)) }) - })[0]) + + return info + }) + + callback(null, peers) }) }), localAddrs: promisify((opts, callback) => {