Skip to content

Commit

Permalink
fix: default to External node
Browse files Browse the repository at this point in the history
Embedded node with chrome.sockets is not ready yet.
Key blockers in js-ipfs need to be resolved first:
- /ipns/<fqdn>/ load fine
- sharded directories (e.g. wikipedia) load fine

We may also decide to keep External as default and just add a button
on Welcome screen that activates embedded note.
  • Loading branch information
lidel committed Apr 15, 2019
1 parent 295c3fc commit 72c34f4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions add-on/src/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
const isFQDN = require('is-fqdn')
const { hasChromeSocketsForTcp } = require('./runtime-checks')

// Detect Beta Channel on Brave via: chrome.runtime.id === 'hjoieblefckbooibpepigmacodalfndh'
// TODO: enable by default when key blockers are resolved
// - [ ] /ipns/<fqdn>/ load fine
// - [ ] sharded directories (e.g. wikipedia) load fine
const DEFAULT_TO_EMBEDDED_GATEWAY = false && hasChromeSocketsForTcp()

exports.optionDefaults = Object.freeze({
active: true, // global ON/OFF switch, overrides everything else
ipfsNodeType: buildDefaultIpfsNodeType(),
Expand All @@ -25,19 +31,19 @@ exports.optionDefaults = Object.freeze({

function buildCustomGatewayUrl () {
// TODO: make more robust (sync with buildDefaultIpfsNodeConfig)
const port = hasChromeSocketsForTcp() ? 9091 : 8080
const port = DEFAULT_TO_EMBEDDED_GATEWAY ? 9091 : 8080
return `http://127.0.0.1:${port}`
}

function buildIpfsApiUrl () {
// TODO: make more robust (sync with buildDefaultIpfsNodeConfig)
const port = hasChromeSocketsForTcp() ? 5003 : 5001
const port = DEFAULT_TO_EMBEDDED_GATEWAY ? 5003 : 5001
return `http://127.0.0.1:${port}`
}

function buildDefaultIpfsNodeType () {
// Right now Brave is the only vendor giving us access to chrome.sockets
return hasChromeSocketsForTcp() ? 'embedded:chromesockets' : 'external'
return DEFAULT_TO_EMBEDDED_GATEWAY ? 'embedded:chromesockets' : 'external'
}

function buildDefaultIpfsNodeConfig () {
Expand Down Expand Up @@ -134,8 +140,7 @@ exports.migrateOptions = async (storage) => {
// Upgrade js-ipfs to js-ipfs + chrome.sockets
const { ipfsNodeType } = await storage.get('ipfsNodeType')
if (ipfsNodeType === 'embedded' && hasChromeSocketsForTcp()) {
console.log(`[ipfs-companion] migrating ipfsNodeType to 'embedded:chromesockets'`)
// Overwrite old config
console.log(`[ipfs-companion] migrating ipfsNodeType: ${ipfsNodeType} → embedded:chromesockets`)
await storage.set({
ipfsNodeType: 'embedded:chromesockets',
ipfsNodeConfig: buildDefaultIpfsNodeConfig()
Expand Down

0 comments on commit 72c34f4

Please sign in to comment.