Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit f245f27

Browse files
feat(swarm): make interface-ipfs-core compliant
1 parent 0c8cbdc commit f245f27

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
"multiaddr": "^2.0.2",
3232
"multipart-stream": "^2.0.1",
3333
"ndjson": "^1.4.3",
34+
"peer-id": "^0.7.0",
35+
"peer-info": "^0.7.1",
3436
"promisify-es6": "^1.0.1",
3537
"qs": "^6.2.1",
38+
"streamifier": "^0.1.1",
3639
"tar-stream": "^1.5.2",
37-
"wreck": "^10.0.0",
38-
"streamifier": "^0.1.1"
40+
"wreck": "^10.0.0"
3941
},
4042
"engines": {
4143
"node": ">=4.2.2"
@@ -100,4 +102,4 @@
100102
"url": "https://github.com./ipfs/js-ipfs-api/issues"
101103
},
102104
"homepage": "https://github.com./ipfs/js-ipfs-api"
103-
}
105+
}

src/api/swarm.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const promisify = require('promisify-es6')
44
const multiaddr = require('multiaddr')
5+
const PeerId = require('peer-id')
6+
const PeerInfo = require('peer-info')
57

68
module.exports = (send) => {
79
return {
@@ -56,11 +58,17 @@ module.exports = (send) => {
5658
if (err) {
5759
return callback(err)
5860
}
59-
callback(null, Object.keys(result.Addrs).map((id) => {
60-
return result.Addrs[id].map((maStr) => {
61-
return multiaddr(maStr).encapsulate('/ipfs/' + id)
61+
62+
const peers = Object.keys(result.Addrs).map((id) => {
63+
const info = new PeerInfo(PeerId.createFromB58String(id))
64+
result.Addrs[id].forEach((addr) => {
65+
info.multiaddr.add(multiaddr(addr))
6266
})
63-
})[0])
67+
68+
return info
69+
})
70+
71+
callback(null, peers)
6472
})
6573
}),
6674
localAddrs: promisify((opts, callback) => {

0 commit comments

Comments
 (0)