From f245f27c0866bfa9aaa5c9675dccddd973593f0f Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Thu, 15 Sep 2016 08:41:46 +0200 Subject: [PATCH] feat(swarm): make interface-ipfs-core compliant --- package.json | 8 +++++--- src/api/swarm.js | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 2e885747d..7642d8ab4 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" @@ -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) => {