Repository navigation
fix(net): js/net and moq-net decode the same inputs the same way #8222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a2051e9
fd7f4cb
04a6f30
0fac868
0abf35a
e059d86
f6db857
7dca161
9e0720c
fa7f323
6efc886
85650e2
a161efa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,9 @@ import * as Lite from "../lite/index.ts"; | |
| import type { Consumer as OriginConsumer, Producer as OriginProducer } from "../origin.ts"; | ||
| import { Stream } from "../stream.ts"; | ||
| import * as Hex from "../util/hex.ts"; | ||
| import { redact } from "../util/log.ts"; | ||
| import { after } from "../util/timer.ts"; | ||
| import { isWebTransportSupported } from "./browser.ts"; | ||
| import { parse, show } from "./endpoint.ts"; | ||
| import type { Established } from "./established.ts"; | ||
| import * as Extensions from "./extensions.ts"; | ||
| import { DISCOVERY_REMOVED, forwardAnnounced } from "./forward.ts"; | ||
|
|
@@ -332,8 +332,8 @@ const websocketWon = new Set<string>(); | |
|
|
||
| /** The {@link websocketWon} key for the URL the WebSocket fallback dials. */ | ||
| function websocketKey(url: URL): string { | ||
| const port = url.port || (url.protocol === "http:" || url.protocol === "ws:" ? "80" : "443"); | ||
| return `${url.hostname}:${port}`; | ||
| const endpoint = parse(url); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return `${endpoint.url.hostname}:${endpoint.port}`; | ||
| } | ||
|
|
||
| /** The default connect signal: never aborts. */ | ||
|
|
@@ -393,17 +393,6 @@ export async function connect({ url, ...props }: ConnectProps): Promise<Establis | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * The URL a browser transport dials. A raw QUIC `moqt:` or `moql:` URL is reached over | ||
| * WebTransport with its scheme swapped for https (draft-ietf-moq-transport-18 §3.1.3); the | ||
| * CONNECT carries the scheme, so a server refuses the raw one. Rebuilt rather than assigned, | ||
| * since the URL setter refuses a change from a non-special scheme to a special one. | ||
| */ | ||
| function dialable(url: URL): URL { | ||
| if (url.protocol !== "moqt:" && url.protocol !== "moql:") return url; | ||
| return new URL(`https:${url.href.slice(url.protocol.length)}`); | ||
| } | ||
|
|
||
| /** Dial `raw`, resolving with the session and the credential the winning transport presented. */ | ||
| async function connectInner( | ||
| raw: URL, | ||
|
|
@@ -413,7 +402,7 @@ async function connectInner( | |
| ): Promise<[Established, Presentation]> { | ||
| const offered = offer(props.versions); | ||
| const dial = credential(raw, tokens, offered.setupToken); | ||
| const url = dialable(dial.url); | ||
| const url = parse(dial.url).url; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const fallbackDial = props.websocket?.url && fallback(raw, props.websocket.url, tokens, offered.setupToken); | ||
| const wiring = (presented: Presentation): SessionProps => ({ | ||
| publish: props.publish, | ||
|
|
@@ -493,10 +482,10 @@ async function connectInner( | |
|
|
||
| // Record who won the race to this server, so QUIC's next head start follows the last result. | ||
| if (session instanceof Session) { | ||
| console.debug(redact(url), "connected via WebSocket"); | ||
| console.debug(show(parse(url)), "connected via WebSocket"); | ||
| websocketWon.add(server); | ||
| } else { | ||
| console.debug(redact(url), "connected via WebTransport"); | ||
| console.debug(show(parse(url)), "connected via WebTransport"); | ||
| websocketWon.delete(server); | ||
| } | ||
|
|
||
|
|
@@ -561,7 +550,7 @@ async function negotiate( | |
| // The DOM lib has no `protocol` property yet. It is "" when none was negotiated, and | ||
| // undefined in a browser that predates subprotocols (Firefox before 155). | ||
| const protocol: string | undefined = (session as { protocol?: string }).protocol || undefined; | ||
| console.debug(redact(url), "negotiated ALPN:", protocol ?? "(none)"); | ||
| console.debug(show(parse(url)), "negotiated ALPN:", protocol ?? "(none)"); | ||
|
|
||
| const ietf = | ||
| protocol === Ietf.ALPN.DRAFT_22 | ||
|
|
@@ -719,7 +708,7 @@ async function hedgeWebTransport( | |
| (err: unknown) => err instanceof Elapsed, | ||
| ); | ||
| if (!hedge) return first; | ||
| console.debug(redact(url), `WebTransport not open after ${WEBTRANSPORT_HEDGE}ms; dialing a second`); | ||
| console.debug(show(parse(url)), `WebTransport not open after ${WEBTRANSPORT_HEDGE}ms; dialing a second`); | ||
|
|
||
| const dials = [first, connectWebTransport(url, cancel, alpns, options)]; | ||
| try { | ||
|
|
@@ -766,7 +755,10 @@ async function connectWebTransport( | |
| // Dev-only path: http:// can't be a real WebTransport origin, so we fetch the | ||
| // self-signed cert's hash over plain HTTP and pin it. Production uses https:// | ||
| // and never reaches here. Keep this at debug so it doesn't read as a problem. | ||
| console.debug(redact(fingerprintUrl), "performing an insecure fingerprint fetch; use https:// in production"); | ||
| console.debug( | ||
| show(parse(fingerprintUrl)), | ||
| "performing an insecure fingerprint fetch; use https:// in production", | ||
| ); | ||
|
|
||
| const fingerprint = await fetchFingerprint(fingerprintUrl, cancel); | ||
| if (!fingerprint) return undefined; | ||
|
|
@@ -883,7 +875,7 @@ async function connectWebSocket( | |
| if (outcome === "open") return quic; | ||
| quic.close(); | ||
| if (outcome !== "redial") return undefined; | ||
| console.debug(redact(url), `WebSocket not open after ${wait}ms; dialing again`); | ||
| console.debug(show(parse(url)), `WebSocket not open after ${wait}ms; dialing again`); | ||
| } finally { | ||
| disarm.abort(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { isLocal, parse, sameHost, show } from "./endpoint.ts"; | ||
|
|
||
| const local = (url: string) => isLocal(parse(new URL(url))); | ||
|
|
||
| test("local literals are recognized in every spelling the dial accepts", () => { | ||
| const spellings = [ | ||
| "https://127.0.0.1/", | ||
| "https://localhost/", | ||
| "https://localhost./", | ||
| "https://a.localhost/", | ||
| "https://[::1]/", | ||
| "https://[::]/", | ||
| "https://10.0.0.1/", | ||
| "https://172.16.0.1/", | ||
| "https://192.168.1.1/", | ||
| "https://169.254.1.1/", | ||
| "https://0.0.0.0/", | ||
| "https://[::ffff:10.0.0.1]/", | ||
| "https://[fe80::1]/", | ||
| "https://[fc00::1]/", | ||
| "moqt://127.0.0.1/", | ||
| "moqt://[::ffff:127.0.0.1]/", | ||
| // Shorthand, hex, and decimal IPv4, which raw QUIC dials as 127.0.0.1. | ||
| "moql://127.1/", | ||
| "moql://0x7f000001/", | ||
| "moql://2130706433/", | ||
| "moql://0177.0.0.1/", | ||
| "moql://LOCALHOST/", | ||
| "moql://0/", | ||
| ]; | ||
| for (const url of spellings) expect(local(url), url).toBe(true); | ||
|
|
||
| for (const url of ["https://example.com/", "https://8.8.8.8/", "https://172.32.0.1/", "https://[2606:4700::1]/"]) { | ||
| expect(local(url), url).toBe(false); | ||
| } | ||
| expect(local("moql://8.8.8.8/")).toBe(false); | ||
| }); | ||
|
|
||
| test("a URL with no host is refused, since nothing here dials one", () => { | ||
| expect(() => parse(new URL("unix:///tmp/moq.sock"))).toThrow(TypeError); | ||
| expect(() => parse(new URL("moql:relay.example"))).toThrow(TypeError); | ||
| }); | ||
|
|
||
| test("a raw QUIC URL dials over https at the same host, port, and path", () => { | ||
| const endpoint = parse(new URL("moql://user:pass@127.1:4443/room?jwt=secret")); | ||
| expect(endpoint.scheme).toBe("moql"); | ||
| expect(endpoint.host).toEqual({ kind: "ipv4", octets: [127, 0, 0, 1] }); | ||
| expect(endpoint.port).toBe(4443); | ||
| expect(endpoint.url.href).toBe("https://user:pass@127.0.0.1:4443/room?jwt=secret"); | ||
|
|
||
| const plain = new URL("https://relay.example/room"); | ||
| expect(parse(plain).url).toBe(plain); | ||
| expect(parse(new URL("moqt://relay.example")).port).toBe(443); | ||
| expect(parse(new URL("http://relay.example")).port).toBe(80); | ||
| }); | ||
|
|
||
| test("hosts compare as dialed, whatever the scheme or spelling", () => { | ||
| const at = (url: string) => parse(new URL(url)); | ||
| expect(sameHost(at("moql://127.1/"), at("https://127.0.0.1:4443/"))).toBe(true); | ||
| expect(sameHost(at("moqt://[::FFFF:7F00:1]/"), at("https://[::ffff:127.0.0.1]/"))).toBe(true); | ||
| expect(sameHost(at("moql://Relay.Example/"), at("wss://relay.example/"))).toBe(true); | ||
| expect(sameHost(at("https://relay.example/"), at("https://relay.example.com/"))).toBe(false); | ||
| }); | ||
|
|
||
| test("an endpoint shows only its scheme, host, and port", () => { | ||
| const shown = (url: string) => show(parse(new URL(url))); | ||
| expect(shown("https://user:password@relay.example.com/anon/room?jwt=secret#frag")).toBe( | ||
| "https://relay.example.com:443", | ||
| ); | ||
| expect(shown("moql://relay.example:4443/secret-token/room")).toBe("moql://relay.example:4443"); | ||
| expect(shown("http://localhost?jwt=secret")).toBe("http://localhost:80"); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: moq-dev/moq
Length of output: 34617
Script executed:
Repository: moq-dev/moq
Length of output: 41870
Script executed:
Repository: moq-dev/moq
Length of output: 19840
Exclude lite-07 from default selection.
When a client offers lite-07 before lite-06, an unpinned JavaScript server selects lite-07. A Rust server using
Versions::all()selects lite-06. Align the unpinned default while preserving explicit lite-07 pins.As per coding guidelines: “Keep their behavior identical.”