Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ Orion Public archive

Add check for already running daemon and custom ports for own daemon #92

Merged
merged 15 commits into from
Apr 29, 2018

Conversation

kernelwhisperer
Copy link
Contributor

@kernelwhisperer kernelwhisperer commented Apr 23, 2018

What changed?

This PR allows orion to connect to an existing IPFS Api (if available at http://localhost:5001)
https://dev.siderus.team/issues/95
https://github.com/Siderus/Orion/issues/89

@kernelwhisperer kernelwhisperer changed the title Add check for already running daemon and custom ports for own daemon WIP Add check for already running daemon and custom ports for own daemon Apr 23, 2018
@kernelwhisperer kernelwhisperer changed the title WIP Add check for already running daemon and custom ports for own daemon [WIP] Add check for already running daemon and custom ports for own daemon Apr 23, 2018
app/daemon.js Outdated
IPFS_PATH: getIPFSRepoPath()
}
}
const ipfsProcess = spawn(binaryPath, ['daemon'], options)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably move this into its own function to avoid repeating code.

app/daemon.js Outdated
const binaryPath = getPathIPFSBinary()
const ipfsRepoPath = `IPFS_PATH=${getIPFSRepoPath()}`

return exec(`${ipfsRepoPath} ${binaryPath} config Addresses.API /ip4/127.0.0.1/tcp/${ORION_API_PORT}`)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we change the default ports to the new ones only if the standard ones are taken?
What do you say?

@kernelwhisperer kernelwhisperer changed the title [WIP] Add check for already running daemon and custom ports for own daemon Add check for already running daemon and custom ports for own daemon Apr 26, 2018
@kernelwhisperer
Copy link
Contributor Author

@koalalorenzo this is ready for review 😄

app/daemon.js Outdated
binaryPath = path
}

export function executeIPFSCommand (command) {
Copy link
Member

Choose a reason for hiding this comment

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

Add some documentation to this method at least, as it will run cmd :D

app/daemon.js Outdated
@@ -102,23 +156,32 @@ export function ensuresIPFSInitialised () {
}

/**
* Returns the multiAddr usable to connect to the local dameon via API
* 5001 -> 5101
Copy link
Member

Choose a reason for hiding this comment

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

Add few lines about ensureAddressesConfigured, why this should be called? what does it do?

app/daemon.js Outdated
@@ -158,3 +219,22 @@ export function getSiderusPeers () {
return Promise.resolve(peers)
})
}

export function promiseRepoUnlocked (timeout = 30) {
Copy link
Member

Choose a reason for hiding this comment

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

add docs here as well :)

app/index.js Outdated
let alertMessage = 'An IPFS instance is already up!'
alertMessage += '\n\nWould you like Orion to connect to the available node, instead of using its own?'

if (apiVersion !== pjson.ipfsVersion) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice :) well done with this!

app/index.js Outdated

getAPIVersion()
.then(apiVersion => {
let customPorts = false
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we move this in another function with a promise returning true/false based on the answer of the user?

@koalalorenzo
Copy link
Member

I made quite a few changes as now it works also on macOS:
https://github.com/Siderus/Orion/pull/92/files/8cd37a292e563af9078376fd046c9cef17e7474e..54b7481aca57ed023cd06f2699753148f352bc49

What changed:

  • Uses global variables defined only in index.js
  • Removes some methods not used anymore (due to the global variables)
  • Ensures that the UI is pointing to the right API endpoint if another instance is running
  • Uses exec instead of promised-exec (no longer maintained)
  • Removes unnecessary dependencies

@0x6431346e tell me what you think!

app/index.js Outdated
})
.then(promiseRepoUnlocked) // ensures that the api are ready
.then(() => ensureDaemonConfigured())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ensureDaemonConfigured is already called on 136, do we need it again?

Copy link
Member

@koalalorenzo koalalorenzo Apr 29, 2018

Choose a reason for hiding this comment

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

One is for the daemon that starts, the other one is to ensure that the configuration is correct for the already running one, but for the configuration there is no live reload AFAIK.

app/daemon.js Outdated
@@ -126,7 +151,7 @@ export function ensuresIPFSInitialised () {
if (isIPFSInitialised()) return Promise.resolve()
console.log('Initialising IPFS repository...')
return new Promise((resolve, reject) => {
const ipfsProcess = spawnIPFSCommand('init')
const ipfsProcess = spawnIPFSCommand('init', `--api=${global.IPFS_MULTIADDR_API}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we pass --api=${global.IPFS_MULTIADDR_API} here and when starting the daemon? since we call ensureDaemonConfigured beforehand, shouldn't it be set?

app/index.js Outdated
global.IPFS_PROCESS = null
global.IPFS_CLIENT = null

// Sets default values for IPFS configurations
global.IPFS_BINARY_PATH = 'go-ipfs/ipfs'
Copy link
Contributor Author

@kernelwhisperer kernelwhisperer Apr 29, 2018

Choose a reason for hiding this comment

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

I'm not sure if this will work, we need to test the app after building it.
EDIT: seems to be ok

Copy link
Member

Choose a reason for hiding this comment

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

You might be right! I think we need to re-introduce app-root-dir

@kernelwhisperer
Copy link
Contributor Author

Looks ready to merge 👍

@koalalorenzo koalalorenzo merged commit 4b77dcf into master Apr 29, 2018
@koalalorenzo koalalorenzo deleted the feature/95-existing-ipfs-daemon branch May 5, 2018 11:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants