@libp2p/interface 2.11.0-8484de8a2 → 2.11.0-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 (68) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/connection-encrypter.d.ts +15 -17
  4. package/dist/src/connection-encrypter.d.ts.map +1 -1
  5. package/dist/src/connection-gater.d.ts +2 -1
  6. package/dist/src/connection-gater.d.ts.map +1 -1
  7. package/dist/src/connection.d.ts +233 -36
  8. package/dist/src/connection.d.ts.map +1 -1
  9. package/dist/src/connection.js.map +1 -1
  10. package/dist/src/errors.d.ts +0 -32
  11. package/dist/src/errors.d.ts.map +1 -1
  12. package/dist/src/errors.js +0 -44
  13. package/dist/src/errors.js.map +1 -1
  14. package/dist/src/index.d.ts +3 -9
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +2 -7
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/metrics.d.ts +2 -2
  19. package/dist/src/metrics.d.ts.map +1 -1
  20. package/dist/src/pubsub.d.ts +3 -1
  21. package/dist/src/pubsub.d.ts.map +1 -1
  22. package/dist/src/pubsub.js.map +1 -1
  23. package/dist/src/stream-handler.d.ts +13 -2
  24. package/dist/src/stream-handler.d.ts.map +1 -1
  25. package/dist/src/stream-muxer.d.ts +30 -113
  26. package/dist/src/stream-muxer.d.ts.map +1 -1
  27. package/dist/src/topology.d.ts +2 -2
  28. package/dist/src/topology.d.ts.map +1 -1
  29. package/dist/src/transport.d.ts +13 -20
  30. package/dist/src/transport.d.ts.map +1 -1
  31. package/dist/src/transport.js.map +1 -1
  32. package/package.json +5 -4
  33. package/src/connection-encrypter.ts +16 -19
  34. package/src/connection-gater.ts +2 -1
  35. package/src/connection.ts +270 -38
  36. package/src/errors.ts +0 -52
  37. package/src/index.ts +3 -10
  38. package/src/metrics.ts +2 -2
  39. package/src/pubsub.ts +3 -1
  40. package/src/stream-handler.ts +15 -2
  41. package/src/stream-muxer.ts +30 -122
  42. package/src/topology.ts +2 -2
  43. package/src/transport.ts +14 -25
  44. package/dist/src/connection-protector.d.ts +0 -9
  45. package/dist/src/connection-protector.d.ts.map +0 -1
  46. package/dist/src/connection-protector.js +0 -2
  47. package/dist/src/connection-protector.js.map +0 -1
  48. package/dist/src/events.d.ts +0 -26
  49. package/dist/src/events.d.ts.map +0 -1
  50. package/dist/src/events.js +0 -36
  51. package/dist/src/events.js.map +0 -1
  52. package/dist/src/message-stream.d.ts +0 -145
  53. package/dist/src/message-stream.d.ts.map +0 -1
  54. package/dist/src/message-stream.js +0 -2
  55. package/dist/src/message-stream.js.map +0 -1
  56. package/dist/src/multiaddr-connection.d.ts +0 -25
  57. package/dist/src/multiaddr-connection.d.ts.map +0 -1
  58. package/dist/src/multiaddr-connection.js +0 -2
  59. package/dist/src/multiaddr-connection.js.map +0 -1
  60. package/dist/src/stream.d.ts +0 -63
  61. package/dist/src/stream.d.ts.map +0 -1
  62. package/dist/src/stream.js +0 -2
  63. package/dist/src/stream.js.map +0 -1
  64. package/src/connection-protector.ts +0 -9
  65. package/src/events.ts +0 -44
  66. package/src/message-stream.ts +0 -168
  67. package/src/multiaddr-connection.ts +0 -27
  68. package/src/stream.ts +0 -70
@@ -1,4 +1,8 @@
1
- import type { AbortOptions, StreamMuxerFactory, PeerId, MessageStream } from './index.js'
1
+ import type { MultiaddrConnection } from './connection.js'
2
+ import type { AbortOptions, Logger, StreamMuxerFactory } from './index.js'
3
+ import type { PeerId } from './peer-id.js'
4
+ import type { Duplex } from 'it-stream-types'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
2
6
 
3
7
  /**
4
8
  * If the remote PeerId is known and passed as an option, the securing operation
@@ -6,9 +10,6 @@ import type { AbortOptions, StreamMuxerFactory, PeerId, MessageStream } from './
6
10
  * corresponds to the public key the remote PeerId is derived from.
7
11
  */
