-
Notifications
You must be signed in to change notification settings - Fork 772
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
refactor(network): use new libp2p SwarmBuilder #4695
Conversation
libp2p/rust-libp2p#4120 introduces a new `SwarmBuilder` simplifying the composition of transports and behaviours into a `Swarm`. This commit showcases the usage of the new `SwarmBuilder` in lighthouse.
|
let (swarm_builder, bandwidth) = | ||
libp2p::SwarmBuilder::with_existing_identity(local_keypair.clone()) | ||
.with_tokio() | ||
// Using `with_other_transport` in order to support mplex. In case mplex would not be needed, the below would be as simple as: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How hard would it be to support a custom encryption protocol in the builder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean a custom multiplexer? Possible. But I don't expect us to write a new multiplexer for TCP any time soon. Thus I would rather like to add such option once it is needed.
In this particular case, Ethereum is planning to move away from mplex. See ethereum/consensus-specs#3490
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean a custom multiplexer?
Yes.
But I don't expect us to write a new multiplexer for TCP any time soon. Thus I would rather like to add such option once it is needed.
But it would support these usecases and allow us to eventually deprecate the other upgrade path. I really do not want us to introduce more ways of doing things without deprecating old ones.
Awesome thanks! I guess we wait for the new builder to land right? |
Yes, this PR is just to validate that we are on the right pathway with the implementation :) |
With libp2p/rust-libp2p#4120 merged, this pull request is now updated. Note that the new |
let mut mplex_config = libp2p_mplex::MplexConfig::new(); | ||
mplex_config.set_max_buffer_size(256); | ||
mplex_config | ||
.set_max_buffer_behaviour(libp2p_mplex::MaxBufferBehaviour::Block); | ||
mplex_config | ||
}, | ||
|| { | ||
let mut yamux_config = libp2p::yamux::Config::default(); | ||
yamux_config | ||
.set_window_update_mode(libp2p::yamux::WindowUpdateMode::on_read()); | ||
yamux_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxinden Can you create issues for making these chainable?
|| { | ||
let mut mplex_config = libp2p_mplex::MplexConfig::new(); | ||
mplex_config.set_max_buffer_size(256); | ||
mplex_config | ||
.set_max_buffer_behaviour(libp2p_mplex::MaxBufferBehaviour::Block); | ||
mplex_config | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify this a lot by making a free-function that returns you the ready to use config, then you could just reference it.
// TODO: Websocket should be optional. | ||
.with_websocket( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought websocket was removed with the introduction of QUIC? I thought I saw something like that in @AgeManning's QUIC PR.
Proposed Changes
libp2p/rust-libp2p#4120 introduces a new
SwarmBuilder
simplifying the composition of transports and behaviours into aSwarm
.This commit showcases the usage of the new
SwarmBuilder
in lighthouse.Additional Info
Note that libp2p/rust-libp2p#4120 is not yet merged. Thus this pull request is just here to proof that libp2p/rust-libp2p#4120 works for lighthouse.
//CC @thomaseizinger