libp2r2p 0.12.24 → 0.12.25

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
@@ -1416,6 +1416,10 @@ event after every relay terminally rejected the original with
1416
1416
  `auth-required:`/`restricted:`/`invalid:`. The replacement and its retry share the original
1417
1417
  deadline; mixed failures and ambiguous timeouts never invoke it.
1418
1418
 
1419
+ `MESSAGE_NOT_PUBLISHED` promotes the latest `retryAt` or `retryAfterMs` found in
1420
+ failed reports and their causes to the top-level error. Session storage can
1421
+ therefore honor relay cooldowns without parsing diagnostic-only report details.
1422
+
1419
1423
  ## Private file channels (0.11)
1420
1424
 
1421
1425
  `libp2r2p/private-messenger/file` provides `createPrivateFileTransfer` for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2r2p",
3
- "version": "0.12.24",
3
+ "version": "0.12.25",
4
4
  "description": "Peer-to-relay-to-peer",
5
5
  "keywords": [
6
6
  "p2r2p",
@@ -47,6 +47,28 @@ function sanitizedReport (report, index) {
47
47
  }
48
48
  }
49
49
 
50
+ function latestRetryAdvice (values, now) {
51
+ const pending = values.slice()
52
+ const seen = new Set()
53
+ let retryAt = 0
54
+ while (pending.length) {
55
+ const current = pending.pop()
56
+ if (!current || typeof current !== 'object' || seen.has(current)) continue
57
+ seen.add(current)
58
+ if (Array.isArray(current)) {
59
+ pending.push(...current)
60
+ continue
61
+ }
62
+ if (Number.isSafeInteger(current.retryAt)) retryAt = Math.max(retryAt, current.retryAt)
63
+ if (Number.isSafeInteger(current.retryAfterMs) && current.retryAfterMs >= 0) {
64
+ retryAt = Math.max(retryAt, now + current.retryAfterMs)
65
+ }
66
+ for (const key of ['cause', 'reason', 'error']) pending.push(current[key])
67
+ if (Array.isArray(current.errors)) pending.push(...current.errors)
68
+ }
69
+ return retryAt
70
+ }
71
+
50
72
  const contextFields = ['operation', 'channelPubkey', 'seederPubkey', 'receiverPubkey', 'eventId']
51
73
  const contextNumbers = ['eventKind', 'since', 'until']
52
74
 
@@ -103,11 +125,13 @@ export async function assertMessagePublished (result, event) {
103
125
  const present = Array.isArray(reports) && reports.length > 0
104
126
  if (present && reports.every(report => report?.success === true)) return
105
127
 
128
+ const retrySources = []
106
129
  const failures = present
107
130
  ? await Promise.all(reports.map(async (report, index) => {
108
131
  if (report?.success === true) return null
109
132
  let settled
110
133
  try { settled = await report?.promise } catch (reason) { settled = { errors: [{ reason }] } }
134
+ retrySources.push(report, settled)
111
135
  // Never retain the broadcast result: it includes plaintext and may carry
112
136
  // delivery.deletionSeckey. Native relay errors retain transport causes.
113
137
  return {
@@ -128,9 +152,12 @@ export async function assertMessagePublished (result, event) {
128
152
  })
129
153
  return `report ${report.index + 1} (${report.total ?? '?'} relays): ${errors.join('; ') || (report.total === 0 ? 'NO_RELAYS' : 'NO_RELAY_ACKNOWLEDGEMENT')}`
130
154
  })
155
+ const now = Date.now()
156
+ const retryAt = latestRetryAdvice(retrySources, now)
131
157
  throw Object.assign(new Error(`MESSAGE_NOT_PUBLISHED: ${details.join(' | ') || reason}`), {
132
158
  code: 'MESSAGE_NOT_PUBLISHED',
133
159
  ...(failures.length && failures.every(report => report.retryWhenAvailable) ? { retryWhenAvailable: true, ...(failures.some(report => report.retryWhenOnline) ? { retryWhenOnline: true } : {}) } : {}),
160
+ ...(retryAt > 0 ? { retryAt, retryAfterMs: Math.max(0, retryAt - now) } : {}),
134
161
  reason,
135
162
  eventId: getEventHash(event),
136
163
  eventKind: event.kind,