libp2r2p 0.12.4 → 0.12.6
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 +23 -18
- package/package.json +1 -1
- package/relay/helpers/error.js +2 -2
- package/relay/helpers/retry-advice.js +4 -6
- package/web-storage-queue/index.js +13 -1
package/README.md
CHANGED
|
@@ -1102,25 +1102,24 @@ Local authentication denials, invalid events and unknown errors qualify for
|
|
|
1102
1102
|
neither policy. Predicates classify individual native errors; callers decide
|
|
1103
1103
|
how to handle mixed per-relay outcomes and application-specific aggregates.
|
|
1104
1104
|
`parseRelayRetryAdvice(reason, params, { now = Date.now() })`, exported by
|
|
1105
|
-
`libp2r2p/relay`, returns `{ retryAt, retryAfterMs
|
|
1105
|
+
`libp2r2p/relay`, returns `{ retryAt, retryAfterMs }` or `null`. It only interprets
|
|
1106
1106
|
leading `rate-limited:` refusals. The optional string `params` is relative
|
|
1107
|
-
milliseconds (e.g. "2500")
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
Future waits are capped at five minutes. Missing or invalid params are ignored
|
|
1113
|
-
and do not instruct clients to retry immediately. Schedulers wait until
|
|
1107
|
+
milliseconds (e.g. "2500"). Values must be positive safe integers in canonical
|
|
1108
|
+
decimal form, without signs, whitespace, fractions, leading zeros or prefixes.
|
|
1109
|
+
Valid values produce both `retryAfterMs` and `retryAt`. Future waits are capped
|
|
1110
|
+
at five minutes. Missing or invalid params are ignored and do not instruct
|
|
1111
|
+
clients to retry immediately. Schedulers wait until
|
|
1114
1112
|
max(local backoff deadline, retryAt), never sum the two or renew the deadline on
|
|
1115
1113
|
online notifications.
|
|
1116
1114
|
|
|
1117
1115
|
Rate limits apply only to the client message type that triggered the refusal:
|
|
1118
1116
|
`EVENT`, `AUTH`, `REQ` and `COUNT` have independent connection cooldowns. Responses
|
|
1119
1117
|
are correlated with pending operations; unknown IDs never create cooldowns.
|
|
1120
|
-
CLOSE cleanup remains immediate.
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1118
|
+
CLOSE cleanup remains immediate. A launcher-owned bridge may store the absolute
|
|
1119
|
+
deadline internally, but it refreshes the standard relative `params` immediately
|
|
1120
|
+
before consumer delivery; the private `@` syntax never crosses the WebSocket wire.
|
|
1121
|
+
No legacy timing objects are interpreted. Params never supply provenance or retry
|
|
1122
|
+
eligibility; native messages, causes and codes remain intact.
|
|
1124
1123
|
|
|
1125
1124
|
## Binary encodings
|
|
1126
1125
|
|
|
@@ -1166,11 +1165,14 @@ the old token: its `ack`, `nack` and `renew` return false. Successful writes wak
|
|
|
1166
1165
|
local waiting consumers. Like the other indexed methods, `putBy` is exclusive
|
|
1167
1166
|
to `idb-queue`; the Web Storage queue's common API is unchanged.
|
|
1168
1167
|
|
|
1169
|
-
|
|
1168
|
+
Both queue implementations support
|
|
1169
|
+
`createQueue({ prefix, evictionPolicy: 'reject', maxBytes })` to opt out of
|
|
1170
1170
|
capacity eviction. Oversized items reject with `QUEUE_ITEM_TOO_LARGE`, full
|
|
1171
1171
|
queues with `QUEUE_CAPACITY_EXCEEDED`; browser quota errors propagate without
|
|
1172
1172
|
trimming existing records. Other eviction policies retain their cache behavior.
|
|
1173
1173
|
Opening a reject-policy queue under a smaller budget preserves existing items.
|
|
1174
|
+
Positional replacement and insertion follow the same rule: they reject instead
|
|
1175
|
+
of evicting when the resulting queue would exceed the limit.
|
|
1174
1176
|
|
|
1175
1177
|
`queue.reserve({ leaseMs = 30000 })` returns `null` or
|
|
1176
1178
|
`{ item, ack, nack, renew }`. Reservation token/deadline are internal record
|
|
@@ -1180,8 +1182,11 @@ PrivateMessenger supplies both. Do not mix reservations with destructive or
|
|
|
1180
1182
|
position-shifting queue operations on the same queue except explicit removal.
|
|
1181
1183
|
A stale token cannot acknowledge a newly reserved or replaced record.
|
|
1182
1184
|
|
|
1183
|
-
`queue.getCapacity()`
|
|
1184
|
-
also expose `requiredBytes` and
|
|
1185
|
+
`queue.getCapacity()` is part of the common API and returns
|
|
1186
|
+
`{ usedBytes, maxBytes }`; capacity rejections also expose `requiredBytes` and
|
|
1187
|
+
`maxBytes`, without retaining the rejected item. IDB queues return a Promise,
|
|
1188
|
+
while Web Storage queues return the object synchronously according to their
|
|
1189
|
+
respective operation conventions; callers can await either form.
|
|
1185
1190
|
|
|
1186
1191
|
|
|
1187
1192
|
### Publication acknowledgement deadlines
|
|
@@ -1281,9 +1286,9 @@ Nym broadcasts intentionally remain a single carrier union.
|
|
|
1281
1286
|
|
|
1282
1287
|
### Relay backpressure and bounded synchronization (0.11.7)
|
|
1283
1288
|
|
|
1284
|
-
Optional decimal `params` milliseconds
|
|
1285
|
-
|
|
1286
|
-
|
|
1289
|
+
Optional decimal `params` milliseconds on relay `CLOSED` and rejected `OK`
|
|
1290
|
+
responses are preserved as normalized `retryAt` and `retryAfterMs` on native relay
|
|
1291
|
+
errors. Only `rate-limited:`
|
|
1287
1292
|
responses apply this advice; invalid values are ignored
|
|
1288
1293
|
and delays are capped at five minutes. New operations of the refused type wait
|
|
1289
1294
|
within their existing deadlines; active subscriptions remain live and `CLOSE`
|
package/package.json
CHANGED
package/relay/helpers/error.js
CHANGED
|
@@ -31,8 +31,8 @@ export function relayCloseError (event, category, cause) {
|
|
|
31
31
|
return categorizeRelayError(error, category)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// Keep native diagnostics and attach only bounded timing advice.
|
|
35
|
-
//
|
|
34
|
+
// Keep native diagnostics and attach only bounded timing advice. The launcher
|
|
35
|
+
// bridge refreshes the standard relative value immediately before delivery.
|
|
36
36
|
export function relayRejectionError (reason, params, fallback) {
|
|
37
37
|
const error = categorizeRelayError(reason, 'relay', fallback)
|
|
38
38
|
Object.assign(error, parseRelayRetryAdvice(error.message, params))
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
// Nostr params use relative milliseconds
|
|
2
|
-
//
|
|
1
|
+
// Nostr params use relative milliseconds. Advice never supplies an error
|
|
2
|
+
// category, provenance or a routing/retry policy.
|
|
3
3
|
export function parseRelayRetryAdvice (reason, params, { now = Date.now() } = {}) {
|
|
4
4
|
if (typeof reason !== 'string' || !reason.startsWith('rate-limited:') ||
|
|
5
|
-
typeof params !== 'string' || params.match(
|
|
5
|
+
typeof params !== 'string' || params.match(/^[1-9]\d*$/)?.[0] !== params || !Number.isFinite(now)) return null
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const value = Number(absolute ? params.slice(1) : params)
|
|
7
|
+
const value = Number(params)
|
|
9
8
|
if (!Number.isSafeInteger(value)) return null
|
|
10
|
-
if (absolute) return { retryAt: Math.min(value, now + 300000) }
|
|
11
9
|
const retryAfterMs = Math.min(value, 300000)
|
|
12
10
|
return { retryAfterMs, retryAt: now + retryAfterMs }
|
|
13
11
|
}
|
|
@@ -53,6 +53,7 @@ export function createQueue ({
|
|
|
53
53
|
|
|
54
54
|
function normalizeEvictionPolicy (policy) {
|
|
55
55
|
if (policy === 'opposite-end' || policy === undefined || policy === null) return 'opposite-end'
|
|
56
|
+
if (policy === 'reject') return 'reject'
|
|
56
57
|
if (policy === 'fifo' || policy === 'head') return 'head'
|
|
57
58
|
if (policy === 'lifo' || policy === 'tail') return 'tail'
|
|
58
59
|
throw new ValidationError('QUEUE_INVALID_EVICTION_POLICY')
|
|
@@ -223,6 +224,12 @@ export function createQueue ({
|
|
|
223
224
|
if (!hasByteLimit()) return state
|
|
224
225
|
const { direction = 'head' } = options
|
|
225
226
|
if (requiredBytes > sessionMaxBytes) throw new Error('QUEUE_ITEM_TOO_LARGE')
|
|
227
|
+
if (configuredEvictionPolicy === 'reject') {
|
|
228
|
+
if (state.usedBytes + requiredBytes > sessionMaxBytes) {
|
|
229
|
+
throw capacityError(requiredBytes, state.usedBytes, sessionMaxBytes)
|
|
230
|
+
}
|
|
231
|
+
return state
|
|
232
|
+
}
|
|
226
233
|
// Make room for the write and retain eviction headroom for the next one.
|
|
227
234
|
const targetBytes = targetBytesAfterWrite(requiredBytes)
|
|
228
235
|
while (state.usedBytes + requiredBytes > targetBytes) {
|
|
@@ -236,7 +243,7 @@ export function createQueue ({
|
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
function recoverByteLimit (state) {
|
|
239
|
-
if (!hasByteLimit()) return state
|
|
246
|
+
if (!hasByteLimit() || configuredEvictionPolicy === 'reject') return state
|
|
240
247
|
return evictToBytes(state, Math.min(sessionMaxBytes, targetBytesAfterWrite(0)), { direction: evictionDirectionFor('recover') })
|
|
241
248
|
}
|
|
242
249
|
|
|
@@ -284,6 +291,7 @@ export function createQueue ({
|
|
|
284
291
|
storage().setItem(key, raw)
|
|
285
292
|
} catch (err) {
|
|
286
293
|
if (!isQuotaExceeded(err) || !hasByteLimit()) throw err
|
|
294
|
+
if (configuredEvictionPolicy === 'reject') throw err
|
|
287
295
|
// Actual browser quota can be lower than the configured logical budget.
|
|
288
296
|
lowerSessionMaxBytes(requiredBytes)
|
|
289
297
|
if (options.evict === false) throw err
|
|
@@ -643,6 +651,10 @@ export function createQueue ({
|
|
|
643
651
|
readState()
|
|
644
652
|
|
|
645
653
|
return {
|
|
654
|
+
getCapacity: () => {
|
|
655
|
+
const state = readState()
|
|
656
|
+
return { usedBytes: state.usedBytes, maxBytes: sessionMaxBytes }
|
|
657
|
+
},
|
|
646
658
|
enqueue: push,
|
|
647
659
|
push,
|
|
648
660
|
pop,
|