aws/s2n-quic

GitHub: aws/s2n-quic

AWS 维护的 IETF QUIC 协议 Rust 实现,提供高性能、易用的异步 API 和丰富的传输层配置能力。

Stars: 1360 | Forks: 177

# s2n-quic `s2n-quic` 是 [IETF QUIC 协议](https://quicwg.org/) 的 Rust 实现,具有以下特点: - 简单、易用的 API。请参阅仅用几次 API 调用构建的 s2n-quic echo server [示例](https://github.com/aws/s2n-quic/blob/main/examples/echo/src/bin/quic_echo_server.rs) - 通过使用 [provider](https://docs.rs/s2n-quic/latest/s2n_quic/provider/index.html) 进行高度配置,实现对功能的细粒度控制 - 广泛的自动化测试,包括模糊测试、集成测试、单元测试、快照测试、效率测试、性能基准测试、互操作性测试以及[更多内容](https://github.com/aws/s2n-quic/blob/main/docs/dev-guide/ci.md) - 集成了 [s2n-tls](https://github.com/aws/s2n-tls)(AWS 简单、小巧、快速且安全的 TLS 实现)以及 [rustls](https://crates.io/crates/rustls) - 对相关标准中的规范性语言有详尽的[合规性覆盖跟踪](https://github.com/aws/s2n-quic/blob/main/docs/dev-guide/ci.md#compliance) - 以及更多其他功能,包括支持 [CUBIC 拥塞控制](https://www.rfc-editor.org/rfc/rfc8312.html)、[数据包发送速率控制](https://www.rfc-editor.org/rfc/rfc9002.html#name-pacing)、支持 [Generic Segmentation Offload](https://lwn.net/Articles/188489/)、[Path MTU 发现](https://www.rfc-editor.org/rfc/rfc8899.html),以及脱离地址的独立[连接标识符](https://www.rfc-editor.org/rfc/rfc9000.html#name-connection-id) 请参阅 [API 文档](https://docs.rs/s2n-quic)、[示例](https://github.com/aws/s2n-quic/tree/main/examples) 和 [s2n-quic 指南](https://aws.github.io/s2n-quic/index.html) 以开始使用 `s2n-quic`。 [![Crates.io](https://img.shields.io/crates/v/s2n-quic.svg)][crates-url] [![docs.rs](https://img.shields.io/docsrs/s2n-quic.svg)][docs-url] [![Apache 2.0 Licensed](https://img.shields.io/badge/license-apache-blue.svg)][license-url] [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/99/993938d8ce5e902ccfb9d6747725c320d855dea3235ed9a304cedf0d94c9321f.svg)][actions-url] [![Dependencies](https://img.shields.io/librariesio/release/cargo/s2n-quic.svg)][dependencies-url] [![MSRV](https://img.shields.io/badge/MSRV-1.92.0-green)][msrv-url] ## 安装 `s2n-quic` 可在 `crates.io` 上获取,并可以通过以下方式添加到项目中: ``` [dependencies] s2n-quic = "1" ``` **注意**:在类 Unix 系统上,[`s2n-tls`](https://github.com/aws/s2n-tls) 将被用作默认的 TLS provider。 在 Linux 系统上,[`aws-lc-rs`](https://github.com/awslabs/aws-lc-rs) 将被用于加密操作。在这些系统上安装可能需要 C 编译器和 CMake。 ## 示例 以下实现了一个基本的 echo server 和 client。client 连接到 server 并将其 `stdin` 通过 stream 传输。server 监听新的 stream 并将其接收到的任何数据返回给 client。然后,client 会将所有的 stream 数据传输到 `stdout`。 ### Server ``` // src/bin/server.rs use s2n_quic::Server; use std::{error::Error, path::Path}; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = Server::builder() .with_tls((Path::new("cert.pem"), Path::new("key.pem")))? .with_io("127.0.0.1:4433")? .start()?; while let Some(mut connection) = server.accept().await { // spawn a new task for the connection tokio::spawn(async move { while let Ok(Some(mut stream)) = connection.accept_bidirectional_stream().await { // spawn a new task for the stream tokio::spawn(async move { // echo any data back to the stream while let Ok(Some(data)) = stream.receive().await { stream.send(data).await.expect("stream should be open"); } }); } }); } Ok(()) } ``` ### Client ``` // src/bin/client.rs use s2n_quic::{client::Connect, Client}; use std::{error::Error, path::Path, net::SocketAddr}; #[tokio::main] async fn main() -> Result<(), Box> { let client = Client::builder() .with_tls(Path::new("cert.pem"))? .with_io("0.0.0.0:0")? .start()?; let addr: SocketAddr = "127.0.0.1:4433".parse()?; let connect = Connect::new(addr).with_server_name("localhost"); let mut connection = client.connect(connect).await?; // ensure the connection doesn't time out with inactivity connection.keep_alive(true)?; // open a new stream and split the receiving and sending sides let stream = connection.open_bidirectional_stream().await?; let (mut receive_stream, mut send_stream) = stream.split(); // spawn a task that copies responses from the server to stdout tokio::spawn(async move { let mut stdout = tokio::io::stdout(); let _ = tokio::io::copy(&mut receive_stream, &mut stdout).await; }); // copy data from stdin and send it to the server let mut stdin = tokio::io::stdin(); tokio::io::copy(&mut stdin, &mut send_stream).await?; Ok(()) } ``` ## 最低支持的 Rust 版本 (MSRV) `s2n-quic` 将维持至少 6 个月的滚动 MSRV(最低支持的 Rust 版本)策略。当前的 s2n-quic 版本不保证能在早于 MSRV 的 Rust 版本上构建。 当前的 MSRV 为 [1.92.0][msrv-url]。 ## 支持的操作系统 `s2n-quic` 可以在 Linux、MacOS 和 Windows 上构建。`s2n-quic` 需要 Linux 内核版本 5.0 或更高版本。不支持早期的 Linux 内核版本,因为它们缺少 `s2n-quic` 所需的 Generic Segmentation Offload (GSO) 功能。 ## 安全问题通知 如果您在 s2n-quic 中发现潜在的安全问题,我们请求您通过我们的[漏洞报告页面](http://aws.amazon.com/security/vulnerability-reporting/)通知 AWS Security。请**不要**创建公开的 GitHub issue。 如果您打包或分发 s2n-quic,或者将 s2n-quic 作为大型多用户服务的一部分使用,您可能有资格获得未来 s2n-quic 版本的提前通知。请联系 s2n-pre-notification@amazon.com。 ## 许可证 该项目基于 [Apache-2.0 许可证][license-url] 授权。
标签:QUIC, Rust, TLS, 内核驱动, 可视化界面, 底层开发, 网络协议, 网络库, 网络流量审计, 通知系统, 防御工具