Skip to content

Commit

Permalink
Merge pull request #4 from Dignifiedquire/no-ip
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
dignifiedquire committed Dec 1, 2015
2 parents c7a1d86 + 9d8e9ea commit 68c90a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
44 changes: 24 additions & 20 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@ var memoized_lookup
function _lookup (ipfs, hash, lookfor, cb) {
ipfs.object.get(hash, function (err, res) {
if (err) {
cb(err, null)
} else {
return cb(err, null)
}

try {
var obj = JSON.parse(res.Data)
} catch (err) {
return cb(err, null)
}

var child = 0
if (obj.type === 'Node') {
while (obj.mins[child] &&
obj.mins[child] <= lookfor) {
child++
}
return memoized_lookup(ipfs, res.Links[child - 1].Hash, lookfor, cb)
} else if (obj.type === 'Leaf') {
while (obj.data[child] &&
obj.data[child].min <= lookfor) {
child++
}

var child = 0
if (obj.type === 'Node') {
while (obj.mins[child] &&
obj.mins[child] <= lookfor) {
child++
}
return memoized_lookup(ipfs, res.Links[child - 1].Hash, lookfor, cb)
} else if (obj.type === 'Leaf') {
while (obj.data[child] &&
obj.data[child].min <= lookfor) {
child++
}

if (obj.data[child - 1].data) {
cb(null, formatData(obj.data[child - 1].data))
} else {
cb('Unmapped range', null)
}
if (obj.data[child - 1].data) {
cb(null, formatData(obj.data[child - 1].data))
} else {
cb('Unmapped range', null)
}
}
})
Expand Down
7 changes: 5 additions & 2 deletions lib/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ module.exports = function lookupPretty (ipfs, multiaddrs, cb) {
if (multiaddrs.length === 0) return cb(null, null)
if (typeof multiaddrs === 'string') multiaddrs = [multiaddrs]

var address = multiaddrs[0].split('/')[2]
if (isLocal(address)) return lookupPretty(ipfs, multiaddrs.slice(1), cb)
var current = multiaddrs[0].split('/')
var address = current[2]

// No ip6 support at the moment
if (isLocal(address) || current[1] === 'ip6') return lookupPretty(ipfs, multiaddrs.slice(1), cb)

lookup(ipfs, address, function (err, res) {
if (err) return cb(err)
Expand Down

0 comments on commit 68c90a3

Please sign in to comment.