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

refactor: return peer ids as strings #1226

Merged
merged 8 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"async": "^3.1.0",
"browser-process-platform": "~0.1.1",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.129.0",
"ipfsd-ctl": "^1.0.2",
"interface-ipfs-core": "^0.131.0",
"ipfsd-ctl": "^2.1.0",
"it-all": "^1.0.1",
"it-concat": "^1.0.0",
"it-pipe": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function toCoreInterface (res) {
return {
provideBufLen: res.ProvideBufLen,
wantlist: (res.Wantlist || []).map(k => new CID(k['/'])),
peers: (res.Peers || []).map(p => new CID(p)),
peers: (res.Peers || []),
blocksReceived: new Big(res.BlocksReceived),
dataReceived: new Big(res.DataReceived),
blocksSent: new Big(res.BlocksSent),
Expand Down
2 changes: 1 addition & 1 deletion src/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = configure(({ ky }) => {
// https://github.com/ipfs/go-ipfs/blob/eb11f569b064b960d1aba4b5b8ca155a3bd2cb21/core/commands/dht.go#L395-L396
for (const { ID, Addrs } of message.Responses) {
return {
id: new CID(ID),
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dht/find-provs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = configure(({ ky }) => {
if (message.Type === 4 && message.Responses) {
for (const { ID, Addrs } of message.Responses) {
yield {
id: new CID(ID),
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = configure(({ ky }) => {
message.id = new CID(message.id)
if (message.responses) {
message.responses = message.responses.map(({ ID, Addrs }) => ({
id: new CID(ID),
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/dht/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = configure(({ ky }) => {
message.id = new CID(message.id)
if (message.responses) {
message.responses = message.responses.map(({ ID, Addrs }) => ({
id: new CID(ID),
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}))
}
Expand Down
2 changes: 1 addition & 1 deletion src/dht/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = configure(({ ky }) => {
message = toCamel(message)
message.id = new CID(message.id)
message.responses = (message.responses || []).map(({ ID, Addrs }) => ({
id: new CID(ID),
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}))
yield message
Expand Down
9 changes: 8 additions & 1 deletion src/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const configure = require('./lib/configure')
const toCamel = require('./lib/object-to-camel')
const multiaddr = require('multiaddr')

module.exports = configure(({ ky }) => {
return async options => {
Expand All @@ -14,6 +15,12 @@ module.exports = configure(({ ky }) => {
searchParams: options.searchParams
}).json()

return toCamel(res)
const output = toCamel(res)

if (output.addresses) {
output.addresses = output.addresses.map(ma => multiaddr(ma))
}

return output
}
})
3 changes: 1 addition & 2 deletions src/swarm/addrs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const CID = require('cids')
const multiaddr = require('multiaddr')
const configure = require('../lib/configure')

Expand All @@ -16,7 +15,7 @@ module.exports = configure(({ ky }) => {
}).json()

return Object.keys(res.Addrs).map(id => ({
id: new CID(id),
id,
addrs: (res.Addrs[id] || []).map(a => multiaddr(a))
}))
}
Expand Down
3 changes: 1 addition & 2 deletions src/swarm/peers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const multiaddr = require('multiaddr')
const CID = require('cids')
const configure = require('../lib/configure')

module.exports = configure(({ ky }) => {
Expand All @@ -25,7 +24,7 @@ module.exports = configure(({ ky }) => {
const info = {}
try {
info.addr = multiaddr(peer.Addr)
info.peer = new CID(peer.Peer)
info.peer = peer.Peer
} catch (error) {
info.error = error
info.rawPeerInfo = peer
Expand Down