Skip to content

Commit

Permalink
quic-transport: connectTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed May 21, 2024
1 parent 2a2cfa0 commit 91d4dbc
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion integ/browser-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/webpack": "^5.28.5",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"html-webpack-plugin": "^5.6.0",
"puppeteer": "^22.8.0",
"puppeteer": "^22.9.0",
"ts-loader": "^9.5.1",
"tslib": "^2.6.2",
"type-fest": "^4.18.2",
Expand Down
2 changes: 1 addition & 1 deletion integ/cxx-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"execa": "^9.0.2",
"execa": "^9.1.0",
"streaming-iterables": "^8.0.1"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"test": "vitest",
"typedoc": "bash mk/typedoc.sh"
},
"packageManager": "pnpm@9.1.0+sha256.22e36fba7f4880ecf749a5ca128b8435da085ecd49575e7fb9e64d6bf4fad394",
"packageManager": "pnpm@9.1.2+sha256.19c17528f9ca20bd442e4ca42f00f1b9808a9cb419383cd04ba32ef19322aba7",
"devDependencies": {
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"@types/wtfnode": "^0.7.3",
"@typescript/lib-dom": "npm:@types/web@0.0.144",
"@typescript/lib-dom": "npm:@types/web@0.0.147",
"@vitest/coverage-v8": "^1.6.0",
"@yoursunny/xo-config": "0.58.0",
"codedown": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoconfig/src/platform_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createFace(router: string, {
if (!H3Transport) {
throw new Error("H3Transport unavailable");
}
return H3Transport.createFace({ fw, addRoutes, lp: { mtu } }, uri.toString());
return H3Transport.createFace({ fw, addRoutes, lp: { mtu } }, uri.toString(), { connectTimeout });
}
default: {
throw new Error(`unknown protocol ${uri.protocol}`);
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@ndn/packet": "workspace:*",
"@ndn/util": "workspace:*",
"dotenv": "^16.4.5",
"env-var": "^7.4.2",
"env-var": "^7.5.0",
"tslib": "^2.6.2",
"wtfnode": "^0.9.2"
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/keychain-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@ndn/repo": "workspace:*",
"@ndn/tlv": "workspace:*",
"@ndn/util": "workspace:*",
"env-var": "^7.4.2",
"env-var": "^7.5.0",
"fast-chunk-string": "^1.0.1",
"get-stdin": "^9.0.0",
"nodemailer": "^6.9.13",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ndnsec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@ndn/tlv": "workspace:*",
"@ndn/util": "workspace:*",
"@yoursunny/asn1": "0.0.20200718",
"execa": "^9.0.2",
"execa": "^9.1.0",
"tslib": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion pkg/pyrepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@ndn/ndnsec": "workspace:^",
"@ndn/nfdmgmt": "workspace:^",
"@types/netmask": "^2.0.5",
"execa": "^9.0.2",
"execa": "^9.1.0",
"netmask": "^2.0.2"
}
}
1 change: 1 addition & 0 deletions pkg/quic-transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@ndn/l3face": "workspace:*",
"@ndn/util": "workspace:*",
"tslib": "^2.6.2"
}
}
26 changes: 22 additions & 4 deletions pkg/quic-transport/src/h3-transport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face";
import { delay } from "@ndn/util";

/** HTTP/3 transport. */
export class H3Transport extends Transport {
Expand All @@ -10,11 +11,19 @@ export class H3Transport extends Transport {
* @param uri - Server URI.
* @param opts - WebTransport options.
*/
public static async connect(uri: string, opts: WebTransportOptions = {}): Promise<H3Transport> {
const tr = new WebTransport(uri, opts);
public static async connect(uri: string, opts: H3Transport.Options = {}): Promise<H3Transport> {
const { connectTimeout = 10000, ...wtOpts } = opts;
const tr = new WebTransport(uri, wtOpts);
void tr.closed.catch(() => undefined);
await tr.ready;
return new H3Transport(uri, opts, tr);
const isTimeout = await Promise.race([
tr.ready,
delay(connectTimeout, true),
]);
if (isTimeout) {
tr.close();
throw new Error("timeout");
}
return new H3Transport(uri, wtOpts, tr);
}

private constructor(
Expand Down Expand Up @@ -63,6 +72,15 @@ export class H3Transport extends Transport {
}

export namespace H3Transport {
/** {@link H3Transport.connect} options. */
export interface Options extends WebTransportOptions {
/**
* Connect timeout (in milliseconds).
* @defaultValue 10000
*/
connectTimeout?: number;
}

/** Create a transport and add to forwarder. */
export const createFace = L3Face.makeCreateFace(H3Transport.connect);
}

0 comments on commit 91d4dbc

Please sign in to comment.