diff --git a/ext/net/03_quic.js b/ext/net/03_quic.js index 85bb9d26a4a3a1..1914da1fb7e360 100644 --- a/ext/net/03_quic.js +++ b/ext/net/03_quic.js @@ -175,14 +175,19 @@ class QuicIncoming { return op_quic_incoming_remote_addr_validated(this.#incoming); } - async accept() { - const conn = await op_quic_incoming_accept(this.#incoming); - return new QuicConn(conn, this.#endpoint); - } - - accept0rtt() { - const conn = op_quic_incoming_accept_0rtt(this.#incoming); - return new QuicConn(conn, this.#endpoint); + accept(options) { + const tOptions = options ? transportOptions(options) : null; + if (options?.zeroRtt) { + const conn = op_quic_incoming_accept_0rtt( + this.#incoming, + tOptions, + ); + return new QuicConn(conn, this.#endpoint); + } + return PromisePrototypeThen( + op_quic_incoming_accept(this.#incoming, tOptions), + (conn) => new QuicConn(conn, this.#endpoint), + ); } refuse() { @@ -411,7 +416,7 @@ function connectQuic(options) { keyPair, ); - if (options.zrtt) { + if (options.zeroRtt) { const conn = op_quic_connecting_0rtt(connecting); if (conn) { return new QuicConn(conn, endpoint); diff --git a/ext/net/lib.deno_net.d.ts b/ext/net/lib.deno_net.d.ts index d72d56def2900d..4bc3e412d0a76c 100644 --- a/ext/net/lib.deno_net.d.ts +++ b/ext/net/lib.deno_net.d.ts @@ -536,7 +536,7 @@ declare namespace Deno { * the TLS handshake completes is vulnerable to replay attacks. * @default {false} */ - zrtt?: ZRTT; + zeroRtt?: ZRTT; } /** @@ -555,6 +555,16 @@ declare namespace Deno { alpnProtocols: string[]; } + export interface QuicAcceptOptions + extends QuicTransportOptions { + /** + * Convert this connection into 0.5-RTT at the cost of weakened security, as + * 0.5-RTT data may be sent before TLS client authentication has occurred. + * @default {false} + */ + zeroRtt?: ZRTT; + } + /** * **UNSTABLE**: New API, yet to be vetted. * @experimental @@ -673,13 +683,9 @@ declare namespace Deno { /** * Accept this incoming connection. */ - accept(): Promise; - - /** - * Convert this connection into 0.5-RTT at the cost of weakened security, as - * 0.5-RTT data may be sent before TLS client authentication has occurred. - */ - accept0rtt(): QuicConn; + accept( + options?: QuicAcceptOptions, + ): ZRTT extends true ? QuicConn : Promise; /** * Refuse this incoming connection. diff --git a/ext/net/quic.rs b/ext/net/quic.rs index 0a25d9417d49be..f17d9153857b20 100644 --- a/ext/net/quic.rs +++ b/ext/net/quic.rs @@ -100,7 +100,7 @@ struct ListenArgs { alpn_protocols: Option>, } -#[derive(Deserialize)] +#[derive(Deserialize, Default, PartialEq)] #[serde(rename_all = "camelCase")] struct TransportConfig { keep_alive_interval: Option, @@ -379,13 +379,13 @@ fn quic_incoming_accept( return Err(QuicError::BadResource("QuicIncoming")); }; match transport_config { - Some(transport_config) => { + Some(transport_config) if transport_config != Default::default() => { let mut config = quinn::ServerConfig::with_crypto(incoming_resource.1.clone()); apply_server_transport_config(&mut config, transport_config)?; Ok(incoming.accept_with(Arc::new(config))?) } - None => Ok(incoming.accept()?), + _ => Ok(incoming.accept()?), } } diff --git a/tests/unit/quic_test.ts b/tests/unit/quic_test.ts index 9d2004ce9009a2..dc3789ac738554 100644 --- a/tests/unit/quic_test.ts +++ b/tests/unit/quic_test.ts @@ -190,7 +190,7 @@ Deno.test("0rtt", async () => { } throw e; } - const conn = incoming.accept0rtt(); + const conn = incoming.accept({ zeroRtt: true }); conn.handshake.then(() => { conn.close(); }); @@ -214,7 +214,7 @@ Deno.test("0rtt", async () => { port: sEndpoint.addr.port, caCerts, alpnProtocols: ["deno-test"], - zrtt: true, + zeroRtt: true, endpoint, });