Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: geoip and peers on map #1334

Merged
merged 4 commits into from
Dec 4, 2019
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
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"internal-nav-helper": "^3.1.0",
"ip": "^1.1.5",
"ipfs-css": "^0.13.1",
"ipfs-geoip": "^3.0.0",
"ipfs-geoip": "^4.0.0",
"ipfs-redux-bundle": "^6.0.1",
"ipld-explorer-components": "^1.5.1",
"is-binary": "^0.1.0",
Expand Down
29 changes: 10 additions & 19 deletions src/bundles/peer-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,20 @@ class PeerLocationResolver {
}

// no ip address cached. are we looking it up already?
var locPromise = this.geoipLookupPromises[ipv4Addr]
if (locPromise) {
if (this.geoipLookupPromises[ipv4Addr]) {
continue
}

this.geoipLookupPromises[ipv4Addr] = this.queue.add(async () => {
return new Promise(resolve => {
const ipfs = getIpfs()

geoip.lookup(ipfs, ipv4Addr, (err, data) => {
delete this.geoipLookupPromises[ipv4Addr]

if (err) {
// mark this one as failed so we don't retry again
this.failedAddrs.set(ipv4Addr, true)
return resolve()
}

// save the data!
this.geoipCache.set(ipv4Addr, data)
resolve()
})
})
try {
const data = await geoip.lookup(getIpfs(), ipv4Addr)
await this.geoipCache.set(ipv4Addr, data)
} catch (e) {
// mark this one as failed so we don't retry again
this.failedAddrs.set(ipv4Addr, true)
} finally {
delete this.geoipLookupPromises[ipv4Addr]
}
})
}

Expand Down
8 changes: 3 additions & 5 deletions src/bundles/peer-locations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const mockPeersBundle = {

function fakeGeoIpData () {
return {
data: JSON.stringify({
Data: JSON.stringify({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYSA this is why tests always failed (always returned no data)

type: 'Leaf',
data: {
min: Infinity,
Expand Down Expand Up @@ -126,10 +126,8 @@ const createMockIpfs = (opts) => {

return {
object: {
get: (_, cb) => {
setTimeout(() => {
cb(null, fakeGeoIpData())
}, randomInt(opts.minLatency, opts.maxLatency))
get: async () => {
return fakeGeoIpData()
}
}
}
Expand Down