Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ members = [
"crates/apollo_proc_macros_tests",
"crates/apollo_propeller",
"crates/apollo_protobuf",
"crates/apollo_quic_datagrams",
"crates/apollo_reverts",
"crates/apollo_rpc",
"crates/apollo_rpc_execution",
Expand Down
118 changes: 118 additions & 0 deletions crates/apollo_quic_datagrams/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
## 0.13.0

- Remove `async-std` support.
See [PR 5954](https://github.com/libp2p/rust-libp2p/pull/5954)

- Deprecate `Config::support_draft_29`.
See [PR 5786](https://github.com/libp2p/rust-libp2p/pull/5786).

## 0.12.0

<!-- Update to libp2p-core v0.43.0 -->

## 0.11.1

- Update `libp2p-tls` to version `0.5.0`, see [PR 5547]

[PR 5547]: https://github.com/libp2p/rust-libp2p/pull/5547

## 0.11.0

- Implement refactored `Transport`.
See [PR 4568](https://github.com/libp2p/rust-libp2p/pull/4568)

## 0.10.3

- Update `quinn` to 0.11 and `libp2p-tls` to 0.4.0.
See [PR 5316](https://github.com/libp2p/rust-libp2p/pull/5316)

- Allow configuring MTU discovery upper bound.
See [PR 5386](https://github.com/libp2p/rust-libp2p/pull/5386).

## 0.10.2

- Change `max_idle_timeout`to 10s.
See [PR 4965](https://github.com/libp2p/rust-libp2p/pull/4965).

## 0.10.1

- Allow disabling path MTU discovery.
See [PR 4823](https://github.com/libp2p/rust-libp2p/pull/4823).

## 0.10.0

- Improve hole-punch timing.
This should improve success rates for hole-punching QUIC connections.
See [PR 4549](https://github.com/libp2p/rust-libp2p/pull/4549).
- Remove deprecated `Error::EndpointDriverCrashed` variant.
See [PR 4738](https://github.com/libp2p/rust-libp2p/pull/4738).

## 0.9.3

- No longer report error when explicit closing of a QUIC endpoint succeeds.
See [PR 4621].

- Support QUIC stateless resets for supported `libp2p_identity::Keypair`s. See [PR 4554].

[PR 4621]: https://github.com/libp2p/rust-libp2p/pull/4621
[PR 4554]: https://github.com/libp2p/rust-libp2p/pull/4554

## 0.9.2

- Cut stable release.

## 0.9.2-alpha

- Add support for reusing an existing socket when dialing localhost address.
See [PR 4304].

[PR 4304]: https://github.com/libp2p/rust-libp2p/pull/4304

## 0.9.1-alpha

- Allow listening on ipv4 and ipv6 separately.
See [PR 4289].

[PR 4289]: https://github.com/libp2p/rust-libp2p/pull/4289

## 0.9.0-alpha

- Use `quinn` instead of `quinn-proto`.
See [PR 3454].

[PR 3454]: https://github.com/libp2p/rust-libp2p/pull/3454

## 0.8.0-alpha

- Raise MSRV to 1.65.
See [PR 3715].

- Add hole punching support by implementing `Transport::dial_as_listener`. See [PR 3964].

[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3964]: https://github.com/libp2p/rust-libp2p/pull/3964

## 0.7.0-alpha.3

- Depend `libp2p-tls` `v0.1.0`.

## 0.7.0-alpha.2

- Update to `libp2p-tls` `v0.1.0-alpha.2`.

- Update to `libp2p-core` `v0.39.0`.

- Add opt-in support for the `/quic` codepoint, interpreted as QUIC version draft-29.
See [PR 3151].

- Wake the transport's task when a new dialer or listener is added. See [3342].

- Discard correct waker upon accepting inbound stream. See [PR 3420].

[PR 3151]: https://github.com/libp2p/rust-libp2p/pull/3151
[PR 3342]: https://github.com/libp2p/rust-libp2p/pull/3342
[PR 3420]: https://github.com/libp2p/rust-libp2p/pull/3420

## 0.7.0-alpha

- Initial alpha release.
56 changes: 56 additions & 0 deletions crates/apollo_quic_datagrams/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[package]
name = "apollo_quic_datagrams"
version = "0.13.0"
authors = ["Parity Technologies <[email protected]>"]
edition.workspace = true
description = "TLS based QUIC transport implementation for libp2p"
repository = "https://github.com/libp2p/rust-libp2p"
license = "MIT"

[dependencies]
futures = { workspace = true }
futures-timer = "3.0.3"
if-watch = "3.2.0"
libp2p = { workspace = true, features = [
"dns",
"gossipsub",
"identify",
"kad",
"macros",
"noise",
"quic",
"serde",
"tcp",
"tls",
"tokio",
"yamux",
] }
quinn = { version = "0.11.6", default-features = false, features = ["futures-io", "rustls"] }
rand = { workspace = true }
rustls = { version = "0.23.9", default-features = false }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["net", "rt", "time"], optional = true }
tracing = { workspace = true }
socket2 = { workspace = true }
ring = "0.17"

[features]
tokio = ["dep:tokio", "if-watch/tokio", "quinn/runtime-tokio"]

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
all-features = true

[dev-dependencies]
libp2p = { workspace = true }
quickcheck = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[[test]]
name = "stream_compliance"
required-features = ["tokio"]

[lints]
workspace = true
178 changes: 178 additions & 0 deletions crates/apollo_quic_datagrams/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use std::sync::Arc;
use std::time::Duration;

use libp2p::tls;
use quinn::crypto::rustls::{QuicClientConfig, QuicServerConfig};
use quinn::{MtuDiscoveryConfig, VarInt};

/// Config for the transport.
#[derive(Clone)]
pub struct Config {
/// Timeout for the initial handshake when establishing a connection.
/// The actual timeout is the minimum of this and the [`Config::max_idle_timeout`].
pub handshake_timeout: Duration,
/// Maximum duration of inactivity in ms to accept before timing out the connection.
pub max_idle_timeout: u32,
/// Period of inactivity before sending a keep-alive packet.
/// Must be set lower than the idle_timeout of both
/// peers to be effective.
///
/// See [`quinn::TransportConfig::keep_alive_interval`] for more
/// info.
pub keep_alive_interval: Duration,
/// Maximum number of incoming bidirectional streams that may be open
/// concurrently by the remote peer.
pub max_concurrent_stream_limit: u32,

/// Max unacknowledged data in bytes that may be sent on a single stream.
pub max_stream_data: u32,

/// Max unacknowledged data in bytes that may be sent in total on all streams
/// of a connection.
pub max_connection_data: u32,

/// Support QUIC version draft-29 for dialing and listening.
///
/// Per default only QUIC Version 1 / [`libp2p_core::multiaddr::Protocol::QuicV1`]
/// is supported.
///
/// If support for draft-29 is enabled servers support draft-29 and version 1 on all
/// QUIC listening addresses.
/// As client the version is chosen based on the remote's address.
#[deprecated(note = "QUIC draft versions are no longer supported")]
pub support_draft_29: bool,

/// TLS client config for the inner [`quinn::ClientConfig`].
client_tls_config: Arc<QuicClientConfig>,
/// TLS server config for the inner [`quinn::ServerConfig`].
server_tls_config: Arc<QuicServerConfig>,
/// Libp2p identity of the node.
keypair: libp2p::identity::Keypair,

/// Parameters governing MTU discovery. See [`MtuDiscoveryConfig`] for details.
mtu_discovery_config: Option<MtuDiscoveryConfig>,
}

#[expect(deprecated)]
impl Config {
/// Creates a new configuration object with default values.
pub fn new(keypair: &libp2p::identity::Keypair) -> Self {
let client_tls_config = Arc::new(
QuicClientConfig::try_from(tls::make_client_config(keypair, None).unwrap()).unwrap(),
);
let server_tls_config = Arc::new(
QuicServerConfig::try_from(tls::make_server_config(keypair).unwrap()).unwrap(),
);
Self {
client_tls_config,
server_tls_config,
support_draft_29: false,
handshake_timeout: Duration::from_secs(5),
max_idle_timeout: 10 * 1000,
max_concurrent_stream_limit: 256,
keep_alive_interval: Duration::from_secs(5),
max_connection_data: 15_000_000,

// Ensure that one stream is not consuming the whole connection.
max_stream_data: 10_000_000,
keypair: keypair.clone(),
mtu_discovery_config: Some(Default::default()),
}
}

/// Set the upper bound to the max UDP payload size that MTU discovery will search for.
pub fn mtu_upper_bound(mut self, value: u16) -> Self {
self.mtu_discovery_config.get_or_insert_with(Default::default).upper_bound(value);
self
}

/// Disable MTU path discovery (it is enabled by default).
pub fn disable_path_mtu_discovery(mut self) -> Self {
self.mtu_discovery_config = None;
self
}
}

/// Represents the inner configuration for [`quinn`].
#[derive(Debug, Clone)]
pub(crate) struct QuinnConfig {
pub(crate) client_config: quinn::ClientConfig,
pub(crate) server_config: quinn::ServerConfig,
pub(crate) endpoint_config: quinn::EndpointConfig,
}

#[expect(deprecated)]
impl From<Config> for QuinnConfig {
fn from(config: Config) -> QuinnConfig {
let Config {
client_tls_config,
server_tls_config,
max_idle_timeout,
max_concurrent_stream_limit,
keep_alive_interval,
max_connection_data,
max_stream_data,
support_draft_29,
handshake_timeout: _,
keypair,
mtu_discovery_config,
} = config;
let mut transport = quinn::TransportConfig::default();
// Disable uni-directional streams.
transport.max_concurrent_uni_streams(0u32.into());
transport.max_concurrent_bidi_streams(max_concurrent_stream_limit.into());
// Disable datagrams.
transport.datagram_receive_buffer_size(None);
transport.keep_alive_interval(Some(keep_alive_interval));
transport.max_idle_timeout(Some(VarInt::from_u32(max_idle_timeout).into()));
transport.allow_spin(false);
transport.stream_receive_window(max_stream_data.into());
transport.receive_window(max_connection_data.into());
transport.mtu_discovery_config(mtu_discovery_config);
let transport = Arc::new(transport);

let mut server_config = quinn::ServerConfig::with_crypto(server_tls_config);
server_config.transport = Arc::clone(&transport);
// Disables connection migration.
// Long-term this should be enabled, however we then need to handle address change
// on connections in the `Connection`.
server_config.migration(false);

let mut client_config = quinn::ClientConfig::new(client_tls_config);
client_config.transport_config(transport);

let mut endpoint_config = keypair
.derive_secret(b"libp2p quic stateless reset key")
.map(|secret| {
let reset_key = Arc::new(ring::hmac::Key::new(ring::hmac::HMAC_SHA256, &secret));
quinn::EndpointConfig::new(reset_key)
})
.unwrap_or_default();

if !support_draft_29 {
endpoint_config.supported_versions(vec![1]);
}

QuinnConfig { client_config, server_config, endpoint_config }
}
}
Loading
Loading