Skip to content

Commit

Permalink
Merge branch 'master' of github.com:libp2p/rust-libp2p into add-upnp-…
Browse files Browse the repository at this point in the history
…protocol
  • Loading branch information
jxs committed Jul 28, 2023
2 parents 92f5cea + fbfe083 commit 0b326bd
Show file tree
Hide file tree
Showing 19 changed files with 670 additions and 1,804 deletions.
37 changes: 35 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ libp2p-perf = { version = "0.2.0", path = "protocols/perf" }
libp2p-ping = { version = "0.43.0", path = "protocols/ping" }
libp2p-plaintext = { version = "0.40.0", path = "transports/plaintext" }
libp2p-pnet = { version = "0.23.0", path = "transports/pnet" }
libp2p-quic = { version = "0.8.0-alpha", path = "transports/quic" }
libp2p-quic = { version = "0.9.0-alpha", path = "transports/quic" }
libp2p-relay = { version = "0.16.1", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" }
libp2p-upnp = { version = "0.1.0", path = "protocols/upnp" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
- [HotShot](https://github.com/EspressoSystems/HotShot) - Decentralized sequencer in Rust developed by [Espresso Systems](https://www.espressosys.com/).
- [ipfs-embed](https://github.com/ipfs-rust/ipfs-embed) - A small embeddable ipfs implementation
used and maintained by [Actyx](https://www.actyx.com).
- [iroh](https://github.com/n0-computer/iroh) - Next-generation implementation of IPFS for Cloud & Mobile platforms.
- [beetle](https://github.com/n0-computer/beetle) - Next-generation implementation of IPFS for Cloud & Mobile platforms.
- [Lighthouse](https://github.com/sigp/lighthouse) - Ethereum consensus client in Rust.
- [Locutus](https://github.com/freenet/locutus) - Global, observable, decentralized key-value store.
- [OpenMina](https://github.com/openmina/openmina) - In-browser Mina Rust implementation.
- [rust-ipfs](https://github.com/rs-ipfs/rust-ipfs) - IPFS implementation in Rust.
- [Starcoin](https://github.com/starcoinorg/starcoin) - A smart contract blockchain network that scales by layering.
- [Subspace](https://github.com/subspace/subspace) - Subspace Network reference implementation
Expand Down
60 changes: 60 additions & 0 deletions docs/maintainer-handbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Maintainer handbook

This document describes what ever maintainer of the repository should know.

## GitHub settings

All settings around GitHub like branch protection settings are managed through https://github.com/libp2p/github-mgmt.
For example, adding, removing or renaming a required CI job will need to be preceded by a PR that changes the configuration.

To streamline things, it is good to _prepare_ such a PR together with the one that changes the CI workflows.
Take care to not merge the configuration change too early because it will block CI of all other PRs because GitHub now requires the new set of jobs (which will only be valid for the PR that actually changes the CI definition).

## Mergify

We utilize mergify as a merge-queue and overall automation bot on the repository.
The configuration file is [.github/mergify.yml](../.github/mergify.yml).

The main feature is the `send-it` label.
Once a PR fulfills all merge requirements (approvals, passing CI, etc), applying the `send-it` labels activates mergify's merge-queue.

- All branch protection rules, i.e. minimum number of reviews, green CI, etc are _implicit_ and thus do not need to be listed.
- Changing the mergify configuration file **always** requires the PR to be merged manually.
In other words, applying `send-it` to a PR that changes the mergify configuration has **no** effect.
This is a security feature of mergify to make sure changes to the automation are carefully reviewed.

In case of a trivial code change, maintainers may choose to apply the `trivial` label.
This will have mergify approve your PR, thus fulfilling all requirements to automatically queue a PR for merging.

## Dependencies

We version our `Cargo.lock` file for better visibility into which dependencies are required for a functional build.
Additionally, this makes us resilient to semver-incompatible updates of our dependencies (which would otherwise result in a build error).

As a consequence, we receive many dependency bump PRs from dependabot.
We have some automation in place to deal with those.

1. semver-compatible updates (i.e. patch bumps for 0.x dependencies and minor bumps for 1.x dependencies) are approved automatically by mergify.
2. all approved dependabot PRs are queued for merging automatically

The `send-it` label is not necessary (but also harmless) for dependabot PRs.

## Issues vs discussions

We typically use issues to handle bugs, feature-requests and track to-be-done work.
As a rule of thumb, we use issues for things that are fairly clear in nature.

Broader ideas or brainstorming happens in GitHub's discussions.
Those allow for more fine-granular threading which is likely to happen for ideas that are not yet fleshed out.

Unless specified otherwise, it is safe to assume that what is documented in issues represents the consensus of the maintainers.

## Labels

For the most part, the labels we use on issues are pretty self-explanatory.

- `decision-pending`: Documents that the issue is blocked.
Maintainers are encouraged to provide their input on issues marked with this label.
- `need/author-input`: Integrates with our [.github/workflows/stale.yml](../.github/workflows/stale.yml) workflow.
Any issue tagged with this label will be auto-closed due to inactivity after a certain time.

7 changes: 7 additions & 0 deletions transports/quic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.9.0-alpha - unreleased

- 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.
Expand Down
8 changes: 4 additions & 4 deletions transports/quic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libp2p-quic"
version = "0.8.0-alpha"
version = "0.9.0-alpha"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
rust-version = { workspace = true }
Expand All @@ -19,15 +19,15 @@ libp2p-tls = { workspace = true }
libp2p-identity = { workspace = true }
log = "0.4"
parking_lot = "0.12.0"
quinn-proto = { version = "0.10.1", default-features = false, features = ["tls-rustls"] }
quinn = { version = "0.10.1", default-features = false, features = ["tls-rustls", "futures-io"] }
rand = "0.8.5"
rustls = { version = "0.21.2", default-features = false }
thiserror = "1.0.44"
tokio = { version = "1.29.1", default-features = false, features = ["net", "rt", "time"], optional = true }

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

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
Expand Down
142 changes: 142 additions & 0 deletions transports/quic/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// 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 quinn::VarInt;
use std::{sync::Arc, time::Duration};

/// 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 send on a single stream.
pub max_stream_data: u32,

/// Max unacknowledged data in bytes that may be send 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.
pub support_draft_29: bool,

/// TLS client config for the inner [`quinn::ClientConfig`].
client_tls_config: Arc<rustls::ClientConfig>,
/// TLS server config for the inner [`quinn::ServerConfig`].
server_tls_config: Arc<rustls::ServerConfig>,
}

impl Config {
/// Creates a new configuration object with default values.
pub fn new(keypair: &libp2p_identity::Keypair) -> Self {
let client_tls_config = Arc::new(libp2p_tls::make_client_config(keypair, None).unwrap());
let server_tls_config = Arc::new(libp2p_tls::make_server_config(keypair).unwrap());
Self {
client_tls_config,
server_tls_config,
support_draft_29: false,
handshake_timeout: Duration::from_secs(5),
max_idle_timeout: 30 * 1000,
max_concurrent_stream_limit: 256,
keep_alive_interval: Duration::from_secs(15),
max_connection_data: 15_000_000,

// Ensure that one stream is not consuming the whole connection.
max_stream_data: 10_000_000,
}
}
}

/// 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,
}

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: _,
} = 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());
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 = quinn::EndpointConfig::default();
if !support_draft_29 {
endpoint_config.supported_versions(vec![1]);
}

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

0 comments on commit 0b326bd

Please sign in to comment.