Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces a new builder concept to allow users more control in building a go-libp2p node. The builder package itself serves as an example of how to configure and connect all the go-libp2p parts into a host. However, there is nothing special about the builder package, and advanced users will make their own builder Config. It’s built around a small and simple DI library I wrote. The DI library has no dependencies, and could be implemented from scratch in a couple of hours. Refer to the godoc at https://pkg.go.dev/git.sr.ht/~marcopolo/di for more details.
In the future, we may split the builder package further to allow reuse of common components without depending on every component. For example, we may move the swarm+host constructor logic into a separate package from the transport constructor logic. That way a user could reuse the swarm+host constructors without depending on the transport constructors.
Today, users can still minimize their dependencies by creating their own Builder config. They may use the existing one as a template and prune the things they don’t need.
I’d like to get feedback from users on this feature before investing more time into it.
History
package builder was born out of frustration with Fx and the convoluted nature of building a Go libp2p host. Especially when one wants to step away from the default path.
Issues with the correct libp2p.New constructor and Fx:
Config.QUICReuse
as an example. The type of that field is[]fx.Option
. Literally any fx option can go in there.The builder package takes a different approach focuses on the following goals:
For reviewers
Commits are meaningful, so it may be helpful to review this commit by commit.
closes #3294 and probably #3251 as well.