Skip to content

Commit cf6128e

Browse files
committed
slight change
1 parent a6ec5b6 commit cf6128e

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

ext/net/03_quic.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,19 @@ class QuicIncoming {
175175
return op_quic_incoming_remote_addr_validated(this.#incoming);
176176
}
177177

178-
async accept() {
179-
const conn = await op_quic_incoming_accept(this.#incoming);
180-
return new QuicConn(conn, this.#endpoint);
181-
}
182-
183-
accept0rtt() {
184-
const conn = op_quic_incoming_accept_0rtt(this.#incoming);
185-
return new QuicConn(conn, this.#endpoint);
178+
accept(options) {
179+
const tOptions = options ? transportOptions(options) : null;
180+
if (options?.zeroRtt) {
181+
const conn = op_quic_incoming_accept_0rtt(
182+
this.#incoming,
183+
tOptions,
184+
);
185+
return new QuicConn(conn, this.#endpoint);
186+
}
187+
return PromisePrototypeThen(
188+
op_quic_incoming_accept(this.#incoming, tOptions),
189+
(conn) => new QuicConn(conn, this.#endpoint),
190+
);
186191
}
187192

188193
refuse() {
@@ -411,7 +416,7 @@ function connectQuic(options) {
411416
keyPair,
412417
);
413418

414-
if (options.zrtt) {
419+
if (options.zeroRtt) {
415420
const conn = op_quic_connecting_0rtt(connecting);
416421
if (conn) {
417422
return new QuicConn(conn, endpoint);

ext/net/lib.deno_net.d.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ declare namespace Deno {
536536
* the TLS handshake completes is vulnerable to replay attacks.
537537
* @default {false}
538538
*/
539-
zrtt?: ZRTT;
539+
zeroRtt?: ZRTT;
540540
}
541541

542542
/**
@@ -555,6 +555,21 @@ declare namespace Deno {
555555
alpnProtocols: string[];
556556
}
557557

558+
/**
559+
* **UNSTABLE**: New API, yet to be vetted.
560+
* @experimental
561+
* @category Network
562+
*/
563+
export interface QuicAcceptOptions<ZRTT extends boolean>
564+
extends QuicTransportOptions {
565+
/**
566+
* Convert this connection into 0.5-RTT at the cost of weakened security, as
567+
* 0.5-RTT data may be sent before TLS client authentication has occurred.
568+
* @default {false}
569+
*/
570+
zeroRtt?: ZRTT;
571+
}
572+
558573
/**
559574
* **UNSTABLE**: New API, yet to be vetted.
560575
* @experimental
@@ -673,13 +688,9 @@ declare namespace Deno {
673688
/**
674689
* Accept this incoming connection.
675690
*/
676-
accept(): Promise<QuicConn>;
677-
678-
/**
679-
* Convert this connection into 0.5-RTT at the cost of weakened security, as
680-
* 0.5-RTT data may be sent before TLS client authentication has occurred.
681-
*/
682-
accept0rtt(): QuicConn;
691+
accept<ZRTT extends boolean>(
692+
options?: QuicAcceptOptions<ZRTT>,
693+
): ZRTT extends true ? QuicConn : Promise<QuicConn>;
683694

684695
/**
685696
* Refuse this incoming connection.

ext/net/quic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct ListenArgs {
100100
alpn_protocols: Option<Vec<String>>,
101101
}
102102

103-
#[derive(Deserialize)]
103+
#[derive(Deserialize, Default, PartialEq)]
104104
#[serde(rename_all = "camelCase")]
105105
struct TransportConfig {
106106
keep_alive_interval: Option<u64>,
@@ -379,13 +379,13 @@ fn quic_incoming_accept(
379379
return Err(QuicError::BadResource("QuicIncoming"));
380380
};
381381
match transport_config {
382-
Some(transport_config) => {
382+
Some(transport_config) if transport_config != Default::default() => {
383383
let mut config =
384384
quinn::ServerConfig::with_crypto(incoming_resource.1.clone());
385385
apply_server_transport_config(&mut config, transport_config)?;
386386
Ok(incoming.accept_with(Arc::new(config))?)
387387
}
388-
None => Ok(incoming.accept()?),
388+
_ => Ok(incoming.accept()?),
389389
}
390390
}
391391

tests/unit/quic_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Deno.test("0rtt", async () => {
190190
}
191191
throw e;
192192
}
193-
const conn = incoming.accept0rtt();
193+
const conn = incoming.accept({ zeroRtt: true });
194194
conn.handshake.then(() => {
195195
conn.close();
196196
});
@@ -214,7 +214,7 @@ Deno.test("0rtt", async () => {
214214
port: sEndpoint.addr.port,
215215
caCerts,
216216
alpnProtocols: ["deno-test"],
217-
zrtt: true,
217+
zeroRtt: true,
218218
endpoint,
219219
});
220220

0 commit comments

Comments
 (0)