Skip to content

Commit

Permalink
feat: kubo 0.33 with AutoTLS enabled (#2917)
Browse files Browse the repository at this point in the history
Release-As: 0.41.0
  • Loading branch information
lidel authored Jan 30, 2025
1 parent 147b421 commit e6a916d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
14 changes: 7 additions & 7 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 @@ -82,7 +82,7 @@
"ipfs-utils": "^9.0.10",
"ipfsd-ctl": "10.0.6",
"it-last": "^1.0.6",
"kubo": "0.32.1",
"kubo": "0.33.0",
"multiaddr": "10.0.1",
"multiaddr-to-uri": "8.0.0",
"portfinder": "^1.0.32",
Expand Down
19 changes: 17 additions & 2 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ function applyDefaults (ipfsd) {
config.API = { HTTPHeaders: {} }

config.Swarm = config.Swarm ?? {}
config.Swarm.DisableNatPortMap = false
config.Swarm.DisableNatPortMap = false // uPnP
config.Swarm.ConnMgr = config.Swarm.ConnMgr ?? {}

config.Discovery = config.Discovery ?? {}
config.Discovery.MDNS = config.Discovery.MDNS ?? {}
config.Discovery.MDNS.Enabled = true

config.AutoTLS = config.AutoTLS ?? {}
config.AutoTLS.Enabled = true

writeConfigFile(ipfsd, config)
}

Expand Down Expand Up @@ -150,7 +153,7 @@ const getGatewayPort = (config) => getHttpPort(config.Addresses.Gateway)
*/
function migrateConfig (ipfsd) {
// Bump revision number when new migration rule is added
const REVISION = 5
const REVISION = 6
const REVISION_KEY = 'daemonConfigRevision'
const CURRENT_REVISION = store.get(REVISION_KEY, 0)

Expand Down Expand Up @@ -231,6 +234,18 @@ function migrateConfig (ipfsd) {
}
}

if (CURRENT_REVISION < 6) {
// Enable AutoTLS if there is no explicit user preference
if (config.AutoTLS === undefined) {
config.AutoTLS = {}
changed = true
}
if (config.AutoTLS.Enabled === undefined) {
config.AutoTLS.Enabled = true
changed = true
}
}

if (changed) {
try {
writeConfigFile(ipfsd, config)
Expand Down
51 changes: 51 additions & 0 deletions test/e2e/launch.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,57 @@ test.describe.serial('Application launch', async () => {
expect(config.Swarm.ConnMgr.HighWater).toEqual(undefined)
})

test('applies config migration v6 (explicitly enable AutoTLS if upgrading from Kubo <0.33)', async () => {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

const initConfig = fs.readJsonSync(configPath)
initConfig.AutoTLS = undefined // simulate kubo <0.33, where there was no AutoTLS section
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
const { peerId } = await daemonReady(app)
expect(peerId).toBe(expectedId)

const config = fs.readJsonSync(configPath)
// ensure app has migrated config and AutoTLS is explicitly enabled now
expect(config.AutoTLS.Enabled).toEqual(true)
})

test('applies config migration v6 (explicitly enable AutoTLS if Kubo >=0.33)', async () => {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

// just read config (it should have empty AutoTLS config)
const initConfig = fs.readJsonSync(configPath)
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
const { peerId } = await daemonReady(app)
expect(peerId).toBe(expectedId)

const config = fs.readJsonSync(configPath)
// ensure ipfs-desktop migrated default Kubo config to explicitly enable AutoTLS
expect(config.AutoTLS.Enabled).toEqual(true)
})

test('applies config migration v6 (respect pre-existing AutoTLS user config)', async () => {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

const initConfig = fs.readJsonSync(configPath)
initConfig.AutoTLS = { Enabled: false } // user explicitly disabled it
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
const { peerId } = await daemonReady(app)
expect(peerId).toBe(expectedId)

const config = fs.readJsonSync(configPath)
// ensure app respected and kept user choice
expect(config.AutoTLS.Enabled).toEqual(false)
})

test('starts with repository with "IPFS_PATH/api" file and no daemon running', async () => {
// create "remote" repo
const { ipfsd } = await makeRepository({ start: true })
Expand Down

0 comments on commit e6a916d

Please sign in to comment.