-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improving init (aka, how do I get a js-ipfs node instance!) #556
Comments
I have seen apis where it is done in this way: const ipfs = new IPFS(options)
ipfs.on('ready', () => {
// We are ready to do things
})
ipfs.on('error', (err) => {
console.error('failed to start', err)
}) These event listeners could also be attached through options for convenience similar to nodes http server const ipfs = new IPFS(options, () => {
console.log('WE ARE READY')
}) |
exactly @dignifiedquire, that goes along the lines of what I was thinking with Option 1 + ready event, it feels like something familiar (like a TCP listener or a HTTP server in Node.js). |
👍 for the events pattern. This would allow us to have more granular events to the state if needed, like I really like this direction! |
Oh nice @haadcode! I was not even thinking that we could do that too. I'm getting even more excited :D |
For the README, the rule of don't use too many inline comments because it messes up how easy it is to work on the code doesn't apply. It might be a good idea to have some of the comments you have above inlined in the code example; that way, people can look at the internal functions and understand what each step is doing. |
@diasdavid @dignifiedquire I would like to work on this in the next couple of weeks (unless someone else has the time earlier) and come up with a module that does what has been discussed above? I'm thinking we can wrap this into a module that can return either js-ipfs daemon or js-ipfs-api daemon. I already have |
@haadcode I'm not sure we want this in another module, I'd rather have ipfsd-ctl and js-ipfs natively supporting this same api, with a shared test suite maybe. And then you install the one you need. |
@haadcode you are welcome to take the lead, but it is better to converge efforts, currently we have:
Which, IMHO, should just be one module that offers the same API that js-ipfs has to create an instance. Also, IMHO I would converge them all to I'm not super sure if we have to have another module (your proposal of ipfs-daemon) that creates either a js-ipfs or js-ipfsd-ctl (go-ipfs) daemon. I would prefer (x100) that we grab the |
I'll play around with this and see how it could work nicely. |
|
(that's a good feature to have) Let's wrap that into a module then and go from there? |
Does IPFS Factory support non-disposable daemons now? Last time I checked it, it didn't. |
@haadcode tagging you, as you volunteer, to lead this effort and the revamp of ipfsd-ctl. Main goal: have a canonical way to spawn js-ipfs in process daemons, js-ipfs remote daemons (using js-ipfs-api to contact them), go-ipfs remote daemons (using js-ipfs-api to contact them) and provide with features to spawn several of ephemeral nodes, which are great for testing. Relevant threads:
|
Yeah, I can take this around beginning of December. If anyone in the meanwhile would like to work on this, please do! |
How is this a security risk bigger or smaller than js-ipfs-api + go-ipfs?
It is, agree on having manageable chunks. |
@diasdavid Ah! I understand now what you mean. This is obviously when running js-ipfs in Node.js :) Ignore that comment, then! |
I would even take it a step forward and call it |
The API proposed here is being prototyped in this repo: https://github.com/haadcode/ipfs-daemon. The idea is not to create a new module but to figure out the optimal API design and move the code from ipfs-daemon to their relevant existing ipfs modules. |
@dignifiedquire proposed in yesterday's call that we should have an explicit The proposed usage would be: const ipfs = new IPFS()
ipfs.on('ready', () => ...)
ipfs.start() Pros
Cons
|
The I agree on keeping a general 'boot this thing up, damn it! :D' function, nevertheless, we should include mechanisms to turn network services on an off, as described on the initial proposal too, with the following comment:
This will be super useful for a lot of cases (and testing!) |
is "how do I get a js-ipfs node instance" already possible with current js-ipfs ? |
@thisconnect the setup described at the very top works with the current version. |
@dignifiedquire thanks for the quick reply and also your answer here #771 (comment) About this issue, is API still open for discussion? i.e. IPFS(options)
.then(ipfs => console.log(ipfs.isOnline()))
.catch(err => console.error(err)) which would/should then work with async/await as well |
@thisconnect we do have a ongoing discussion about the exposed interface over here: #557 And worth mentioning, today we're exposing both callbacks and promises via js-ipfs/src/core/components/config.js Lines 53 to 55 in fe71013
Basically, what that means is that we're assuming you're using promises if you don't provide a callback to the function. So |
Ok, grabbing this issue again, lot's of discussion have happened with tons of valuable input. I'm going ahead and attempt to coalesce all of the ideas into one proposal in which I'll be implementing in the next couple of days. This will be the time where feedback is more crucial than ever, as I'll have to move forward with this pretty quickly. New Init APIInit'ing an IPFS instance will look like this:
Satelite modules ipfsd-ctl vs ipfs-daemon vs ipfs-factoryWe need a thing that lets us spawn nodes (js-ipfs and go-ipfs) easily, so that apps like orbit, our tests and benchmarks can switch between different combinations (js-ipfs, js-ipfs daemon + js-ipfs-api, go-ipfs + js-ipfs-api) without too much configuration. This endeavor doesn't have to be part of "Improving Init", but it would be definitely useful to a lot of contributors, users and even for our testing. Currently, we have:
ipfsd-ctl is the one that has more adoption. |
All right, work happening here! #790 |
Was added in ipfs#2521 but not updated here.
There has been a lot of feedback when it comes to the API for creating an IPFS node instance, some feedback from myself included. It is true, the process is a bit cumbersome, instead of having something beautiful as
We have:
Yes, it is not nice, but why is it this way right now? Why can't it be
sync
, well for some reasons:init
needs to get the repo started if it doesn't exist, since IPFS Repo use pull-blob-store adapters and these are async (because a Repo can be a network storage), this call needs to be asyncload
is when we take a repo and load all the config values. This also can't be sync because we only store the Private Key on the config and the generation of the PublicKey needs to be async (Thanks WebCrypto! see more at: Awesome Async Crypto + Less magic to 'run in the browser' #485))goOnline
this is where we turn on bitswap, it means that we are ready to fetch and serve blocks from and to other nodes.This can be way more nicer, however, starting from documentation of this methods, examples and explaining what the functions are doing inside the readme.
Another thing to consider is making the IPFS instance an event emitter with a 'ready' event, so that
Option 1
can be achieved by loading everything as options and emitting aready
event.Other things to consider
goOnline
should be bitswap.on andbitswap.off
, as we will need soon to be able to enable and disable things like thedht
.I would love to hear everyone's thoughts on this, I might be missing something that might get us to a even nicer start process, looking forward for feedback :) Thank you!
The text was updated successfully, but these errors were encountered: