@cardonjs/realtime-do 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +804 -2
- package/dist/client.d.ts +65 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +338 -0
- package/dist/client.js.map +1 -0
- package/dist/connect.d.ts +29 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +83 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/presence.d.ts +68 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +88 -0
- package/dist/presence.js.map +1 -0
- package/dist/protocol.d.ts +70 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +106 -0
- package/dist/protocol.js.map +1 -0
- package/dist/publisher.d.ts +39 -0
- package/dist/publisher.d.ts.map +1 -0
- package/dist/publisher.js +101 -0
- package/dist/publisher.js.map +1 -0
- package/dist/room.d.ts +58 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +604 -0
- package/dist/room.js.map +1 -0
- package/dist/testing.d.ts +65 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +99 -0
- package/dist/testing.js.map +1 -0
- package/dist/ticket.d.ts +64 -0
- package/dist/ticket.d.ts.map +1 -0
- package/dist/ticket.js +178 -0
- package/dist/ticket.js.map +1 -0
- package/dist/validation.d.ts +46 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +113 -0
- package/dist/validation.js.map +1 -0
- package/llms.txt +233 -0
- package/package.json +59 -3
package/dist/room.js
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room: a plain Durable Object class (no `cloudflare:workers` import, no RPC) that holds
|
|
3
|
+
* hibernating WebSockets. The Worker talks to it with `stub.fetch` on internal URLs.
|
|
4
|
+
*
|
|
5
|
+
* Nothing about a connection lives in instance memory: channels and the identity (hashed) are
|
|
6
|
+
* the socket's tags, everything else is in its attachment, and revocation markers are in
|
|
7
|
+
* Durable Object storage, so the room behaves the same after the runtime evicts the instance
|
|
8
|
+
* and wakes it again for the next event. The only in-memory value is a cache (the earliest
|
|
9
|
+
* expiry), rebuilt by a full sweep after a wake-up.
|
|
10
|
+
*/
|
|
11
|
+
import { presenceRecord, selectPresence, validPresenceQuery, } from "./presence.js";
|
|
12
|
+
import { CLOSE_DISCONNECTED, CLOSE_PROTOCOL, CLOSE_REAUTHENTICATE, CONNECT_HEADER, IDENTITY_TAG_PREFIX, identityTag, PATH, TICKET_KEY_PREFIX, ticketKey, validIdentity, } from "./protocol.js";
|
|
13
|
+
import { assertValidChannels, assertValidRoom, DEFAULT_MAX_EVENT_BYTES, eventFrame, MAX_EVENT_BYTES_LIMIT, TICKET_PATTERN, TICKET_PROTOCOL, validEvent, } from "./validation.js";
|
|
14
|
+
const OPEN = 1;
|
|
15
|
+
/** Cloudflare's limit of hibernatable WebSockets per object. */
|
|
16
|
+
const MAX_CONNECTIONS_LIMIT = 32_768;
|
|
17
|
+
const MAX_AGE_LIMIT = 604_800;
|
|
18
|
+
/** How long `disconnect` refuses new connections of the identity. */
|
|
19
|
+
const REVOCATION_WINDOW_MS = 60_000;
|
|
20
|
+
/** Storage key prefix of revocation markers; the rest is the identity tag (a hash). */
|
|
21
|
+
const REVOKED_PREFIX = "revoked:";
|
|
22
|
+
/** `storage.delete` takes at most 128 keys. */
|
|
23
|
+
const DELETE_BATCH = 128;
|
|
24
|
+
/** Pending (unused, unexpired) tickets per room and per identity in a room. */
|
|
25
|
+
const MAX_PENDING_TICKETS = 1000;
|
|
26
|
+
const MAX_PENDING_TICKETS_PER_IDENTITY = 5;
|
|
27
|
+
const MIN_TICKET_TTL_SECONDS = 5;
|
|
28
|
+
const MAX_TICKET_TTL_SECONDS = 120;
|
|
29
|
+
const isTime = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
30
|
+
/** The entry for an issue request (`PATH.ticket`); throws on anything malformed. */
|
|
31
|
+
function validTicketRequest(body, now) {
|
|
32
|
+
if (body === undefined || Array.isArray(body))
|
|
33
|
+
throw new TypeError("ticket request");
|
|
34
|
+
const { room, identity, channels, ttlSeconds, connectionExpiresAt } = body;
|
|
35
|
+
assertValidRoom(room);
|
|
36
|
+
assertValidChannels(channels);
|
|
37
|
+
const valid = validIdentity(identity);
|
|
38
|
+
if (typeof ttlSeconds !== "number" ||
|
|
39
|
+
!Number.isInteger(ttlSeconds) ||
|
|
40
|
+
ttlSeconds < MIN_TICKET_TTL_SECONDS ||
|
|
41
|
+
ttlSeconds > MAX_TICKET_TTL_SECONDS) {
|
|
42
|
+
throw new TypeError("ticket ttl");
|
|
43
|
+
}
|
|
44
|
+
if (connectionExpiresAt !== undefined && !isTime(connectionExpiresAt)) {
|
|
45
|
+
throw new TypeError("ticket connection expiry");
|
|
46
|
+
}
|
|
47
|
+
const ttlEnd = now + ttlSeconds * 1000;
|
|
48
|
+
// A ticket never outlives the credential it was exchanged for.
|
|
49
|
+
const expiresAt = connectionExpiresAt === undefined ? ttlEnd : Math.min(ttlEnd, connectionExpiresAt);
|
|
50
|
+
// An entry nobody could use is never stored.
|
|
51
|
+
if (expiresAt <= now)
|
|
52
|
+
throw new TypeError("ticket already expired");
|
|
53
|
+
return {
|
|
54
|
+
v: 1,
|
|
55
|
+
room,
|
|
56
|
+
identity: { id: valid.id, kind: valid.kind },
|
|
57
|
+
channels: [...channels],
|
|
58
|
+
expiresAt,
|
|
59
|
+
...(connectionExpiresAt === undefined ? {} : { connectionExpiresAt }),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** A stored entry read back, or `undefined` when it is missing or malformed. */
|
|
63
|
+
function storedTicket(value) {
|
|
64
|
+
if (typeof value !== "object" || value === null)
|
|
65
|
+
return undefined;
|
|
66
|
+
const entry = value;
|
|
67
|
+
try {
|
|
68
|
+
if (entry.v !== 1 || !isTime(entry.expiresAt))
|
|
69
|
+
return undefined;
|
|
70
|
+
if (entry.connectionExpiresAt !== undefined && !isTime(entry.connectionExpiresAt)) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
assertValidRoom(entry.room);
|
|
74
|
+
assertValidChannels(entry.channels);
|
|
75
|
+
const identity = validIdentity(entry.identity);
|
|
76
|
+
return { ...entry, identity, channels: [...entry.channels] };
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const sameIdentity = (a, b) => a.id === b.id && a.kind === b.kind;
|
|
83
|
+
/** `crt_` and 32 random bytes in base64url without padding. */
|
|
84
|
+
function newTicket() {
|
|
85
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
86
|
+
let binary = "";
|
|
87
|
+
for (const byte of bytes)
|
|
88
|
+
binary += String.fromCharCode(byte);
|
|
89
|
+
return `crt_${btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`;
|
|
90
|
+
}
|
|
91
|
+
/** Every ticket failure: no detail, so a caller cannot tell unknown from used or expired. */
|
|
92
|
+
const refusedTicket = () => json({ error: "ticket" }, 401);
|
|
93
|
+
/** A ticket request to a room that is not SQLite-backed (the helpers turn it into an Error). */
|
|
94
|
+
const noSqlite = () => json({ error: "sqlite" }, 501);
|
|
95
|
+
function integerOption(name, value, fallback, min, max) {
|
|
96
|
+
if (value === undefined)
|
|
97
|
+
return fallback;
|
|
98
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
|
|
99
|
+
throw new TypeError(`defineRoom: ${name} must be an integer from ${min} to ${max}.`);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
function hookOption(name, value) {
|
|
104
|
+
if (value !== undefined && typeof value !== "function") {
|
|
105
|
+
throw new TypeError(`defineRoom: ${name} must be a function.`);
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
function validConfig(options) {
|
|
110
|
+
if (options !== undefined && (typeof options !== "object" || options === null)) {
|
|
111
|
+
throw new TypeError("defineRoom: options must be an object.");
|
|
112
|
+
}
|
|
113
|
+
const o = options ?? {};
|
|
114
|
+
const maxConnections = integerOption("maxConnections", o.maxConnections, 1000, 1, MAX_CONNECTIONS_LIMIT);
|
|
115
|
+
return {
|
|
116
|
+
maxConnections,
|
|
117
|
+
maxConnectionsPerIdentity: integerOption("maxConnectionsPerIdentity", o.maxConnectionsPerIdentity, Math.min(5, maxConnections), 1, maxConnections),
|
|
118
|
+
maxEventBytes: integerOption("maxEventBytes", o.maxEventBytes, DEFAULT_MAX_EVENT_BYTES, 256, MAX_EVENT_BYTES_LIMIT),
|
|
119
|
+
maxAgeMs: integerOption("maxConnectionAgeSeconds", o.maxConnectionAgeSeconds, 3600, 1, MAX_AGE_LIMIT) *
|
|
120
|
+
1000,
|
|
121
|
+
onConnect: hookOption("onConnect", o.onConnect),
|
|
122
|
+
onDisconnect: hookOption("onDisconnect", o.onDisconnect),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function readAttachment(ws) {
|
|
126
|
+
try {
|
|
127
|
+
const value = ws.deserializeAttachment();
|
|
128
|
+
if (value === null || typeof value !== "object" || value.v !== 1)
|
|
129
|
+
return undefined;
|
|
130
|
+
if (typeof value.exp !== "number")
|
|
131
|
+
return undefined;
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function closeQuietly(ws, code, reason) {
|
|
139
|
+
try {
|
|
140
|
+
ws.close(code, reason);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Already closed.
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function json(body, status = 200) {
|
|
147
|
+
return Response.json(body, { status });
|
|
148
|
+
}
|
|
149
|
+
const notFound = () => new Response(null, { status: 404 });
|
|
150
|
+
const badRequest = () => new Response(null, { status: 400 });
|
|
151
|
+
async function readJson(request) {
|
|
152
|
+
try {
|
|
153
|
+
const body = (await request.json());
|
|
154
|
+
return typeof body === "object" && body !== null
|
|
155
|
+
? body
|
|
156
|
+
: undefined;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Logs a hook failure without the identity or the error message (they may hold personal data). */
|
|
163
|
+
function logHookFailure(hook, error) {
|
|
164
|
+
const name = error instanceof Error ? error.name : typeof error;
|
|
165
|
+
console.error(`realtime-do: the ${hook} hook failed (${name}).`);
|
|
166
|
+
}
|
|
167
|
+
/** Returns the Durable Object class the project exports from its Worker entry. */
|
|
168
|
+
export function defineRoom(options) {
|
|
169
|
+
const config = validConfig(options);
|
|
170
|
+
return class Room {
|
|
171
|
+
#state;
|
|
172
|
+
#env;
|
|
173
|
+
/**
|
|
174
|
+
* Cache: no open socket expires before this time (epoch ms). `undefined` after a wake-up,
|
|
175
|
+
* which forces one full sweep. Correctness never depends on it: it only skips sweeps.
|
|
176
|
+
*/
|
|
177
|
+
#nextExpiry;
|
|
178
|
+
/** The synchronous storage, `null` when the class is not SQLite-backed; probed once. */
|
|
179
|
+
#kv;
|
|
180
|
+
constructor(state, env) {
|
|
181
|
+
this.#state = state;
|
|
182
|
+
this.#env = env;
|
|
183
|
+
// Answered by the runtime without waking the object.
|
|
184
|
+
state.setWebSocketAutoResponse(new WebSocketRequestResponsePair("ping", "pong"));
|
|
185
|
+
}
|
|
186
|
+
async fetch(request) {
|
|
187
|
+
const { pathname } = new URL(request.url);
|
|
188
|
+
if (request.method === "GET" && pathname === PATH.connect)
|
|
189
|
+
return this.#connect(request);
|
|
190
|
+
if (request.method === "POST" && pathname === PATH.publish)
|
|
191
|
+
return this.#publish(request);
|
|
192
|
+
if (request.method === "GET" && pathname === PATH.count) {
|
|
193
|
+
this.#expire();
|
|
194
|
+
return json({ count: this.#open().length });
|
|
195
|
+
}
|
|
196
|
+
if (request.method === "POST" && pathname === PATH.disconnect) {
|
|
197
|
+
return this.#disconnect(request);
|
|
198
|
+
}
|
|
199
|
+
if (request.method === "POST" && pathname === PATH.presence)
|
|
200
|
+
return this.#presence(request);
|
|
201
|
+
if (request.method === "POST" && pathname === PATH.ticket)
|
|
202
|
+
return this.#issueTicket(request);
|
|
203
|
+
if (request.method === "GET" && pathname === PATH.ticketConnect) {
|
|
204
|
+
return this.#connectWithTicket(request);
|
|
205
|
+
}
|
|
206
|
+
return notFound();
|
|
207
|
+
}
|
|
208
|
+
/** Clients only send `"ping"` (answered by the auto-response); anything else is a violation. */
|
|
209
|
+
async webSocketMessage(ws, _message) {
|
|
210
|
+
closeQuietly(ws, CLOSE_PROTOCOL, "Unexpected message");
|
|
211
|
+
}
|
|
212
|
+
async webSocketClose(ws) {
|
|
213
|
+
await this.#gone(ws);
|
|
214
|
+
}
|
|
215
|
+
async webSocketError(ws) {
|
|
216
|
+
await this.#gone(ws);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The synchronous storage API, or `null` on a room that is not SQLite-backed: there,
|
|
220
|
+
* workerd still returns `storage.kv`, but every call on it throws. Only tickets need it.
|
|
221
|
+
*/
|
|
222
|
+
#syncKv() {
|
|
223
|
+
if (this.#kv === undefined) {
|
|
224
|
+
try {
|
|
225
|
+
const kv = this.#state.storage.kv;
|
|
226
|
+
kv.get(TICKET_KEY_PREFIX); // throws without SQLite; never a ticket key
|
|
227
|
+
this.#kv = kv;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
this.#kv = null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return this.#kv;
|
|
234
|
+
}
|
|
235
|
+
/** The identity tag the socket was accepted with, if the runtime can still tell. */
|
|
236
|
+
#identityTagOf(ws) {
|
|
237
|
+
try {
|
|
238
|
+
return this.#state.getTags(ws).find((tag) => tag.startsWith(IDENTITY_TAG_PREFIX));
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** Open sockets: what `count()` and the hooks report, and what receives events. */
|
|
245
|
+
#open(tag) {
|
|
246
|
+
return this.#state.getWebSockets(tag).filter((ws) => ws.readyState === OPEN);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Lazy expiry (there is no alarm): sockets past their age must re-authenticate. Skipped
|
|
250
|
+
* while no socket can have expired yet; a full sweep rebuilds that bound.
|
|
251
|
+
*/
|
|
252
|
+
#expire() {
|
|
253
|
+
const now = Date.now();
|
|
254
|
+
if (this.#nextExpiry !== undefined && now < this.#nextExpiry)
|
|
255
|
+
return;
|
|
256
|
+
let next = Number.POSITIVE_INFINITY;
|
|
257
|
+
for (const ws of this.#open()) {
|
|
258
|
+
const attachment = readAttachment(ws);
|
|
259
|
+
if (attachment === undefined || attachment.exp <= now) {
|
|
260
|
+
closeQuietly(ws, CLOSE_REAUTHENTICATE, "Re-authenticate");
|
|
261
|
+
}
|
|
262
|
+
else if (attachment.exp < next) {
|
|
263
|
+
next = attachment.exp;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
this.#nextExpiry = next;
|
|
267
|
+
}
|
|
268
|
+
/** True while a `disconnect` of this identity is less than the window old. */
|
|
269
|
+
async #revoked(tag) {
|
|
270
|
+
const key = REVOKED_PREFIX + tag;
|
|
271
|
+
const at = await this.#state.storage.get(key);
|
|
272
|
+
if (at === undefined)
|
|
273
|
+
return false;
|
|
274
|
+
if (typeof at === "number" && Date.now() - at < REVOCATION_WINDOW_MS)
|
|
275
|
+
return true;
|
|
276
|
+
// Expired: delete it lazily. Not awaited, so the caller's checks and accept follow the
|
|
277
|
+
// read with no other await in between (writes apply to the storage cache at once).
|
|
278
|
+
this.#state.storage.delete(key).catch(() => undefined);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
async #connect(request) {
|
|
282
|
+
if (request.headers.get("upgrade")?.toLowerCase() !== "websocket")
|
|
283
|
+
return badRequest();
|
|
284
|
+
let room;
|
|
285
|
+
let identity;
|
|
286
|
+
let channels;
|
|
287
|
+
try {
|
|
288
|
+
const raw = JSON.parse(request.headers.get(CONNECT_HEADER) ?? "");
|
|
289
|
+
assertValidRoom(raw?.room);
|
|
290
|
+
assertValidChannels(raw?.channels);
|
|
291
|
+
room = raw.room;
|
|
292
|
+
identity = validIdentity(raw?.identity);
|
|
293
|
+
channels = [...raw.channels];
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
return badRequest();
|
|
297
|
+
}
|
|
298
|
+
return this.#accept(room, identity, channels);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Issues a ticket: stored under its hash (`ticketKey`), answered once. The caps count only
|
|
302
|
+
* unexpired tickets; expired ones are deleted here.
|
|
303
|
+
*/
|
|
304
|
+
async #issueTicket(request) {
|
|
305
|
+
const kv = this.#syncKv();
|
|
306
|
+
if (kv === null)
|
|
307
|
+
return noSqlite();
|
|
308
|
+
const body = await readJson(request);
|
|
309
|
+
let entry;
|
|
310
|
+
try {
|
|
311
|
+
entry = validTicketRequest(body, Date.now());
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
return badRequest();
|
|
315
|
+
}
|
|
316
|
+
// Every await (hashing) comes first. From the revocation check to the write, only
|
|
317
|
+
// synchronous calls: no other request of this room runs in between, so a `disconnect`
|
|
318
|
+
// either ran before (its marker is seen here; an unawaited `storage.put` is already in
|
|
319
|
+
// what `kv.get` reads, checked against workerd) or runs after (and deletes this ticket),
|
|
320
|
+
// and the caps hold under concurrent issues.
|
|
321
|
+
const tag = await identityTag(entry.identity);
|
|
322
|
+
const ticket = newTicket();
|
|
323
|
+
const key = await ticketKey(ticket);
|
|
324
|
+
const now = Date.now();
|
|
325
|
+
const revokedAt = kv.get(REVOKED_PREFIX + tag);
|
|
326
|
+
if (typeof revokedAt === "number" && now - revokedAt < REVOCATION_WINDOW_MS) {
|
|
327
|
+
return json({ error: "limit" }, 429);
|
|
328
|
+
}
|
|
329
|
+
let total = 0;
|
|
330
|
+
let ofIdentity = 0;
|
|
331
|
+
// Read in full before deleting: no delete while the storage cursor is open.
|
|
332
|
+
for (const [pendingKey, pending] of [...kv.list({ prefix: TICKET_KEY_PREFIX })]) {
|
|
333
|
+
const stored = storedTicket(pending);
|
|
334
|
+
if (stored === undefined || stored.expiresAt <= now) {
|
|
335
|
+
kv.delete(pendingKey);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
total++;
|
|
339
|
+
if (sameIdentity(stored.identity, entry.identity))
|
|
340
|
+
ofIdentity++;
|
|
341
|
+
}
|
|
342
|
+
if (total >= MAX_PENDING_TICKETS || ofIdentity >= MAX_PENDING_TICKETS_PER_IDENTITY) {
|
|
343
|
+
return json({ error: "limit" }, 429);
|
|
344
|
+
}
|
|
345
|
+
kv.put(key, entry);
|
|
346
|
+
return json({ ticket, expiresAt: entry.expiresAt });
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Consumes the ticket, then connects like `#connect` with what it was issued for. Every
|
|
350
|
+
* ticket failure is the same 401; the ticket is used up even when the connect is refused.
|
|
351
|
+
*/
|
|
352
|
+
async #connectWithTicket(request) {
|
|
353
|
+
if (request.headers.get("upgrade")?.toLowerCase() !== "websocket")
|
|
354
|
+
return badRequest();
|
|
355
|
+
const kv = this.#syncKv();
|
|
356
|
+
if (kv === null)
|
|
357
|
+
return noSqlite();
|
|
358
|
+
let room;
|
|
359
|
+
let ticket;
|
|
360
|
+
try {
|
|
361
|
+
const raw = JSON.parse(request.headers.get(CONNECT_HEADER) ?? "");
|
|
362
|
+
assertValidRoom(raw?.room);
|
|
363
|
+
room = raw.room;
|
|
364
|
+
ticket = raw?.ticket;
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return badRequest();
|
|
368
|
+
}
|
|
369
|
+
if (typeof ticket !== "string" || !TICKET_PATTERN.test(ticket))
|
|
370
|
+
return refusedTicket();
|
|
371
|
+
const key = await ticketKey(ticket);
|
|
372
|
+
// Single use: the read and the delete are synchronous calls in one turn of this event, so
|
|
373
|
+
// no other request of the room (a Durable Object runs one JavaScript turn at a time) can
|
|
374
|
+
// read the entry between them. Two connects with one ticket: exactly one finds it.
|
|
375
|
+
const raw = kv.get(key);
|
|
376
|
+
if (raw !== undefined)
|
|
377
|
+
kv.delete(key);
|
|
378
|
+
const stored = storedTicket(raw);
|
|
379
|
+
if (stored === undefined || stored.expiresAt <= Date.now() || stored.room !== room) {
|
|
380
|
+
return refusedTicket();
|
|
381
|
+
}
|
|
382
|
+
// The client offered subprotocols, so the 101 must select one or a browser fails it.
|
|
383
|
+
return this.#accept(room, stored.identity, stored.channels, stored.connectionExpiresAt, TICKET_PROTOCOL);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* The revocation check, the caps and the accept, shared by both connects. `notAfter` (epoch
|
|
387
|
+
* ms) caps the socket's expiry; it never extends `maxConnectionAgeSeconds`. `protocol` is
|
|
388
|
+
* the subprotocol the 101 selects.
|
|
389
|
+
*/
|
|
390
|
+
async #accept(room, identity, channels, notAfter, protocol) {
|
|
391
|
+
const tag = await identityTag(identity);
|
|
392
|
+
if (await this.#revoked(tag))
|
|
393
|
+
return json({ error: "limit" }, 429);
|
|
394
|
+
// No await from here to the accept, so the checks and the accept run as one step: no
|
|
395
|
+
// other connect or disconnect of this room can run in between.
|
|
396
|
+
this.#expire();
|
|
397
|
+
// The caps count every socket the runtime still holds, open or closing: a peer that never
|
|
398
|
+
// answers a close frame must not be able to pile up sockets.
|
|
399
|
+
if (this.#state.getWebSockets().length >= config.maxConnections ||
|
|
400
|
+
this.#state.getWebSockets(tag).length >= config.maxConnectionsPerIdentity) {
|
|
401
|
+
return json({ error: "limit" }, 429);
|
|
402
|
+
}
|
|
403
|
+
const connections = this.#open().length + 1;
|
|
404
|
+
const identityConnections = this.#open(tag).length + 1;
|
|
405
|
+
const pair = new WebSocketPair();
|
|
406
|
+
const server = pair[1];
|
|
407
|
+
// At most 8 channels + 1 identity tag (74 ASCII characters): within the platform's 10
|
|
408
|
+
// tags of up to 256 bytes.
|
|
409
|
+
this.#state.acceptWebSocket(server, [...channels, tag]);
|
|
410
|
+
const at = Date.now();
|
|
411
|
+
// Jittered age in [90 %, 100 %] of the maximum, never above it; earlier if the ticket's
|
|
412
|
+
// credential expires first.
|
|
413
|
+
const aged = at + Math.floor(config.maxAgeMs * (0.9 + Math.random() * 0.1));
|
|
414
|
+
const exp = notAfter === undefined ? aged : Math.min(aged, notAfter);
|
|
415
|
+
const attachment = {
|
|
416
|
+
v: 1,
|
|
417
|
+
room,
|
|
418
|
+
id: identity.id,
|
|
419
|
+
kind: identity.kind,
|
|
420
|
+
channels,
|
|
421
|
+
at,
|
|
422
|
+
exp,
|
|
423
|
+
};
|
|
424
|
+
server.serializeAttachment(attachment);
|
|
425
|
+
if (this.#nextExpiry !== undefined)
|
|
426
|
+
this.#nextExpiry = Math.min(this.#nextExpiry, exp);
|
|
427
|
+
if (config.onConnect) {
|
|
428
|
+
try {
|
|
429
|
+
await config.onConnect({
|
|
430
|
+
room,
|
|
431
|
+
identity,
|
|
432
|
+
channels: Object.freeze([...channels]),
|
|
433
|
+
connectedAt: new Date(at),
|
|
434
|
+
connections,
|
|
435
|
+
identityConnections,
|
|
436
|
+
env: this.#env,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
logHookFailure("onConnect", error);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return new Response(null, {
|
|
444
|
+
status: 101,
|
|
445
|
+
webSocket: pair[0],
|
|
446
|
+
...(protocol === undefined ? {} : { headers: { "sec-websocket-protocol": protocol } }),
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
async #publish(request) {
|
|
450
|
+
const body = await readJson(request);
|
|
451
|
+
let frame;
|
|
452
|
+
let channel;
|
|
453
|
+
try {
|
|
454
|
+
const event = validEvent(body?.event, config.maxEventBytes);
|
|
455
|
+
frame = eventFrame(event);
|
|
456
|
+
channel = event.channel;
|
|
457
|
+
}
|
|
458
|
+
catch {
|
|
459
|
+
return badRequest();
|
|
460
|
+
}
|
|
461
|
+
this.#expire();
|
|
462
|
+
let delivered = 0;
|
|
463
|
+
for (const ws of this.#open(channel)) {
|
|
464
|
+
try {
|
|
465
|
+
ws.send(frame);
|
|
466
|
+
delivered++;
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
// One failed socket does not stop the others; its close event will follow.
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return json({ delivered });
|
|
473
|
+
}
|
|
474
|
+
async #disconnect(request) {
|
|
475
|
+
const body = await readJson(request);
|
|
476
|
+
let identity;
|
|
477
|
+
try {
|
|
478
|
+
identity = validIdentity(body?.identity);
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
return badRequest();
|
|
482
|
+
}
|
|
483
|
+
const tag = await identityTag(identity);
|
|
484
|
+
const now = Date.now();
|
|
485
|
+
// The marker first, then the close, with no await between: a connect of this identity
|
|
486
|
+
// either was accepted already (and is closed here) or sees the marker.
|
|
487
|
+
const written = this.#state.storage.put(REVOKED_PREFIX + tag, now);
|
|
488
|
+
let closed = 0;
|
|
489
|
+
for (const ws of this.#open(tag)) {
|
|
490
|
+
closeQuietly(ws, CLOSE_DISCONNECTED, "Disconnected");
|
|
491
|
+
closed++;
|
|
492
|
+
}
|
|
493
|
+
// Its pending tickets too: one could otherwise be used once the window is over. A room
|
|
494
|
+
// that is not SQLite-backed holds no tickets (and its synchronous storage throws).
|
|
495
|
+
const kv = this.#syncKv();
|
|
496
|
+
if (kv !== null) {
|
|
497
|
+
for (const [key, pending] of [...kv.list({ prefix: TICKET_KEY_PREFIX })]) {
|
|
498
|
+
const stored = storedTicket(pending);
|
|
499
|
+
if (stored === undefined || sameIdentity(stored.identity, identity))
|
|
500
|
+
kv.delete(key);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
await written;
|
|
504
|
+
await this.#pruneMarkers(now);
|
|
505
|
+
return json({ closed });
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Open connections with their identity, channels, connect time and last answered `"ping"`.
|
|
509
|
+
* Read from the attachments and the runtime's auto-response timestamps: nothing is stored.
|
|
510
|
+
*/
|
|
511
|
+
async #presence(request) {
|
|
512
|
+
const body = await readJson(request);
|
|
513
|
+
if (body === undefined || Array.isArray(body))
|
|
514
|
+
return badRequest();
|
|
515
|
+
let query;
|
|
516
|
+
try {
|
|
517
|
+
query = validPresenceQuery(body.query);
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
return badRequest();
|
|
521
|
+
}
|
|
522
|
+
// The identity tag narrows the listing to that identity's few sockets; the channel tag
|
|
523
|
+
// otherwise. The expiry below may still sweep the whole room (bounded by maxConnections).
|
|
524
|
+
const tag = query.identity !== undefined ? await identityTag(query.identity) : query.channel;
|
|
525
|
+
// No await from here on: what is listed is one consistent view of the room.
|
|
526
|
+
this.#expire();
|
|
527
|
+
const now = Date.now();
|
|
528
|
+
const records = [];
|
|
529
|
+
for (const ws of this.#open(tag)) {
|
|
530
|
+
const attachment = readAttachment(ws);
|
|
531
|
+
if (attachment === undefined || attachment.done)
|
|
532
|
+
continue;
|
|
533
|
+
const pinged = this.#state.getWebSocketAutoResponseTimestamp(ws)?.getTime();
|
|
534
|
+
try {
|
|
535
|
+
// Checked like the publisher checks the answer (identity, channels, times), so one
|
|
536
|
+
// malformed attachment is skipped instead of making the whole answer invalid.
|
|
537
|
+
records.push(presenceRecord({
|
|
538
|
+
identity: { id: attachment.id, kind: attachment.kind },
|
|
539
|
+
channels: attachment.channels,
|
|
540
|
+
connectedAt: attachment.at,
|
|
541
|
+
lastSeenAt: typeof pinged === "number" && typeof attachment.at === "number"
|
|
542
|
+
? Math.max(attachment.at, pinged)
|
|
543
|
+
: attachment.at,
|
|
544
|
+
}));
|
|
545
|
+
}
|
|
546
|
+
catch {
|
|
547
|
+
// Not listed. Never logged: the attachment holds the identity id.
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// The shared selection applies both filters (so `identity` with `channel` intersect),
|
|
551
|
+
// the activity window, the order and the limit.
|
|
552
|
+
const selected = selectPresence(records, query, now);
|
|
553
|
+
return json({ connections: selected.records, total: selected.total });
|
|
554
|
+
}
|
|
555
|
+
/** Deletes revocation markers older than the window (other identities' included). */
|
|
556
|
+
async #pruneMarkers(now) {
|
|
557
|
+
const markers = await this.#state.storage.list({ prefix: REVOKED_PREFIX });
|
|
558
|
+
const expired = [];
|
|
559
|
+
for (const [key, at] of markers) {
|
|
560
|
+
if (typeof at !== "number" || now - at >= REVOCATION_WINDOW_MS)
|
|
561
|
+
expired.push(key);
|
|
562
|
+
}
|
|
563
|
+
for (let i = 0; i < expired.length; i += DELETE_BATCH) {
|
|
564
|
+
await this.#state.storage.delete(expired.slice(i, i + DELETE_BATCH));
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async #gone(ws) {
|
|
568
|
+
closeQuietly(ws, 1000, "");
|
|
569
|
+
const attachment = readAttachment(ws);
|
|
570
|
+
if (attachment === undefined || attachment.done)
|
|
571
|
+
return;
|
|
572
|
+
try {
|
|
573
|
+
ws.serializeAttachment({ ...attachment, done: true });
|
|
574
|
+
}
|
|
575
|
+
catch {
|
|
576
|
+
// Some runtimes refuse writes on a closed socket; the hook may then run twice at most.
|
|
577
|
+
}
|
|
578
|
+
if (!config.onDisconnect)
|
|
579
|
+
return;
|
|
580
|
+
const identity = Object.freeze({ id: attachment.id, kind: attachment.kind });
|
|
581
|
+
// The socket's own identity tag, read synchronously so both counts are one view of the
|
|
582
|
+
// room; hashed again only if the runtime cannot give the tags of a closed socket.
|
|
583
|
+
const tag = this.#identityTagOf(ws) ?? (await identityTag(identity));
|
|
584
|
+
const others = (list) => list.filter((other) => other !== ws).length;
|
|
585
|
+
const connections = others(this.#open());
|
|
586
|
+
const identityConnections = others(this.#open(tag));
|
|
587
|
+
try {
|
|
588
|
+
await config.onDisconnect({
|
|
589
|
+
room: attachment.room,
|
|
590
|
+
identity,
|
|
591
|
+
channels: Object.freeze([...attachment.channels]),
|
|
592
|
+
connectedAt: new Date(attachment.at),
|
|
593
|
+
connections,
|
|
594
|
+
identityConnections,
|
|
595
|
+
env: this.#env,
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
catch (error) {
|
|
599
|
+
logHookFailure("onDisconnect", error);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
//# sourceMappingURL=room.js.map
|
package/dist/room.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room.js","sourceRoot":"","sources":["../src/room.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAGL,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,IAAI,EAEJ,iBAAiB,EACjB,SAAS,EACT,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,iBAAiB,CAAC;AAgEzB,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,gEAAgE;AAChE,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,qEAAqE;AACrE,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,uFAAuF;AACvF,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,+CAA+C;AAC/C,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,+EAA+E;AAC/E,MAAM,mBAAm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