mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
Add Experimental QUIC support (#4577)
## Issue Addressed #4402 ## Proposed Changes This PR adds QUIC support to Lighthouse. As this is not officially spec'd this will only work between lighthouse <-> lighthouse connections. We attempt a QUIC connection (if the node advertises it) and if it fails we fallback to TCP. This should be a backwards compatible modification. We want to test this functionality on live networks to observe any improvements in bandwidth/latency. NOTE: This also removes the websockets transport as I believe no one is really using it. It should be mentioned in our release however. Co-authored-by: João Oliveira <hello@jxs.pt>
This commit is contained in:
@@ -58,18 +58,24 @@ pub struct Config {
|
||||
/// that no discovery address has been set in the CLI args.
|
||||
pub enr_address: (Option<Ipv4Addr>, Option<Ipv6Addr>),
|
||||
|
||||
/// The udp4 port to broadcast to peers in order to reach back for discovery.
|
||||
/// The udp ipv4 port to broadcast to peers in order to reach back for discovery.
|
||||
pub enr_udp4_port: Option<u16>,
|
||||
|
||||
/// The tcp4 port to broadcast to peers in order to reach back for libp2p services.
|
||||
/// The quic ipv4 port to broadcast to peers in order to reach back for libp2p services.
|
||||
pub enr_quic4_port: Option<u16>,
|
||||
|
||||
/// The tcp ipv4 port to broadcast to peers in order to reach back for libp2p services.
|
||||
pub enr_tcp4_port: Option<u16>,
|
||||
|
||||
/// The udp6 port to broadcast to peers in order to reach back for discovery.
|
||||
/// The udp ipv6 port to broadcast to peers in order to reach back for discovery.
|
||||
pub enr_udp6_port: Option<u16>,
|
||||
|
||||
/// The tcp6 port to broadcast to peers in order to reach back for libp2p services.
|
||||
/// The tcp ipv6 port to broadcast to peers in order to reach back for libp2p services.
|
||||
pub enr_tcp6_port: Option<u16>,
|
||||
|
||||
/// The quic ipv6 port to broadcast to peers in order to reach back for libp2p services.
|
||||
pub enr_quic6_port: Option<u16>,
|
||||
|
||||
/// Target number of connected peers.
|
||||
pub target_peers: usize,
|
||||
|
||||
@@ -102,6 +108,9 @@ pub struct Config {
|
||||
/// Disables the discovery protocol from starting.
|
||||
pub disable_discovery: bool,
|
||||
|
||||
/// Disables quic support.
|
||||
pub disable_quic_support: bool,
|
||||
|
||||
/// Attempt to construct external port mappings with UPnP.
|
||||
pub upnp_enabled: bool,
|
||||
|
||||
@@ -149,57 +158,76 @@ impl Config {
|
||||
/// Sets the listening address to use an ipv4 address. The discv5 ip_mode and table filter are
|
||||
/// adjusted accordingly to ensure addresses that are present in the enr are globally
|
||||
/// reachable.
|
||||
pub fn set_ipv4_listening_address(&mut self, addr: Ipv4Addr, tcp_port: u16, udp_port: u16) {
|
||||
pub fn set_ipv4_listening_address(
|
||||
&mut self,
|
||||
addr: Ipv4Addr,
|
||||
tcp_port: u16,
|
||||
disc_port: u16,
|
||||
quic_port: u16,
|
||||
) {
|
||||
self.listen_addresses = ListenAddress::V4(ListenAddr {
|
||||
addr,
|
||||
udp_port,
|
||||
disc_port,
|
||||
quic_port,
|
||||
tcp_port,
|
||||
});
|
||||
self.discv5_config.listen_config = discv5::ListenConfig::from_ip(addr.into(), udp_port);
|
||||
self.discv5_config.listen_config = discv5::ListenConfig::from_ip(addr.into(), disc_port);
|
||||
self.discv5_config.table_filter = |enr| enr.ip4().as_ref().map_or(false, is_global_ipv4)
|
||||
}
|
||||
|
||||
/// Sets the listening address to use an ipv6 address. The discv5 ip_mode and table filter is
|
||||
/// adjusted accordingly to ensure addresses that are present in the enr are globally
|
||||
/// reachable.
|
||||
pub fn set_ipv6_listening_address(&mut self, addr: Ipv6Addr, tcp_port: u16, udp_port: u16) {
|
||||
pub fn set_ipv6_listening_address(
|
||||
&mut self,
|
||||
addr: Ipv6Addr,
|
||||
tcp_port: u16,
|
||||
disc_port: u16,
|
||||
quic_port: u16,
|
||||
) {
|
||||
self.listen_addresses = ListenAddress::V6(ListenAddr {
|
||||
addr,
|
||||
udp_port,
|
||||
disc_port,
|
||||
quic_port,
|
||||
tcp_port,
|
||||
});
|
||||
|
||||
self.discv5_config.listen_config = discv5::ListenConfig::from_ip(addr.into(), udp_port);
|
||||
self.discv5_config.listen_config = discv5::ListenConfig::from_ip(addr.into(), disc_port);
|
||||
self.discv5_config.table_filter = |enr| enr.ip6().as_ref().map_or(false, is_global_ipv6)
|
||||
}
|
||||
|
||||
/// Sets the listening address to use both an ipv4 and ipv6 address. The discv5 ip_mode and
|
||||
/// table filter is adjusted accordingly to ensure addresses that are present in the enr are
|
||||
/// globally reachable.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn set_ipv4_ipv6_listening_addresses(
|
||||
&mut self,
|
||||
v4_addr: Ipv4Addr,
|
||||
tcp4_port: u16,
|
||||
udp4_port: u16,
|
||||
disc4_port: u16,
|
||||
quic4_port: u16,
|
||||
v6_addr: Ipv6Addr,
|
||||
tcp6_port: u16,
|
||||
udp6_port: u16,
|
||||
disc6_port: u16,
|
||||
quic6_port: u16,
|
||||
) {
|
||||
self.listen_addresses = ListenAddress::DualStack(
|
||||
ListenAddr {
|
||||
addr: v4_addr,
|
||||
udp_port: udp4_port,
|
||||
disc_port: disc4_port,
|
||||
quic_port: quic4_port,
|
||||
tcp_port: tcp4_port,
|
||||
},
|
||||
ListenAddr {
|
||||
addr: v6_addr,
|
||||
udp_port: udp6_port,
|
||||
disc_port: disc6_port,
|
||||
quic_port: quic6_port,
|
||||
tcp_port: tcp6_port,
|
||||
},
|
||||
);
|
||||
self.discv5_config.listen_config = discv5::ListenConfig::default()
|
||||
.with_ipv4(v4_addr, udp4_port)
|
||||
.with_ipv6(v6_addr, udp6_port);
|
||||
.with_ipv4(v4_addr, disc4_port)
|
||||
.with_ipv6(v6_addr, disc6_port);
|
||||
|
||||
self.discv5_config.table_filter = |enr| match (&enr.ip4(), &enr.ip6()) {
|
||||
(None, None) => false,
|
||||
@@ -213,27 +241,32 @@ impl Config {
|
||||
match listen_addr {
|
||||
ListenAddress::V4(ListenAddr {
|
||||
addr,
|
||||
udp_port,
|
||||
disc_port,
|
||||
quic_port,
|
||||
tcp_port,
|
||||
}) => self.set_ipv4_listening_address(addr, tcp_port, udp_port),
|
||||
}) => self.set_ipv4_listening_address(addr, tcp_port, disc_port, quic_port),
|
||||
ListenAddress::V6(ListenAddr {
|
||||
addr,
|
||||
udp_port,
|
||||
disc_port,
|
||||
quic_port,
|
||||
tcp_port,
|
||||
}) => self.set_ipv6_listening_address(addr, tcp_port, udp_port),
|
||||
}) => self.set_ipv6_listening_address(addr, tcp_port, disc_port, quic_port),
|
||||
ListenAddress::DualStack(
|
||||
ListenAddr {
|
||||
addr: ip4addr,
|
||||
udp_port: udp4_port,
|
||||
disc_port: disc4_port,
|
||||
quic_port: quic4_port,
|
||||
tcp_port: tcp4_port,
|
||||
},
|
||||
ListenAddr {
|
||||
addr: ip6addr,
|
||||
udp_port: udp6_port,
|
||||
disc_port: disc6_port,
|
||||
quic_port: quic6_port,
|
||||
tcp_port: tcp6_port,
|
||||
},
|
||||
) => self.set_ipv4_ipv6_listening_addresses(
|
||||
ip4addr, tcp4_port, udp4_port, ip6addr, tcp6_port, udp6_port,
|
||||
ip4addr, tcp4_port, disc4_port, quic4_port, ip6addr, tcp6_port, disc6_port,
|
||||
quic6_port,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -272,7 +305,8 @@ impl Default for Config {
|
||||
);
|
||||
let listen_addresses = ListenAddress::V4(ListenAddr {
|
||||
addr: Ipv4Addr::UNSPECIFIED,
|
||||
udp_port: 9000,
|
||||
disc_port: 9000,
|
||||
quic_port: 9001,
|
||||
tcp_port: 9000,
|
||||
});
|
||||
|
||||
@@ -305,10 +339,11 @@ impl Default for Config {
|
||||
network_dir,
|
||||
listen_addresses,
|
||||
enr_address: (None, None),
|
||||
|
||||
enr_udp4_port: None,
|
||||
enr_quic4_port: None,
|
||||
enr_tcp4_port: None,
|
||||
enr_udp6_port: None,
|
||||
enr_quic6_port: None,
|
||||
enr_tcp6_port: None,
|
||||
target_peers: 50,
|
||||
gs_config,
|
||||
@@ -320,6 +355,7 @@ impl Default for Config {
|
||||
disable_peer_scoring: false,
|
||||
client_version: lighthouse_version::version_with_platform(),
|
||||
disable_discovery: false,
|
||||
disable_quic_support: false,
|
||||
upnp_enabled: true,
|
||||
network_load: 3,
|
||||
private: false,
|
||||
|
||||
Reference in New Issue
Block a user