2025-01-01 04:12:39 +09:00
|
|
|
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
2021-06-29 01:43:03 +02:00
|
|
|
|
|
|
|
|
|
/// <reference no-default-lib="true" />
|
|
|
|
|
/// <reference lib="esnext" />
|
2023-11-01 20:26:12 +01:00
|
|
|
|
/// <reference lib="esnext.disposable" />
|
2021-06-29 01:43:03 +02:00
|
|
|
|
|
|
|
|
|
declare namespace Deno {
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export interface NetAddr {
|
|
|
|
|
transport: "tcp" | "udp";
|
|
|
|
|
hostname: string;
|
|
|
|
|
port: number;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export interface UnixAddr {
|
|
|
|
|
transport: "unix" | "unixpacket";
|
|
|
|
|
path: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export type Addr = NetAddr | UnixAddr;
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** A generic network listener for stream-oriented protocols.
|
|
|
|
|
*
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2024-04-05 17:01:03 -06:00
|
|
|
|
export interface Listener<T extends Conn = Conn, A extends Addr = Addr>
|
2023-11-01 20:26:12 +01:00
|
|
|
|
extends AsyncIterable<T>, Disposable {
|
2021-06-29 01:43:03 +02:00
|
|
|
|
/** Waits for and resolves to the next connection to the `Listener`. */
|
2023-08-27 17:55:04 -03:00
|
|
|
|
accept(): Promise<T>;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
/** Close closes the listener. Any pending accept promises will be rejected
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* with errors. */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
close(): void;
|
|
|
|
|
/** Return the address of the `Listener`. */
|
2024-04-05 17:01:03 -06:00
|
|
|
|
readonly addr: A;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
|
2023-08-27 17:55:04 -03:00
|
|
|
|
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
2023-01-20 16:32:55 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make the listener block the event loop from finishing.
|
|
|
|
|
*
|
|
|
|
|
* Note: the listener blocks the event loop from finishing by default.
|
|
|
|
|
* This method is only meaningful after `.unref()` is called.
|
|
|
|
|
*/
|
|
|
|
|
ref(): void;
|
|
|
|
|
|
|
|
|
|
/** Make the listener not block the event loop from finishing. */
|
|
|
|
|
unref(): void;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** Specialized listener that accepts TLS connections.
|
|
|
|
|
*
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2024-04-05 17:01:03 -06:00
|
|
|
|
export type TlsListener = Listener<TlsConn, NetAddr>;
|
|
|
|
|
|
|
|
|
|
/** Specialized listener that accepts TCP connections.
|
|
|
|
|
*
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export type TcpListener = Listener<TcpConn, NetAddr>;
|
|
|
|
|
|
|
|
|
|
/** Specialized listener that accepts Unix connections.
|
|
|
|
|
*
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export type UnixListener = Listener<UnixConn, UnixAddr>;
|
2021-10-26 22:27:47 +02:00
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2024-09-10 07:07:12 +10:00
|
|
|
|
export interface Conn<A extends Addr = Addr> extends Disposable {
|
|
|
|
|
/** Read the incoming data from the connection into an array buffer (`p`).
|
|
|
|
|
*
|
|
|
|
|
* Resolves to either the number of bytes read during the operation or EOF
|
|
|
|
|
* (`null`) if there was nothing more to read.
|
|
|
|
|
*
|
|
|
|
|
* It is possible for a read to successfully return with `0` bytes. This
|
|
|
|
|
* does not indicate EOF.
|
|
|
|
|
*
|
|
|
|
|
* **It is not guaranteed that the full buffer will be read in a single
|
|
|
|
|
* call.**
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* // If the text "hello world" is received by the client:
|
|
|
|
|
* const conn = await Deno.connect({ hostname: "example.com", port: 80 });
|
|
|
|
|
* const buf = new Uint8Array(100);
|
|
|
|
|
* const numberOfBytesRead = await conn.read(buf); // 11 bytes
|
|
|
|
|
* const text = new TextDecoder().decode(buf); // "hello world"
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* @category I/O
|
|
|
|
|
*/
|
|
|
|
|
read(p: Uint8Array): Promise<number | null>;
|
|
|
|
|
/** Write the contents of the array buffer (`p`) to the connection.
|
|
|
|
|
*
|
|
|
|
|
* Resolves to the number of bytes written.
|
|
|
|
|
*
|
|
|
|
|
* **It is not guaranteed that the full buffer will be written in a single
|
|
|
|
|
* call.**
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const conn = await Deno.connect({ hostname: "example.com", port: 80 });
|
|
|
|
|
* const encoder = new TextEncoder();
|
|
|
|
|
* const data = encoder.encode("Hello world");
|
|
|
|
|
* const bytesWritten = await conn.write(data); // 11
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* @category I/O
|
|
|
|
|
*/
|
|
|
|
|
write(p: Uint8Array): Promise<number>;
|
|
|
|
|
/** Closes the connection, freeing the resource.
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const conn = await Deno.connect({ hostname: "example.com", port: 80 });
|
|
|
|
|
*
|
|
|
|
|
* // ...
|
|
|
|
|
*
|
|
|
|
|
* conn.close();
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
close(): void;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
/** The local address of the connection. */
|
2024-04-05 17:01:03 -06:00
|
|
|
|
readonly localAddr: A;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
/** The remote address of the connection. */
|
2024-04-05 17:01:03 -06:00
|
|
|
|
readonly remoteAddr: A;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
/** Shuts down (`shutdown(2)`) the write side of the connection. Most
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* callers should just use `close()`. */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
closeWrite(): Promise<void>;
|
2022-02-15 13:35:22 +01:00
|
|
|
|
|
2024-01-14 18:04:33 +01:00
|
|
|
|
/** Make the connection block the event loop from finishing.
|
2022-12-28 10:29:48 +01:00
|
|
|
|
*
|
|
|
|
|
* Note: the connection blocks the event loop from finishing by default.
|
|
|
|
|
* This method is only meaningful after `.unref()` is called.
|
|
|
|
|
*/
|
|
|
|
|
ref(): void;
|
2024-01-14 18:04:33 +01:00
|
|
|
|
/** Make the connection not block the event loop from finishing. */
|
2022-12-28 10:29:48 +01:00
|
|
|
|
unref(): void;
|
|
|
|
|
|
2022-02-15 13:35:22 +01:00
|
|
|
|
readonly readable: ReadableStream<Uint8Array>;
|
|
|
|
|
readonly writable: WritableStream<Uint8Array>;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2024-01-14 18:06:26 +01:00
|
|
|
|
export interface TlsHandshakeInfo {
|
|
|
|
|
/**
|
|
|
|
|
* Contains the ALPN protocol selected during negotiation with the server.
|
|
|
|
|
* If no ALPN protocol selected, returns `null`.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocol: string | null;
|
|
|
|
|
}
|
2021-11-26 10:59:53 -08:00
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2024-04-05 17:01:03 -06:00
|
|
|
|
export interface TlsConn extends Conn<NetAddr> {
|
2021-10-26 22:27:47 +02:00
|
|
|
|
/** Runs the client or server handshake protocol to completion if that has
|
|
|
|
|
* not happened yet. Calling this method is optional; the TLS handshake
|
|
|
|
|
* will be completed automatically as soon as data is sent or received. */
|
2021-11-26 10:59:53 -08:00
|
|
|
|
handshake(): Promise<TlsHandshakeInfo>;
|
2021-10-26 22:27:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export interface ListenOptions {
|
2024-07-09 16:57:27 +10:00
|
|
|
|
/** The port to listen on.
|
|
|
|
|
*
|
|
|
|
|
* Set to `0` to listen on any available port.
|
|
|
|
|
*/
|
2021-06-29 01:43:03 +02:00
|
|
|
|
port: number;
|
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2021-09-07 16:26:21 +09:00
|
|
|
|
*
|
|
|
|
|
* __Note about `0.0.0.0`__ While listening `0.0.0.0` works on all platforms,
|
|
|
|
|
* the browsers on Windows don't work with the address `0.0.0.0`.
|
|
|
|
|
* You should show the message like `server running on localhost:8080` instead of
|
2022-12-13 14:14:41 +01:00
|
|
|
|
* `server running on 0.0.0.0:8080` if your program supports Windows.
|
|
|
|
|
*
|
|
|
|
|
* @default {"0.0.0.0"} */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
hostname?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 21:04:27 +02:00
|
|
|
|
/** @category Network */
|
|
|
|
|
export interface TcpListenOptions extends ListenOptions {
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 01:43:03 +02:00
|
|
|
|
/** Listen announces on the local transport address.
|
2021-09-02 18:28:12 -04:00
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const listener1 = Deno.listen({ port: 80 })
|
|
|
|
|
* const listener2 = Deno.listen({ hostname: "192.0.2.1", port: 80 })
|
|
|
|
|
* const listener3 = Deno.listen({ hostname: "[2001:db8::1]", port: 80 });
|
|
|
|
|
* const listener4 = Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* Requires `allow-net` permission.
|
|
|
|
|
*
|
2022-08-23 10:57:01 +10:00
|
|
|
|
* @tags allow-net
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export function listen(
|
2022-10-26 21:04:27 +02:00
|
|
|
|
options: TcpListenOptions & { transport?: "tcp" },
|
2024-04-05 17:01:03 -06:00
|
|
|
|
): TcpListener;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
|
2024-01-23 13:02:25 +01:00
|
|
|
|
/** Options which can be set when opening a Unix listener via
|
|
|
|
|
* {@linkcode Deno.listen} or {@linkcode Deno.listenDatagram}.
|
|
|
|
|
*
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface UnixListenOptions {
|
|
|
|
|
/** A path to the Unix Socket. */
|
|
|
|
|
path: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Listen announces on the local transport address.
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" })
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Requires `allow-read` and `allow-write` permission.
|
|
|
|
|
*
|
|
|
|
|
* @tags allow-read, allow-write
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
// deno-lint-ignore adjacent-overload-signatures
|
|
|
|
|
export function listen(
|
|
|
|
|
options: UnixListenOptions & { transport: "unix" },
|
2024-04-05 17:01:03 -06:00
|
|
|
|
): UnixListener;
|
2024-01-23 13:02:25 +01:00
|
|
|
|
|
2024-04-18 18:21:08 +01:00
|
|
|
|
/**
|
|
|
|
|
* Provides certified key material from strings. The key material is provided in
|
|
|
|
|
* `PEM`-format (Privacy Enhanced Mail, https://www.rfc-editor.org/rfc/rfc1422) which can be identified by having
|
|
|
|
|
* `-----BEGIN-----` and `-----END-----` markers at the beginning and end of the strings. This type of key is not compatible
|
|
|
|
|
* with `DER`-format keys which are binary.
|
|
|
|
|
*
|
|
|
|
|
* Deno supports RSA, EC, and PKCS8-format keys.
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const key = {
|
|
|
|
|
* key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
|
|
|
|
|
* cert: "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n" }
|
|
|
|
|
* };
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface TlsCertifiedKeyPem {
|
|
|
|
|
/** The format of this key material, which must be PEM. */
|
|
|
|
|
keyFormat?: "pem";
|
|
|
|
|
/** Private key in `PEM` format. RSA, EC, and PKCS8-format keys are supported. */
|
|
|
|
|
key: string;
|
|
|
|
|
/** Certificate chain in `PEM` format. */
|
|
|
|
|
cert: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @category Network */
|
|
|
|
|
export interface ListenTlsOptions extends TcpListenOptions {
|
2021-06-29 01:43:03 +02:00
|
|
|
|
transport?: "tcp";
|
2023-07-04 15:28:50 +02:00
|
|
|
|
|
|
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols to announce to
|
|
|
|
|
* the client. If not specified, no ALPN extension will be included in the
|
|
|
|
|
* TLS handshake.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocols?: string[];
|
2021-06-29 01:43:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Listen announces on the local transport address over TLS (transport layer
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* security).
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
2024-01-24 03:35:23 +11:00
|
|
|
|
* using listener = Deno.listenTls({
|
|
|
|
|
* port: 443,
|
|
|
|
|
* cert: Deno.readTextFileSync("./server.crt"),
|
|
|
|
|
* key: Deno.readTextFileSync("./server.key"),
|
|
|
|
|
* });
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* ```
|
|
|
|
|
*
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* Requires `allow-net` permission.
|
|
|
|
|
*
|
2022-08-23 10:57:01 +10:00
|
|
|
|
* @tags allow-net
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2024-04-18 18:21:08 +01:00
|
|
|
|
export function listenTls(
|
2024-09-11 07:55:42 +10:00
|
|
|
|
options: ListenTlsOptions & TlsCertifiedKeyPem,
|
2024-04-18 18:21:08 +01:00
|
|
|
|
): TlsListener;
|
2021-06-29 01:43:03 +02:00
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export interface ConnectOptions {
|
|
|
|
|
/** The port to connect to. */
|
|
|
|
|
port: number;
|
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2022-12-13 14:14:41 +01:00
|
|
|
|
* If not specified,
|
|
|
|
|
*
|
|
|
|
|
* @default {"127.0.0.1"} */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
hostname?: string;
|
|
|
|
|
transport?: "tcp";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* Connects to the hostname (default is "127.0.0.1") and port on the named
|
|
|
|
|
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const conn1 = await Deno.connect({ port: 80 });
|
|
|
|
|
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
|
|
|
|
|
* const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
|
|
|
|
|
* const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* Requires `allow-net` permission for "tcp".
|
|
|
|
|
*
|
2022-08-23 10:57:01 +10:00
|
|
|
|
* @tags allow-net
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2022-02-27 15:18:30 +01:00
|
|
|
|
export function connect(options: ConnectOptions): Promise<TcpConn>;
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2024-04-05 17:01:03 -06:00
|
|
|
|
export interface TcpConn extends Conn<NetAddr> {
|
2022-02-27 15:18:30 +01:00
|
|
|
|
/**
|
2022-12-13 14:14:41 +01:00
|
|
|
|
* Enable/disable the use of Nagle's algorithm.
|
|
|
|
|
*
|
2022-12-14 00:54:11 +01:00
|
|
|
|
* @param [noDelay=true]
|
2022-02-27 15:18:30 +01:00
|
|
|
|
*/
|
2022-12-14 00:54:11 +01:00
|
|
|
|
setNoDelay(noDelay?: boolean): void;
|
|
|
|
|
/** Enable/disable keep-alive functionality. */
|
|
|
|
|
setKeepAlive(keepAlive?: boolean): void;
|
2022-02-27 15:18:30 +01:00
|
|
|
|
}
|
2021-06-29 01:43:03 +02:00
|
|
|
|
|
2024-01-14 22:50:58 +01:00
|
|
|
|
/** @category Network */
|
|
|
|
|
export interface UnixConnectOptions {
|
|
|
|
|
transport: "unix";
|
|
|
|
|
path: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2024-09-07 09:01:36 +10:00
|
|
|
|
export interface UnixConn extends Conn<UnixAddr> {}
|
2022-03-04 20:33:13 +01:00
|
|
|
|
|
2024-01-14 22:50:58 +01:00
|
|
|
|
/** Connects to the hostname (default is "127.0.0.1") and port on the named
|
|
|
|
|
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const conn1 = await Deno.connect({ port: 80 });
|
|
|
|
|
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
|
|
|
|
|
* const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
|
|
|
|
|
* const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
|
|
|
|
|
* const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Requires `allow-net` permission for "tcp" and `allow-read` for "unix".
|
|
|
|
|
*
|
|
|
|
|
* @tags allow-net, allow-read
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
// deno-lint-ignore adjacent-overload-signatures
|
|
|
|
|
export function connect(options: UnixConnectOptions): Promise<UnixConn>;
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
export interface ConnectTlsOptions {
|
|
|
|
|
/** The port to connect to. */
|
|
|
|
|
port: number;
|
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2022-12-13 14:14:41 +01:00
|
|
|
|
*
|
|
|
|
|
* @default {"127.0.0.1"} */
|
2021-06-29 01:43:03 +02:00
|
|
|
|
hostname?: string;
|
2021-09-30 09:26:15 +02:00
|
|
|
|
/** A list of root certificates that will be used in addition to the
|
|
|
|
|
* default root certificates to verify the peer's certificate.
|
|
|
|
|
*
|
|
|
|
|
* Must be in PEM format. */
|
|
|
|
|
caCerts?: string[];
|
2023-07-04 15:28:50 +02:00
|
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols supported by
|
|
|
|
|
* the client. If not specified, no ALPN extension will be included in the
|
|
|
|
|
* TLS handshake.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocols?: string[];
|
2021-06-29 01:43:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Establishes a secure connection over TLS (transport layer security) using
|
2024-09-16 14:35:55 +02:00
|
|
|
|
* an optional list of CA certs, hostname (default is "127.0.0.1") and port.
|
|
|
|
|
*
|
|
|
|
|
* The CA cert list is optional and if not included Mozilla's root
|
|
|
|
|
* certificates will be used (see also https://github.com/ctz/webpki-roots for
|
|
|
|
|
* specifics).
|
|
|
|
|
*
|
|
|
|
|
* Mutual TLS (mTLS or client certificates) are supported by providing a
|
|
|
|
|
* `key` and `cert` in the options as PEM-encoded strings.
|
2021-09-02 18:28:12 -04:00
|
|
|
|
*
|
|
|
|
|
* ```ts
|
2021-09-30 09:26:15 +02:00
|
|
|
|
* const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* const conn1 = await Deno.connectTls({ port: 80 });
|
2021-09-30 09:26:15 +02:00
|
|
|
|
* const conn2 = await Deno.connectTls({ caCerts: [caCert], hostname: "192.0.2.1", port: 80 });
|
2021-09-02 18:28:12 -04:00
|
|
|
|
* const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 });
|
2021-09-30 09:26:15 +02:00
|
|
|
|
* const conn4 = await Deno.connectTls({ caCerts: [caCert], hostname: "golang.org", port: 80});
|
2021-09-02 18:28:12 -04:00
|
|
|
|
*
|
2024-04-18 18:21:08 +01:00
|
|
|
|
* const key = "----BEGIN PRIVATE KEY----...";
|
|
|
|
|
* const cert = "----BEGIN CERTIFICATE----...";
|
2024-09-16 14:35:55 +02:00
|
|
|
|
* const conn5 = await Deno.connectTls({ port: 80, key, cert });
|
2024-04-18 18:21:08 +01:00
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Requires `allow-net` permission.
|
|
|
|
|
*
|
|
|
|
|
* @tags allow-net
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export function connectTls(
|
2024-09-16 14:35:55 +02:00
|
|
|
|
options: ConnectTlsOptions | (ConnectTlsOptions & TlsCertifiedKeyPem),
|
2024-04-18 18:21:08 +01:00
|
|
|
|
): Promise<TlsConn>;
|
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
|
/** @category Network */
|
2021-10-29 17:13:31 +02:00
|
|
|
|
export interface StartTlsOptions {
|
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address.
|
2022-12-13 14:14:41 +01:00
|
|
|
|
*
|
|
|
|
|
* @default {"127.0.0.1"} */
|
2021-10-29 17:13:31 +02:00
|
|
|
|
hostname?: string;
|
|
|
|
|
/** A list of root certificates that will be used in addition to the
|
|
|
|
|
* default root certificates to verify the peer's certificate.
|
|
|
|
|
*
|
|
|
|
|
* Must be in PEM format. */
|
|
|
|
|
caCerts?: string[];
|
2023-07-04 15:28:50 +02:00
|
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols to announce to
|
|
|
|
|
* the client. If not specified, no ALPN extension will be included in the
|
|
|
|
|
* TLS handshake.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocols?: string[];
|
2021-10-29 17:13:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Start TLS handshake from an existing connection using an optional list of
|
|
|
|
|
* CA certificates, and hostname (default is "127.0.0.1"). Specifying CA certs
|
|
|
|
|
* is optional. By default the configured root certificates are used. Using
|
|
|
|
|
* this function requires that the other end of the connection is prepared for
|
|
|
|
|
* a TLS handshake.
|
|
|
|
|
*
|
2022-10-18 11:28:27 +09:00
|
|
|
|
* Note that this function *consumes* the TCP connection passed to it, thus the
|
|
|
|
|
* original TCP connection will be unusable after calling this. Additionally,
|
|
|
|
|
* you need to ensure that the TCP connection is not being used elsewhere when
|
|
|
|
|
* calling this function in order for the TCP connection to be consumed properly.
|
|
|
|
|
* For instance, if there is a `Promise` that is waiting for read operation on
|
|
|
|
|
* the TCP connection to complete, it is considered that the TCP connection is
|
|
|
|
|
* being used elsewhere. In such a case, this function will fail.
|
|
|
|
|
*
|
2021-10-29 17:13:31 +02:00
|
|
|
|
* ```ts
|
|
|
|
|
* const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" });
|
|
|
|
|
* const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
|
2022-10-18 11:28:27 +09:00
|
|
|
|
* // `conn` becomes unusable after calling `Deno.startTls`
|
2021-10-29 17:13:31 +02:00
|
|
|
|
* const tlsConn = await Deno.startTls(conn, { caCerts: [caCert], hostname: "localhost" });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Requires `allow-net` permission.
|
2022-08-17 13:12:24 +10:00
|
|
|
|
*
|
2022-08-23 10:57:01 +10:00
|
|
|
|
* @tags allow-net
|
2022-08-17 13:12:24 +10:00
|
|
|
|
* @category Network
|
2021-10-29 17:13:31 +02:00
|
|
|
|
*/
|
|
|
|
|
export function startTls(
|
2024-04-05 17:01:03 -06:00
|
|
|
|
conn: TcpConn,
|
2021-10-29 17:13:31 +02:00
|
|
|
|
options?: StartTlsOptions,
|
|
|
|
|
): Promise<TlsConn>;
|
2024-09-23 15:18:52 -04:00
|
|
|
|
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicEndpointOptions {
|
|
|
|
|
/**
|
|
|
|
|
* A literal IP address or host name that can be resolved to an IP address.
|
|
|
|
|
* @default {"::"}
|
|
|
|
|
*/
|
|
|
|
|
hostname?: string;
|
|
|
|
|
/**
|
|
|
|
|
* The port to bind to.
|
|
|
|
|
* @default {0}
|
|
|
|
|
*/
|
|
|
|
|
port?: number;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-20 13:48:48 +01:00
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicTransportOptions {
|
|
|
|
|
/** Period of inactivity before sending a keep-alive packet. Keep-alive
|
|
|
|
|
* packets prevent an inactive but otherwise healthy connection from timing
|
|
|
|
|
* out. Only one side of any given connection needs keep-alive enabled for
|
|
|
|
|
* the connection to be preserved.
|
|
|
|
|
* @default {undefined}
|
|
|
|
|
*/
|
|
|
|
|
keepAliveInterval?: number;
|
|
|
|
|
/** Maximum duration of inactivity to accept before timing out the
|
|
|
|
|
* connection. The true idle timeout is the minimum of this and the peer’s
|
|
|
|
|
* own max idle timeout.
|
|
|
|
|
* @default {undefined}
|
|
|
|
|
*/
|
|
|
|
|
maxIdleTimeout?: number;
|
|
|
|
|
/** Maximum number of incoming bidirectional streams that may be open
|
|
|
|
|
* concurrently.
|
|
|
|
|
* @default {100}
|
|
|
|
|
*/
|
|
|
|
|
maxConcurrentBidirectionalStreams?: number;
|
|
|
|
|
/** Maximum number of incoming unidirectional streams that may be open
|
|
|
|
|
* concurrently.
|
|
|
|
|
* @default {100}
|
|
|
|
|
*/
|
|
|
|
|
maxConcurrentUnidirectionalStreams?: number;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/**
|
|
|
|
|
* The congestion control algorithm used when sending data over this connection.
|
|
|
|
|
* @default {"default"}
|
|
|
|
|
*/
|
|
|
|
|
congestionControl?: "throughput" | "low-latency" | "default";
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface ConnectQuicOptions<ZRTT extends boolean>
|
|
|
|
|
extends QuicTransportOptions {
|
2024-12-20 13:48:48 +01:00
|
|
|
|
/** The port to connect to. */
|
|
|
|
|
port: number;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** A literal IP address or host name that can be resolved to an IP address. */
|
|
|
|
|
hostname: string;
|
|
|
|
|
/** The name used for validating the certificate provided by the server. If
|
|
|
|
|
* not provided, defaults to `hostname`. */
|
|
|
|
|
serverName?: string | undefined;
|
|
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols supported by
|
2024-12-20 13:48:48 +01:00
|
|
|
|
* the client. QUIC requires the use of ALPN.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocols: string[];
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** A list of root certificates that will be used in addition to the
|
|
|
|
|
* default root certificates to verify the peer's certificate.
|
|
|
|
|
*
|
|
|
|
|
* Must be in PEM format. */
|
|
|
|
|
caCerts?: string[];
|
|
|
|
|
/**
|
|
|
|
|
* If no endpoint is provided, a new one is bound on an ephemeral port.
|
|
|
|
|
*/
|
|
|
|
|
endpoint?: QuicEndpoint;
|
|
|
|
|
/**
|
|
|
|
|
* Attempt to convert the connection into 0-RTT. Any data sent before
|
|
|
|
|
* the TLS handshake completes is vulnerable to replay attacks.
|
|
|
|
|
* @default {false}
|
|
|
|
|
*/
|
|
|
|
|
zeroRtt?: ZRTT;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface QuicServerTransportOptions extends QuicTransportOptions {
|
|
|
|
|
/**
|
|
|
|
|
* Preferred IPv4 address to be communicated to the client during
|
|
|
|
|
* handshaking. If the client is able to reach this address it will switch
|
|
|
|
|
* to it.
|
|
|
|
|
* @default {undefined}
|
|
|
|
|
*/
|
|
|
|
|
preferredAddressV4?: string;
|
|
|
|
|
/**
|
|
|
|
|
* Preferred IPv6 address to be communicated to the client during
|
|
|
|
|
* handshaking. If the client is able to reach this address it will switch
|
|
|
|
|
* to it.
|
|
|
|
|
* @default {undefined}
|
|
|
|
|
*/
|
|
|
|
|
preferredAddressV6?: string;
|
|
|
|
|
}
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface QuicListenOptions extends QuicServerTransportOptions {
|
|
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols to announce to
|
2024-12-20 13:48:48 +01:00
|
|
|
|
* the client. QUIC requires the use of ALPN.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocols: string[];
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** Server private key in PEM format */
|
|
|
|
|
key: string;
|
|
|
|
|
/** Cert chain in PEM format */
|
|
|
|
|
cert: string;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface QuicAcceptOptions<ZRTT extends boolean>
|
|
|
|
|
extends QuicServerTransportOptions {
|
|
|
|
|
/** Application-Layer Protocol Negotiation (ALPN) protocols to announce to
|
|
|
|
|
* the client. QUIC requires the use of ALPN.
|
|
|
|
|
*/
|
|
|
|
|
alpnProtocols?: string[];
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicCloseInfo {
|
|
|
|
|
/** A number representing the error code for the error. */
|
|
|
|
|
closeCode: number;
|
|
|
|
|
/** A string representing the reason for closing the connection. */
|
|
|
|
|
reason: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface QuicSendStreamOptions {
|
|
|
|
|
/** Indicates the send priority of this stream relative to other streams for
|
|
|
|
|
* which the value has been set.
|
|
|
|
|
* @default {0}
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
sendOrder?: number;
|
|
|
|
|
/** Wait until there is sufficient flow credit to create the stream.
|
|
|
|
|
* @default {false}
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
waitUntilAvailable?: boolean;
|
|
|
|
|
}
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export class QuicEndpoint {
|
2024-12-20 13:48:48 +01:00
|
|
|
|
/**
|
2025-01-06 15:24:59 +01:00
|
|
|
|
* Create a QUIC endpoint which may be used for client or server connections.
|
|
|
|
|
*
|
|
|
|
|
* Requires `allow-net` permission.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @tags allow-net
|
|
|
|
|
* @category Network
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
constructor(options?: QuicEndpointOptions);
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** Return the address of the `QuicListener`. */
|
|
|
|
|
readonly addr: NetAddr;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2025-01-06 15:24:59 +01:00
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* Listen announces on the local transport address over QUIC.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
listen(options: QuicListenOptions): QuicListener;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2025-01-06 15:24:59 +01:00
|
|
|
|
* Closes the endpoint. All associated connections will be closed and incoming
|
|
|
|
|
* connections will be rejected.
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
close(info?: QuicCloseInfo): void;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* Specialized listener that accepts QUIC connections.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicListener extends AsyncIterable<QuicConn> {
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** Waits for and resolves to the next incoming connection. */
|
|
|
|
|
incoming(): Promise<QuicIncoming>;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** Wait for the next incoming connection and accepts it. */
|
2024-12-20 13:48:48 +01:00
|
|
|
|
accept(): Promise<QuicConn>;
|
|
|
|
|
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** Stops the listener. This does not close the endpoint. */
|
|
|
|
|
stop(): void;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
|
|
|
|
[Symbol.asyncIterator](): AsyncIterableIterator<QuicConn>;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
|
|
|
|
|
/** The endpoint for this listener. */
|
|
|
|
|
readonly endpoint: QuicEndpoint;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
2025-01-06 15:24:59 +01:00
|
|
|
|
* An incoming connection for which the server has not yet begun its part of
|
|
|
|
|
* the handshake.
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface QuicIncoming {
|
|
|
|
|
/**
|
|
|
|
|
* The local IP address which was used when the peer established the
|
|
|
|
|
* connection.
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
readonly localIp: string;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The peer’s UDP address.
|
2024-12-20 13:48:48 +01:00
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
readonly remoteAddr: NetAddr;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the socket address that is initiating this connection has proven
|
|
|
|
|
* that they can receive traffic.
|
|
|
|
|
*/
|
|
|
|
|
readonly remoteAddressValidated: boolean;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accept this incoming connection.
|
|
|
|
|
*/
|
|
|
|
|
accept<ZRTT extends boolean>(
|
|
|
|
|
options?: QuicAcceptOptions<ZRTT>,
|
|
|
|
|
): ZRTT extends true ? QuicConn : Promise<QuicConn>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refuse this incoming connection.
|
|
|
|
|
*/
|
|
|
|
|
refuse(): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ignore this incoming connection attempt, not sending any packet in response.
|
|
|
|
|
*/
|
|
|
|
|
ignore(): void;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicConn {
|
|
|
|
|
/** Close closes the listener. Any pending accept promises will be rejected
|
|
|
|
|
* with errors. */
|
2025-01-06 15:24:59 +01:00
|
|
|
|
close(info?: QuicCloseInfo): void;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
/** Opens and returns a bidirectional stream. */
|
|
|
|
|
createBidirectionalStream(
|
|
|
|
|
options?: QuicSendStreamOptions,
|
|
|
|
|
): Promise<QuicBidirectionalStream>;
|
|
|
|
|
/** Opens and returns a unidirectional stream. */
|
|
|
|
|
createUnidirectionalStream(
|
|
|
|
|
options?: QuicSendStreamOptions,
|
|
|
|
|
): Promise<QuicSendStream>;
|
|
|
|
|
/** Send a datagram. The provided data cannot be larger than
|
|
|
|
|
* `maxDatagramSize`. */
|
|
|
|
|
sendDatagram(data: Uint8Array): Promise<void>;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** Receive a datagram. */
|
|
|
|
|
readDatagram(): Promise<Uint8Array>;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** The endpoint for this connection. */
|
|
|
|
|
readonly endpoint: QuicEndpoint;
|
|
|
|
|
/** Returns a promise that resolves when the TLS handshake is complete. */
|
|
|
|
|
readonly handshake: Promise<void>;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
/** Return the remote address for the connection. Clients may change
|
|
|
|
|
* addresses at will, for example when switching to a cellular internet
|
|
|
|
|
* connection.
|
|
|
|
|
*/
|
|
|
|
|
readonly remoteAddr: NetAddr;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/**
|
|
|
|
|
* The negotiated ALPN protocol, if provided. Only available after the
|
|
|
|
|
* handshake is complete. */
|
2024-12-20 13:48:48 +01:00
|
|
|
|
readonly protocol: string | undefined;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
/** The negotiated server name. Only available on the server after the
|
|
|
|
|
* handshake is complete. */
|
|
|
|
|
readonly serverName: string | undefined;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
/** Returns a promise that resolves when the connection is closed. */
|
|
|
|
|
readonly closed: Promise<QuicCloseInfo>;
|
|
|
|
|
/** A stream of bidirectional streams opened by the peer. */
|
|
|
|
|
readonly incomingBidirectionalStreams: ReadableStream<
|
|
|
|
|
QuicBidirectionalStream
|
|
|
|
|
>;
|
|
|
|
|
/** A stream of unidirectional streams opened by the peer. */
|
|
|
|
|
readonly incomingUnidirectionalStreams: ReadableStream<QuicReceiveStream>;
|
|
|
|
|
/** Returns the datagram stream for sending and receiving datagrams. */
|
|
|
|
|
readonly maxDatagramSize: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicBidirectionalStream {
|
|
|
|
|
/** Returns a QuicReceiveStream instance that can be used to read incoming data. */
|
|
|
|
|
readonly readable: QuicReceiveStream;
|
|
|
|
|
/** Returns a QuicSendStream instance that can be used to write outgoing data. */
|
|
|
|
|
readonly writable: QuicSendStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export interface QuicSendStream extends WritableStream<Uint8Array> {
|
|
|
|
|
/** Indicates the send priority of this stream relative to other streams for
|
|
|
|
|
* which the value has been set. */
|
|
|
|
|
sendOrder: number;
|
2025-01-06 15:24:59 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 62-bit stream ID, unique within this connection.
|
|
|
|
|
*/
|
|
|
|
|
readonly id: bigint;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
2025-01-06 15:24:59 +01:00
|
|
|
|
export interface QuicReceiveStream extends ReadableStream<Uint8Array> {
|
|
|
|
|
/**
|
|
|
|
|
* 62-bit stream ID, unique within this connection.
|
|
|
|
|
*/
|
|
|
|
|
readonly id: bigint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* **UNSTABLE**: New API, yet to be vetted.
|
|
|
|
|
* Establishes a secure connection over QUIC using a hostname and port. The
|
|
|
|
|
* cert file is optional and if not included Mozilla's root certificates will
|
|
|
|
|
* be used. See also https://github.com/ctz/webpki-roots for specifics.
|
|
|
|
|
*
|
|
|
|
|
* ```ts
|
|
|
|
|
* const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
|
|
|
|
|
* const conn1 = await Deno.connectQuic({ hostname: "example.com", port: 443, alpnProtocols: ["h3"] });
|
|
|
|
|
* const conn2 = await Deno.connectQuic({ caCerts: [caCert], hostname: "example.com", port: 443, alpnProtocols: ["h3"] });
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* If an endpoint is shared among many connections, 0-RTT can be enabled.
|
|
|
|
|
* When 0-RTT is successful, a QuicConn will be synchronously returned
|
|
|
|
|
* and data can be sent immediately with it. **Any data sent before the
|
|
|
|
|
* TLS handshake completes is vulnerable to replay attacks.**
|
|
|
|
|
*
|
|
|
|
|
* Requires `allow-net` permission.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
* @tags allow-net
|
|
|
|
|
* @category Network
|
|
|
|
|
*/
|
|
|
|
|
export function connectQuic<ZRTT extends boolean>(
|
|
|
|
|
options: ConnectQuicOptions<ZRTT>,
|
|
|
|
|
): ZRTT extends true ? (QuicConn | Promise<QuicConn>) : Promise<QuicConn>;
|
2024-12-20 13:48:48 +01:00
|
|
|
|
|
2024-09-23 15:18:52 -04:00
|
|
|
|
export {}; // only export exports
|
2021-06-29 01:43:03 +02:00
|
|
|
|
}
|