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

feat: allows a custom IpfsApi constructor to be used #261

Merged
merged 5 commits into from
Aug 7, 2018

Conversation

alanshaw
Copy link
Member

We decided in #257 that it would be best to bundle ipfs, ipfs-api and go-ipfs-dep but allow the user to pass their own implementations for "advanced mode" usage aka. us and our tests.

This PR is step 1 and it allows the user to pass an IpfsApi constructor to Factory.create or f.spawn.

@ghost ghost assigned alanshaw May 24, 2018
@ghost ghost added the status/in-progress In progress label May 24, 2018

const node = new Daemon(options)

series([
(cb) => options.init
? node.init(cb)
? node.init(options.initOptions, cb)
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this was a bug where initOptions weren't being passed to the daemon when they were set at the factory level.

Copy link
Member

Choose a reason for hiding this comment

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

good catch

@@ -16,6 +16,7 @@ class FactoryClient {
options.host = 'localhost'
}

this.options = options
this.port = options.port
this.host = options.host
Copy link
Member

Choose a reason for hiding this comment

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

Since we are storing options in the factory instance, I think we should remove the following two lines (this.port and this.host). In addition, we should change L:28 to:

this.baseUrl = `${options.secure ? 'https://' : 'http://'}${options.host}:${options.port}`

This way, we would have a more similar factory with the factory-daemon and the factory-in-proc, which do not have port and host defined in their instances. What do you think?


const node = new Daemon(options)

series([
(cb) => options.init
? node.init(cb)
? node.init(options.initOptions, cb)
Copy link
Member

Choose a reason for hiding this comment

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

good catch

* @return {*}
*/
constructor (options) {
if (options && options.type === 'proc') {
throw new Error('This Factory does not know how to spawn in proc nodes')
}
options = Object.assign({}, { type: 'go' }, options)
this.options = options
this.type = options.type
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking if we should also remove this.type, as it is also duplicated.

@alanshaw
Copy link
Member Author

alanshaw commented Jun 1, 2018

@vasco-santos I moved this.host, this.port, this.type and this.exec (copied from options) into this.options for all the factories. So now they're all similar.

This is a breaking change if anyone was using these properties directly from the factory so I've labelled the commit as such.

@vasco-santos
Copy link
Member

thanks @alanshaw ! I will just wait for the CI Green PR to be merged, and I will merge this afterword.

@ghost ghost assigned vasco-santos Jun 1, 2018
@vasco-santos
Copy link
Member

I rebased this with Master and there is a test failing for windows.

I will create a new release for ipfsd-ctl for now and we find out the problem with this PR build later.

@alanshaw
Copy link
Member Author

Any news on this? I think the windows test failure is unrelated...

@vasco-santos vasco-santos force-pushed the feat/pass-your-own-ipfs-api branch 2 times, most recently from 88b0bc8 to 7ba3238 Compare June 19, 2018 17:39
@vasco-santos
Copy link
Member

Hey @alanshaw

I have tried to understand this error, but no luck so far. The error appears in the test added in this PR, but I believe it may not be related with the added code.

There are some reports online regarding the kill enosys but, as I don't have a windows machine, I cannot debug this locally. Can you give it a try?

BREAKING CHANGE: host, port, type and exec are no longer accessible directly from factory instances, use `options.type` etc. instead.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@alanshaw alanshaw force-pushed the feat/pass-your-own-ipfs-api branch from 7ba3238 to f17ee4b Compare August 6, 2018 21:43
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@alanshaw
Copy link
Member Author

alanshaw commented Aug 6, 2018

@vasco-santos the issue was that the test was relying on ipfsd-ctl to kill the process using SIGKILL after it didn't shutdown gracefully. This would have been fine except that windows doesn't support SIGKILL and fails with the kill ENOSYS we were seeing. I've created an issue for that here: #286

I've changed the PR to use a proper API client to stop the node using the /api/v0/shutdown route instead of relying on the graceless shutdown feature.

Hopefully this is good to merge now?

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @alanshaw

@vasco-santos vasco-santos merged commit dacde26 into master Aug 7, 2018
@ghost ghost removed the status/in-progress In progress label Aug 7, 2018
@vasco-santos vasco-santos deleted the feat/pass-your-own-ipfs-api branch August 7, 2018 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants