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: uppercase Discovery.MDNS.enabled in default config #1632

Merged
merged 3 commits into from
Sep 14, 2020
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
45 changes: 44 additions & 1 deletion src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,53 @@ function applyDefaults (ipfsd) {

config.Discovery = config.Discovery || {}
config.Discovery.MDNS = config.Discovery.MDNS || {}
config.Discovery.MDNS.enabled = true
config.Discovery.MDNS.Enabled = true

writeConfigFile(ipfsd, config)
}

// Apply one-time updates to the config of IPFS node.
// This is the place where we execute fixes and performance tweaks for existing users.
function migrateConfig (ipfsd) {
// Bump revision number when new migration rule is added
const REVISION = 1
const REVISION_KEY = 'daemonConfigRevision'

// Migration is applied only once per revision
if (store.get(REVISION_KEY) >= REVISION) return

// Read config
let config = null
let changed = false
try {
config = readConfigFile(ipfsd)
} catch (err) {
// This is a best effort check, dont blow up here, that should happen else where.
logger.error(`[daemon] migrateConfig: error reading config file: ${err.message || err}`)
return
}

// Cleanup https://github.com/ipfs-shipyard/ipfs-desktop/issues/1631
if (config.Discovery && config.Discovery.MDNS && config.Discovery.MDNS.enabled) {
config.Discovery.MDNS.Enabled = config.Discovery.MDNS.Enabled || true
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this true everytime?

Copy link
Member

Choose a reason for hiding this comment

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

no, user could remove it or explicitly set it to false to disable noise in LAN

delete config.Discovery.MDNS.enabled
changed = true
}

// TODO: update config.Swarm.ConnMgr.*

if (changed) {
try {
writeConfigFile(ipfsd, config)
store.set(REVISION_KEY, REVISION)
} catch (err) {
logger.error(`[daemon] migrateConfig: error writing config file: ${err.message || err}`)
return
}
}
store.set(REVISION_KEY, REVISION)
}

// Check for * and webui://- in allowed origins on API headers.
// The wildcard was a ipfsd-ctl default, that we don't want, and
// webui://- was an earlier experiement that should be cleared out.
Expand Down Expand Up @@ -276,6 +318,7 @@ module.exports = Object.freeze({
apiFileExists,
rmApiFile,
applyDefaults,
migrateConfig,
checkCorsConfig,
checkPorts
})
3 changes: 2 additions & 1 deletion src/daemon/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { join } = require('path')
const { app } = require('electron')
const { showDialog } = require('../dialogs')
const logger = require('../common/logger')
const { applyDefaults, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config')
const { applyDefaults, migrateConfig, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config')
const { getCustomBinary } = require('../custom-ipfs-binary')

function cannotConnectDialog (addr) {
Expand Down Expand Up @@ -52,6 +52,7 @@ async function spawn ({ flags, path, keysize }) {
})

if (configExists(ipfsd)) {
migrateConfig(ipfsd)
checkCorsConfig(ipfsd)
return { ipfsd, isRemote: false }
}
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/launch.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ describe('Application launch', function () {
await ipfsd.stop()
})

it('applies config migration to existing config', async function () {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

// setup "broken" config for the test
const initConfig = fs.readJsonSync(configPath)
// simulate bug from https://github.com/ipfs-shipyard/ipfs-desktop/issues/1631
delete initConfig.Discovery.MDNS.Enabled
initConfig.Discovery.MDNS.enabled = true
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
expect(app.isRunning()).to.be.true()

const { peerId } = await daemonReady(app)
expect(peerId).to.be.equal(expectedId)

const config = fs.readJsonSync(configPath)
// ensure app has migrated config
expect(config.Discovery.MDNS.enabled).to.be.undefined()
expect(config.Discovery.MDNS.Enabled).to.be.true()
})

it('fixes cors config if access to "*" is granted', async function () {
// create config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })
Expand Down