-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New builder #3386
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
Open
MarcoPolo
wants to merge
5
commits into
master
Choose a base branch
from
new-builder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New builder #3386
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1644eb7
to
a41185a
Compare
tagging @marten-seemann, as he was curious about these changes |
# Overview 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 build 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: - It's a bad combination of Options functions with a Config struct and Fx options. - The reason for that is that Fx, doesn't provide a good way to have a default value for some setting. For example, there's no way to provide a default resource manager that gets overwritten if a user provides their own resource manager. There are plenty of hacks to workaround this, but they inevitably introduce strange new concepts to the user (e.g. abusing Fx labels, groups, or weird constructors.) - It's hard to pull out one part if you only need that part. For example, if you want the logic around AutoNAT without pulling in any dependency on WebRTC, it's currently hard. - Fx Options type erase the thing they provide. Take `Config.QUICReuse` as an example. The type of that field is `[]fx.Option`. Literally any fx option can go in there. - Fx is a fairly large dependency. The builder package takes a different approach focuses on the following goals: - Ergonomic defaults. - Clear layout of required objects. - Let users to select only the services and components they need. - Let users get references to instantiated services. Don't hide everything in the basic host.
a41185a
to
99af443
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.