libp2r2p 0.10.24 → 0.10.26

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
@@ -854,3 +854,16 @@ A stale token cannot acknowledge a newly reserved or replaced record.
854
854
 
855
855
  `queue.getCapacity()` returns `{ usedBytes, maxBytes }`; capacity rejections
856
856
  also expose `requiredBytes` and `maxBytes`, without retaining the rejected item.
857
+
858
+
859
+ ### Publication acknowledgement deadlines
860
+
861
+ `RelayPool.sendEvent` returns immediately when the first relay accepts an event,
862
+ when all relays fail, or when the operation's `timeout` expires (30 seconds by
863
+ default, including connection work). `timeoutUntilFirstFulfillment` now defaults
864
+ to `null`, removing the former 3-second cutoff. Explicit shorter deadlines remain
865
+ supported and still finalize pending reports as timeouts. `promise` provides the
866
+ complete per-relay report without delaying the first-success return. Connection
867
+ establishment retains its separate 3-second deadline. PrivateMessenger inherits
868
+ this publication policy, including seeder/recovery messages. A timeout indicates
869
+ missing acknowledgement and cannot prove that the recipient did not receive it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2r2p",
3
- "version": "0.10.24",
3
+ "version": "0.10.26",
4
4
  "description": "Peer-to-relay-to-peer",
5
5
  "keywords": [
6
6
  "p2r2p",
@@ -97,7 +97,7 @@
97
97
  "@noble/curves": "2.2.0",
98
98
  "@noble/hashes": "2.2.0",
99
99
  "@scure/base": "2.0.0",
100
- "nmmr": "2.0.0"
100
+ "nmmr": "2.0.1"
101
101
  },
102
102
  "devDependencies": {
103
103
  "eslint": "^9.39.5",
@@ -11,7 +11,6 @@ import { RelayConnection } from './relay-connection.js'
11
11
  const CONNECTION_TIMEOUT_MS = 3000
12
12
  const COUNT_TIMEOUT_MS = 5000
13
13
  const COUNT_TIMEOUT_AFTER_FIRST_COUNT_MS = 500
14
- const SEND_TIMEOUT_UNTIL_FIRST_FULFILLMENT_MS = 3000
15
14
  const SEND_TIMEOUT_MS = 30000
16
15
  const LIVE_OVERLAP_SECONDS = 600
17
16
  const LIVE_PROGRESS_INTERVAL_MS = 60000
@@ -136,13 +135,23 @@ export class RelayPool {
136
135
  #liveSubCounts = new Map() // url -> number of active live subscriptions
137
136
  #timeout = 30000 // 30 seconds
138
137
  #createRelay
138
+ #WebSocket
139
139
  #admission
140
140
 
141
- constructor ({ _createRelay = url => new RelayConnection(url), ...capacity } = {}) {
142
- this.#createRelay = _createRelay
141
+ constructor ({ _createRelay, WebSocket: WebSocketImpl, ...capacity } = {}) {
142
+ this.#WebSocket = WebSocketImpl
143
+ this.#createRelay = _createRelay ?? (url => new RelayConnection(url, this.#WebSocket ? { WebSocket: this.#WebSocket } : undefined))
143
144
  this.#admission = new ReadAdmission(capacity)
144
145
  }
145
146
 
147
+ // Injects the WebSocket implementation used by new pooled connections (e.g.
148
+ // a launcher-owned relay multiplexer). Existing connections keep the
149
+ // implementation they were created with.
150
+ setWebSocket (WebSocketImpl) {
151
+ if (typeof WebSocketImpl !== 'function') throw new ValidationError('INVALID_WEBSOCKET_IMPLEMENTATION')
152
+ this.#WebSocket = WebSocketImpl
153
+ }
154
+
146
155
  #scheduleIdleDisconnect (url) {
147
156
  clearTimeout(this.#relayTimeouts.get(url))
148
157
  this.#relayTimeouts.set(url, maybeUnref(setTimeout(() => {
@@ -1110,8 +1119,8 @@ export class RelayPool {
1110
1119
  }
1111
1120
  }
1112
1121
 
1113
- // Returns after the first acknowledgement window. timeout is one deadline for
1114
- // the whole operation, while timeoutUntilFirstFulfillment controls only this
1122
+ // Returns on the first acknowledgement, all failures, or the 30s deadline.
1123
+ // An optional timeoutUntilFirstFulfillment imposes an earlier deadline on this
1115
1124
  // initial return and closes pending reports when it fails. null disables either
1116
1125
  // timer independently. onRelayResult receives one
1117
1126
  // { relay, success, outcome, reason? } result per relay as it settles; outcome
@@ -1120,7 +1129,7 @@ export class RelayPool {
1120
1129
  // Await `promise` for the complete report, including every relay outcome.
1121
1130
  async sendEvent (event, relays, {
1122
1131
  timeout = SEND_TIMEOUT_MS,
1123
- timeoutUntilFirstFulfillment = SEND_TIMEOUT_UNTIL_FIRST_FULFILLMENT_MS,
1132
+ timeoutUntilFirstFulfillment = null,
1124
1133
  getAuthEvent,
1125
1134
  onRelayResult
1126
1135
  } = {}) {