-
Notifications
You must be signed in to change notification settings - Fork 450
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
Improve libp2p config #576
Comments
https://github.com/libp2p/go-libp2p/blob/v0.5.2/libp2p.go#L33-L55 We might consider a similar approach |
We should also consider #202 (listen, announce and noAnnounce addresses here) |
Here are my thoughts on moving js-libp2p configuration to a functional configuration model. I think this would allow us to make libp2p more extensible and improve the UX around configuration. The ProblemCurrently js-libp2p is diffult to configure, esecially for new users. Due to its modularity there are a variety of options to configure and configuring things improperly can result in a node that doesn't do what is needed. Requirements
ConsiderationsThis propsal will require internal updates to libp2p to ensure its API supports making it easily extendable. There are likely some internal order of operations issues that will need to be resolved as part of this work, as we'll need to ensure all internals like the upgrader and registrar are created prior to calling configuration functions. The Proposal: functional configurationThis proposal aims to migrate
The API
The first param is an optional Exporting Configurationsjs-libp2p will export various configuration functions, and this set will likely grow over time. Functions will exist in the Example ConfigurationsNodejs Nodejs Base Browser Browser Base Pubsub Module Exported ConfigurationsModules like the DHT, which require more advanced configuration and wiring into libp2p should export configuration functions allow users to more easily add it to their nodes. It is ideal for modules with more complex configuration to export at least 2 functions, a default and an advanced configuration. For the DHT this might look like The default With the DHT we also really want to move this under the Peer and Content Routing components of libp2p, as well as moving RandomWalk into the PeerDiscovery system. This change would enable the DHT to handle the configuration itself, removing a lot of the complexity out of libp2p core. This allows libp2p to focus on being easily extendable. Actionable ErrorsWhen users are getting started, they should be provided with errors that are as actionable as possible. For example, if a user installs libp2p,
const libp2p = require('libp2p')
const { browser } = require('libp2p/src/configs')
(async () => {
// `Libp2p.create` will throw an actionable error: "Error: you are missing modules. You can fix this by running: npm install --save-prod libp2p-websockets libp2p-webrtc-star libp2p-mplex libp2p-secio libp2p-gossipsub"
const libp2p = await Libp2p.create(browser)
await libp2p.start()
})() Running the above code would throw an error with a very specific message on all the modules that need to be installed. The user should be able to run the provided |
Not sure how useful, but some related notes:
|
+1 on @jacobheun comment gonna leave this here for a easier reference #578 (comment) Its about having unified entry points for configs that automatically adjust to env. Plus when implementing this don't forget about fringe envs like electron, react-native, etc. |
@jacobheun this looks the type of config that we really need! 🚀 Just a few pieces missing in my head: What type of configuration we offer in the event of What is your plan on configurations out of scope of subsystems? We would do the How would we do the |
IMO, we shouldn't have defaults that try to satisfy multiple environments. This is really where actionable error messages should kick in, to guide the user. As @hugomrdias mentions in #578 (comment), we can use browser build targeting via the
Not sure I follow what you mean. Is this in regards to configuring systems that aren't included in the base? If so, there are two options as I see it:
I think in most instances users will use the 1st option when customizing, but users that need very fine control could use option 2.
Configuring this should be easy once we add support for this, as it will just involve setting the listen/announce/noAnnounce addresses on the pertinent system (PeerStore/TransportManager/etc). For defaults, we would really only set default listening addresses and likely when we setup each transport. I imagine we will also include sample functions for joining the public network (stardust/webrtc-star/etc) for both browser and nodejs, which would include announce addresses. |
I have a related inquiry that might help in this thread. In a week or so I’m going to want to use libp2p to get me a connection between two peers. I need to write some JS code that starts a peer and returns me something I can put in another peer in order to get a connection between them. I need code that will work in the browser and in Node.js and allow peers in each environment to connect to each other. What is the smallest amount of code I can write to do that? Back in June 2018 I found the configuration process so daunting that I wrote https://github.com/mikeal/libp2p-simple . With all the refactors that have happened this is probably much easier now, or is it? |
Just registering my view that the current libp2p config is full of gotchas. For example, I can't use This looks consistent and intuitive (IMO, once it was clear that libp2p: {
// other config here...
config: {
peerDiscovery: {
[WebRTCStar.tag]: {
enabled: true
}
},
transport: {
[WebRTCStar.tag]: {
wrtc
}
}
}
} but it explodes with:
because This works but looks weird: libp2p: {
// other config here...
config: {
peerDiscovery: {
[WebRTCStar.tag]: {
enabled: true
}
},
transport: {
WebRTCStar: {
wrtc
}
}
}
} It'd be great if this stuff could be consistent in any future version. Just making the config keys case-insensitive would do it. |
We should also takes this into account for this endeavour: XPosting @jacobheun comment on #798 (comment)
|
Discussion on pre configuration, builds and repo structure relevant for this: libp2p/js-libp2p-relay-server#2 (comment) |
Continuing the conversation in two separate issues: |
Type: Enhancement
Severity: N/A
Description:
The developer experience of the current libp2p config is one of the pain points for libp2p users, particularly new users. Moreover, there are a few inconsistencies in the config structure and the distance between the modules setup and the configuration for those modules causes some confusion among libp2p users.
Here follows a few ideas already discussed around this topic:
User friendly libp2p configs
Known issues
The text was updated successfully, but these errors were encountered: