Skip to content

Commit

Permalink
feat(quic): basic endpoint & connection
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakuraMizu committed Aug 4, 2024
1 parent 07124ee commit c4e9db5
Show file tree
Hide file tree
Showing 11 changed files with 2,492 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"compio-tls",
"compio-log",
"compio-process",
"compio-quic",
]
resolver = "2"

Expand Down Expand Up @@ -49,6 +50,7 @@ nix = "0.29.0"
once_cell = "1.18.0"
os_pipe = "1.1.4"
paste = "1.0.14"
rustls = { version = "0.23.1", default-features = false }
slab = "0.4.9"
socket2 = "0.5.6"
tempfile = "3.8.1"
Expand Down
57 changes: 57 additions & 0 deletions compio-quic/Cargo.toml
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"]
34 changes: 34 additions & 0 deletions compio-quic/examples/client.rs
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();
}
29 changes: 29 additions & 0 deletions compio-quic/examples/server.rs
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();
}
Loading

0 comments on commit c4e9db5

Please sign in to comment.