Skip to content

Commit

Permalink
Don't do dnslookups when API is down
Browse files Browse the repository at this point in the history
- adds `.isUp` property to `api.js`
- also closes #54
  • Loading branch information
lidel committed Feb 5, 2016
1 parent b391dc9 commit bfb4ee3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ const { Request } = require('sdk/request')
const { XMLHttpRequest } = require('sdk/net/xhr')
const { URL } = require('sdk/url')

const pw = require('./peer-watch.js')
const dnsCache = require('./dns-cache.js')

Object.defineProperty(exports, 'isUp', {
get: function () {
return pw.peerCount != null
}
})

function apiUrl (path) {
return URL('http://' + prefs.customGatewayHost + ':' + prefs.customApiPort + '/api/v0/' + path).toString()
}
Expand Down Expand Up @@ -69,7 +76,7 @@ function isDnslinkPresent (fqdn) {

function isDnslinkPresentCached (fqdn) {
let ipfsSupport = dnsCache.get(fqdn)
if (typeof ipfsSupport === 'undefined') {
if (typeof ipfsSupport === 'undefined' && exports.isUp) {
ipfsSupport = isDnslinkPresent(fqdn)
if (ipfsSupport !== null) { // dont cache is API was down
dnsCache.put(fqdn, ipfsSupport)
Expand Down
4 changes: 2 additions & 2 deletions lib/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ panel.port.on('open-preferences', hidePanelAnd(function () {
onReady: function (tab) {
tab.attach({
contentScriptWhen: 'end',
contentScript: 'AddonManager.getAddonByID("' + self.id + '", function(aAddon) {' +
contentScript: 'if (typeof AddonManager !== \'undefined\'){AddonManager.getAddonByID("' + self.id + '", function(aAddon) {' +
'unsafeWindow.gViewController.commands.cmd_showItemDetails.doCommand(aAddon, true);' +
'});'
'});}'
})
}
})
Expand Down
10 changes: 9 additions & 1 deletion lib/peer-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ const gui = require('./gui.js')
const gw = require('./gateways.js')
const _ = require('sdk/l10n').get

let peerCount = null

function ipfsHealthCheck () {
api.getSwarmPeers((peers) => {
const peerCount = (peers && peers.Strings) ? peers.Strings.length : null
peerCount = (peers && peers.Strings) ? peers.Strings.length : null
gui.setButtonBadge(peerCount)

if (prefs.automatic) {
Expand Down Expand Up @@ -38,3 +40,9 @@ require('sdk/system/unload').when(() => {
})

exports.triggerManualCheck = ipfsHealthCheck

Object.defineProperty(exports, 'peerCount', {
get: function () {
return peerCount
}
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "ipfs-firefox-addon@lidel.org",
"description": "Access IPFS resources via custom HTTP2IPFS gateway",
"author": "Marcin Rataj",
"version": "1.5.0",
"version": "1.5.1",
"license": "CC0-1.0",
"homepage": "https://github.com/lidel/ipfs-firefox-addon",
"icon": "resource://ipfs-firefox-addon-at-lidel-dot-org/data/icon-on-64.png",
Expand Down

0 comments on commit bfb4ee3

Please sign in to comment.