Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat(swarm): make interface-ipfs-core compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 15, 2016
1 parent 0c8cbdc commit f245f27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -100,4 +102,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
16 changes: 12 additions & 4 deletions src/api/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit f245f27

Please sign in to comment.