libp2r2p 0.12.1 → 0.12.3
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/README.md
CHANGED
|
@@ -264,6 +264,8 @@ requests, uses an origin/identity Web Lock when available, and stops on pause or
|
|
|
264
264
|
close. Missing-key retries have no polling timer. MAC failures permit three total
|
|
265
265
|
attempts, persisted across reloads; exhausted packets remain until FIFO eviction.
|
|
266
266
|
`retryPendingDecryptions({ force: true })` explicitly retries exhausted packets.
|
|
267
|
+
Callers should request it when a committed content-key revision provides new
|
|
268
|
+
evidence, while startup, resume and routine reconciliation retain normal retries.
|
|
267
269
|
Success enters the normal acknowledged inbox before removing the pending item.
|
|
268
270
|
The session coordinator forwards this API.
|
|
269
271
|
|
|
@@ -294,6 +296,11 @@ Web Lock when available; waits hold neither that lock nor the normal inbox/IDB
|
|
|
294
296
|
queues. Fragment assembly survives scheduling boundaries. Pause/close cancel
|
|
295
297
|
waits; channel removal fences its queued and in-flight results.
|
|
296
298
|
|
|
299
|
+
`PRIVATE_MESSENGER_PAUSED` errors include the stable `code` and a copied
|
|
300
|
+
`pauseReasons` array. `QUEUE_CAPACITY_EXCEEDED` errors identify the affected
|
|
301
|
+
`inbox` or `seeds` queue and include bounded `requiredBytes`, `usedBytes` and
|
|
302
|
+
`maxBytes` diagnostics. These fields contain no messages or ciphertext.
|
|
303
|
+
|
|
297
304
|
Private-channel consumers may opt in
|
|
298
305
|
with `onDecryptionFailure({ error, record })`, returning true only after durable
|
|
299
306
|
handling, and replay records with `replayDeferredDecryptions`. Without the hook,
|
package/idb-queue/index.js
CHANGED
|
@@ -54,6 +54,15 @@ function byteLength (value) {
|
|
|
54
54
|
return encoder.encode(String(value)).length
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
function capacityError (requiredBytes, usedBytes, maxBytes) {
|
|
58
|
+
return Object.assign(new Error('QUEUE_CAPACITY_EXCEEDED'), {
|
|
59
|
+
code: 'QUEUE_CAPACITY_EXCEEDED',
|
|
60
|
+
requiredBytes,
|
|
61
|
+
usedBytes,
|
|
62
|
+
maxBytes
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
function normalizeEvictionPolicy (policy) {
|
|
58
67
|
if (policy === 'opposite-end' || policy === undefined || policy === null) return 'opposite-end'
|
|
59
68
|
if (policy === 'reject') return 'reject'
|
|
@@ -471,7 +480,7 @@ export async function createQueue ({
|
|
|
471
480
|
if (requiredBytes > sessionMaxBytes) throw new Error('QUEUE_ITEM_TOO_LARGE')
|
|
472
481
|
if (configuredEvictionPolicy === 'reject') {
|
|
473
482
|
if (state.usedBytes + requiredBytes > sessionMaxBytes) {
|
|
474
|
-
throw
|
|
483
|
+
throw capacityError(requiredBytes, state.usedBytes, sessionMaxBytes)
|
|
475
484
|
}
|
|
476
485
|
return
|
|
477
486
|
}
|
|
@@ -480,7 +489,7 @@ export async function createQueue ({
|
|
|
480
489
|
while (state.usedBytes + requiredBytes > targetBytes) {
|
|
481
490
|
if (!await evictOne(tx, state, options)) break
|
|
482
491
|
}
|
|
483
|
-
if (state.usedBytes + requiredBytes > sessionMaxBytes) throw
|
|
492
|
+
if (state.usedBytes + requiredBytes > sessionMaxBytes) throw capacityError(requiredBytes, state.usedBytes, sessionMaxBytes)
|
|
484
493
|
}
|
|
485
494
|
|
|
486
495
|
async function evictToBytes (tx, state, targetBytes, options = {}) {
|
package/package.json
CHANGED
|
@@ -133,6 +133,30 @@ const SEED_QUEUE_INDEXES = {
|
|
|
133
133
|
byChannelTime: ['channelPubkey', SEED_TIME],
|
|
134
134
|
byTime: SEED_TIME
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
function isQueueCapacityError (error) {
|
|
138
|
+
return error?.code === 'QUEUE_CAPACITY_EXCEEDED' || error?.message === 'QUEUE_CAPACITY_EXCEEDED'
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function annotateQueueCapacityError (error, queue, getCapacity) {
|
|
142
|
+
if (!isQueueCapacityError(error)) return error
|
|
143
|
+
let capacity = {}
|
|
144
|
+
try {
|
|
145
|
+
capacity = await getCapacity?.() || {}
|
|
146
|
+
} catch {
|
|
147
|
+
// Preserve the original queue failure even if a follow-up snapshot fails.
|
|
148
|
+
}
|
|
149
|
+
const value = key => Number.isSafeInteger(error?.[key])
|
|
150
|
+
? error[key]
|
|
151
|
+
: Number.isSafeInteger(capacity?.[key]) ? capacity[key] : undefined
|
|
152
|
+
return Object.assign(error, {
|
|
153
|
+
code: 'QUEUE_CAPACITY_EXCEEDED',
|
|
154
|
+
queue,
|
|
155
|
+
...(value('requiredBytes') == null ? {} : { requiredBytes: value('requiredBytes') }),
|
|
156
|
+
...(value('usedBytes') == null ? {} : { usedBytes: value('usedBytes') }),
|
|
157
|
+
...(value('maxBytes') == null ? {} : { maxBytes: value('maxBytes') })
|
|
158
|
+
})
|
|
159
|
+
}
|
|
136
160
|
const encoder = new TextEncoder()
|
|
137
161
|
const noContentKeys = async () => ({})
|
|
138
162
|
|
|
@@ -1788,7 +1812,10 @@ export class PrivateMessenger {
|
|
|
1788
1812
|
}
|
|
1789
1813
|
|
|
1790
1814
|
pausedError () {
|
|
1791
|
-
return Object.assign(new Error('PRIVATE_MESSENGER_PAUSED'), {
|
|
1815
|
+
return Object.assign(new Error('PRIVATE_MESSENGER_PAUSED'), {
|
|
1816
|
+
code: 'PRIVATE_MESSENGER_PAUSED',
|
|
1817
|
+
pauseReasons: this.readStatus().pauseReasons
|
|
1818
|
+
})
|
|
1792
1819
|
}
|
|
1793
1820
|
|
|
1794
1821
|
recoveryTask (attempt, { network = false, retryable = isRecoverableStorageFailure } = {}) {
|
|
@@ -2124,15 +2151,20 @@ export class PrivateMessenger {
|
|
|
2124
2151
|
}
|
|
2125
2152
|
this.recordInterruption([channelPubkey], message.outer?.created_at || message.event?.created_at || nowSeconds())
|
|
2126
2153
|
// Do not await stop from inside its own transport callback.
|
|
2127
|
-
const atCapacity = err
|
|
2154
|
+
const atCapacity = isQueueCapacityError(err)
|
|
2128
2155
|
if (!atCapacity && isRecoverableStorageFailure(err)) this.pendingStorageWrites.set(JSON.stringify(dedupeKey || [channelPubkey, type]), { record, dedupeKey, at: message.outer?.created_at || message.event?.created_at })
|
|
2129
|
-
;(atCapacity ? this.pause('capacity') : isRecoverableStorageFailure(err) ? this.pauseInternally('storage') : this.pause('storage')).catch(error => this.onError?.(error))
|
|
2130
2156
|
if (atCapacity) {
|
|
2157
|
+
await annotateQueueCapacityError(err, 'inbox', () => this.queue.getCapacity())
|
|
2158
|
+
const pause = this.pause('capacity')
|
|
2159
|
+
Object.assign(err, { pauseReasons: this.readStatus().pauseReasons })
|
|
2160
|
+
pause.catch(error => this.onError?.(error))
|
|
2131
2161
|
this.capacityRequiredBytes = Math.max(this.capacityRequiredBytes, err.requiredBytes || 0)
|
|
2132
2162
|
if (!this.capacityTimer) {
|
|
2133
2163
|
this.capacityTimer = setInterval(() => this.checkCapacity().catch(error => this.onError?.(error)), 1000)
|
|
2134
2164
|
this.capacityTimer.unref?.()
|
|
2135
2165
|
}
|
|
2166
|
+
} else {
|
|
2167
|
+
;(isRecoverableStorageFailure(err) ? this.pauseInternally('storage') : this.pause('storage')).catch(error => this.onError?.(error))
|
|
2136
2168
|
}
|
|
2137
2169
|
await this.flushStateWrites()
|
|
2138
2170
|
throw err
|
|
@@ -2165,7 +2197,12 @@ export class PrivateMessenger {
|
|
|
2165
2197
|
}
|
|
2166
2198
|
return
|
|
2167
2199
|
}
|
|
2168
|
-
|
|
2200
|
+
try {
|
|
2201
|
+
return await this.runSeedQueueOperation(() => this.enqueueQueueSeed(channelPubkey, seed))
|
|
2202
|
+
} catch (error) {
|
|
2203
|
+
await annotateQueueCapacityError(error, 'seeds', () => this.seedQueue?.getCapacity?.())
|
|
2204
|
+
throw error
|
|
2205
|
+
}
|
|
2169
2206
|
}
|
|
2170
2207
|
|
|
2171
2208
|
async enqueueQueueSeed (channelPubkey, seed) {
|
|
@@ -48,6 +48,11 @@ function replaceErrorMetadata (item, error) {
|
|
|
48
48
|
return Object.assign(next, errorMetadata(error))
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function createdAtMetadata (item) {
|
|
52
|
+
const value = item?.packet?.outer?.created_at ?? item?.outer?.created_at
|
|
53
|
+
return Number.isSafeInteger(value) ? { outerCreatedAt: value } : {}
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
export function pendingContentKeyGroup (item) {
|
|
52
57
|
const receiver = item?.receiverPubkey
|
|
53
58
|
const own = item?.ownContentPubkey
|
|
@@ -92,7 +97,7 @@ export async function createPendingDecryption ({ prefix, indexedDB, maxBytes = P
|
|
|
92
97
|
const notify = (action, detail) => {
|
|
93
98
|
report({ action, ...detail })
|
|
94
99
|
const key = `${action}:${detail.code || detail.reason || ''}`
|
|
95
|
-
counts[key] = { count: (counts[key]?.count || 0) + 1,
|
|
100
|
+
counts[key] = { count: (counts[key]?.count || 0) + 1, sample: detail }
|
|
96
101
|
if (!timer) { timer = setTimeout(flush, 1000); timer.unref?.() }
|
|
97
102
|
}
|
|
98
103
|
return {
|
|
@@ -129,7 +134,16 @@ export async function createPendingDecryption ({ prefix, indexedDB, maxBytes = P
|
|
|
129
134
|
if (evictedBytes) notify('discarded', { reason: 'capacity', bytes: evictedBytes })
|
|
130
135
|
const coordinates = Object.fromEntries(['eventId', 'eventKind', 'senderPubkey', 'receiverPubkey', 'ownContentPubkey', 'peerContentPubkey', 'hasOwnContentKey']
|
|
131
136
|
.filter(key => ['string', 'boolean', 'number'].includes(typeof error[key])).map(key => [key, error[key]]))
|
|
132
|
-
notify('deferred', {
|
|
137
|
+
notify('deferred', {
|
|
138
|
+
...coordinates,
|
|
139
|
+
...createdAtMetadata(record),
|
|
140
|
+
code: error.code,
|
|
141
|
+
stage: error.stage,
|
|
142
|
+
id,
|
|
143
|
+
channelPubkey: item.channelPubkey,
|
|
144
|
+
capacityBytesBefore: before.usedBytes,
|
|
145
|
+
capacityBytesAfter: after.usedBytes
|
|
146
|
+
})
|
|
133
147
|
return true
|
|
134
148
|
})
|
|
135
149
|
},
|
|
@@ -148,7 +162,7 @@ export async function createPendingDecryption ({ prefix, indexedDB, maxBytes = P
|
|
|
148
162
|
recovered (item) {
|
|
149
163
|
return serial(async () => {
|
|
150
164
|
await queue.removeBy('byId', item.id)
|
|
151
|
-
notify('recovered', { id: item.id, channelPubkey: item.channelPubkey })
|
|
165
|
+
notify('recovered', { id: item.id, channelPubkey: item.channelPubkey, ...createdAtMetadata(item) })
|
|
152
166
|
})
|
|
153
167
|
},
|
|
154
168
|
failed (item, error) {
|
|
@@ -161,7 +175,9 @@ export async function createPendingDecryption ({ prefix, indexedDB, maxBytes = P
|
|
|
161
175
|
macAttempts: current.macAttempts + (error.code === 'INVALID_MAC' ? 1 : 0)
|
|
162
176
|
}
|
|
163
177
|
await queue.putBy('byId', updated, { existingOnly: true })
|
|
164
|
-
if (updated.macAttempts >= 3 && item.macAttempts < 3)
|
|
178
|
+
if (updated.macAttempts >= 3 && item.macAttempts < 3) {
|
|
179
|
+
notify('suspended', { id: item.id, code: error.code, channelPubkey: item.channelPubkey, ...createdAtMetadata(updated) })
|
|
180
|
+
}
|
|
165
181
|
})
|
|
166
182
|
},
|
|
167
183
|
clearChannel: channel => serial(() => queue.removeBy('byChannel', channel)),
|
|
@@ -38,6 +38,15 @@ export function createQueue ({
|
|
|
38
38
|
return encoder.encode(String(value)).length
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
function capacityError (requiredBytes, usedBytes, maxBytes) {
|
|
42
|
+
return Object.assign(new Error('QUEUE_CAPACITY_EXCEEDED'), {
|
|
43
|
+
code: 'QUEUE_CAPACITY_EXCEEDED',
|
|
44
|
+
requiredBytes,
|
|
45
|
+
usedBytes,
|
|
46
|
+
maxBytes
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
function hasByteLimit () {
|
|
42
51
|
return Number.isFinite(sessionMaxBytes)
|
|
43
52
|
}
|
|
@@ -222,7 +231,7 @@ export function createQueue ({
|
|
|
222
231
|
: evictOneFromHead(state, options)
|
|
223
232
|
if (!evicted) break
|
|
224
233
|
}
|
|
225
|
-
if (state.usedBytes + requiredBytes > sessionMaxBytes) throw
|
|
234
|
+
if (state.usedBytes + requiredBytes > sessionMaxBytes) throw capacityError(requiredBytes, state.usedBytes, sessionMaxBytes)
|
|
226
235
|
return state
|
|
227
236
|
}
|
|
228
237
|
|
|
@@ -291,7 +300,7 @@ export function createQueue ({
|
|
|
291
300
|
if (hasByteLimit() && stored.byteSize > sessionMaxBytes) throw new Error('QUEUE_ITEM_TOO_LARGE')
|
|
292
301
|
if (delta > 0) {
|
|
293
302
|
if (options.evict === false) {
|
|
294
|
-
if (hasByteLimit() && state.usedBytes + delta > sessionMaxBytes) throw
|
|
303
|
+
if (hasByteLimit() && state.usedBytes + delta > sessionMaxBytes) throw capacityError(delta, state.usedBytes, sessionMaxBytes)
|
|
295
304
|
} else {
|
|
296
305
|
evictToFit(state, delta, options)
|
|
297
306
|
}
|