@libp2p/circuit-relay-v2 3.2.24-8484de8a2 → 3.2.24-87bc8d4fb

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.
Files changed (51) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/constants.d.ts +4 -0
  4. package/dist/src/constants.d.ts.map +1 -1
  5. package/dist/src/constants.js +4 -0
  6. package/dist/src/constants.js.map +1 -1
  7. package/dist/src/index.d.ts +7 -170
  8. package/dist/src/index.d.ts.map +1 -1
  9. package/dist/src/index.js +2 -12
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/server/index.d.ts +45 -41
  12. package/dist/src/server/index.d.ts.map +1 -1
  13. package/dist/src/server/index.js +47 -30
  14. package/dist/src/server/index.js.map +1 -1
  15. package/dist/src/server/reservation-store.d.ts +36 -2
  16. package/dist/src/server/reservation-store.d.ts.map +1 -1
  17. package/dist/src/server/reservation-store.js.map +1 -1
  18. package/dist/src/transport/discovery.d.ts +17 -2
  19. package/dist/src/transport/discovery.d.ts.map +1 -1
  20. package/dist/src/transport/discovery.js +2 -2
  21. package/dist/src/transport/discovery.js.map +1 -1
  22. package/dist/src/transport/index.d.ts +42 -34
  23. package/dist/src/transport/index.d.ts.map +1 -1
  24. package/dist/src/transport/index.js +5 -291
  25. package/dist/src/transport/index.js.map +1 -1
  26. package/dist/src/transport/reservation-store.d.ts +37 -3
  27. package/dist/src/transport/reservation-store.d.ts.map +1 -1
  28. package/dist/src/transport/reservation-store.js +6 -4
  29. package/dist/src/transport/reservation-store.js.map +1 -1
  30. package/dist/src/transport/transport.d.ts +54 -0
  31. package/dist/src/transport/transport.d.ts.map +1 -0
  32. package/dist/src/transport/transport.js +314 -0
  33. package/dist/src/transport/transport.js.map +1 -0
  34. package/dist/src/utils.d.ts.map +1 -1
  35. package/dist/src/utils.js +59 -36
  36. package/dist/src/utils.js.map +1 -1
  37. package/package.json +24 -19
  38. package/src/constants.ts +5 -0
  39. package/src/index.ts +8 -207
  40. package/src/server/index.ts +100 -35
  41. package/src/server/reservation-store.ts +42 -2
  42. package/src/transport/discovery.ts +22 -4
  43. package/src/transport/index.ts +46 -338
  44. package/src/transport/reservation-store.ts +46 -8
  45. package/src/transport/transport.ts +380 -0
  46. package/src/utils.ts +66 -37
  47. package/dist/src/transport/stream-to-conn.d.ts +0 -19
  48. package/dist/src/transport/stream-to-conn.d.ts.map +0 -1
  49. package/dist/src/transport/stream-to-conn.js +0 -60
  50. package/dist/src/transport/stream-to-conn.js.map +0 -1
  51. package/src/transport/stream-to-conn.ts +0 -91
package/dist/src/utils.js CHANGED
@@ -1,5 +1,3 @@
1
- import { setMaxListeners } from '@libp2p/interface';
2
- import { pipe } from '@libp2p/utils';
3
1
  import { CODE_P2P_CIRCUIT } from '@multiformats/multiaddr';
4
2
  import { P2P } from '@multiformats/multiaddr-matcher';
5
3
  import { fmt, code, and } from '@multiformats/multiaddr-matcher/utils';
@@ -7,16 +5,27 @@ import { anySignal } from 'any-signal';
7
5
  import { CID } from 'multiformats/cid';
8
6
  import { sha256 } from 'multiformats/hashes/sha2';
9
7
  import { DurationLimitError, TransferLimitError } from './errors.js';
10
- function countStreamBytes(source, limit, options) {
8
+ async function* countStreamBytes(source, limit, options) {
11
9
  const limitBytes = limit.remaining;
12
- const abortIfStreamByteLimitExceeded = (evt) => {
13
- const len = BigInt(evt.data.byteLength);
14
- limit.remaining -= len;
15
- if (limit.remaining < 0) {
16
- source.abort(new TransferLimitError(`data limit of ${limitBytes} bytes exceeded`));
10
+ for await (const buf of source) {
11
+ const len = BigInt(buf.byteLength);
12
+ if ((limit.remaining - len) < 0) {
13
+ // this is a safe downcast since len is guarantee to be in the range for a number
14
+ const remaining = Number(limit.remaining);
15
+ limit.remaining = 0n;
16
+ try {
17
+ if (remaining !== 0) {
18
+ yield buf.subarray(0, remaining);
19
+ }
20
+ }
21
+ catch (err) {
22
+ options.log.error(err);
23
+ }
24
+ throw new TransferLimitError(`data limit of ${limitBytes} bytes exceeded`);
17
25
  }
18
- };
19
- source.addEventListener('message', abortIfStreamByteLimitExceeded);
26
+ limit.remaining -= len;
27
+ yield buf;
28
+ }
20
29
  }
21
30
  export function createLimitedRelay(src, dst, abortSignal, reservation, options) {
22
31
  function abortStreams(err) {
@@ -27,40 +36,54 @@ export function createLimitedRelay(src, dst, abortSignal, reservation, options)
27
36
  const signals = [abortSignal, reservation.signal];
28
37
  if (reservation.limit?.duration != null) {
29
38
  options.log('limiting relayed connection duration to %dms', reservation.limit.duration);
30
- const durationSignal = AbortSignal.timeout(reservation.limit.duration);
31
- setMaxListeners(Infinity, durationSignal);
32
- signals.push(durationSignal);
39
+ signals.push(AbortSignal.timeout(reservation.limit.duration));
33
40
  }
34
41
  const signal = anySignal(signals);
35
- setMaxListeners(Infinity, signal);
42
+ let srcDstFinished = false;
43
+ let dstSrcFinished = false;
36
44
  let dataLimit;
37
45
  if (reservation.limit?.data != null) {
38
46
  dataLimit = {
39
47
  remaining: reservation.limit.data
40
48
  };
41
49
  }
42
- const onAbort = () => {
43
- let err;
44
- if (abortSignal.aborted) {
45
- err = abortSignal.reason;
46
- }
47
- else {
48
- err = new DurationLimitError(`duration limit of ${reservation.limit?.duration} ms exceeded`);
49
- }
50
- abortStreams(err);
51
- };
52
- signal.addEventListener('abort', onAbort, { once: true });
53
- if (dataLimit != null) {
54
- countStreamBytes(dst, dataLimit, options);
55
- countStreamBytes(src, dataLimit, options);
56
- }
57
- // join the streams together
58
- pipe(src, dst, src)
59
- .catch(err => {
60
- abortStreams(err);
61
- })
62
- .finally(() => {
63
- signal.clear();
50
+ queueMicrotask(() => {
51
+ const onAbort = () => {
52
+ options.log('relayed connection reached time limit');
53
+ dst.abort(new DurationLimitError(`duration limit of ${reservation.limit?.duration} ms exceeded`));
54
+ };
55
+ signal.addEventListener('abort', onAbort, { once: true });
56
+ void dst.sink(dataLimit == null ? src.source : countStreamBytes(src.source, dataLimit, options))
57
+ .catch(err => {
58
+ options.log.error('error while relaying streams src -> dst', err);
59
+ abortStreams(err);
60
+ })
61
+ .finally(() => {
62
+ srcDstFinished = true;
63
+ if (dstSrcFinished) {
64
+ signal.removeEventListener('abort', onAbort);
65
+ signal.clear();
66
+ }
67
+ });
68
+ });
69
+ queueMicrotask(() => {
70
+ const onAbort = () => {
71
+ options.log('relayed connection reached time limit');
72
+ src.abort(new DurationLimitError(`duration limit of ${reservation.limit?.duration} ms exceeded`));
73
+ };
74
+ signal.addEventListener('abort', onAbort, { once: true });
75
+ void src.sink(dataLimit == null ? dst.source : countStreamBytes(dst.source, dataLimit, options))
76
+ .catch(err => {
77
+ options.log.error('error while relaying streams dst -> src', err);
78
+ abortStreams(err);
79
+ })
80
+ .finally(() => {
81
+ dstSrcFinished = true;
82
+ if (srcDstFinished) {
83
+ signal.removeEventListener('abort', onAbort);
84
+ signal.clear();
85
+ }
86
+ });
64
87
  });
65
88
  }
66
89
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,uCAAuC,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAMpE,SAAS,gBAAgB,CAAE,MAAqB,EAAE,KAA4B,EAAE,OAAsB;IACpG,MAAM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aAAa,GAAG,GAAG,CAC9B,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAC7C,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAC9B,IAAI,CAAC,gBAAgB,CAAC,CACvB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/circuit-relay-v2",
3
- "version": "3.2.24-8484de8a2",
3
+ "version": "3.2.24-87bc8d4fb",
4
4
  "description": "Implementation of Circuit Relay v2",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-circuit-relay-v2#readme",
@@ -45,35 +45,40 @@
45
45
  "doc-check": "aegir doc-check"
46
46
  },
47
47
  "dependencies": {
48
- "@libp2p/crypto": "5.1.8-8484de8a2",
49
- "@libp2p/interface": "2.11.0-8484de8a2",
50
- "@libp2p/interface-internal": "2.3.19-8484de8a2",
51
- "@libp2p/peer-collections": "6.0.35-8484de8a2",
52
- "@libp2p/peer-id": "5.1.9-8484de8a2",
53
- "@libp2p/peer-record": "8.0.35-8484de8a2",
54
- "@libp2p/utils": "6.7.2-8484de8a2",
55
- "@multiformats/multiaddr": "^13.0.1",
56
- "@multiformats/multiaddr-matcher": "^3.0.1",
48
+ "@libp2p/crypto": "5.1.8-87bc8d4fb",
49
+ "@libp2p/interface": "2.11.0-87bc8d4fb",
50
+ "@libp2p/interface-internal": "2.3.19-87bc8d4fb",
51
+ "@libp2p/peer-collections": "6.0.35-87bc8d4fb",
52
+ "@libp2p/peer-id": "5.1.9-87bc8d4fb",
53
+ "@libp2p/peer-record": "8.0.35-87bc8d4fb",
54
+ "@libp2p/utils": "6.7.2-87bc8d4fb",
55
+ "@multiformats/multiaddr": "^12.4.4",
56
+ "@multiformats/multiaddr-matcher": "^2.0.0",
57
57
  "any-signal": "^4.1.1",
58
+ "it-protobuf-stream": "^2.0.2",
59
+ "it-stream-types": "^2.0.2",
58
60
  "main-event": "^1.0.1",
59
- "multiformats": "^13.4.0",
61
+ "multiformats": "^13.3.6",
60
62
  "nanoid": "^5.1.5",
61
63
  "progress-events": "^1.0.1",
62
- "protons-runtime": "^5.6.0",
64
+ "protons-runtime": "^5.5.0",
63
65
  "retimeable-signal": "^1.0.1",
64
66
  "uint8arraylist": "^2.4.8",
65
67
  "uint8arrays": "^5.1.0"
66
68
  },
67
69
  "devDependencies": {
68
- "@libp2p/logger": "5.2.0-8484de8a2",
69
- "aegir": "^47.0.21",
70
+ "@libp2p/interface-compliance-tests": "6.5.0-87bc8d4fb",
71
+ "@libp2p/logger": "5.2.0-87bc8d4fb",
72
+ "aegir": "^47.0.14",
70
73
  "delay": "^6.0.0",
71
- "it-all": "^3.0.9",
72
- "it-protobuf-stream": "^2.0.3",
73
- "p-event": "^6.0.1",
74
+ "it-drain": "^3.0.9",
75
+ "it-pair": "^2.0.6",
76
+ "it-pushable": "^3.2.3",
77
+ "it-to-buffer": "^4.0.9",
74
78
  "p-wait-for": "^5.0.2",
75
- "protons": "^7.7.0",
76
- "sinon": "^21.0.0",
79
+ "protons": "^7.6.1",
80
+ "race-signal": "^1.1.3",
81
+ "sinon": "^20.0.0",
77
82
  "sinon-ts": "^2.0.0"
78
83
  },
79
84
  "sideEffects": false
package/src/constants.ts CHANGED
@@ -3,6 +3,11 @@ import { KEEP_ALIVE } from '@libp2p/interface'
3
3
  const second = 1000
4
4
  const minute = 60 * second
5
5
 
6
+ /**
7
+ * Multicodec code
8
+ */
9
+ export const CIRCUIT_PROTO_CODE = 290
10
+
6
11
  /**
7
12
  * The maximum number of relay reservations the relay server will accept
8
13
  */
package/src/index.ts CHANGED
@@ -40,11 +40,7 @@
40
40
  */
41
41
 
42
42
  import { TypedEventEmitter } from 'main-event'
43
- import { CircuitRelayServer } from './server/index.js'
44
- import { CircuitRelayTransport } from './transport/index.ts'
45
43
  import type { Limit } from './pb/index.js'
46
- import type { ComponentLogger, ConnectionGater, Libp2pEvents, Metrics, PeerId, PeerStore, PrivateKey, TopologyFilter, Transport, TypedEventTarget, Upgrader } from '@libp2p/interface'
47
- import type { AddressManager, ConnectionManager, RandomWalk, Registrar, TransportManager } from '@libp2p/interface-internal'
48
44
  import type { PeerMap } from '@libp2p/peer-collections'
49
45
  import type { Multiaddr } from '@multiformats/multiaddr'
50
46
  import type { RetimeableAbortSignal } from 'retimeable-signal'
@@ -84,210 +80,15 @@ export interface CircuitRelayService extends TypedEventEmitter<CircuitRelayServi
84
80
  reservations: PeerMap<RelayReservation>
85
81
  }
86
82
 
83
+ export { circuitRelayServer } from './server/index.js'
84
+ export type { CircuitRelayServerInit, CircuitRelayServerComponents } from './server/index.js'
85
+ export type { ReservationStoreInit as ServerReservationStoreInit } from './server/reservation-store.js'
86
+ export { circuitRelayTransport } from './transport/index.js'
87
+ export type { RelayDiscoveryComponents } from './transport/discovery.js'
88
+ export type { ReservationStoreInit as TransportReservationStoreInit } from './transport/reservation-store.js'
89
+ export type { CircuitRelayTransportInit, CircuitRelayTransportComponents } from './transport/index.js'
90
+
87
91
  export {
88
92
  RELAY_V2_HOP_CODEC,
89
93
  RELAY_V2_STOP_CODEC
90
94
  } from './constants.js'
91
-
92
- export interface ServerReservationStoreInit {
93
- /**
94
- * maximum number of reservations allowed
95
- *
96
- * @default 15
97
- */
98
- maxReservations?: number
99
-
100
- /**
101
- * interval after which stale reservations are cleared
102
- *
103
- * @default 300000
104
- */
105
- reservationClearInterval?: number
106
-
107
- /**
108
- * apply default relay limits to a new reservation
109
- *
110
- * @default true
111
- */
112
- applyDefaultLimit?: boolean
113
-
114
- /**
115
- * reservation ttl
116
- *
117
- * @default 7200000
118
- */
119
- reservationTtl?: number
120
-
121
- /**
122
- * The maximum time a relayed connection can be open for
123
- */
124
- defaultDurationLimit?: number
125
-
126
- /**
127
- * The maximum amount of data allowed to be transferred over a relayed connection
128
- */
129
- defaultDataLimit?: bigint
130
- }
131
-
132
- export interface CircuitRelayServerComponents {
133
- registrar: Registrar
134
- peerStore: PeerStore
135
- addressManager: AddressManager
136
- peerId: PeerId
137
- privateKey: PrivateKey
138
- connectionManager: ConnectionManager
139
- connectionGater: ConnectionGater
140
- logger: ComponentLogger
141
- metrics?: Metrics
142
- }
143
-
144
- export interface CircuitRelayServerInit {
145
- /**
146
- * Incoming hop requests must complete within this time in ms otherwise
147
- * the stream will be reset
148
- *
149
- * @default 30000
150
- */
151
- hopTimeout?: number
152
-
153
- /**
154
- * Configuration of reservations
155
- */
156
- reservations?: ServerReservationStoreInit
157
-
158
- /**
159
- * The maximum number of simultaneous HOP inbound streams that can be open at once
160
- */
161
- maxInboundHopStreams?: number
162
-
163
- /**
164
- * The maximum number of simultaneous HOP outbound streams that can be open at once
165
- */
166
- maxOutboundHopStreams?: number
167
-
168
- /**
169
- * The maximum number of simultaneous STOP outbound streams that can be open at
170
- * once.
171
- *
172
- * @default 300
173
- */
174
- maxOutboundStopStreams?: number
175
- }
176
-
177
- export function circuitRelayServer (init: CircuitRelayServerInit = {}): (components: CircuitRelayServerComponents) => CircuitRelayService {
178
- return (components) => {
179
- return new CircuitRelayServer(components, init)
180
- }
181
- }
182
-
183
- export interface RelayDiscoveryEvents {
184
- 'relay:discover': CustomEvent<PeerId>
185
- }
186
-
187
- export interface TransportReservationStoreComponents {
188
- peerId: PeerId
189
- connectionManager: ConnectionManager
190
- peerStore: PeerStore
191
- events: TypedEventTarget<Libp2pEvents>
192
- logger: ComponentLogger
193
- metrics?: Metrics
194
- }
195
-
196
- export interface TransportReservationStoreInit {
197
- /**
198
- * Multiple relays may be discovered simultaneously - to prevent listening
199
- * on too many relays, this value controls how many to attempt to reserve a
200
- * slot on at once. If set to more than one, we may end up listening on
201
- * more relays than the `maxReservations` value, but on networks with poor
202
- * connectivity the user may wish to attempt to reserve on multiple relays
203
- * simultaneously.
204
- *
205
- * @default 1
206
- */
207
- reservationConcurrency?: number
208
-
209
- /**
210
- * Limit the number of potential relays we will dial
211
- *
212
- * @default 100
213
- */
214
- maxReservationQueueLength?: number
215
-
216
- /**
217
- * When creating a reservation it must complete within this number of ms
218
- *
219
- * @default 5000
220
- */
221
- reservationCompletionTimeout?: number
222
- }
223
-
224
- export interface RelayDiscoveryComponents {
225
- peerStore: PeerStore
226
- connectionManager: ConnectionManager
227
- transportManager: TransportManager
228
- registrar: Registrar
229
- logger: ComponentLogger
230
- randomWalk: RandomWalk
231
- events: TypedEventTarget<Libp2pEvents>
232
- }
233
-
234
- export interface RelayDiscoveryInit {
235
- filter?: TopologyFilter
236
- }
237
-
238
- export interface CircuitRelayTransportComponents extends RelayDiscoveryComponents {
239
- peerId: PeerId
240
- upgrader: Upgrader
241
- addressManager: AddressManager
242
- connectionGater: ConnectionGater
243
- }
244
-
245
- /**
246
- * RelayConfig configures the circuit v2 relay transport.
247
- */
248
- export interface CircuitRelayTransportInit extends TransportReservationStoreInit {
249
- /**
250
- * An optional filter used to prevent duplicate attempts to reserve relay
251
- * slots on the same peer
252
- */
253
- discoveryFilter?: TopologyFilter
254
-
255
- /**
256
- * The maximum number of simultaneous STOP inbound streams that can be open at
257
- * once - each inbound relayed connection uses a STOP stream
258
- *
259
- * @default 300
260
- */
261
- maxInboundStopStreams?: number
262
-
263
- /**
264
- * The maximum number of simultaneous STOP outbound streams that can be open
265
- * at once. If this transport is used along with the relay server these
266
- * settings should be set to the same value
267
- *
268
- * @default 300
269
- */
270
- maxOutboundStopStreams?: number
271
-
272
- /**
273
- * Incoming STOP requests (e.g. when a remote peer wants to dial us via a
274
- * relay) must finish the initial protocol negotiation within this timeout in
275
- * ms
276
- *
277
- * @deprecated Configure `connectionManager.inboundUpgradeTimeout` instead
278
- */
279
- stopTimeout?: number
280
-
281
- /**
282
- * When creating a reservation it must complete within this number of ms
283
- *
284
- * @default 10_000
285
- */
286
- reservationCompletionTimeout?: number
287
- }
288
-
289
- export function circuitRelayTransport (init: CircuitRelayTransportInit = {}): (components: CircuitRelayTransportComponents) => Transport {
290
- return (components) => {
291
- return new CircuitRelayTransport(components, init)
292
- }
293
- }