8
12
  export interface SecureConnectionOptions extends AbortOptions {
9
- /**
10
- * This will be set if the remote peer is known in advance
11
- */
12
13
  remotePeer?: PeerId
13
14
 
14
15
  /**
@@ -20,6 +21,13 @@ export interface SecureConnectionOptions extends AbortOptions {
20
21
  skipStreamMuxerNegotiation?: boolean
21
22
  }
22
23
 
24
+ /**
25
+ * A stream with an optional logger
26
+ */
27
+ export interface SecurableStream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
28
+ log?: Logger
29
+ }
30
+
23
31
  /**
24
32
  * A libp2p connection encrypter module must be compliant to this interface
25
33
  * to ensure all exchanged data between two peers is encrypted.
@@ -32,30 +40,19 @@ export interface ConnectionEncrypter<Extension = unknown> {
32
40
  * pass it for extra verification, otherwise it will be determined during
33
41
  * the handshake.
34
42
  */
35
- secureOutbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<Extension>>
43
+ secureOutbound <Stream extends SecurableStream = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>
36
44
 
37
45
  /**
38
46
  * Decrypt incoming data. If the remote PeerId is known,
39
47
  * pass it for extra verification, otherwise it will be determined during
40
48
  * the handshake
41
49
  */
42
- secureInbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<Extension>>
50
+ secureInbound <Stream extends SecurableStream = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>
43
51
  }
44
52
 
