Skip to content

Commit

Permalink
quic
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Jan 15, 2024
1 parent bc8d00c commit 28254df
Show file tree
Hide file tree
Showing 21 changed files with 1,250 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ junit.xml

# Jupyter files
.ipynb_checkpoints/
Untitled*.ipynb
Untitled*.ipynb
111 changes: 97 additions & 14 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"ext/kv",
"ext/net",
"ext/node",
"ext/quic",
"ext/url",
"ext/web",
"ext/webgpu",
Expand Down Expand Up @@ -69,6 +70,7 @@ deno_io = { version = "0.42.0", path = "./ext/io" }
deno_net = { version = "0.124.0", path = "./ext/net" }
deno_node = { version = "0.69.0", path = "./ext/node" }
deno_kv = { version = "0.40.0", path = "./ext/kv" }
deno_quic = { version = "0.1.0", path = "./ext/quic" }
deno_tls = { version = "0.119.0", path = "./ext/tls" }
deno_url = { version = "0.132.0", path = "./ext/url" }
deno_web = { version = "0.163.0", path = "./ext/web" }
Expand Down Expand Up @@ -166,6 +168,7 @@ elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh"
p224 = { version = "0.13.0", features = ["ecdh"] }
p256 = { version = "0.13.2", features = ["ecdh"] }
p384 = { version = "0.13.0", features = ["ecdh"] }
quinn = "=0.10.2"

# crypto
rsa = { version = "0.9.3", default-features = false, features = ["std", "pem", "hazmat"] } # hazmat needed for PrehashSigner in ext/node
Expand Down Expand Up @@ -250,6 +253,8 @@ opt-level = 3
opt-level = 3
[profile.bench.package.deno_net]
opt-level = 3
[profile.bench.package.deno_quic]
opt-level = 3
[profile.bench.package.deno_crypto]
opt-level = 3
[profile.bench.package.deno_node]
Expand Down Expand Up @@ -306,6 +311,8 @@ opt-level = 3
opt-level = 3
[profile.release.package.deno_net]
opt-level = 3
[profile.release.package.deno_quic]
opt-level = 3
[profile.release.package.deno_web]
opt-level = 3
[profile.release.package.deno_crypto]
Expand Down
1 change: 1 addition & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ mod ts {
deno_broadcast_channel::get_declaration(),
);
op_crate_libs.insert("deno.net", deno_net::get_declaration());
op_crate_libs.insert("deno.quic", deno_quic::get_declaration());

// ensure we invalidate the build properly.
for (_, path) in op_crate_libs.iter() {
Expand Down
5 changes: 5 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ pub(crate) static UNSTABLE_GRANULAR_FLAGS: &[(
"Enable unstable Web Worker APIs",
11,
),
(
deno_runtime::deno_quic::UNSTABLE_FEATURE_NAME,
"Enable unstable QUIC API",
12,
),
];

pub(crate) fn unstable_exit_cb(_feature: &str, api_name: &str) {
Expand Down
92 changes: 92 additions & 0 deletions cli/tests/unit/quic_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { assertEquals } from "./test_util.ts";

const cert = Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt");
const key = Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key");
const caCerts = [Deno.readTextFileSync("cli/tests/testdata/tls/RootCA.pem")];

async function pair(): Promise<[Deno.QuicConn, Deno.QuicConn]> {
const listener = await Deno.listenQuic({
hostname: "localhost",
port: 0,
cert,
key,
alpnProtocols: ["deno-test"],
});

const [connA, connB] = await Promise.all([
listener.accept(),
Deno.connectQuic({
hostname: "localhost",
port: listener.addr.port,
caCerts,
alpnProtocols: ["deno-test"],
}),
]);

return [connA, connB];
}

Deno.test("bidirectional stream", async () => {
const [server, client] = await pair();

const encoded = (new TextEncoder()).encode("hi!");

{
const bi = await server.createBidirectionalStream({ sendOrder: 42 });
assertEquals(bi.writable.sendOrder, 42);
bi.writable.sendOrder = 0;
assertEquals(bi.writable.sendOrder, 0);
await bi.writable.getWriter().write(encoded);
}

{
const { value: bi } = await client.incomingBidirectionalStreams.getReader()
.read();
const { value: data } = await bi!.readable.getReader().read();
assertEquals(data, encoded);
}

server.close({ closeCode: 0, reason: "" });
client.close({ closeCode: 0, reason: "" });
});

Deno.test("unidirectional stream", async () => {
const [server, client] = await pair();

const encoded = (new TextEncoder()).encode("hi!");

{
const uni = await server.createUnidirectionalStream({ sendOrder: 42 });
assertEquals(uni.sendOrder, 42);
uni.sendOrder = 0;
assertEquals(uni.sendOrder, 0);
await uni.getWriter().write(encoded);
}

{
const { value: uni } = await client.incomingUnidirectionalStreams
.getReader()
.read();
const { value: data } = await uni!.getReader().read();
assertEquals(data, encoded);
}

server.close({ closeCode: 0, reason: "" });
client.close({ closeCode: 0, reason: "" });
});

Deno.test("datagrams", async () => {
const [server, client] = await pair();

const encoded = (new TextEncoder()).encode("hi!");

await server.datagrams.writable.getWriter().write(encoded);

const { value: data } = await client.datagrams.readable.getReader().read();
assertEquals(data, encoded);

server.close({ closeCode: 0, reason: "" });
client.close({ closeCode: 0, reason: "" });
});
Loading

0 comments on commit 28254df

Please sign in to comment.