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

Commit

Permalink
chore: update responses
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Nov 13, 2018
1 parent 7900d27 commit d6c24c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
34 changes: 21 additions & 13 deletions src/dht/findpeer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,40 @@ module.exports = (send) => {
res = res[0]
}

// Type 2 keys
if (res.Type !== 2) {
// Type 2 keys (inconsistencies between go core and js core)
if (res.Type !== 2 && res.type !== 2) {
const errMsg = `key was not found (type 2)`

return callback(errcode(new Error(errMsg), 'ERR_KEY_TYPE_2_NOT_FOUND'))
}

const id = res.Responses[0].ID
const addresses = res.Responses[0].Addrs.map((addr) => {
// inconsistencies js / go - go does not add `/ipfs/{id}` to the address
// inconsistencies between go core and js core
let id
let addrs

if (res.Responses) {
id = res.Responses[0].ID
addrs = res.Responses[0].Addrs
} else {
id = res.responses[0].id
addrs = res.responses[0].addrs
}

// inconsistencies js / go - go does not add `/ipfs/{id}` to the address
addrs = addrs.map((addr) => {
if (addr.split('/ipfs/') > -1) {
return addr
} else {
return `${addr}/ipfs/${id}`
}
})

const response = {
...res,
Responses: [{
ID: id,
Addrs: addresses
callback(null, {
responses: [{
id,
addrs
}]
}

callback(null, response)
})
}

send({
Expand Down
15 changes: 12 additions & 3 deletions src/dht/findprovs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@ module.exports = (send) => {
res = res[0]
}

// Type 4 keys
if (res.Type !== 4) {
// Type 4 keys (inconsistencies between go core and js core)
if (res.Type !== 4 && res.type !== 4) {
const errMsg = `key was not found (type 4)`

return callback(errcode(new Error(errMsg), 'ERR_KEY_TYPE_4_NOT_FOUND'))
}

callback(null, res)
// inconsistencies between go core and js core
const recResponses = res.Responses || res.responses

// providers array (handling inconsistencies)
const responses = recResponses.map((r) => ({
id: r.ID || r.id,
addrs: r.Addrs || r.addrs
}))

callback(null, { responses })
}

send({
Expand Down

0 comments on commit d6c24c5

Please sign in to comment.