-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quic): basic endpoint & connection
- Loading branch information
1 parent
07124ee
commit c4e9db5
Showing
11 changed files
with
2,492 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[package] | ||
name = "compio-quic" | ||
version = "0.1.0" | ||
description = "QUIC for compio" | ||
categories = ["asynchronous", "network-programming"] | ||
keywords = ["async", "net", "quic"] | ||
edition = { workspace = true } | ||
authors = { workspace = true } | ||
readme = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[dependencies] | ||
# Workspace dependencies | ||
compio-buf = { workspace = true, features = ["bytes"] } | ||
compio-log = { workspace = true } | ||
compio-net = { workspace = true } | ||
compio-runtime = { workspace = true, features = ["time"] } | ||
|
||
quinn-proto = "0.11.3" | ||
rustls = { workspace = true } | ||
rustls-platform-verifier = { version = "0.3.3", optional = true } | ||
rustls-native-certs = { version = "0.7.1", optional = true } | ||
webpki-roots = { version = "0.26.3", optional = true } | ||
|
||
# Utils | ||
event-listener = "5.3.1" | ||
flume = { workspace = true } | ||
futures-util = { workspace = true } | ||
thiserror = "1.0.63" | ||
|
||
# Windows specific dependencies | ||
[target.'cfg(windows)'.dependencies] | ||
windows-sys = { workspace = true, features = ["Win32_Networking_WinSock"] } | ||
|
||
# Linux specific dependencies | ||
[target.'cfg(target_os = "linux")'.dependencies] | ||
|
||
[target.'cfg(unix)'.dependencies] | ||
libc = { workspace = true } | ||
|
||
[dev-dependencies] | ||
compio-driver = { workspace = true } | ||
compio-macros = { workspace = true } | ||
rcgen = "0.13.1" | ||
socket2 = { workspace = true, features = ["all"] } | ||
tracing-subscriber = "0.3.18" | ||
|
||
[features] | ||
default = ["webpki-roots"] | ||
platform-verifier = ["dep:rustls-platform-verifier"] | ||
native-certs = ["dep:rustls-native-certs"] | ||
webpki-roots = ["dep:webpki-roots"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::net::{IpAddr, Ipv6Addr, SocketAddr}; | ||
|
||
use compio_quic::Endpoint; | ||
use tracing_subscriber::filter::LevelFilter; | ||
|
||
#[compio_macros::main] | ||
async fn main() { | ||
tracing_subscriber::fmt() | ||
.with_max_level(LevelFilter::TRACE) | ||
.init(); | ||
|
||
let endpoint = Endpoint::client() | ||
.with_no_server_verification() | ||
.with_alpn_protocols(&["hq-29"]) | ||
.with_key_log() | ||
.bind("[::1]:0") | ||
.await | ||
.unwrap(); | ||
|
||
{ | ||
let conn = endpoint | ||
.connect( | ||
SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 4433), | ||
"localhost", | ||
None, | ||
) | ||
.unwrap() | ||
.await | ||
.unwrap(); | ||
conn.close(1u32.into(), "bye"); | ||
conn.closed().await; | ||
} | ||
endpoint.close(0u32.into(), "").await.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use compio_quic::Endpoint; | ||
use tracing_subscriber::filter::LevelFilter; | ||
|
||
#[compio_macros::main] | ||
async fn main() { | ||
tracing_subscriber::fmt() | ||
.with_max_level(LevelFilter::TRACE) | ||
.init(); | ||
|
||
let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap(); | ||
let cert_chain = vec![cert.cert.into()]; | ||
let key_der = cert.key_pair.serialize_der().try_into().unwrap(); | ||
|
||
let endpoint = Endpoint::server() | ||
.with_single_cert(cert_chain, key_der) | ||
.unwrap() | ||
.with_alpn_protocols(&["hq-29"]) | ||
.with_key_log() | ||
.bind("[::1]:4433") | ||
.await | ||
.unwrap(); | ||
|
||
if let Some(incoming) = endpoint.wait_incoming().await { | ||
let conn = incoming.await.unwrap(); | ||
conn.closed().await; | ||
} | ||
|
||
endpoint.close(0u32.into(), "").await.unwrap(); | ||
} |
Oops, something went wrong.