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

Commit

Permalink
fix: dht.findPeer API endpoint returns ndjson (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Apr 6, 2020
1 parent f8bd931 commit 524ff32
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/ipfs-http-client/src/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ module.exports = configure(api => {
return async function findPeer (peerId, options = {}) {
options.arg = `${Buffer.isBuffer(peerId) ? new CID(peerId) : peerId}`

const res = await api.post('dht/findpeer', {
const res = await api.ndjson('dht/findpeer', {
timeout: options.timeout,
signal: options.signal,
searchParams: options
})

const data = await res.json()

if (data.Type === 3) {
throw new Error(data.Extra)
}
for await (const data of res) {
if (data.Type === 3) {
throw new Error(data.Extra)
}

if (data.Type === 2 && data.Responses) {
const { ID, Addrs } = data.Responses[0]
return {
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
if (data.Type === 2 && data.Responses) {
const { ID, Addrs } = data.Responses[0]
return {
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}
}
}

Expand Down

0 comments on commit 524ff32

Please sign in to comment.