Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add experimental support for QUIC #11514

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b448b6d
Patch libp2p
kpp May 24, 2022
bb7abd9
Build QUIC transport
kpp May 24, 2022
450d260
Pass quic_port through cli args
kpp May 24, 2022
f052690
Build quic transport from cli args
kpp May 24, 2022
4d61feb
Review fixes: ipv6 :: addr
kpp May 26, 2022
5504f4c
Merge branch 'master' into kpp-quic
kpp Jul 12, 2022
f661801
Upgrade libp2p to 0.47.0
kpp Jul 12, 2022
0b56dc1
Merge branch 'master' into kpp-quic
kpp Jul 18, 2022
81bdbdf
upgrade libp2p to 0.50.0
melekes Nov 18, 2022
21cf90c
on_swarm_event and on_connection_handler_event
melekes Nov 21, 2022
8a227e4
replace `Swarm::new` with `Swarm::with_threadpool_executor`
melekes Nov 21, 2022
8a97a52
on_swarm_event and on_connection_handler_event part 2
melekes Nov 21, 2022
e9b731b
on_swarm_event and on_connection_handler_event part 3
melekes Nov 21, 2022
d27d73a
on_swarm_event and on_connection_handler_event part 4
melekes Nov 21, 2022
672cac2
update libp2p
melekes Nov 21, 2022
41ab633
Merge branch 'master' into anton/upgrade-libp2p-to-0.50.0
melekes Nov 28, 2022
2fa1b2b
libp2p 0.50.0
melekes Nov 28, 2022
b3c33b5
rename OutboundQueryCompleted to OutboundQueryProgressed
melekes Nov 28, 2022
20437d7
remove unused var
melekes Nov 28, 2022
dbb7bec
accumulate outbound_query_records until query is finished
melekes Nov 28, 2022
bc53171
Merge branch 'anton/upgrade-libp2p-to-0.50.0' into kpp-quic
kpp Nov 29, 2022
458c7aa
Use --experimental-quic flag for cli
kpp Nov 29, 2022
46c473e
Merge branch 'master' into kpp-quic
kpp Jan 31, 2023
1360b83
Review fixes
kpp Jan 31, 2023
fcc4b51
Update client/network/src/transport.rs
kpp Apr 25, 2023
62ff75e
Merge branch 'master' into kpp-quic
kpp Jun 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub struct NetworkParams {
#[arg(long, value_name = "PORT", conflicts_with_all = &[ "listen_addr" ])]
pub port: Option<u16>,

/// Enable experimental QUIC transport.
#[clap(long)]
pub experimental_quic: bool,

/// Always forbid connecting to private IPv4/IPv6 addresses (as specified in
/// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with
/// `--reserved-nodes` or `--bootnodes`. Enabled by default for chains marked as "live" in
Expand Down Expand Up @@ -236,6 +240,7 @@ impl NetworkParams {
yamux_window_size: None,
ipfs_server: self.ipfs_server,
sync_mode: self.sync.into(),
experimental_quic: self.experimental_quic,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ futures = "0.3.21"
futures-timer = "3.0.2"
ip_network = "0.4.1"
libp2p = { version = "0.51.3", features = ["dns", "identify", "kad", "macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux", "websocket", "request-response"] }
libp2p-quic = { version = "0.7.0-alpha.3", features = ["tokio"] }
linked_hash_set = "0.1.3"
log = "0.4.17"
lru = "0.10.0"
Expand Down
4 changes: 4 additions & 0 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ pub struct NetworkConfiguration {
/// a modification of the way the implementation works. Different nodes with different
/// configured values remain compatible with each other.
pub yamux_window_size: Option<u32>,
/// If true, enables a possibility to accept QUIC connections. Incoming connections
/// won't be accepted unless a QUIC `Multiaddr` is passed as part of `listen_addresses`.
pub experimental_quic: bool,
}

impl NetworkConfiguration {
Expand Down Expand Up @@ -658,6 +661,7 @@ impl NetworkConfiguration {
kademlia_disjoint_query_paths: false,
yamux_window_size: None,
ipfs_server: false,
experimental_quic: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ where
config_mem,
network_config.yamux_window_size,
yamux_maximum_buffer_size,
network_config.experimental_quic,
)
};

Expand Down
29 changes: 27 additions & 2 deletions client/network/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! Transport that serves as a common ground for all connections.

use either::Either;
use futures::future::Either as FutureEither;
use libp2p::{
core::{
muxing::StreamMuxerBox,
Expand All @@ -27,10 +28,19 @@ use libp2p::{
},
dns, identity, noise, tcp, websocket, PeerId, Transport, TransportExt,
};
use libp2p_quic::{self as quic, Config as QuicConfig, GenTransport as QuicTransport};
use std::{sync::Arc, time::Duration};

pub use libp2p::bandwidth::BandwidthSinks;

/// Builds the QUIC transport
fn build_quic_transport(keypair: &identity::Keypair) -> Boxed<(PeerId, quic::Connection)> {
let config = QuicConfig::new(&keypair);
let transport = QuicTransport::<quic::tokio::Provider>::new(config).boxed();

transport
}

/// Builds the transport that serves as a common ground for all connections.
///
/// If `memory_only` is true, then only communication within the same process are allowed. Only
Expand All @@ -51,6 +61,7 @@ pub fn build_transport(
memory_only: bool,
yamux_window_size: Option<u32>,
yamux_maximum_buffer_size: usize,
enable_quic: bool,
) -> (Boxed<(PeerId, StreamMuxerBox)>, Arc<BandwidthSinks>) {
// Build the base layer of the transport.
let transport = if !memory_only {
Expand Down Expand Up @@ -95,11 +106,25 @@ pub fn build_transport(
yamux_config
};

let transport = transport
let tcp_transport = transport
.upgrade(upgrade::Version::V1Lazy)
.authenticate(authentication_config)
.multiplex(multiplexing_config)
.timeout(Duration::from_secs(20))
.timeout(Duration::from_secs(20));

let quic_transport = if enable_quic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better if we return tcp_transport without an OptionalTransport when quic is disabled? I.e. why wrap tcp_transport in OrTransport if we know quic is None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's an experimental feature. Once it is stable there will be OrTransport without optional quic. And stabilization will require very little amount of changes.

Copy link
Contributor

@dmitry-markin dmitry-markin Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the either way is OK.

OptionalTransport::some(build_quic_transport(&keypair))
} else {
OptionalTransport::none()
};

let transport = tcp_transport.or_transport(quic_transport);

let transport = transport
.map(|either_output, _| match either_output {
FutureEither::Left((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
FutureEither::Right((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
})
.boxed();

transport.with_bandwidth_logging()
Expand Down