@cero-base/core 3.6.1 → 3.6.2
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/package.json +1 -1
- package/src/pairing/index.js +11 -8
package/package.json
CHANGED
package/src/pairing/index.js
CHANGED
|
@@ -284,21 +284,24 @@ export class Pairing extends ReadyResource {
|
|
|
284
284
|
// a promise is settled here once it is kept or void, never by a read of its keys
|
|
285
285
|
const done = inviter ? await this._done(requests) : []
|
|
286
286
|
for (const { id } of done) await this.db.call('del-request', { id }).catch(safetyCatch)
|
|
287
|
+
// one reading of the clock for what is dropped and for the next wake: what runs out between
|
|
288
|
+
// the two would be neither dropped nor waited for
|
|
289
|
+
const now = Date.now()
|
|
287
290
|
// apply has no clock: past its invite, a promise nobody kept is withdrawn here
|
|
288
291
|
if (inviter && can(role, REMOVE)) {
|
|
289
292
|
for (const row of requests) {
|
|
290
|
-
if (!row.promised || !expired(row)) continue
|
|
293
|
+
if (!row.promised || !expired(row, now)) continue
|
|
291
294
|
await this.db.call('deny', { id: row.id, reason: 'expired' }).catch(safetyCatch)
|
|
292
295
|
}
|
|
293
296
|
}
|
|
294
297
|
// past its expiry an invite is dropped, so the log stops admitting, and a spent one
|
|
295
298
|
// forgotten, since no joiner uses it past then
|
|
296
299
|
if (can(role, REMOVE)) {
|
|
297
|
-
for (const row of [...invites, ...spent].filter(expired)) {
|
|
300
|
+
for (const row of [...invites, ...spent].filter((row) => expired(row, now))) {
|
|
298
301
|
await this.db.call('del-invite', { id: row.id }).catch(safetyCatch)
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
|
-
this._arm([...invites, ...requests, ...spent])
|
|
304
|
+
this._arm([...invites, ...requests, ...spent], now)
|
|
302
305
|
// an admission is owed its keys until they are read; a promise, until done or past its invite
|
|
303
306
|
const over = (row) => row.promised && (done.includes(row) || expired(row))
|
|
304
307
|
const owed = inviter ? requests.filter((row) => row.admitted && !over(row)) : []
|
|
@@ -335,17 +338,17 @@ export class Pairing extends ReadyResource {
|
|
|
335
338
|
|
|
336
339
|
// wakes the next _sync just past the nearest expiry: expired() only holds after it
|
|
337
340
|
/** @private */
|
|
338
|
-
_arm(rows) {
|
|
341
|
+
_arm(rows, now) {
|
|
339
342
|
clearTimeout(this._expiry)
|
|
340
343
|
this._expiry = null
|
|
341
344
|
// a sync that awaited past close arms nothing: _close cleared the timer already
|
|
342
345
|
if (this.closing || this.closed) return
|
|
343
|
-
const live = rows.filter((row) => row.expires > 0 && !expired(row))
|
|
346
|
+
const live = rows.filter((row) => row.expires > 0 && !expired(row, now))
|
|
344
347
|
const next = Math.min(...live.map((row) => row.expires))
|
|
345
348
|
if (!Number.isFinite(next)) return
|
|
346
349
|
this._expiry = setTimeout(
|
|
347
350
|
() => this._sync().catch(safetyCatch),
|
|
348
|
-
Math.min(next -
|
|
351
|
+
Math.min(next - now + 1, MAX_DELAY)
|
|
349
352
|
)
|
|
350
353
|
}
|
|
351
354
|
|
|
@@ -815,8 +818,8 @@ function seal(answer, secret, reply) {
|
|
|
815
818
|
return proof ? b4a.concat([proof, message]) : message
|
|
816
819
|
}
|
|
817
820
|
|
|
818
|
-
function expired({ expires }) {
|
|
819
|
-
return expires > 0 &&
|
|
821
|
+
function expired({ expires }, now = Date.now()) {
|
|
822
|
+
return expires > 0 && now > expires
|
|
820
823
|
}
|
|
821
824
|
|
|
822
825
|
// anyone can send to an address: what does not decode is dropped, never thrown
|