Skip to content

Commit

Permalink
slight change
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Dec 21, 2024
1 parent a6ec5b6 commit c69a4d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
23 changes: 14 additions & 9 deletions ext/net/03_quic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions ext/net/lib.deno_net.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ declare namespace Deno {
* the TLS handshake completes is vulnerable to replay attacks.
* @default {false}
*/
zrtt?: ZRTT;
zeroRtt?: ZRTT;
}

/**
Expand All @@ -555,6 +555,16 @@ declare namespace Deno {
alpnProtocols: string[];
}

export interface QuicAcceptOptions<ZRTT extends boolean>
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
Expand Down Expand Up @@ -673,13 +683,9 @@ declare namespace Deno {
/**
* Accept this incoming connection.
*/
accept(): Promise<QuicConn>;

/**
* 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<ZRTT extends boolean>(
options?: QuicAcceptOptions<ZRTT>,
): ZRTT extends true ? QuicConn : Promise<QuicConn>;

/**
* Refuse this incoming connection.
Expand Down
6 changes: 3 additions & 3 deletions ext/net/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct ListenArgs {
alpn_protocols: Option<Vec<String>>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
struct TransportConfig {
keep_alive_interval: Option<u64>,
Expand Down Expand Up @@ -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()?),
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/quic_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -214,7 +214,7 @@ Deno.test("0rtt", async () => {
port: sEndpoint.addr.port,
caCerts,
alpnProtocols: ["deno-test"],
zrtt: true,
zeroRtt: true,
endpoint,
});

Expand Down

0 comments on commit c69a4d6

Please sign in to comment.