45
- export interface SecuredConnection<Extension = unknown> {
46
- /**
47
- * The decrypted data stream
48
- */
49
- connection: MessageStream
50
-
51
- /**
52
- * Any extension data transferred as part of the encryption handshake
53
- */
53
+ export interface SecuredConnection<Stream = any, Extension = unknown> {
54
+ conn: Stream
54
55
  remoteExtensions?: Extension
55
-
56
- /**
57
- * The identifier of the remote peer
58
- */
59
56
  remotePeer: PeerId
60
57
 
61
58
  /**
@@ -1,4 +1,5 @@
1
- import type { MultiaddrConnection, PeerId } from './index.js'
1
+ import type { MultiaddrConnection } from './connection.js'
2
+ import type { PeerId } from './peer-id.js'
2
3
  import type { Multiaddr } from '@multiformats/multiaddr'
3
4
 
4
5
  export interface ConnectionGater {
package/src/connection.ts CHANGED
@@ -1,29 +1,179 @@
1
- import type { AbortOptions, Logger, TypedEventTarget, Stream, MessageStreamEvents, PeerId, MultiaddrConnectionTimeline, MessageStreamStatus, MessageStreamDirection } from './index.js'
1
+ import type { AbortOptions, Logger } from './index.js'
2
+ import type { PeerId } from './peer-id.js'
2
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
+ import type { Duplex, Source } from 'it-stream-types'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
3
6
 
4
- export type ConnectionStatus = MessageStreamStatus
7
+ export interface ConnectionTimeline {
8
+ /**
9
+ * When the connection was opened
10
+ */
11
+ open: number
12
+
13
+ /**
14
+ * When the MultiaddrConnection was upgraded to a Connection - e.g. the type
15
+ * of connection encryption and multiplexing was negotiated.
16
+ */
17
+ upgraded?: number
18
+
19
+ /**
20
+ * When the connection was closed.
21
+ */
22
+ close?: number
23
+ }
5
24
 
6
25
  /**
7
- * Connection limits are present on connections that are only allowed to
8
- * transfer a certain amount of bytes or be open for a certain number
9
- * of seconds.
26
+ * Outbound connections are opened by the local node, inbound streams are opened by the remote
27
+ */
28
+ export type Direction = 'inbound' | 'outbound'
29
+
30
+ export interface StreamTimeline {
31
+ /**
32
+ * A timestamp of when the stream was opened
33
+ */
34
+ open: number
35
+
36
+ /**
37
+ * A timestamp of when the stream was closed for both reading and writing
38
+ */
39
+ close?: number
40
+
41
+ /**
42
+ * A timestamp of when the stream was closed for reading
43
+ */
44
+ closeRead?: number
45
+
46
+ /**
47
+ * A timestamp of when the stream was closed for writing
48
+ */
49
+ closeWrite?: number
50
+
51
+ /**
52
+ * A timestamp of when the stream was reset
53
+ */
54
+ reset?: number
55
+
56
+ /**
57
+ * A timestamp of when the stream was aborted
58
+ */
59
+ abort?: number
60
+ }
61
+
62
+ /**
63
+ * The states a stream can be in
64
+ */
65
+ export type StreamStatus = 'open' | 'closing' | 'closed' | 'aborted' | 'reset'
66
+
67
+ /**
68
+ * The states the readable end of a stream can be in
10
69
  *
11
- * These limits are applied by Circuit Relay v2 servers, for example and
12
- * the connection will normally be closed abruptly if the limits are
13
- * exceeded.
70
+ * ready - the readable end is ready for reading
71
+ * closing - the readable end is closing
72
+ * closed - the readable end has closed
14
73
  */
15
- export interface ConnectionLimits {
74
+ export type ReadStatus = 'ready' | 'closing' | 'closed'
75
+
76
+ /**
77
+ * The states the writable end of a stream can be in
78
+ *
79
+ * ready - the writable end is ready for writing
80
+ * writing - the writable end is in the process of being written to
81
+ * done - the source passed to the `.sink` function yielded all values without error
82
+ * closing - the writable end is closing
83
+ * closed - the writable end has closed
84
+ */
85
+ export type WriteStatus = 'ready' | 'writing' | 'done' | 'closing' | 'closed'
86
+
87
+ /**
88
+ * A Stream is a data channel between two peers that
89
+ * can be written to and read from at both ends.
90
+ *
91
+ * It may be encrypted and multiplexed depending on the
92
+ * configuration of the nodes.
93
+ */
94
+ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>, Promise<void>> {
16
95
  /**
17
- * If present this is the number of bytes remaining that may be
18
- * transferred over this connection
96
+ * Closes the stream for **reading** *and* **writing**.
97
+ *
98
+ * Any buffered data in the source can still be consumed and the stream will end normally.
99
+ *
100
+ * This will cause a `CLOSE` message to be sent to the remote, *unless* the sink has already ended.
101
+ *
102
+ * The sink and the source will return normally.
19
103
  */
20
- bytes?: bigint
104
+ close(options?: AbortOptions): Promise<void>
21
105
 
22
106
  /**
23
- * If present this is the number of seconds that this connection will
24
- * remain open for
107
+ * Closes the stream for **reading**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.
108
+ *
109
+ * This function is called automatically by the muxer when it receives a `CLOSE` message from the remote.
110
+ *
111
+ * The source will return normally, the sink will continue to consume.
25
112
  */
26
- seconds?: number
113
+ closeRead(options?: AbortOptions): Promise<void>
114
+
115
+ /**
116
+ * Closes the stream for **writing**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.
117
+ *
118
+ * The source will return normally, the sink will continue to consume.
119
+ */
120
+ closeWrite(options?: AbortOptions): Promise<void>
121
+
122
+ /**
123
+ * Closes the stream for **reading** *and* **writing**. This should be called when a *local error* has occurred.
124
+ *
125
+ * Note, if called without an error any buffered data in the source can still be consumed and the stream will end normally.
126
+ *
127
+ * This will cause a `RESET` message to be sent to the remote, *unless* the sink has already ended.
128
+ *
129
+ * The sink will return and the source will throw.
130
+ */
131
+ abort(err: Error): void
132
+
133
+ /**
134
+ * Unique identifier for a stream. Identifiers are not unique across muxers.
135
+ */
136
+ id: string
137
+
138
+ /**
139
+ * Outbound streams are opened by the local node, inbound streams are opened by the remote
140
+ */
141
+ direction: Direction
142
+
143
+ /**
144
+ * Lifecycle times for the stream
145
+ */
146
+ timeline: StreamTimeline
147
+
148
+ /**
149
+ * The protocol negotiated for this stream
150
+ */
151
+ protocol?: string
152
+
153
+ /**
154
+ * User defined stream metadata
155
+ */
156
+ metadata: Record<string, any>
157
+
158
+ /**
159
+ * The current status of the stream
160
+ */
161
+ status: StreamStatus
162
+
163
+ /**
164
+ * The current status of the readable end of the stream
165
+ */
166
+ readStatus: ReadStatus
167
+
168
+ /**
169
+ * The current status of the writable end of the stream
170
+ */
171
+ writeStatus: WriteStatus
172
+
173
+ /**
174
+ * The stream logger
175
+ */
176
+ log: Logger
27
177
  }
28
178
 
29
179
  export interface NewStreamOptions extends AbortOptions {
@@ -36,11 +186,10 @@ export interface NewStreamOptions extends AbortOptions {
36
186
 
37
187
  /**
38
188
  * Opt-in to running over a limited connection - one that has restrictions
39
- * on the amount of data that may be transferred or how long it may be open
40
- * for.
189
+ * on the amount of data that may be transferred or how long it may be open for.
41
190
  *
42
- * These limits are typically enforced by a relay server, if the protocol will
43
- * be transferring a lot of data or the stream will be open for a long time
191
+ * These limits are typically enforced by a relay server, if the protocol
192
+ * will be transferring a lot of data or the stream will be open for a long time
44
193
  * consider upgrading to a direct connection before opening the stream.
45
194
  *
46
195
  * @default false
@@ -75,13 +224,38 @@ export interface NewStreamOptions extends AbortOptions {
75
224
  negotiateFully?: boolean
76
225
  }
77
226
 
227
+ export type ConnectionStatus = 'open' | 'closing' | 'closed'
228
+
229
+ /**
230
+ * Connection limits are present on connections that are only allowed to
231
+ * transfer a certain amount of bytes or be open for a certain number
232
+ * of seconds.
233
+ *
234
+ * These limits are applied by Circuit Relay v2 servers, for example and
235
+ * the connection will normally be closed abruptly if the limits are
236
+ * exceeded.
237
+ */
238
+ export interface ConnectionLimits {
239
+ /**
240
+ * If present this is the number of bytes remaining that may be
241
+ * transferred over this connection
242
+ */
243
+ bytes?: bigint
244
+
245
+ /**
246
+ * If present this is the number of seconds that this connection will
247
+ * remain open for
248
+ */
249
+ seconds?: number
250
+ }
251
+
78
252
  /**
79
253
  * A Connection is a high-level representation of a connection
80
254
  * to a remote peer that may have been secured by encryption and
81
255
  * multiplexed, depending on the configuration of the nodes
82
256
  * between which the connection is made.
83
257
  */
84
- export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, 'drain' | 'message'>> {
258
+ export interface Connection {
85
259
  /**
86
260
  * The unique identifier for this connection
87
261
  */
@@ -97,6 +271,11 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
97
271
  */
98
272
  remotePeer: PeerId
99
273
 
274
+ /**
275
+ * A list of tags applied to this connection
276
+ */
277
+ tags: string[]
278
+
100
279
  /**
101
280
  * A list of open streams on this connection
102
281
  */
@@ -105,12 +284,12 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
105
284
  /**
106
285
  * Outbound connections are opened by the local node, inbound streams are opened by the remote
107
286
  */
108
- direction: MessageStreamDirection
287
+ direction: Direction
109
288
 
110
289
  /**
111
- * When stream life cycle events occurred
290
+ * Lifecycle times for the connection
112
291
  */
113
- timeline: MultiaddrConnectionTimeline
292
+ timeline: ConnectionTimeline
114
293
 
115
294
  /**
116
295
  * The multiplexer negotiated for this connection
@@ -127,11 +306,6 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
127
306
  */
128
307
  status: ConnectionStatus
129
308
 
130
- /**
131
- * Whether this connection is direct or, for example, is via a relay
132
- */
133
- direct: boolean
134
-
135
309
  /**
136
310
  * If present, this connection has limits applied to it, perhaps by an
137
311
  * intermediate relay. Once the limits have been reached the connection will
@@ -146,28 +320,26 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
146
320
  */
147
321
  rtt?: number
148
322
 
149
- /**
150
- * The connection logger, used to log connection-specific information
151
- */
152
- log: Logger
153
-
154
323
  /**
155
324
  * Create a new stream on this connection and negotiate one of the passed protocols
156
325
  */
157
326
  newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>
158
327
 
159
328
  /**
160
- * Gracefully close the connection. The returned promise will resolve when all
161
- * queued data has been written to the underlying transport. Any unread data
162
- * will still be emitted as a 'message' event.
329
+ * Gracefully close the connection. All queued data will be written to the
330
+ * underlying transport.
163
331
  */
164
332
  close(options?: AbortOptions): Promise<void>
165
333
 
166
334
  /**
167
- * Immediately close the connection. Any data queued to be sent or read will
168
- * be discarded.
335
+ * Immediately close the connection, any queued data will be discarded
169
336
  */
170
337
  abort(err: Error): void
338
+
339
+ /**
340
+ * The connection logger
341
+ */
342
+ log: Logger
171
343
  }
172
344
 
173
345
  export const connectionSymbol = Symbol.for('@libp2p/connection')
@@ -175,3 +347,63 @@ export const connectionSymbol = Symbol.for('@libp2p/connection')
175
347
  export function isConnection (other: any): other is Connection {
176
348
  return other != null && Boolean(other[connectionSymbol])
177
349
  }
350
+
351
+ export interface ConnectionProtector {
352
+ /**
353
+ * Takes a given Connection and creates a private encryption stream
354
+ * between its two peers from the PSK the Protector instance was
355
+ * created with.
356
+ */
357
+ protect(connection: MultiaddrConnection, options?: AbortOptions): Promise<MultiaddrConnection>
358
+ }
359
+
360
+ export interface MultiaddrConnectionTimeline {
361
+ /**
362
+ * When the connection was opened
363
+ */
364
+ open: number
365
+
366
+ /**
367
+ * When the MultiaddrConnection was upgraded to a Connection - the type of
368
+ * connection encryption and multiplexing was negotiated.
369
+ */
370
+ upgraded?: number
371
+
372
+ /**
373
+ * When the connection was closed.
374
+ */
375
+ close?: number
376
+ }
377
+
378
+ /**
379
+ * A MultiaddrConnection is returned by transports after dialing
380
+ * a peer. It is a low-level primitive and is the raw connection
381
+ * without encryption or stream multiplexing.
382
+ */
383
+ export interface MultiaddrConnection extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
384
+ /**
385
+ * Gracefully close the connection. All queued data will be written to the
386
+ * underlying transport.
387
+ */
388
+ close(options?: AbortOptions): Promise<void>
389
+
390
+ /**
391
+ * Immediately close the connection, any queued data will be discarded
392
+ */
393
+ abort(err: Error): void
394
+
395
+ /**
396
+ * The address of the remote end of the connection
397
+ */
398
+ remoteAddr: Multiaddr
399
+
400
+ /**
401
+ * When connection life cycle events occurred
402
+ */
403
+ timeline: MultiaddrConnectionTimeline
404
+
405
+ /**
406
+ * The multiaddr connection logger
407
+ */
408
+ log: Logger
409
+ }
package/src/errors.ts CHANGED
@@ -132,34 +132,6 @@ export class MuxerClosedError extends Error {
132
132
  }
133
133
  }
134
134
 
135
- /**
136
- * Thrown when a protocol stream is closed during an operation
137
- *
138
- * @deprecated delete if unused
139
- */
140
- export class StreamClosedError extends Error {
141
- static name = 'StreamClosedError'
142
-
143
- constructor (message = 'The stream has been closed') {
144
- super(message)
145
- this.name = 'StreamClosedError'
146
- }
147
- }
148
-
149
- /**
150
- * Thrown when a protocol stream is closing during an operation
151
- *
152
- * @deprecated delete if unused
153
- */
154
- export class StreamClosingError extends Error {
155
- static name = 'StreamClosingError'
156
-
157
- constructor (message = 'The stream is closing') {
158
- super(message)
159
- this.name = 'StreamClosingError'
160
- }
161
- }
162
-
163
135
  /**
164
136
  * Thrown when a protocol stream is reset by the remote muxer
165
137
  */
@@ -172,18 +144,6 @@ export class StreamResetError extends Error {
172
144
  }
173
145
  }
174
146
 
175
- /**
176
- * Thrown when a protocol stream is aborted locally
177
- */
178
- export class StreamAbortedError extends Error {
179
- static name = 'StreamAbortedError'
180
-
181
- constructor (message = 'The stream has been aborted') {
182
- super(message)
183
- this.name = 'StreamAbortedError'
184
- }
185
- }
186
-
187
147
  /**
188
148
  * Thrown when a stream is in an invalid state
189
149
  */
@@ -196,18 +156,6 @@ export class StreamStateError extends Error {
196
156
  }
197
157
  }
198
158
 
199
- /**
200
- * Thrown when a stream buffer is full
201
- */
202
- export class StreamBufferError extends Error {
203
- static name = 'StreamBufferError'
204
-
205
- constructor (message = 'The stream buffer was full') {
206
- super(message)
207
- this.name = 'StreamBufferError'
208
- }
209
- }
210
-
211
159
  /**
212
160
  * Thrown when a value could not be found
213
161
  */
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * ```
15
15
  */
16
16
 
17
- import type { Connection, NewStreamOptions } from './connection.js'
17
+ import type { Connection, NewStreamOptions, Stream } from './connection.js'
18
18
  import type { ContentRouting } from './content-routing.js'
19
19
  import type { Ed25519PublicKey, PublicKey, RSAPublicKey, Secp256k1PublicKey } from './keys.js'
20
20
  import type { Metrics } from './metrics.js'
@@ -24,7 +24,6 @@ import type { PeerRouting } from './peer-routing.js'
24
24
  import type { Address, Peer, PeerStore } from './peer-store.js'
25
25
  import type { Startable } from './startable.js'
26
26
  import type { StreamHandler, StreamHandlerOptions } from './stream-handler.js'
27
- import type { Stream } from './stream.js'
28
27
  import type { Topology } from './topology.js'
29
28
  import type { Listener, OutboundConnectionUpgradeEvents } from './transport.js'
30
29
  import type { DNS } from '@multiformats/dns'
@@ -916,14 +915,9 @@ export const serviceDependencies = Symbol.for('@libp2p/service-dependencies')
916
915
  export * from './connection.js'
917
916
  export * from './connection-encrypter.js'
918
917
  export * from './connection-gater.js'
919
- export * from './connection-protector.js'
920
918
  export * from './content-routing.js'
921
- export * from './errors.js'
922
- export * from './events.js'
923
919
  export * from './keys.js'
924
- export * from './message-stream.js'
925
920
  export * from './metrics.js'
926
- export * from './multiaddr-connection.js'
927
921
  export * from './peer-discovery.js'
928
922
  export * from './peer-id.js'
929
923
  export * from './peer-info.js'
@@ -931,11 +925,10 @@ export * from './peer-routing.js'
931
925
  export * from './peer-store.js'
932
926
  export * from './pubsub.js'
933
927
  export * from './record.js'
934
- export * from './startable.js'
935
928
  export * from './stream-handler.js'
936
929
  export * from './stream-muxer.js'
937
- export * from './stream.js'
938
930
  export * from './topology.js'
939
931
  export * from './transport.js'
940
-
932
+ export * from './errors.js'
941
933
  export * from 'main-event'
934
+ export * from './startable.js'
package/src/metrics.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MultiaddrConnection, Stream } from './index.js'
1
+ import type { MultiaddrConnection, Stream, Connection } from './connection.js'
2
2
 
3
3
  /**
4
4
  * Create tracked metrics with these options. Loosely based on the
@@ -434,7 +434,7 @@ export interface Metrics {
434
434
  /**
435
435
  * Track a newly opened protocol stream
436
436
  */
437
- trackProtocolStream(stream: Stream): void
437
+ trackProtocolStream(stream: Stream, connection: Connection): void
438
438
 
439
439
  /**
440
440
  * Register an arbitrary metric. Call this to set help/labels for metrics
package/src/pubsub.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { Stream, PublicKey, PeerId } from './index.js'
1
+ import type { Stream } from './connection.js'
2
+ import type { PublicKey } from './keys.js'
3
+ import type { PeerId } from './peer-id.js'
2
4
  import type { Pushable } from 'it-pushable'
3
5
  import type { TypedEventTarget } from 'main-event'
4
6
  import type { Uint8ArrayList } from 'uint8arraylist'
@@ -1,10 +1,23 @@
1
- import type { AbortOptions, Connection, Stream } from './index.ts'
1
+ import type { Connection, Stream } from './connection.js'
2
+ import type { AbortOptions } from './index.ts'
3
+
4
+ export interface IncomingStreamData {
5
+ /**
6
+ * The newly opened stream
7
+ */
8
+ stream: Stream
9
+
10
+ /**
11
+ * The connection the stream was opened on
12
+ */
13
+ connection: Connection
14
+ }
2
15
 
3
16
  export interface StreamHandler {
4
17
  /**
5
18
  * A callback function that accepts the incoming stream data
6
19
  */
7
- (stream: Stream, connection: Connection): void | Promise<void>
20
+ (data: IncomingStreamData): void | Promise<void>
8
21
  }
9
22
 
10
23
  export interface StreamHandlerOptions extends AbortOptions {