@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,160 +1,68 @@
1
- import type { Stream, TypedEventTarget, MessageStream, AbortOptions } from './index.js'
2
-
3
- /**
4
- * User-facing message stream muxer options
5
- */
6
- export interface StreamMuxerOptions<MuxedStreamOptions extends StreamOptions = StreamOptions> {
7
- /**
8
- * Configuration options for each outgoing/incoming stream
9
- */
10
- streamOptions?: MuxedStreamOptions
11
-
12
- /**
13
- * libp2p is notified of incoming streams via the muxer's 'stream' event.
14
- *
15
- * During connection establishment there may be a small window where a muxer
16
- * starts to process incoming stream data before a listener has been added for
17
- * the 'stream' event.
18
- *
19
- * If no handler is registered for this event incoming streams can be missed
20
- * so when this is the case muxers queue streams internally as "early
21
- * streams", and will defer emitting the 'stream' event until after a listener
22
- * has been registered.
23
- *
24
- * Allowing an unlimited amount of early streams can cause excessive memory
25
- * consumption so this setting controls how many early streams to store when
26
- * no 'stream' listener has been registered.
27
- *
28
- * If more streams than this are opened before a listener is added the muxed
29
- * connection will be reset.
30
- *
31
- * @default 10
32
- */
33
- maxEarlyStreams?: number
34
-
35
- /**
36
- * Maximum size of a message in bytes that we'll send on a stream - this
37
- * ensures that a single stream doesn't hog a connection
38
- *
39
- * @default 65_536
40
- */
41
- maxMessageSize?: number
1
+ import type { Direction, Stream } from './connection.js'
2
+ import type { AbortOptions, Logger } from './index.js'
3
+ import type { Duplex } from 'it-stream-types'
4
+ import type { Uint8ArrayList } from 'uint8arraylist'
42
5
 
6
+ export interface StreamMuxerFactory {
43
7
  /**
44
- * Maximum number of concurrent inbound streams that we accept - if the peer
45
- * tries to open more streams, those will be reset immediately
46
- *
47
- * @default 1_000
8
+ * The protocol used to select this muxer during connection opening
48
9
  */
49
- maxInboundStreams?: number
10
+ protocol: string
50
11
 
51
12
  /**
52
- * Maximum number of concurrent outbound streams that we accept - if the
53
- * application tries to open more streams, the call to `newStream` will throw
54
- *
55
- * @default 1_000
13
+ * Creates a new stream muxer to be used with a new connection
56
14
  */
57
- maxOutboundStreams?: number
15
+ createStreamMuxer(init?: StreamMuxerInit): StreamMuxer
58
16
  }
59
17
 
60
18
  /**
61
- * User-facing message stream options
19
+ * A libp2p stream muxer
62
20
  */
63
- export interface StreamOptions {
64
- /**
65
- * If no data is sent or received in this number of ms the stream will be
66
- * reset and an 'error' event emitted.
67
- *
68
- * @default 120_000
69
- */
70
- inactivityTimeout?: number
71
-
72
- /**
73
- * The maximum number of bytes to store when paused or before a 'message'
74
- * event handler is added.
75
- *
76
- * If the internal buffer overflows this value the stream will be reset.
77
- *
78
- * @default 4_194_304
79
- */
80
- maxReadBufferLength?: number
81
-
82
- /**
83
- * The maximum number of bytes to store when the remote end of the stream is
84
- * applying backpressure, or when it is slow to accept new bytes.
85
- *
86
- * If the internal buffer overflows this value the stream will be reset.
87
- *
88
- * @default Infinity
89
- */
90
- maxWriteBufferLength?: number
91
- }
92
-
93
- export interface StreamMuxerFactory<Muxer extends StreamMuxer = StreamMuxer> {
21
+ export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
94
22
  /**
95
23
  * The protocol used to select this muxer during connection opening
96
24
  */
97
25
  protocol: string
98
26
 
99
27
  /**
100
- * Creates a new stream muxer to be used with a new connection
101
- */
102
- createStreamMuxer(maConn: MessageStream): Muxer
103
- }
104
-
105
- export interface StreamMuxerEvents<MuxedStream extends Stream = Stream> {
106
- /**
107
- * An incoming stream was created
28
+ * A list of streams that are currently open. Closed streams will not be returned.
108
29
  */
109
- stream: CustomEvent<MuxedStream>
110
- }
111
-
112
- export interface CreateStreamOptions extends AbortOptions, StreamOptions {
30
+ readonly streams: Stream[]
113
31
  /**
114
- * If a single protocol was requested and the muxer has support for this,
115
- * pre-negotiate the protocol using this value, otherwise multistream-select
116
- * will be run over the stream after opening.
32
+ * Initiate a new stream with the given name. If no name is
33
+ * provided, the id of the stream will be used.
117
34
  */
118
- protocol?: string
119
- }
35
+ newStream(name?: string): Stream | Promise<Stream>
120
36
 
121
- export type StreamMuxerStatus = 'open' | 'closing' | 'closed'
122
-
123
- /**
124
- * A libp2p stream muxer
125
- */
126
- export interface StreamMuxer<MuxedStream extends Stream = Stream> extends TypedEventTarget<StreamMuxerEvents<MuxedStream>> {
127
37
  /**
128
- * The protocol used to select this muxer during connection opening
38
+ * Close or abort all tracked streams and stop the muxer
129
39
  */
130
- protocol: string
40
+ close(options?: AbortOptions): Promise<void>
131
41
 
132
42
  /**
133
- * A list of streams that are currently open
43
+ * Close or abort all tracked streams and stop the muxer
134
44
  */
135
- streams: MuxedStream[]
45
+ abort(err: Error): void
46
+ }
136
47
 
48
+ export interface StreamMuxerInit {
137
49
  /**
138
- * The status of the muxer
50
+ * A callback function invoked every time an incoming stream is opened
139
51
  */
140
- status: StreamMuxerStatus
52
+ onIncomingStream?(stream: Stream): void
141
53
 
142
54
  /**
143
- * Create a new stream
55
+ * A callback function invoke every time a stream ends
144
56
  */
145
- createStream(options?: CreateStreamOptions): MuxedStream | Promise<MuxedStream>
57
+ onStreamEnd?(stream: Stream): void
146
58
 
147
59
  /**
148
- * Immediately close the muxer, abort every open stream and discard any
149
- * unsent/unread data.
60
+ * Outbound stream muxers are opened by the local node, inbound stream muxers are opened by the remote
150
61
  */
151
- abort (err: Error): void
62
+ direction?: Direction
152
63
 
153
64
  /**
154
- * Gracefully close the muxer. All open streams will be gracefully closed, and
155
- * the returned promise will either resolve when any/all unsent data has been
156
- * sent, or it will reject if the passed abort signal fires before this
157
- * happens.
65
+ * The logger used by the connection
158
66
  */
159
- close (options?: AbortOptions): Promise<void>
67
+ log?: Logger
160
68
  }
package/src/topology.ts CHANGED
@@ -40,11 +40,11 @@ export interface Topology {
40
40
  * Invoked when a new connection is opened to a peer that supports the
41
41
  * registered protocol
42
42
  */
43
- onConnect?(peerId: PeerId, conn: Connection): void | Promise<void>
43
+ onConnect?(peerId: PeerId, conn: Connection): void
44
44
 
45
45
  /**
46
46
  * Invoked when the last connection to a peer that supports the registered
47
47
  * protocol closes
48
48
  */
49
- onDisconnect?(peerId: PeerId): void | Promise<void>
49
+ onDisconnect?(peerId: PeerId): void
50
50
  }
package/src/transport.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { AbortOptions, ClearableSignal, ConnectionEncrypter, MultiaddrConnection, Connection, ConnectionLimits, StreamMuxerFactory, PeerId } from './index.js'
1
+ import type { Connection, ConnectionLimits, MultiaddrConnection } from './connection.js'
2
+ import type { AbortOptions, ClearableSignal, ConnectionEncrypter } from './index.js'
3
+ import type { StreamMuxerFactory } from './stream-muxer.js'
2
4
  import type { Multiaddr } from '@multiformats/multiaddr'
3
5
  import type { TypedEventTarget } from 'main-event'
4
6
  import type { ProgressOptions, ProgressEvent } from 'progress-events'
@@ -27,19 +29,16 @@ export interface Listener extends TypedEventTarget<ListenerEvents> {
27
29
  * Start a listener
28
30
  */
29
31
  listen(multiaddr: Multiaddr): Promise<void>
30
-
31
32
  /**
32
33
  * Get listen addresses
33
34
  */
34
35
  getAddrs(): Multiaddr[]
35
-
36
36
  /**
37
37
  * Close listener
38
38
  *
39
39
  * @returns {Promise<void>}
40
40
  */
41
41
  close(): Promise<void>
42
-
43
42
  /**
44
43
  * Allows transports to amend announce addresses - to add certificate hashes
45
44
  * or other metadata that cannot be known before runtime
@@ -135,6 +134,15 @@ export enum FaultTolerance {
135
134
  * Options accepted by the upgrader during connection establishment
136
135
  */
137
136
  export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, Required<AbortOptions> {
137
+ /**
138
+ * If true the invoking transport is expected to implement it's own encryption
139
+ * and an encryption protocol will not attempted to be negotiated via
140
+ * multi-stream select
141
+ *
142
+ * @default false
143
+ */
144
+ skipEncryption?: boolean
145
+
138
146
  /**
139
147
  * If true no connection protection will be performed on the connection.
140
148
  */
@@ -164,23 +172,6 @@ export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent =
164
172
  initiator?: boolean
165
173
  }
166
174
 
167
- /**
168
- * Options accepted by the upgrader during connection establishment
169
- */
170
- export interface UpgraderWithoutEncryptionOptions extends UpgraderOptions {
171
- /**
172
- * If true the invoking transport is expected to implement it's own encryption
173
- * and an encryption protocol will not attempted to be negotiated via
174
- * multi-stream select
175
- */
176
- skipEncryption: true
177
-
178
- /**
179
- * If `skipEncryption` is true, a remote PeerId must be supplied
180
- */
181
- remotePeer: PeerId
182
- }
183
-
184
175
  export type InboundConnectionUpgradeEvents =
185
176
  ProgressEvent<'upgrader:encrypt-inbound-connection'> |
186
177
  ProgressEvent<'upgrader:multiplex-inbound-connection'>
@@ -193,15 +184,13 @@ export interface Upgrader {
193
184
  /**
194
185
  * Upgrades an outbound connection created by the `dial` method of a transport
195
186
  */
196
- upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>
197
- upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<Connection>
187
+ upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>
198
188
 
199
189
  /**
200
190
  * Upgrades an inbound connection received by a transport listener and
201
191
  * notifies other libp2p components about the new connection
202
192
  */
203
- upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>
204
- upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<void>
193
+ upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>
205
194
 
206
195
  /**
207
196
  * Used by transports that perform part of the upgrade process themselves and
@@ -1,9 +0,0 @@
1
- import type { AbortOptions, MessageStream } from './index.ts';
2
- export interface ConnectionProtector {
3
- /**
4
- * Takes a MessageStream and creates a private encryption stream between
5
- * the two peers from the shared key the Protector instance was created with.
6
- */
7
- protect(connection: MessageStream, options?: AbortOptions): Promise<MessageStream>;
8
- }
9
- //# sourceMappingURL=connection-protector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-protector.d.ts","sourceRoot":"","sources":["../../src/connection-protector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,OAAO,CAAE,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;CACpF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=connection-protector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-protector.js","sourceRoot":"","sources":["../../src/connection-protector.ts"],"names":[],"mappings":""}
@@ -1,26 +0,0 @@
1
- import type { Uint8ArrayList } from 'uint8arraylist';
2
- /**
3
- * A custom implementation of MessageEvent as the Undici version does too much
4
- * validation in it's constructor so is very slow.
5
- */
6
- export declare class StreamMessageEvent extends Event {
7
- data: Uint8Array | Uint8ArrayList;
8
- constructor(data: Uint8Array | Uint8ArrayList, eventInitDict?: EventInit);
9
- }
10
- /**
11
- * An event dispatched when the stream is closed. The `error` property can be
12
- * inspected to discover if the closing was graceful or not, and the `remote`
13
- * property shows which end of the stream initiated the closure
14
- */
15
- export declare class StreamCloseEvent extends Event {
16
- error?: Error;
17
- local?: boolean;
18
- constructor(local?: boolean, error?: Error, eventInitDict?: EventInit);
19
- }
20
- export declare class StreamAbortEvent extends StreamCloseEvent {
21
- constructor(error: Error, eventInitDict?: EventInit);
22
- }
23
- export declare class StreamResetEvent extends StreamCloseEvent {
24
- constructor(error: Error, eventInitDict?: EventInit);
25
- }
26
- //# sourceMappingURL=events.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IACpC,IAAI,EAAE,UAAU,GAAG,cAAc,CAAA;gBAE3B,IAAI,EAAE,UAAU,GAAG,cAAc,EAAE,aAAa,CAAC,EAAE,SAAS;CAK1E;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAClC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;gBAET,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,SAAS;CAMvE;AAED,qBAAa,gBAAiB,SAAQ,gBAAgB;gBACvC,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,SAAS;CAGrD;AAED,qBAAa,gBAAiB,SAAQ,gBAAgB;gBACvC,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,SAAS;CAGrD"}
@@ -1,36 +0,0 @@
1
- /**
2
- * A custom implementation of MessageEvent as the Undici version does too much
3
- * validation in it's constructor so is very slow.
4
- */
5
- export class StreamMessageEvent extends Event {
6
- data;
7
- constructor(data, eventInitDict) {
8
- super('message', eventInitDict);
9
- this.data = data;
10
- }
11
- }
12
- /**
13
- * An event dispatched when the stream is closed. The `error` property can be
14
- * inspected to discover if the closing was graceful or not, and the `remote`
15
- * property shows which end of the stream initiated the closure
16
- */
17
- export class StreamCloseEvent extends Event {
18
- error;
19
- local;
20
- constructor(local, error, eventInitDict) {
21
- super('close', eventInitDict);
22
- this.error = error;
23
- this.local = local;
24
- }
25
- }
26
- export class StreamAbortEvent extends StreamCloseEvent {
27
- constructor(error, eventInitDict) {
28
- super(true, error, eventInitDict);
29
- }
30
- }
31
- export class StreamResetEvent extends StreamCloseEvent {
32
- constructor(error, eventInitDict) {
33
- super(false, error, eventInitDict);
34
- }
35
- }
36
- //# sourceMappingURL=events.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACpC,IAAI,CAA6B;IAExC,YAAa,IAAiC,EAAE,aAAyB;QACvE,KAAK,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;QAE/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAClC,KAAK,CAAQ;IACb,KAAK,CAAU;IAEtB,YAAa,KAAe,EAAE,KAAa,EAAE,aAAyB;QACpE,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;QAE7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IACpD,YAAa,KAAY,EAAE,aAAyB;QAClD,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,aAAa,CAAC,CAAA;IACnC,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IACpD,YAAa,KAAY,EAAE,aAAyB;QAClD,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,CAAA;IACpC,CAAC;CACF"}
@@ -1,145 +0,0 @@
1
- import type { Logger, StreamCloseEvent, StreamMessageEvent, TypedEventTarget, AbortOptions } from './index.js';
2
- import type { Uint8ArrayList } from 'uint8arraylist';
3
- /**
4
- * The direction of the message stream
5
- */
6
- export type MessageStreamDirection = 'inbound' | 'outbound';
7
- /**
8
- * The states a message stream can be in
9
- */
10
- export type MessageStreamStatus = 'open' | 'closing' | 'closed' | 'aborted' | 'reset';
11
- /**
12
- * The states the readable end of a message stream can be in
13
- */
14
- export type MessageStreamReadStatus = 'readable' | 'paused' | 'closing' | 'closed';
15
- /**
16
- * The states the writable end of a message stream can be in
17
- */
18
- export type MessageStreamWriteStatus = 'writable' | 'closing' | 'closed';
19
- /**
20
- * An object that records the times of various events
21
- */
22
- export interface MessageStreamTimeline {
23
- /**
24
- * A timestamp of when the message stream was opened
25
- */
26
- open: number;
27
- /**
28
- * A timestamp of when the message stream was closed for both reading and
29
- * writing by both ends of the stream
30
- */
31
- close?: number;
32
- }
33
- export interface MessageStreamEvents {
34
- /**
35
- * Data was received from the remote end of the message stream
36
- */
37
- message: StreamMessageEvent;
38
- /**
39
- * The local send buffer has emptied and the stream may be written to once
40
- * more, unless it is currently closing.
41
- */
42
- drain: Event;
43
- /**
44
- * The underlying resource is closed - no further events will be emitted and
45
- * the stream cannot be used to send or receive any more data.
46
- *
47
- * When the `.error` field is set, the `local` property of the event will be
48
- * `true` value if the `.abort` was invoked, otherwise it means a remote error
49
- * occurred and the peer sent a reset signal.
50
- */
51
- close: StreamCloseEvent;
52
- /**
53
- * Where the stream implementation supports half-closing, it may emit this
54
- * event when the remote end of the stream closes it's writable end.
55
- *
56
- * After this event is received no further 'message' events will be emitted
57
- * though the stream can still be written to, if it has not been closed at
58
- * this end.
59
- */
60
- remoteCloseWrite: Event;
61
- /**
62
- * The outgoing write queue emptied - there are no more bytes queued for
63
- * sending to the remote end of the stream.
64
- */
65
- idle: Event;
66
- }
67
- export interface MessageStream<Timeline extends MessageStreamTimeline = MessageStreamTimeline> extends TypedEventTarget<MessageStreamEvents>, AsyncIterable<Uint8Array | Uint8ArrayList> {
68
- /**
69
- * The current status of the message stream
70
- */
71
- status: MessageStreamStatus;
72
- /**
73
- * Timestamps of when stream events occurred
74
- */
75
- timeline: Timeline;
76
- /**
77
- * A logging implementation that can be used to log stream-specific messages
78
- */
79
- log: Logger;
80
- /**
81
- * Whether this stream is inbound or outbound
82
- */
83
- direction: MessageStreamDirection;
84
- /**
85
- * The maximum number of bytes to store when paused. If receipt of more bytes
86
- * from the remote end of the stream causes the buffer size to exceed this
87
- * value the stream will be reset and an 'error' event emitted.
88
- */
89
- maxReadBufferLength: number;
90
- /**
91
- * If no data is transmitted over the stream in this many ms, the stream will
92
- * be aborted with an InactivityTimeoutError
93
- */
94
- inactivityTimeout: number;
95
- /**
96
- * If this property is `true`, the underlying transport has signalled that its
97
- * write buffer is full and that `.send` should not be called again.
98
- *
99
- * A `drain` event will be emitted after which is its safe to call `.send`
100
- * again to resume sending.
101
- */
102
- writableNeedsDrain: boolean;
103
- /**
104
- * Write data to the stream. If the method returns false it means the
105
- * internal buffer is now full and the caller should wait for the 'drain'
106
- * event before sending more data.
107
- *
108
- * This method may throw if:
109
- * - The internal send buffer is full
110
- * - The stream has previously been closed for writing locally or remotely
111
- */
112
- send(data: Uint8Array | Uint8ArrayList): boolean;
113
- /**
114
- * Stop accepting new data to send and return a promise that resolves when any
115
- * unsent data has been written into the underlying resource.
116
- */
117
- close(options?: AbortOptions): Promise<void>;
118
- /**
119
- * Stop accepting new data to send, discard any unsent/unread data, and emit a
120
- * 'close' event with the 'error' property set to the passed error.
121
- */
122
- abort(err: Error): void;
123
- /**
124
- * Stop emitting further 'message' events. Any received data will be stored in
125
- * an internal buffer. If the buffer size reaches `maxReadBufferLength`, the
126
- * stream will be reset and a StreamAbortEvent emitted.
127
- *
128
- * If the underlying resource supports it, the remote peer will be instructed
129
- * to pause transmission of further data.
130
- */
131
- pause(): void;
132
- /**
133
- * Resume emitting 'message' events.
134
- *
135
- * If the underlying resource supports it, the remote peer will be informed
136
- * that it is ok to start sending data again.
137
- */
138
- resume(): void;
139
- /**
140
- * Queue the passed data to be emitted as a 'message' event either during the
141
- * next tick or sooner if data is received from the underlying resource.
142
- */
143
- push(buf: Uint8Array | Uint8ArrayList): void;
144
- }
145
- //# sourceMappingURL=message-stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-stream.d.ts","sourceRoot":"","sources":["../../src/message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,UAAU,CAAA;AAE3D;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAA;AAErF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAA;AAElF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAA;AAExE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAA;IAE3B;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAA;IAEZ;;;;;;;OAOG;IACH,KAAK,EAAE,gBAAgB,CAAA;IAEvB;;;;;;;OAOG;IACH,gBAAgB,EAAE,KAAK,CAAA;IAEvB;;;OAGG;IACH,IAAI,EAAE,KAAK,CAAA;CACZ;AAED,MAAM,WAAW,aAAa,CAAC,QAAQ,SAAS,qBAAqB,GAAG,qBAAqB,CAAE,SAAQ,gBAAgB,CAAC,mBAAmB,CAAC,EAAE,aAAa,CAAC,UAAU,GAAG,cAAc,CAAC;IACtL;;OAEG;IACH,MAAM,EAAE,mBAAmB,CAAA;IAE3B;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAA;IAElB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,SAAS,EAAE,sBAAsB,CAAA;IAEjC;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,CAAA;IAE3B;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAA;IAEzB;;;;;;OAMG;IACH,kBAAkB,EAAE,OAAO,CAAA;IAE3B;;;;;;;;OAQG;IACH,IAAI,CAAE,IAAI,EAAE,UAAU,GAAG,cAAc,GAAG,OAAO,CAAA;IAEjD;;;OAGG;IACH,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7C;;;OAGG;IACH,KAAK,CAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAA;IAExB;;;;;;;OAOG;IACH,KAAK,IAAK,IAAI,CAAA;IAEd;;;;;OAKG;IACH,MAAM,IAAK,IAAI,CAAA;IAEf;;;OAGG;IACH,IAAI,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,GAAG,IAAI,CAAA;CAC9C"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=message-stream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-stream.js","sourceRoot":"","sources":["../../src/message-stream.ts"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- import type { MessageStream, MessageStreamTimeline } from './message-stream.ts';
2
- import type { Multiaddr } from '@multiformats/multiaddr';
3
- export interface MultiaddrConnectionTimeline extends MessageStreamTimeline {
4
- /**
5
- * When the MultiaddrConnection was upgraded to a Connection - the type of
6
- * connection encryption and multiplexing was negotiated.
7
- */
8
- upgraded?: number;
9
- }
10
- /**
11
- * A MultiaddrConnection is returned by a transport after dialing a peer. It is
12
- * a low-level primitive and is the raw connection, typically without encryption
13
- * or stream multiplexing.
14
- */
15
- export interface MultiaddrConnection extends MessageStream<MultiaddrConnectionTimeline> {
16
- /**
17
- * The address of the remote end of the connection
18
- */
19
- remoteAddr: Multiaddr;
20
- /**
21
- * When stream life cycle events occurred
22
- */
23
- timeline: MultiaddrConnectionTimeline;
24
- }
25
- //# sourceMappingURL=multiaddr-connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiaddr-connection.d.ts","sourceRoot":"","sources":["../../src/multiaddr-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB;IACxE;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,aAAa,CAAC,2BAA2B,CAAC;IACrF;;OAEG;IACH,UAAU,EAAE,SAAS,CAAA;IAErB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAA;CACtC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=multiaddr-connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multiaddr-connection.js","sourceRoot":"","sources":["../../src/multiaddr-connection.ts"],"names":[],"mappings":""}
@@ -1,63 +0,0 @@
1
- import type { AbortOptions } from './index.ts';
2
- import type { MessageStream, MessageStreamReadStatus, MessageStreamWriteStatus } from './message-stream.js';
3
- /**
4
- * A Stream is a lightweight data channel between two peers that can be written
5
- * to and read from at both ends.
6
- *
7
- * It is half-closable - that is in order for it to be closed fully and any
8
- * associated memory reclaimed, both ends must close their writeable end of the
9
- * stream.
10
- *
11
- * It's also possible to close the readable end of the stream, but this depends
12
- * on the underlying stream muxer supporting this operation which not all do.
13
- */
14
- export interface Stream extends MessageStream {
15
- /**
16
- * Unique identifier for a stream. Identifiers are not unique across muxers.
17
- */
18
- id: string;
19
- /**
20
- * The protocol negotiated for this stream
21
- */
22
- protocol: string;
23
- /**
24
- * The status of the readable end of the stream
25
- */
26
- readStatus: MessageStreamReadStatus;
27
- /**
28
- * The status of the writable end of the stream
29
- */
30
- writeStatus: MessageStreamWriteStatus;
31
- /**
32
- * The status of the readable end of the remote end of the stream - n.b. this
33
- * requires the underlying stream transport to support sending STOP_SENDING
34
- * messages or similar.
35
- */
36
- remoteReadStatus: MessageStreamReadStatus;
37
- /**
38
- * The status of the writable end of the remote end of the stream
39
- */
40
- remoteWriteStatus: MessageStreamWriteStatus;
41
- /**
42
- * Close stream for writing and return a promise that resolves once any
43
- * pending data has been passed to the underlying transport.
44
- *
45
- * Note that the stream itself will remain readable until the remote end also
46
- * closes it's writable end.
47
- *
48
- * To close without waiting for the remote, call `.abort` instead. If you want
49
- * to wait for data to be sent first, ensure if the `.writableStatus` property
50
- * is not 'paused', if it is, wait for a `drain` event before aborting.
51
- */
52
- close(options?: AbortOptions): Promise<void>;
53
- /**
54
- * Send a message to the remote end of the stream informing them that any
55
- * incoming data will be discarded so they should stop sending.
56
- *
57
- * This requires the underlying resource to support this operation - for
58
- * example the QUIC, WebTransport, WebRTC transports do but anything
59
- * multiplexed using Yamux or Mplex do not.
60
- */
61
- closeRead(options?: AbortOptions): Promise<void>;
62
- }
63
- //# sourceMappingURL=stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAE3G;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAO,SAAQ,aAAa;IAC3C;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,UAAU,EAAE,uBAAuB,CAAA;IAEnC;;OAEG;IACH,WAAW,EAAE,wBAAwB,CAAA;IAErC;;;;OAIG;IACH,gBAAgB,EAAE,uBAAuB,CAAA;IAEzC;;OAEG;IACH,iBAAiB,EAAE,wBAAwB,CAAA;IAE3C;;;;;;;;;;OAUG;IACH,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7C;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=stream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":""}