diff --git a/src/dht/findpeer.js b/src/dht/findpeer.js index 9ae9d996d..fa34a7a92 100644 --- a/src/dht/findpeer.js +++ b/src/dht/findpeer.js @@ -25,16 +25,27 @@ 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 { @@ -42,15 +53,12 @@ module.exports = (send) => { } }) - const response = { - ...res, - Responses: [{ - ID: id, - Addrs: addresses + callback(null, { + responses: [{ + id, + addrs }] - } - - callback(null, response) + }) } send({ diff --git a/src/dht/findprovs.js b/src/dht/findprovs.js index 1ffd53310..24c946c64 100644 --- a/src/dht/findprovs.js +++ b/src/dht/findprovs.js @@ -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({