arcadible 1.0.52 → 1.0.53

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.
@@ -203,10 +203,13 @@ export function wires({ drop = null, game, origin, tickets, }) {
203
203
  return;
204
204
  }
205
205
  // the wires a player is on, counted here as Arcadible counts
206
- // them: past them a wire is full (`too_many` in the first
207
- // protocol)
206
+ // them, a connection unheard for too long not among them, as the
207
+ // sweep would drop it: past them a wire is full (`too_many` in
208
+ // the first protocol)
209
+ const at = Date.now();
208
210
  const theirs = [...running].filter(([other, { on: those }]) => other !== id &&
209
- [...those.values()].some((each) => each.member.id === who.member.id)).length;
211
+ [...those.values()].some((each) => each.member.id === who.member.id &&
212
+ at - each.heard <= LIMITS.idle)).length;
210
213
  if (theirs >= LIMITS.wires) {
211
214
  refuse(protocol === 2 ? "full" : "too_many");
212
215
  return;
@@ -129,19 +129,18 @@ export function closeOf(code, protocol = 1) {
129
129
  const said = code === "too_many" ? "full" : code;
130
130
  return [CLOSED_V2[said], `${said} ${RETRIES[said]}`];
131
131
  }
132
- // [function]
133
- // tokens that refill at `rate` a second, up to `burst`: whether one is
134
- // there to take, at `at`.
135
132
  function bucket(rate, burst) {
136
133
  let tokens = burst;
137
134
  let last = 0;
138
- return function take(at) {
139
- tokens = Math.min(burst, tokens + ((at - last) / 1000) * rate);
140
- last = at;
141
- if (tokens < 1)
142
- return false;
143
- tokens -= 1;
144
- return true;
135
+ return {
136
+ has(at) {
137
+ tokens = Math.min(burst, tokens + ((at - last) / 1000) * rate);
138
+ last = at;
139
+ return tokens >= 1;
140
+ },
141
+ take() {
142
+ tokens -= 1;
143
+ },
145
144
  };
146
145
  }
147
146
  // [function]
@@ -235,14 +234,21 @@ export function createRoom(options) {
235
234
  };
236
235
  return {
237
236
  admit(member, protocol = 1) {
238
- const on = options.list();
237
+ // a connection unheard for too long holds no place, though the sweep
238
+ // hasn't dropped it yet: windows that died free their member's 8,
239
+ // and a crashed member their seat, by the sweep's rule
240
+ const at = now();
241
+ const on = options
242
+ .list()
243
+ .filter((each) => at - each.heard <= LIMITS.idle);
239
244
  const theirs = on.filter((each) => each.member.id === member.id).length;
240
245
  // a thing that's full is `full` in the second protocol, and the
241
246
  // first's `too_many` in the first
242
247
  const full = protocol === 2 ? "full" : "too_many";
243
248
  if (theirs >= LIMITS.connections)
244
249
  return full;
245
- if (theirs === 0 && members().length >= LIMITS.members)
250
+ const others = new Set(on.map((each) => each.member.id)).size;
251
+ if (theirs === 0 && others >= LIMITS.members)
246
252
  return full;
247
253
  return null;
248
254
  },
@@ -309,11 +315,14 @@ export function createRoom(options) {
309
315
  sends.set(mine.member.id, take);
310
316
  }
311
317
  // past a member's rate, or the wire's, a message is dropped, and its
312
- // sender told
313
- if (!take(at) || !wire(at)) {
318
+ // sender told; it takes from neither, so one the wire refuses never
319
+ // spends the member's own, nor one past the member's the wire's
320
+ if (!take.has(at) || !wire.has(at)) {
314
321
  refuse("busy");
315
322
  return;
316
323
  }
324
+ take.take();
325
+ wire.take();
317
326
  message(second ? frame : frame.send, mine.member);
318
327
  },
319
328
  server(data) {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "name": "arcadible",
45
- "version": "1.0.52"
45
+ "version": "1.0.53"
46
46
  },
47
47
  "node_modules/@cacheable/memory": {
48
48
  "dependencies": {
@@ -2433,5 +2433,5 @@
2433
2433
  }
2434
2434
  },
2435
2435
  "requires": true,
2436
- "version": "1.0.52"
2436
+ "version": "1.0.53"
2437
2437
  }
package/package.json CHANGED
@@ -68,5 +68,5 @@
68
68
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
69
69
  },
70
70
  "type": "module",
71
- "version": "1.0.52"
71
+ "version": "1.0.53"
72
72
  }