@codemem/core 0.49.0-beta.5 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{coordinator-runtime-BXJQAKFD.js → coordinator-runtime-BYCjEE7A.js} +2 -2
- package/dist/{coordinator-runtime-BXJQAKFD.js.map → coordinator-runtime-BYCjEE7A.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +76 -49
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +1 -1
- package/dist/internal/relay-host.d.ts +1 -0
- package/dist/internal/relay-host.d.ts.map +1 -1
- package/dist/internal/relay-host.js +1 -1
- package/dist/internal/relay-runtime.js +4 -4
- package/dist/{relay-health-zrKtNQLQ.js → relay-health-CeyhVeuq.js} +2 -2
- package/dist/{relay-health-zrKtNQLQ.js.map → relay-health-CeyhVeuq.js.map} +1 -1
- package/dist/relay-health.d.ts.map +1 -1
- package/dist/relay-noise-stream.d.ts +7 -0
- package/dist/relay-noise-stream.d.ts.map +1 -1
- package/dist/{relay-peer-client-DrTb2oZt.js → relay-peer-client-j0rOyeuZ.js} +2537 -2512
- package/dist/{relay-peer-client-DrTb2oZt.js.map → relay-peer-client-j0rOyeuZ.js.map} +1 -1
- package/dist/{relay-server-CLNJrfOV.js → relay-server-TOaojlAm.js} +276 -120
- package/dist/relay-server-TOaojlAm.js.map +1 -0
- package/dist/relay-server-diagnostic.d.ts +108 -0
- package/dist/relay-server-diagnostic.d.ts.map +1 -0
- package/dist/relay-server-test-fixtures.d.ts +2 -2
- package/dist/relay-server-test-fixtures.d.ts.map +1 -1
- package/dist/relay-server.d.ts +7 -2
- package/dist/relay-server.d.ts.map +1 -1
- package/dist/scope-membership-cache.d.ts +1 -0
- package/dist/scope-membership-cache.d.ts.map +1 -1
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/sync-daemon.d.ts.map +1 -1
- package/dist/sync-reachability-pass-5bOMxdoW.js +2 -0
- package/dist/{sync-reachability-pass-CUe5bK61.js → sync-reachability-pass-Co6WjaUD.js} +2 -2
- package/dist/{sync-reachability-pass-CUe5bK61.js.map → sync-reachability-pass-Co6WjaUD.js.map} +1 -1
- package/package.json +3 -3
- package/dist/relay-server-CLNJrfOV.js.map +0 -1
- package/dist/sync-reachability-pass-D9cA54fj.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemem/core",
|
|
3
|
-
"version": "0.49.0
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dist/"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@codemem/embeddings": "^0.49.0
|
|
42
|
+
"@codemem/embeddings": "^0.49.0",
|
|
43
43
|
"@types/better-sqlite3": "^9.6.0",
|
|
44
44
|
"@types/ws": "8.18.1",
|
|
45
45
|
"typescript": "^7.0.2",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"zod": "4.6.6"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@codemem/embeddings": "^0.49.0
|
|
68
|
+
"@codemem/embeddings": "^0.49.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependenciesMeta": {
|
|
71
71
|
"@codemem/embeddings": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relay-server-CLNJrfOV.js","names":[],"sources":["../src/relay-coordinator-client.ts","../src/relay-address-allowance.ts","../src/relay-server-restore.ts","../src/relay-server.ts"],"sourcesContent":["import { decodeRelayCheckPacket } from \"./relay-admission-codec.js\";\nimport type { RelayServerOptions } from \"./relay-server.js\";\n\nexport interface RelayCoordinatorClientOptions {\n\t/** Full configured admission endpoint, including any externally signed mount prefix. */\n\treadonly url: string;\n\t/** Disposable localhost fixtures only. Remote cleartext is never accepted. */\n\treadonly allowLoopbackHttp?: boolean;\n\t/**\n\t * Sends the request instead of global fetch, for example a Workers service binding.\n\t * The URL is still validated and sent unchanged, because the route checks its pathname.\n\t */\n\treadonly fetcher?: { fetch(url: string, init: RequestInit): Promise<Response> };\n}\n\nfunction admissionUrl(options: RelayCoordinatorClientOptions): URL {\n\tconst url = new URL(options.url);\n\tconst loopback = [\"127.0.0.1\", \"[::1]\"].includes(url.hostname);\n\tif (\n\t\t(url.protocol !== \"https:\" &&\n\t\t\t!(url.protocol === \"http:\" && loopback && options.allowLoopbackHttp)) ||\n\t\turl.username ||\n\t\turl.password ||\n\t\turl.search ||\n\t\turl.hash ||\n\t\t!url.pathname.endsWith(\"/v1/relay/admission-check\")\n\t)\n\t\tthrow new Error(\"Invalid relay coordinator endpoint\");\n\treturn url;\n}\n\nasync function readReply(response: Response): Promise<Uint8Array | null> {\n\tconst reader = response.body?.getReader();\n\tif (!reader) return null;\n\tconst bytes = new Uint8Array(1024);\n\tlet size = 0;\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) return bytes.slice(0, size);\n\t\t\tif (size + value.length > bytes.length) return null;\n\t\t\tbytes.set(value, size);\n\t\t\tsize += value.length;\n\t\t}\n\t} finally {\n\t\tvoid reader.cancel().catch(() => {});\n\t\treader.releaseLock();\n\t}\n}\n\n/** Each verifier uses its own configured origin. This client neither retries nor follows redirects. */\nexport function createRelayCoordinatorClient(\n\toptions: RelayCoordinatorClientOptions,\n): RelayServerOptions[\"coordinator\"] {\n\tconst url = admissionUrl(options).href;\n\tconst fetcher = options.fetcher;\n\tconst send = fetcher\n\t\t? (init: RequestInit) => fetcher.fetch(url, init)\n\t\t: (init: RequestInit) => fetch(url, init);\n\t// Workers throws a TypeError for redirect \"error\", including on service-binding\n\t// fetch. A fetcher gets \"manual\" instead: any 3xx reply is a non-200 denial below.\n\tconst redirect: RequestInit[\"redirect\"] = fetcher ? \"manual\" : \"error\";\n\treturn {\n\t\tasync check({ packet, deviceHeader, signal }) {\n\t\t\ttry {\n\t\t\t\tif (signal.aborted) return null;\n\t\t\t\tconst body = decodeRelayCheckPacket(packet).bodyBytes;\n\t\t\t\tconst response = await send({\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tredirect,\n\t\t\t\t\tsignal,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\t\t\"accept-encoding\": \"identity\",\n\t\t\t\t\t\t\"X-Opencode-Device\": deviceHeader,\n\t\t\t\t\t\t\"X-Opencode-Timestamp\": packet.timestamp,\n\t\t\t\t\t\t\"X-Opencode-Nonce\": packet.nonce,\n\t\t\t\t\t\t\"X-Opencode-Signature\": packet.signature,\n\t\t\t\t\t},\n\t\t\t\t\tbody: new Uint8Array(body),\n\t\t\t\t});\n\t\t\t\tif (response.status !== 200) {\n\t\t\t\t\tvoid response.body?.cancel().catch(() => {});\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tconst reply = await readReply(response);\n\t\t\t\treturn signal.aborted ? null : reply;\n\t\t\t} catch {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\t};\n}\n","/**\n * Pre-authentication upgrade fairness per network address (relay operations\n * contract, \"Shedding, health, and switches\"): ten upgrade attempts a minute\n * with a burst of two. Counters live only in memory, expire after a minute of\n * inactivity, and hold at most 4,096 addresses, so a flood of new addresses is\n * refused rather than growing the table. Addresses are never logged or stored.\n */\nexport const RELAY_ADDRESS_BURST = 2;\nexport const RELAY_ADDRESS_REFILL_MS = 6000;\nexport const RELAY_ADDRESS_EXPIRY_MS = 60_000;\nexport const RELAY_ADDRESS_MAX_ENTRIES = 4096;\n/** Unregistered sockets one address may hold at once. */\nexport const RELAY_ADDRESS_PENDING_SOCKETS = 2;\n\n/**\n * The fairness key for a client address. One subscriber usually holds a whole\n * IPv6 /64, so an IPv6 address is keyed by its first four groups; otherwise one\n * host could take a new bucket per address and fill the table. IPv4, including\n * IPv4-mapped IPv6, keys by the full address. Anything unparsable keys as itself.\n * Plain string parsing keeps this free of Node modules for the Workers host.\n */\nexport function relayAddressKey(address: string): string {\n\tconst lower = address.trim().toLowerCase();\n\tconst zone = lower.indexOf(\"%\");\n\tconst trimmed = zone === -1 ? lower : lower.slice(0, zone);\n\tif (!trimmed.includes(\":\")) return trimmed;\n\tconst mapped = /^(?:(?:0{1,4}:){5}|::)ffff:(\\d{1,3}(?:\\.\\d{1,3}){3})$/.exec(trimmed);\n\tif (mapped?.[1]) return mapped[1];\n\tconst groups = expandIPv6(trimmed);\n\treturn groups ? `${groups.slice(0, 4).join(\":\")}::/64` : trimmed;\n}\n\nfunction expandIPv6(address: string): string[] | null {\n\tif (address.includes(\".\")) return null;\n\tconst halves = address.split(\"::\");\n\tif (halves.length > 2) return null;\n\tconst head = halves[0] ? halves[0].split(\":\") : [];\n\tconst tail = halves.length === 2 && halves[1] ? halves[1].split(\":\") : [];\n\tconst missing = 8 - head.length - tail.length;\n\tif (halves.length === 1 ? missing !== 0 : missing < 1) return null;\n\tconst groups = [...head, ...Array<string>(halves.length === 2 ? missing : 0).fill(\"0\"), ...tail];\n\tif (!groups.every((group) => /^[0-9a-f]{1,4}$/.test(group))) return null;\n\treturn groups.map((group) => group.replace(/^0+(?=.)/, \"\"));\n}\n\ninterface Allowance {\n\ttokens: number;\n\tupdated: number;\n}\n\nexport class RelayAddressAllowances {\n\tprivate readonly allowances = new Map<string, Allowance>();\n\n\tconstructor(private readonly now: () => number = () => performance.now()) {}\n\n\t/** Spends one upgrade attempt for the address. False when none is left or the table is full. */\n\ttake(address: string): boolean {\n\t\tconst at = this.now();\n\t\tfor (const [key, allowance] of this.allowances)\n\t\t\tif (at - allowance.updated >= RELAY_ADDRESS_EXPIRY_MS) this.allowances.delete(key);\n\t\tlet allowance = this.allowances.get(address);\n\t\tif (!allowance) {\n\t\t\tif (this.allowances.size >= RELAY_ADDRESS_MAX_ENTRIES) return false;\n\t\t\tallowance = { tokens: RELAY_ADDRESS_BURST, updated: at };\n\t\t\tthis.allowances.set(address, allowance);\n\t\t}\n\t\tallowance.tokens = Math.min(\n\t\t\tRELAY_ADDRESS_BURST,\n\t\t\tallowance.tokens + (at - allowance.updated) / RELAY_ADDRESS_REFILL_MS,\n\t\t);\n\t\tallowance.updated = at;\n\t\tif (allowance.tokens < 1) return false;\n\t\tallowance.tokens -= 1;\n\t\treturn true;\n\t}\n}\n","import { relayDevice, relayExact, relayHex, relayInteger } from \"./relay-control-codec.js\";\n\n/**\n * Bounded registration metadata that a hibernating host may store beside one socket.\n * It holds no packets, signatures, keys, routes, challenges, or queued frames.\n */\nexport interface RelayRegistrationSnapshot {\n\treadonly v: 1;\n\treadonly realmId: string;\n\treadonly deviceId: string;\n\treadonly keyId: string;\n\treadonly acceptedAtUtcMs: number;\n\t/**\n\t * Renewal stays forbidden until this UTC time: `acceptedAtUtcMs + 720000`, with no guard.\n\t * acceptedAtUtcMs is rounded up from the UTC instant the original check started, so on one\n\t * host clock a restored socket never renews before Node would. Disagreement between two host\n\t * clocks can move renewal up to 10 s earlier. That only shifts the renewal rate limit, because\n\t * every renewal is a fresh single-use coordinator check that issues its own lease, while the\n\t * existing lease stays bounded by restoreNotAfterUtcMs, which keeps the guard.\n\t */\n\treadonly renewNotBeforeUtcMs: number;\n\t/** `utcSnapshot + effectiveRemainingMs - 10000` from the relay operations contract. */\n\treadonly restoreNotAfterUtcMs: number;\n}\n\nexport interface RelayRestoredLease {\n\treadonly deviceId: string;\n\treadonly keyId: string;\n\t/** Time left before restoreNotAfterUtcMs, measured on the waking host's UTC clock. */\n\treadonly remainingMs: number;\n\t/** Time left before renewal is allowed, never negative. */\n\treadonly renewInMs: number;\n}\n\n/** Covers two host clocks that are each within five seconds of UTC. */\nexport const RELAY_RESTORE_GUARD_MS = 10_000;\nexport const RELAY_RENEW_AFTER_MS = 720_000;\nconst MAX_LEASE_MS = 900_000;\nconst FIELDS = [\n\t\"v\",\n\t\"realmId\",\n\t\"deviceId\",\n\t\"keyId\",\n\t\"acceptedAtUtcMs\",\n\t\"renewNotBeforeUtcMs\",\n\t\"restoreNotAfterUtcMs\",\n] as const;\n\nfunction utcReading(value: number): number | null {\n\treturn Number.isFinite(value) && value >= 0 ? value : null;\n}\n\n/**\n * Snapshots the remaining monotonic lease and the host UTC clock in the same synchronous turn.\n * Returns null when there is no restorable lease: the UTC clock is unusable, or no more than\n * the 10 s guard remains.\n */\nexport function snapshotRelayRegistration(input: {\n\treadonly realmId: string;\n\treadonly deviceId: string;\n\treadonly keyId: string;\n\treadonly startedMs: number;\n\treadonly expiresMs: number;\n\treadonly nowMs: number;\n\treadonly utcMs: number;\n}): RelayRegistrationSnapshot | null {\n\tconst utc = utcReading(input.utcMs);\n\tif (utc === null || input.expiresMs - input.nowMs <= RELAY_RESTORE_GUARD_MS) return null;\n\t// Rounding moves acceptance later and the restore bound earlier, never the other way.\n\tconst acceptedAtUtcMs = Math.ceil(utc - (input.nowMs - input.startedMs));\n\tconst snapshot: RelayRegistrationSnapshot = {\n\t\tv: 1,\n\t\trealmId: input.realmId,\n\t\tdeviceId: input.deviceId,\n\t\tkeyId: input.keyId,\n\t\tacceptedAtUtcMs,\n\t\trenewNotBeforeUtcMs: acceptedAtUtcMs + RELAY_RENEW_AFTER_MS,\n\t\trestoreNotAfterUtcMs: Math.floor(\n\t\t\tutc + (input.expiresMs - input.nowMs) - RELAY_RESTORE_GUARD_MS,\n\t\t),\n\t};\n\treturn validSnapshot(snapshot, input.realmId) ? snapshot : null;\n}\n\nfunction validSnapshot(value: unknown, realmId: string): value is RelayRegistrationSnapshot {\n\tif (!relayExact(value, FIELDS)) return false;\n\tconst accepted = value.acceptedAtUtcMs;\n\tconst restoreBy = value.restoreNotAfterUtcMs;\n\treturn (\n\t\tvalue.v === 1 &&\n\t\tvalue.realmId === realmId &&\n\t\trelayDevice(value.deviceId) &&\n\t\trelayHex(value.keyId) &&\n\t\trelayInteger(accepted) &&\n\t\trelayInteger(restoreBy) &&\n\t\tvalue.renewNotBeforeUtcMs === accepted + RELAY_RENEW_AFTER_MS &&\n\t\trestoreBy > accepted &&\n\t\trestoreBy - accepted <= MAX_LEASE_MS - RELAY_RESTORE_GUARD_MS\n\t);\n}\n\n/**\n * Reads untrusted host metadata for one socket. Any malformed, foreign, future-dated,\n * or expired snapshot returns null. Remaining time never exceeds the stored UTC bound.\n */\nexport function readRelayRegistrationSnapshot(\n\tvalue: unknown,\n\tcontext: { readonly realmId: string; readonly utcMs: number },\n): RelayRestoredLease | null {\n\tconst utc = utcReading(context.utcMs);\n\tif (utc === null || !validSnapshot(value, context.realmId)) return null;\n\tif (value.acceptedAtUtcMs > utc + RELAY_RESTORE_GUARD_MS) return null;\n\tconst remainingMs = value.restoreNotAfterUtcMs - utc;\n\tif (remainingMs <= 0) return null;\n\treturn {\n\t\tdeviceId: value.deviceId,\n\t\tkeyId: value.keyId,\n\t\tremainingMs,\n\t\trenewInMs: Math.max(0, value.renewNotBeforeUtcMs - utc),\n\t};\n}\n","import {\n\tdecodeRelayCheckPacket,\n\ttype RelayAdmissionBody,\n\ttype RelayCheckPacket,\n\ttype RelayRegistrationBody,\n} from \"./relay-admission-codec.js\";\nimport type { RelayAdmissionBudgetStatus } from \"./relay-admission-decision.js\";\nimport { readRelayAdmissionReply } from \"./relay-admission-reply.js\";\nimport {\n\tdecodeRelayControl,\n\tencodeRelayControl,\n\ttype RelayControl,\n\trelayHex,\n} from \"./relay-control-codec.js\";\nimport { decodeRelayDataFrame } from \"./relay-data-frame.js\";\nimport {\n\tRELAY_RENEW_AFTER_MS,\n\ttype RelayRegistrationSnapshot,\n\treadRelayRegistrationSnapshot,\n\tsnapshotRelayRegistration,\n} from \"./relay-server-restore.js\";\nimport {\n\tcreateRelayServiceProof,\n\ttype RelayServiceSigner,\n\trelayRealmId,\n} from \"./relay-service-proof.js\";\n\nexport interface RelayServerSocket {\n\t/** Calls onWritten exactly once when the adapter no longer owns these bytes, or with an error. */\n\tsendText(json: string, onWritten: (error?: Error) => void): void;\n\t/** Calls onWritten exactly once when the adapter no longer owns these bytes, or with an error. */\n\tsendBinary(frame: Uint8Array, onWritten: (error?: Error) => void): void;\n\tbufferedBytes(): number;\n\tpauseInput(): void;\n\tresumeInput(): void;\n\tclose(): void;\n}\nexport interface RelaySocketEvents {\n\ttext(bytes: Uint8Array): Promise<void>;\n\tbinary(bytes: Uint8Array): void;\n\tclosed(): void;\n\tpending(): boolean;\n}\nexport interface RelayServerLimits {\n\tsockets: number;\n\tpendingSockets: number;\n\troutes: number;\n\tdeviceRoutes: number;\n\tqueuedBytes: number;\n\tdeviceQueuedBytes: number;\n\tcoordinatorTimeoutMs: number;\n\tquotaTimeoutMs: number;\n\t/** Wire bytes per exchange. Unlike other limits, an omitted value means the ceiling. */\n\trouteBytes: number;\n}\nexport interface RelayQuotaPort {\n\t/** Must reserve durable or finite preallocated capacity. Missing or uncertain outcomes deny. */\n\treserve(\n\t\trequest: {\n\t\t\treadonly purpose: \"control\" | \"open\" | \"traffic\";\n\t\t\treadonly realmId: string;\n\t\t\treadonly deviceId: string;\n\t\t\treadonly peerDeviceId: string | null;\n\t\t\treadonly units: number;\n\t\t},\n\t\tsignal: AbortSignal,\n\t): Promise<RelayAdmissionBudgetStatus>;\n}\nexport interface RelayServerOptions {\n\treadonly namespace: {\n\t\treadonly authorityId: string;\n\t\treadonly groupId: string;\n\t\treadonly relayAudienceId: string;\n\t};\n\treadonly limits?: Partial<RelayServerLimits>;\n\treadonly coordinator: {\n\t\tcheck(request: {\n\t\t\treadonly packet: RelayCheckPacket;\n\t\t\treadonly deviceHeader: string;\n\t\t\treadonly signal: AbortSignal;\n\t\t}): Promise<Uint8Array | null>;\n\t};\n\treadonly quota: RelayQuotaPort;\n\treadonly signer: RelayServiceSigner;\n\t/** Defaults to globalThis.performance and Date.now. */\n\treadonly clock?: { monotonicMs(): number; utcMs(): number };\n\t/** Returns `bytes` cryptographically random bytes. Defaults to crypto.getRandomValues. */\n\treadonly random?: (bytes: number) => Uint8Array;\n\t/**\n\t * Runs after a registration is verified and before REGISTERED is sent, so a hibernating\n\t * host can store the snapshot with the socket. A null snapshot means there is no restorable\n\t * lease, because the UTC clock is unusable or no more than the 10 s guard remains. The host must\n\t * then clear any stored copy. Throwing closes the socket.\n\t *\n\t * Host adapters must also clear the stored snapshot when the engine calls `socket.close()`,\n\t * so a socket the engine closed cannot be restored after a later wake.\n\t */\n\treadonly onRegistration?: (\n\t\tsocket: RelayServerSocket,\n\t\tsnapshot: RelayRegistrationSnapshot | null,\n\t) => void;\n}\nconst CEILINGS: RelayServerLimits = {\n\tsockets: 128,\n\tpendingSockets: 16,\n\troutes: 32,\n\tdeviceRoutes: 4,\n\tqueuedBytes: 16 * 1024 * 1024,\n\tdeviceQueuedBytes: 2 * 1024 * 1024,\n\tcoordinatorTimeoutMs: 30_000,\n\tquotaTimeoutMs: 3000,\n\trouteBytes: 20 * 1024 * 1024,\n};\nconst DIRECTION_BYTES = 256 * 1024;\n/** Longest lifetime of any route, from OPEN to forced expiry. */\nconst ROUTE_LIFETIME_MS = 60_000;\n/** First traffic grant per direction. Later grants double up to DIRECTION_BYTES. */\nconst INITIAL_TRAFFIC_GRANT = 16 * 1024;\nconst MAX_FRAME = 65_558;\nconst textBytes = new TextEncoder();\nfunction defaultRandom(bytes: number): Uint8Array {\n\treturn globalThis.crypto.getRandomValues(new Uint8Array(bytes));\n}\nfunction randomHex(random: (bytes: number) => Uint8Array, bytes: number): string {\n\tconst value = random(bytes);\n\tif (!(value instanceof Uint8Array) || value.length !== bytes)\n\t\tthrow new Error(\"Invalid relay random bytes\");\n\treturn Array.from(value, (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\n/** Hosts whose timer handles lack unref, such as Workers, skip it. */\nfunction background(timer: ReturnType<typeof setTimeout>): void {\n\t(timer as { unref?: () => unknown }).unref?.();\n}\ninterface Registration {\n\treadonly deviceId: string;\n\treadonly keyId: string;\n\treadonly expires: number;\n\treadonly started: number;\n}\ninterface Connection {\n\treadonly socket: RelayServerSocket;\n\treadonly cancel: AbortController;\n\treadonly setupExpires: number;\n\tregistration?: Registration;\n\tchallenge?: { readonly id: string; readonly expires: number };\n\tphase: \"service\" | \"signing\" | \"register\" | \"checking\" | \"ready\";\n\tclosing: boolean;\n\tphysicalClosed: boolean;\n\tpending: boolean;\n\tcontrolPending: boolean;\n\treadonly controls: { readonly message: RelayControl; readonly resolve: () => void }[];\n\tpaused: boolean;\n\t/** Application bytes still owned by the adapter, including control text and DATA. */\n\twrites: number;\n\theld: number;\n\ttimer?: ReturnType<typeof setTimeout>;\n\t/** Present only on restored sockets: wake time and sessions already answered with CLOSE abort. */\n\treadonly restored?: { readonly at: number; readonly orphans: Set<string> };\n}\ninterface BufferChange {\n\treadonly additionalBytes?: number;\n\treadonly releasedHeld?: { readonly connection: Connection; readonly bytes: number };\n\treadonly deviceId?: string;\n}\ninterface Direction {\n\tsender: Connection;\n\tcredit: number;\n\t/** Minimum size of the next traffic reservation. */\n\tnextGrant: number;\n\treadonly frames: Uint8Array[];\n\twaiting: boolean;\n\tpendingEnd: boolean;\n\tended: boolean;\n\tendForwarded: boolean;\n\t/** Bytes submitted by this direction whose write callback has not completed. */\n\twrites: number;\n}\ninterface Route {\n\treadonly id: string;\n\treadonly source: Connection;\n\ttarget?: Connection;\n\treadonly context: RelayAdmissionBody;\n\treadonly cancel: AbortController;\n\treadonly directions: readonly [Direction, Direction];\n\texpires: number;\n\taccepted: boolean;\n\tclosed: boolean;\n\tbytes: number;\n\tframes: number;\n\ttimer?: ReturnType<typeof setTimeout>;\n}\n\n/** An unwired, single-namespace state machine. It opens no listeners and supplies no quota implementation. */\nexport function createRelayServer(options: RelayServerOptions) {\n\tconst engine = new RelayServerEngine(options);\n\treturn {\n\t\tadopt: (socket: RelayServerSocket) => engine.adopt(socket),\n\t\t/** Re-adopts a socket after host eviction, or returns null so the host closes it. */\n\t\trestore: (socket: RelayServerSocket, snapshot: unknown) => engine.restore(socket, snapshot),\n\t\tclose: () => engine.close(),\n\t\tcounters: () => engine.counters(),\n\t};\n}\n\nclass RelayServerEngine {\n\tprivate readonly connections = new Set<Connection>();\n\tprivate readonly registrations = new Map<string, Connection>();\n\tprivate readonly routes = new Map<string, Route>();\n\tprivate readonly limits: RelayServerLimits;\n\tprivate readonly namespace: RelayServerOptions[\"namespace\"];\n\tprivate readonly realmId: string;\n\tprivate stopped = false;\n\t/** Live routes aborted because a traffic reservation was denied, uncertain or timed out. */\n\tprivate trafficQuotaAborts = 0;\n\tconstructor(private readonly options: RelayServerOptions) {\n\t\tthis.namespace = Object.freeze({ ...options.namespace });\n\t\tthis.realmId = relayRealmId(this.namespace.authorityId, this.namespace.groupId);\n\t\tif (!relayHex(this.namespace.relayAudienceId)) throw new Error(\"Invalid relay namespace\");\n\t\tthis.limits = { ...CEILINGS };\n\t\tfor (const key of Object.keys(CEILINGS) as (keyof RelayServerLimits)[]) {\n\t\t\tconst value = options.limits?.[key] ?? (key === \"routeBytes\" ? CEILINGS.routeBytes : 0);\n\t\t\tif (!Number.isSafeInteger(value) || value < 0 || value > CEILINGS[key])\n\t\t\t\tthrow new Error(\"Invalid relay limits\");\n\t\t\tthis.limits[key] = value;\n\t\t}\n\t}\n\tprivate now(): number {\n\t\treturn this.options.clock?.monotonicMs() ?? globalThis.performance.now();\n\t}\n\tprivate utc(): number {\n\t\treturn this.options.clock?.utcMs() ?? Date.now();\n\t}\n\tcounters() {\n\t\treturn {\n\t\t\tsockets: this.connections.size,\n\t\t\tpendingSockets: [...this.connections].filter((connection) => connection.pending).length,\n\t\t\troutes: this.routes.size,\n\t\t\tqueuedBytes: this.queuedBytes(),\n\t\t\ttrafficQuotaAborts: this.trafficQuotaAborts,\n\t\t};\n\t}\n\tprivate accepting(): boolean {\n\t\treturn (\n\t\t\t!this.stopped &&\n\t\t\ttypeof this.options.quota?.reserve === \"function\" &&\n\t\t\tObject.values(this.limits).every((value) => value !== 0) &&\n\t\t\tthis.connections.size < this.limits.sockets\n\t\t);\n\t}\n\tadopt(socket: RelayServerSocket): RelaySocketEvents | null {\n\t\tif ([...this.connections].some((connection) => connection.socket === socket)) return null;\n\t\tif (!this.accepting() || this.counters().pendingSockets >= this.limits.pendingSockets)\n\t\t\treturn null;\n\t\tconst connection: Connection = {\n\t\t\tsocket,\n\t\t\tcancel: new AbortController(),\n\t\t\tsetupExpires: this.now() + 30_000,\n\t\t\tphase: \"service\",\n\t\t\tclosing: false,\n\t\t\tphysicalClosed: false,\n\t\t\tpending: true,\n\t\t\tcontrolPending: false,\n\t\t\tcontrols: [],\n\t\t\tpaused: false,\n\t\t\twrites: 0,\n\t\t\theld: 0,\n\t\t};\n\t\tthis.connections.add(connection);\n\t\tthis.armConnection(connection);\n\t\treturn this.events(connection);\n\t}\n\t/** Restores only the registration. Routes, challenges, controls, and frames never survive. */\n\trestore(socket: RelayServerSocket, snapshot: unknown): RelaySocketEvents | null {\n\t\tconst known = [...this.connections].find((connection) => connection.socket === socket);\n\t\tif (known) {\n\t\t\t// A tracked socket cannot be re-adopted. Fail closed instead of merging state.\n\t\t\tthis.disconnect(known);\n\t\t\treturn null;\n\t\t}\n\t\tif (!this.accepting()) return null;\n\t\tconst lease = readRelayRegistrationSnapshot(snapshot, {\n\t\t\trealmId: this.realmId,\n\t\t\tutcMs: this.utc(),\n\t\t});\n\t\tif (!lease) return null;\n\t\tconst claimants = [...this.connections].filter(\n\t\t\t// A closing peer still counts, so no third socket can take the device during teardown.\n\t\t\t(other) => other.registration?.deviceId === lease.deviceId,\n\t\t);\n\t\tif (claimants.length > 0) {\n\t\t\t// Two sockets claiming one device after wake cannot be ordered. Close both.\n\t\t\tfor (const other of claimants) this.disconnect(other);\n\t\t\treturn null;\n\t\t}\n\t\tconst now = this.now();\n\t\tconst registration: Registration = Object.freeze({\n\t\t\tdeviceId: lease.deviceId,\n\t\t\tkeyId: lease.keyId,\n\t\t\tstarted: now + lease.renewInMs - RELAY_RENEW_AFTER_MS,\n\t\t\texpires: now + lease.remainingMs,\n\t\t});\n\t\tconst connection: Connection = {\n\t\t\tsocket,\n\t\t\tcancel: new AbortController(),\n\t\t\tsetupExpires: now,\n\t\t\tregistration,\n\t\t\tphase: \"ready\",\n\t\t\tclosing: false,\n\t\t\tphysicalClosed: false,\n\t\t\tpending: false,\n\t\t\tcontrolPending: false,\n\t\t\tcontrols: [],\n\t\t\tpaused: false,\n\t\t\twrites: 0,\n\t\t\theld: 0,\n\t\t\trestored: { at: now, orphans: new Set() },\n\t\t};\n\t\tthis.connections.add(connection);\n\t\tthis.registrations.set(registration.deviceId, connection);\n\t\treturn this.events(connection);\n\t}\n\tprivate events(connection: Connection): RelaySocketEvents {\n\t\treturn {\n\t\t\tpending: () => connection.pending && !connection.closing,\n\t\t\ttext: (bytes) => this.text(connection, bytes),\n\t\t\tbinary: (bytes) => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.binary(connection, bytes);\n\t\t\t\t} catch {\n\t\t\t\t\tthis.disconnect(connection);\n\t\t\t\t}\n\t\t\t},\n\t\t\tclosed: () => {\n\t\t\t\tconnection.physicalClosed = true;\n\t\t\t\tthis.disconnect(connection);\n\t\t\t\tthis.connections.delete(connection);\n\t\t\t},\n\t\t};\n\t}\n\tclose(): void {\n\t\tthis.stopped = true;\n\t\tfor (const connection of this.connections) this.disconnect(connection);\n\t}\n\tprivate live(connection: Connection): boolean {\n\t\tif (connection.closing || this.stopped) return false;\n\t\tif (connection.pending && this.now() >= connection.setupExpires) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn false;\n\t\t}\n\t\tif (connection.registration && this.now() >= connection.registration.expires) {\n\t\t\tif (this.registrations.get(connection.registration.deviceId) === connection)\n\t\t\t\tthis.registrations.delete(connection.registration.deviceId);\n\t\t}\n\t\tif (connection.challenge && this.now() >= connection.challenge.expires) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\tprivate registered(connection: Connection): Registration | null {\n\t\tif (!this.live(connection)) return null;\n\t\tconst registration = connection.registration;\n\t\tif (\n\t\t\t!registration ||\n\t\t\tthis.now() >= registration.expires ||\n\t\t\tthis.registrations.get(registration.deviceId) !== connection\n\t\t)\n\t\t\treturn null;\n\t\treturn registration;\n\t}\n\tprivate armConnection(connection: Connection): void {\n\t\tif (connection.timer) clearTimeout(connection.timer);\n\t\tconst deadlines: number[] = [];\n\t\tif (connection.pending) deadlines.push(connection.setupExpires);\n\t\tif (connection.challenge) deadlines.push(connection.challenge.expires);\n\t\t// Registration expiry is checked lazily, so an idle registered socket arms no timer.\n\t\tif (connection.closing || deadlines.length === 0) return;\n\t\tconnection.timer = setTimeout(\n\t\t\t() => {\n\t\t\t\tif (this.live(connection)) this.armConnection(connection);\n\t\t\t},\n\t\t\tMath.max(1, Math.ceil(Math.min(...deadlines) - this.now())),\n\t\t);\n\t\tbackground(connection.timer);\n\t}\n\tprivate disconnect(connection: Connection): void {\n\t\tif (connection.closing) return;\n\t\tconnection.closing = true;\n\t\tconnection.cancel.abort();\n\t\tfor (const control of connection.controls.splice(0)) control.resolve();\n\t\tif (connection.timer) clearTimeout(connection.timer);\n\t\tconst registration = connection.registration;\n\t\tif (registration && this.registrations.get(registration.deviceId) === connection)\n\t\t\tthis.registrations.delete(registration.deviceId);\n\t\tfor (const route of this.routes.values())\n\t\t\tif (route.source === connection || route.target === connection)\n\t\t\t\tthis.removeRoute(route, \"abort\");\n\t\ttry {\n\t\t\tif (connection.paused) connection.socket.resumeInput();\n\t\t\tconnection.socket.close();\n\t\t} catch {\n\t\t\t/* Physical slots remain charged until closed(). */\n\t\t}\n\t}\n\tprivate send(connection: Connection, message: RelayControl): void {\n\t\tif (!this.live(connection)) return;\n\t\ttry {\n\t\t\tconst json = encodeRelayControl(message);\n\t\t\tconst bytes = textBytes.encode(json).byteLength;\n\t\t\tif (!this.withinBuffers(connection, { additionalBytes: bytes })) {\n\t\t\t\tthis.disconnect(connection);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconnection.writes += bytes;\n\t\t\tlet written = false;\n\t\t\tconnection.socket.sendText(json, (error) => {\n\t\t\t\tif (written) return;\n\t\t\t\twritten = true;\n\t\t\t\tconnection.writes -= bytes;\n\t\t\t\tif (error) this.disconnect(connection);\n\t\t\t\tthis.updatePressure();\n\t\t\t});\n\t\t\tif (!this.withinBuffers(connection)) this.disconnect(connection);\n\t\t} catch {\n\t\t\t// A throwing adapter may still own text bytes until its callback or physical close.\n\t\t\tthis.disconnect(connection);\n\t\t}\n\t}\n\tprivate reject(connection: Connection, session: string): void {\n\t\tthis.send(connection, { v: 1, type: \"REJECTED\", session, body: {} });\n\t}\n\tprivate contextMatches(body: RelayRegistrationBody | RelayAdmissionBody): boolean {\n\t\treturn (\n\t\t\tbody.authorityId === this.namespace.authorityId &&\n\t\t\tbody.groupId === this.namespace.groupId &&\n\t\t\tbody.relayAudienceId === this.namespace.relayAudienceId\n\t\t);\n\t}\n\tprivate async bounded<T>(\n\t\tsignal: AbortSignal,\n\t\ttimeout: number,\n\t\toperation: (signal: AbortSignal) => Promise<T>,\n\t): Promise<T | null> {\n\t\tif (signal.aborted || timeout <= 0) return null;\n\t\tconst controller = new AbortController();\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet cancel = () => {};\n\t\ttry {\n\t\t\treturn await new Promise<T | null>((resolve) => {\n\t\t\t\tconst finish = (value: T | null) => {\n\t\t\t\t\tresolve(value);\n\t\t\t\t\tcontroller.abort();\n\t\t\t\t};\n\t\t\t\tcancel = () => finish(null);\n\t\t\t\tsignal.addEventListener(\"abort\", cancel, { once: true });\n\t\t\t\ttimer = setTimeout(cancel, timeout);\n\t\t\t\tbackground(timer);\n\t\t\t\tPromise.resolve()\n\t\t\t\t\t.then(() => {\n\t\t\t\t\t\tif (controller.signal.aborted) return null;\n\t\t\t\t\t\treturn operation(controller.signal);\n\t\t\t\t\t})\n\t\t\t\t\t.then(finish, () => finish(null));\n\t\t\t});\n\t\t} catch {\n\t\t\treturn null;\n\t\t} finally {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\tsignal.removeEventListener(\"abort\", cancel);\n\t\t\tcontroller.abort();\n\t\t}\n\t}\n\tprivate async quota(\n\t\tconnection: Connection,\n\t\tpurpose: \"control\" | \"open\" | \"traffic\",\n\t\tunits: number,\n\t\tsignal: AbortSignal,\n\t\tpeerDeviceId: string | null = null,\n\t): Promise<boolean> {\n\t\t// Empty identity spends only the trusted realm's pre-registration control allocation.\n\t\tconst deviceId = connection.registration?.deviceId ?? \"\";\n\t\tconst status = await this.bounded(signal, this.limits.quotaTimeoutMs, (abort) =>\n\t\t\tthis.options.quota.reserve(\n\t\t\t\t{ purpose, realmId: this.realmId, deviceId, peerDeviceId, units },\n\t\t\t\tabort,\n\t\t\t),\n\t\t);\n\t\treturn status === \"reserved\" && !signal.aborted && this.live(connection);\n\t}\n\tprivate async text(connection: Connection, bytes: Uint8Array): Promise<void> {\n\t\ttry {\n\t\t\tif (!this.live(connection)) return;\n\t\t\tconst message = decodeRelayControl(bytes);\n\t\t\tif (\n\t\t\t\tconnection.pending &&\n\t\t\t\t(connection.controlPending ||\n\t\t\t\t\t(connection.phase === \"service\" && message.type !== \"SERVICE_CHALLENGE\") ||\n\t\t\t\t\t(connection.phase === \"register\" && message.type !== \"REGISTER\"))\n\t\t\t) {\n\t\t\t\tthis.disconnect(connection);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (message.type === \"OPEN\" && !connection.controlPending) {\n\t\t\t\tawait this.open(connection, message);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.capturePendingEnd(connection, message);\n\t\t\tif (\n\t\t\t\tconnection.controls.length + Number(connection.controlPending) >=\n\t\t\t\tthis.limits.deviceRoutes + 1\n\t\t\t) {\n\t\t\t\tthis.disconnect(connection);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tconnection.controls.push({ message, resolve });\n\t\t\t\tthis.nextControl(connection);\n\t\t\t});\n\t\t} catch {\n\t\t\tthis.disconnect(connection);\n\t\t}\n\t}\n\tprivate nextControl(connection: Connection): void {\n\t\tif (connection.controlPending || !this.live(connection)) return;\n\t\tconst control = connection.controls.shift();\n\t\tif (!control) return;\n\t\tconnection.controlPending = true;\n\t\tvoid this.runControl(connection, control.message).finally(() => {\n\t\t\tconnection.controlPending = false;\n\t\t\tcontrol.resolve();\n\t\t\tthis.nextControl(connection);\n\t\t});\n\t}\n\tprivate async runControl(connection: Connection, message: RelayControl): Promise<void> {\n\t\ttry {\n\t\t\tif (!(await this.quota(connection, \"control\", 1, connection.cancel.signal))) {\n\t\t\t\tthis.disconnect(connection);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait this.control(connection, message);\n\t\t} catch {\n\t\t\tthis.disconnect(connection);\n\t\t}\n\t}\n\tprivate capturePendingEnd(connection: Connection, message: RelayControl): void {\n\t\tif (message.type !== \"CLOSE\" || message.body.mode !== \"end\") return;\n\t\tconst route = this.routes.get(message.session);\n\t\tif (!route?.accepted || (connection !== route.source && connection !== route.target)) return;\n\t\tconst direction = route.directions[Number(connection === route.target)];\n\t\tif (direction) direction.pendingEnd = true;\n\t}\n\tprivate async control(connection: Connection, message: RelayControl): Promise<void> {\n\t\tswitch (message.type) {\n\t\t\tcase \"OPEN\":\n\t\t\t\t// Busy OPENs remain denials, but their replies spend control quota first.\n\t\t\t\tthis.reject(connection, message.session);\n\t\t\t\treturn;\n\t\t\tcase \"SERVICE_CHALLENGE\":\n\t\t\t\tawait this.service(connection, message);\n\t\t\t\treturn;\n\t\t\tcase \"REGISTER\":\n\t\t\t\tawait this.register(connection, message);\n\t\t\t\treturn;\n\t\t\tcase \"ACCEPTED\":\n\t\t\tcase \"REJECTED\":\n\t\t\tcase \"CLOSE\":\n\t\t\t\tthis.routeControl(connection, message);\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\tthis.disconnect(connection);\n\t\t}\n\t}\n\tprivate async service(\n\t\tconnection: Connection,\n\t\tmessage: Extract<RelayControl, { type: \"SERVICE_CHALLENGE\" }>,\n\t): Promise<void> {\n\t\tif (\n\t\t\t(connection.phase !== \"service\" && connection.phase !== \"ready\") ||\n\t\t\tmessage.body.audienceId !== this.namespace.relayAudienceId ||\n\t\t\t(connection.registration &&\n\t\t\t\tthis.now() < connection.registration.started + RELAY_RENEW_AFTER_MS)\n\t\t) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconnection.phase = \"signing\";\n\t\tconst body = await this.bounded(\n\t\t\tconnection.cancel.signal,\n\t\t\tthis.limits.coordinatorTimeoutMs,\n\t\t\t() =>\n\t\t\t\tcreateRelayServiceProof({\n\t\t\t\t\taudienceId: this.namespace.relayAudienceId,\n\t\t\t\t\tchallengeId: message.session,\n\t\t\t\t\tutcMs: this.utc(),\n\t\t\t\t\tsigner: this.options.signer,\n\t\t\t\t}),\n\t\t);\n\t\tif (!body || !this.live(connection)) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tthis.send(connection, { v: 1, type: \"SERVICE_PROOF\", session: message.session, body });\n\t\tif (!this.live(connection)) return;\n\t\tconnection.challenge = {\n\t\t\tid: randomHex(this.options.random ?? defaultRandom, 16),\n\t\t\texpires: this.now() + 30_000,\n\t\t};\n\t\tconnection.phase = \"register\";\n\t\tthis.send(connection, {\n\t\t\tv: 1,\n\t\t\ttype: \"SOCKET_CHALLENGE\",\n\t\t\tsession: connection.challenge.id,\n\t\t\tbody: {},\n\t\t});\n\t\tthis.armConnection(connection);\n\t}\n\tprivate async check(connection: Connection, packet: RelayCheckPacket, signal: AbortSignal) {\n\t\tconst started = this.now();\n\t\tconst decoded = decodeRelayCheckPacket(packet);\n\t\tlet deviceHeader: string;\n\t\tif (decoded.kind === \"registration\") deviceHeader = decoded.value.deviceId;\n\t\telse deviceHeader = decoded.value.sourceDeviceId;\n\t\tconst bytes = await this.bounded(signal, this.limits.coordinatorTimeoutMs, (abort) =>\n\t\t\tthis.options.coordinator.check({ packet, deviceHeader, signal: abort }),\n\t\t);\n\t\tif (!bytes || signal.aborted || !this.live(connection)) return null;\n\t\tconst reply = readRelayAdmissionReply(bytes, packet);\n\t\tif (!reply || this.now() >= started + reply.remainingMs) return null;\n\t\treturn { started, expires: started + reply.remainingMs };\n\t}\n\tprivate async register(\n\t\tconnection: Connection,\n\t\tmessage: Extract<RelayControl, { type: \"REGISTER\" }>,\n\t): Promise<void> {\n\t\tconst check = decodeRelayCheckPacket(message.body);\n\t\tconst challenge = connection.challenge;\n\t\tif (\n\t\t\tconnection.phase !== \"register\" ||\n\t\t\t!challenge ||\n\t\t\tcheck.kind !== \"registration\" ||\n\t\t\tmessage.session !== challenge.id ||\n\t\t\tcheck.value.socketChallengeId !== challenge.id ||\n\t\t\t!this.contextMatches(check.value) ||\n\t\t\t(connection.registration &&\n\t\t\t\t(connection.registration.deviceId !== check.value.deviceId ||\n\t\t\t\t\tconnection.registration.keyId !== check.value.keyId))\n\t\t) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconnection.phase = \"checking\";\n\t\t// Retain the challenge deadline while the single-use request is in flight.\n\t\tconst grant = await this.check(connection, message.body, connection.cancel.signal);\n\t\tif (!grant || !this.live(connection)) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconst identity = check.value;\n\t\tthis.completeRegistration(\n\t\t\tconnection,\n\t\t\tObject.freeze({\n\t\t\t\tdeviceId: identity.deviceId,\n\t\t\t\tkeyId: identity.keyId,\n\t\t\t\tstarted: grant.started,\n\t\t\t\texpires: grant.expires,\n\t\t\t}),\n\t\t\tmessage.session,\n\t\t);\n\t}\n\tprivate completeRegistration(\n\t\tconnection: Connection,\n\t\tregistration: Registration,\n\t\tsession: string,\n\t): void {\n\t\tconst peers = [...this.connections].filter(\n\t\t\t(other) => other !== connection && other.registration?.deviceId === registration.deviceId,\n\t\t);\n\t\tconst hadClosingPeer = peers.some((other) => other.closing);\n\t\t// A verified key change invalidates old routes even when the replacement cannot fit.\n\t\tfor (const other of peers)\n\t\t\tif (other.registration?.keyId !== registration.keyId) this.disconnect(other);\n\t\tif (hadClosingPeer || peers.length > 1) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconst reply: RelayControl = {\n\t\t\tv: 1,\n\t\t\ttype: \"REGISTERED\",\n\t\t\tsession,\n\t\t\tbody: {\n\t\t\t\tdeviceId: registration.deviceId,\n\t\t\t\tkeyId: registration.keyId,\n\t\t\t\tauthorityId: this.namespace.authorityId,\n\t\t\t\trealmId: this.realmId,\n\t\t\t\tremainingMs: Math.floor(registration.expires - this.now()),\n\t\t\t},\n\t\t};\n\t\tif (\n\t\t\t!this.withinBuffers(connection, {\n\t\t\t\tdeviceId: registration.deviceId,\n\t\t\t\tadditionalBytes: textBytes.encode(encodeRelayControl(reply)).byteLength,\n\t\t\t})\n\t\t) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tif (!this.announceRegistration(connection, registration)) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tfor (const other of peers) this.disconnect(other);\n\t\tconnection.registration = registration;\n\t\tconnection.challenge = undefined;\n\t\tconnection.pending = false;\n\t\tconnection.phase = \"ready\";\n\t\tthis.registrations.set(registration.deviceId, connection);\n\t\tthis.send(connection, reply);\n\t\tthis.armConnection(connection);\n\t}\n\tprivate announceRegistration(connection: Connection, registration: Registration): boolean {\n\t\tconst hook = this.options.onRegistration;\n\t\tif (!hook) return true;\n\t\ttry {\n\t\t\thook(\n\t\t\t\tconnection.socket,\n\t\t\t\tsnapshotRelayRegistration({\n\t\t\t\t\trealmId: this.realmId,\n\t\t\t\t\tdeviceId: registration.deviceId,\n\t\t\t\t\tkeyId: registration.keyId,\n\t\t\t\t\tstartedMs: registration.started,\n\t\t\t\t\texpiresMs: registration.expires,\n\t\t\t\t\tnowMs: this.now(),\n\t\t\t\t\tutcMs: this.utc(),\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\tprivate reserveRoute(\n\t\tconnection: Connection,\n\t\tmessage: Extract<RelayControl, { type: \"OPEN\" }>,\n\t): Route | null {\n\t\tconst source = this.registered(connection);\n\t\tconst check = decodeRelayCheckPacket(message.body.checks[0]);\n\t\tif (\n\t\t\t!source ||\n\t\t\tcheck.kind !== \"admission\" ||\n\t\t\t!this.contextMatches(check.value) ||\n\t\t\tsource.deviceId !== check.value.sourceDeviceId ||\n\t\t\tsource.keyId !== check.value.sourceKeyId ||\n\t\t\tthis.routes.has(message.session) ||\n\t\t\tthis.routes.size >= this.limits.routes\n\t\t)\n\t\t\treturn null;\n\t\tconst context = check.value;\n\t\tfor (const device of [context.sourceDeviceId, context.targetDeviceId]) {\n\t\t\tconst count = [...this.routes.values()].filter((route) =>\n\t\t\t\t[route.context.sourceDeviceId, route.context.targetDeviceId].includes(device),\n\t\t\t).length;\n\t\t\tif (count >= this.limits.deviceRoutes) return null;\n\t\t}\n\t\tif (\n\t\t\t[...this.routes.values()].some(\n\t\t\t\t(route) =>\n\t\t\t\t\troute.context.sourceDeviceId === context.sourceDeviceId &&\n\t\t\t\t\troute.context.targetDeviceId === context.targetDeviceId,\n\t\t\t)\n\t\t)\n\t\t\treturn null;\n\t\tconst direction = (sender: Connection): Direction => ({\n\t\t\tsender,\n\t\t\tcredit: 0,\n\t\t\tnextGrant: INITIAL_TRAFFIC_GRANT,\n\t\t\tframes: [],\n\t\t\twaiting: false,\n\t\t\tpendingEnd: false,\n\t\t\tended: false,\n\t\t\tendForwarded: false,\n\t\t\twrites: 0,\n\t\t});\n\t\tconst route: Route = {\n\t\t\tid: message.session,\n\t\t\tsource: connection,\n\t\t\tcontext,\n\t\t\tcancel: new AbortController(),\n\t\t\tdirections: [direction(connection), direction(connection)],\n\t\t\texpires: this.now() + ROUTE_LIFETIME_MS,\n\t\t\taccepted: false,\n\t\t\tclosed: false,\n\t\t\tbytes: 0,\n\t\t\tframes: 0,\n\t\t};\n\t\tthis.routes.set(route.id, route);\n\t\tthis.armRoute(route);\n\t\treturn route;\n\t}\n\tprivate async open(\n\t\tconnection: Connection,\n\t\tmessage: Extract<RelayControl, { type: \"OPEN\" }>,\n\t): Promise<void> {\n\t\tconst route = this.reserveRoute(connection, message);\n\t\tconnection.controlPending = true;\n\t\ttry {\n\t\t\tif (!(await this.quota(connection, \"control\", 1, connection.cancel.signal))) {\n\t\t\t\tthis.disconnect(connection);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!route) {\n\t\t\t\tthis.reject(connection, message.session);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!(await this.quota(\n\t\t\t\t\tconnection,\n\t\t\t\t\t\"open\",\n\t\t\t\t\t1,\n\t\t\t\t\troute.cancel.signal,\n\t\t\t\t\troute.context.targetDeviceId,\n\t\t\t\t))\n\t\t\t) {\n\t\t\t\tthis.removeRoute(route, \"reject\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t} finally {\n\t\t\tconnection.controlPending = false;\n\t\t\tthis.nextControl(connection);\n\t\t}\n\t\t// A reserved route bounds coordinator work without blocking other routes' controls.\n\t\tawait this.admitRoute(connection, message, route);\n\t}\n\tprivate async admitRoute(\n\t\tconnection: Connection,\n\t\tmessage: Extract<RelayControl, { type: \"OPEN\" }>,\n\t\troute: Route,\n\t): Promise<void> {\n\t\tconst grant = await this.check(connection, message.body.checks[0], route.cancel.signal);\n\t\tif (!grant || !this.routeLive(route) || !this.registered(connection)) {\n\t\t\tthis.removeRoute(route, \"reject\");\n\t\t\treturn;\n\t\t}\n\t\troute.expires = Math.min(route.expires, grant.expires);\n\t\tif (!this.routeLive(route)) return;\n\t\t// Presence lookup follows this relay's independent positive coordinator decision.\n\t\tconst target = this.registrations.get(route.context.targetDeviceId);\n\t\tconst registration = target && this.registered(target);\n\t\tif (\n\t\t\t!target ||\n\t\t\ttarget === connection ||\n\t\t\t!registration ||\n\t\t\tregistration.keyId !== route.context.targetKeyId\n\t\t) {\n\t\t\tthis.removeRoute(route, \"reject\");\n\t\t\treturn;\n\t\t}\n\t\troute.target = target;\n\t\troute.directions[1].sender = target;\n\t\tthis.armRoute(route);\n\t\tthis.send(target, message);\n\t}\n\tprivate routeLive(route: Route): boolean {\n\t\tif (route.closed) return false;\n\t\tif (this.now() >= route.expires) {\n\t\t\tthis.removeRoute(route, route.accepted ? \"abort\" : \"reject\");\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\tprivate armRoute(route: Route): void {\n\t\tif (route.timer) clearTimeout(route.timer);\n\t\troute.timer = setTimeout(\n\t\t\t() => {\n\t\t\t\tif (this.routeLive(route)) this.armRoute(route);\n\t\t\t},\n\t\t\tMath.max(1, Math.ceil(route.expires - this.now())),\n\t\t);\n\t\tbackground(route.timer);\n\t}\n\tprivate routeControl(connection: Connection, message: RelayControl): void {\n\t\tconst route = this.routes.get(message.session);\n\t\tif (!route || !this.routeLive(route)) return;\n\t\tif (connection !== route.source && connection !== route.target) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tif (message.type === \"CLOSE\") {\n\t\t\tif (message.body.mode === \"abort\" || !route.accepted) {\n\t\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst direction = route.directions[Number(connection === route.target)];\n\t\t\tif (!direction || direction.ended) {\n\t\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdirection.ended = true;\n\t\t\tthis.flushEnd(route, direction);\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tconnection !== route.target ||\n\t\t\troute.accepted ||\n\t\t\t(message.type !== \"ACCEPTED\" && message.type !== \"REJECTED\")\n\t\t) {\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\treturn;\n\t\t}\n\t\tif (message.type === \"REJECTED\") {\n\t\t\tthis.removeRoute(route, \"reject\");\n\t\t\treturn;\n\t\t}\n\t\troute.accepted = true;\n\t\tthis.send(route.source, { v: 1, type: \"ACCEPTED\", session: route.id, body: {} });\n\t}\n\tprivate removeRoute(route: Route, mode: \"abort\" | \"reject\" | \"clean\"): void {\n\t\tif (route.closed) return;\n\t\troute.closed = true;\n\t\tthis.routes.delete(route.id);\n\t\troute.cancel.abort();\n\t\tif (route.timer) clearTimeout(route.timer);\n\t\tfor (const direction of route.directions) {\n\t\t\tfor (const frame of direction.frames) direction.sender.held -= frame.length;\n\t\t\tdirection.frames.length = 0;\n\t\t\tdirection.waiting = false;\n\t\t}\n\t\tif (mode === \"reject\") this.reject(route.source, route.id);\n\t\tif (mode === \"abort\")\n\t\t\tfor (const connection of [route.source, route.target])\n\t\t\t\tif (connection)\n\t\t\t\t\tthis.send(connection, {\n\t\t\t\t\t\tv: 1,\n\t\t\t\t\t\ttype: \"CLOSE\",\n\t\t\t\t\t\tsession: route.id,\n\t\t\t\t\t\tbody: { mode: \"abort\" },\n\t\t\t\t\t});\n\t\tthis.updatePressure();\n\t}\n\tprivate binary(connection: Connection, bytes: Uint8Array): void {\n\t\tif (!this.live(connection)) return;\n\t\tif (connection.pending) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconst frame = decodeRelayDataFrame(bytes);\n\t\tconst route = this.routes.get(frame.sessionId);\n\t\tif (!route) {\n\t\t\tthis.orphan(connection, frame.sessionId);\n\t\t\treturn;\n\t\t}\n\t\tif (!this.routeLive(route)) return;\n\t\tif (connection !== route.source && connection !== route.target) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconst direction = route.directions[Number(connection === route.target)];\n\t\tif (\n\t\t\t!route.accepted ||\n\t\t\t!direction ||\n\t\t\tdirection.pendingEnd ||\n\t\t\tdirection.ended ||\n\t\t\t++route.frames > 2048 ||\n\t\t\tbytes.length > this.limits.routeBytes - route.bytes\n\t\t) {\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\treturn;\n\t\t}\n\t\troute.bytes += bytes.length;\n\t\t// Already-parsed socket batches may arrive after pauseInput. Charge every retained copy.\n\t\tconnection.held += bytes.length;\n\t\tif (\n\t\t\t!this.withinBuffers(connection) ||\n\t\t\tthis.directionQueued(direction) + bytes.length > DIRECTION_BYTES\n\t\t) {\n\t\t\tconnection.held -= bytes.length;\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\treturn;\n\t\t}\n\t\tdirection.frames.push(new Uint8Array(bytes));\n\t\tthis.drainDirection(route, direction);\n\t}\n\t/** Restored sockets may still send DATA for routes lost with the evicted instance. */\n\tprivate orphan(connection: Connection, session: string): void {\n\t\t// After the longest lifetime of a lost route, unknown DATA is a protocol error as on Node.\n\t\tconst restored = connection.restored;\n\t\tif (!restored || this.now() >= restored.at + ROUTE_LIFETIME_MS) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tconst orphans = restored.orphans;\n\t\tif (orphans.has(session)) return;\n\t\tif (orphans.size >= this.limits.deviceRoutes) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\torphans.add(session);\n\t\tvoid this.abortOrphan(connection, session).catch(() => this.disconnect(connection));\n\t}\n\tprivate async abortOrphan(connection: Connection, session: string): Promise<void> {\n\t\t// The reply spends control quota like any other server-originated control.\n\t\tif (!(await this.quota(connection, \"control\", 1, connection.cancel.signal))) {\n\t\t\tthis.disconnect(connection);\n\t\t\treturn;\n\t\t}\n\t\tthis.send(connection, { v: 1, type: \"CLOSE\", session, body: { mode: \"abort\" } });\n\t}\n\tprivate drainDirection(route: Route, direction: Direction): void {\n\t\tif (!this.routeLive(route) || direction.waiting) return;\n\t\twhile (direction.frames[0] && direction.credit >= direction.frames[0].length) {\n\t\t\tthis.forward(route, direction);\n\t\t\tif (route.closed) return;\n\t\t}\n\t\tif (direction.frames.length > 0) {\n\t\t\tdirection.waiting = true;\n\t\t\tvoid this.reserveTraffic(route, direction).catch(() => this.removeRoute(route, \"abort\"));\n\t\t} else this.flushEnd(route, direction);\n\t\tthis.updatePressure();\n\t}\n\tprivate async reserveTraffic(route: Route, direction: Direction): Promise<void> {\n\t\tconst peer =\n\t\t\tdirection.sender === route.source\n\t\t\t\t? route.context.targetDeviceId\n\t\t\t\t: route.context.sourceDeviceId;\n\t\tconst queued = direction.frames.reduce((sum, frame) => sum + frame.length, 0);\n\t\t// Small exchanges spend roughly their actual size. Sustained transfers grow\n\t\t// toward full-size grants so the reservation count stays logarithmic.\n\t\tconst units = Math.min(\n\t\t\tDIRECTION_BYTES,\n\t\t\tthis.limits.routeBytes - route.bytes + queued,\n\t\t\tMath.max(queued, direction.nextGrant),\n\t\t);\n\t\tconst reserved = await this.quota(\n\t\t\tdirection.sender,\n\t\t\t\"traffic\",\n\t\t\tunits,\n\t\t\troute.cancel.signal,\n\t\t\tpeer,\n\t\t);\n\t\tif (!this.routeLive(route)) return;\n\t\tdirection.waiting = false;\n\t\tif (!reserved) {\n\t\t\tthis.trafficQuotaAborts++;\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\treturn;\n\t\t}\n\t\tdirection.credit += units;\n\t\tdirection.nextGrant = Math.min(DIRECTION_BYTES, units * 2);\n\t\tthis.drainDirection(route, direction);\n\t}\n\tprivate recipient(route: Route, direction: Direction): Connection | undefined {\n\t\tif (direction.sender === route.source) return route.target;\n\t\treturn route.source;\n\t}\n\tprivate forward(route: Route, direction: Direction): void {\n\t\tconst bytes = direction.frames[0];\n\t\tconst target = this.recipient(route, direction);\n\t\tif (!bytes || !target || !this.routeLive(route)) return;\n\t\tif (\n\t\t\t!this.live(target) ||\n\t\t\t!this.withinBuffers(target, {\n\t\t\t\tadditionalBytes: bytes.length,\n\t\t\t\treleasedHeld: { connection: direction.sender, bytes: bytes.length },\n\t\t\t}) ||\n\t\t\tthis.directionQueued(direction) > DIRECTION_BYTES\n\t\t) {\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\treturn;\n\t\t}\n\t\tdirection.frames.shift();\n\t\tdirection.sender.held -= bytes.length;\n\t\tdirection.credit -= bytes.length;\n\t\tdirection.writes += bytes.length;\n\t\ttarget.writes += bytes.length;\n\t\tif (!this.withinBuffers(target) || this.directionQueued(direction) > DIRECTION_BYTES) {\n\t\t\ttarget.writes -= bytes.length;\n\t\t\tdirection.writes -= bytes.length;\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\treturn;\n\t\t}\n\t\tlet written = false;\n\t\ttry {\n\t\t\ttarget.socket.sendBinary(bytes, (error) => {\n\t\t\t\tif (written) return;\n\t\t\t\twritten = true;\n\t\t\t\ttarget.writes -= bytes.length;\n\t\t\t\tdirection.writes -= bytes.length;\n\t\t\t\tif (error) this.removeRoute(route, \"abort\");\n\t\t\t\telse if (this.routeLive(route)) this.flushEnd(route, direction);\n\t\t\t\tthis.updatePressure();\n\t\t\t});\n\t\t\tif (!this.withinBuffers(target) || this.directionQueued(direction) > DIRECTION_BYTES)\n\t\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\tthis.updatePressure();\n\t\t} catch {\n\t\t\t// A throwing adapter may already own the frame. Only its callback or closure releases it.\n\t\t\tthis.removeRoute(route, \"abort\");\n\t\t\tthis.disconnect(target);\n\t\t}\n\t}\n\tprivate flushEnd(route: Route, direction: Direction): void {\n\t\tif (\n\t\t\tdirection.ended &&\n\t\t\tdirection.frames.length === 0 &&\n\t\t\t!direction.waiting &&\n\t\t\tdirection.writes === 0 &&\n\t\t\t!direction.endForwarded\n\t\t) {\n\t\t\tdirection.endForwarded = true;\n\t\t\tconst target = this.recipient(route, direction);\n\t\t\tif (target)\n\t\t\t\tthis.send(target, { v: 1, type: \"CLOSE\", session: route.id, body: { mode: \"end\" } });\n\t\t}\n\t\tif (route.directions.every((entry) => entry.endForwarded && entry.writes === 0))\n\t\t\tthis.removeRoute(route, \"clean\");\n\t}\n\tprivate socketBytes(connection: Connection): number {\n\t\t// Physical closure releases adapter writes, while route cleanup still owns held frames.\n\t\tif (connection.physicalClosed) return connection.held;\n\t\ttry {\n\t\t\tconst bytes = connection.socket.bufferedBytes();\n\t\t\tif (!Number.isSafeInteger(bytes) || bytes < 0) return Number.POSITIVE_INFINITY;\n\t\t\treturn Math.max(connection.writes, bytes) + connection.held;\n\t\t} catch {\n\t\t\treturn Number.POSITIVE_INFINITY;\n\t\t}\n\t}\n\tprivate queuedBytes(): number {\n\t\tlet total = 0;\n\t\tfor (const connection of this.connections) total += this.socketBytes(connection);\n\t\treturn total;\n\t}\n\tprivate withinBuffers(connection: Connection, change: BufferChange = {}): boolean {\n\t\tconst additional = change.additionalBytes ?? 0;\n\t\tconst deviceId = change.deviceId ?? connection.registration?.deviceId;\n\t\tlet total = additional;\n\t\tlet deviceBytes = additional;\n\t\tfor (const current of this.connections) {\n\t\t\tlet bytes = this.socketBytes(current);\n\t\t\tif (change.releasedHeld?.connection === current) bytes -= change.releasedHeld.bytes;\n\t\t\tif (bytes < 0) return false;\n\t\t\ttotal += bytes;\n\t\t\tconst currentDevice = current === connection ? deviceId : current.registration?.deviceId;\n\t\t\tif (deviceId !== undefined && currentDevice === deviceId) deviceBytes += bytes;\n\t\t}\n\t\treturn (\n\t\t\ttotal <= this.limits.queuedBytes &&\n\t\t\t(deviceId === undefined || deviceBytes <= this.limits.deviceQueuedBytes)\n\t\t);\n\t}\n\tprivate directionQueued(direction: Direction): number {\n\t\treturn direction.frames.reduce((sum, frame) => sum + frame.length, direction.writes);\n\t}\n\tprivate updatePressure(): void {\n\t\tfor (const connection of this.connections) {\n\t\t\tif (connection.closing) continue;\n\t\t\tconst pressure = [...this.routes.values()].some((route) =>\n\t\t\t\troute.directions.some(\n\t\t\t\t\t(direction) =>\n\t\t\t\t\t\tdirection.sender === connection &&\n\t\t\t\t\t\t(direction.waiting || this.directionQueued(direction) >= DIRECTION_BYTES - MAX_FRAME),\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (pressure === connection.paused) continue;\n\t\t\tconnection.paused = pressure;\n\t\t\ttry {\n\t\t\t\tif (pressure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