@libp2p/utils 6.7.2-6059227cb → 6.7.2-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 (159) hide show
  1. package/README.md +1 -1
  2. package/dist/index.min.js +1 -7
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/abort-options.d.ts +7 -0
  5. package/dist/src/abort-options.d.ts.map +1 -0
  6. package/dist/src/abort-options.js +14 -0
  7. package/dist/src/abort-options.js.map +1 -0
  8. package/dist/src/abstract-stream.d.ts +130 -14
  9. package/dist/src/abstract-stream.d.ts.map +1 -1
  10. package/dist/src/abstract-stream.js +321 -39
  11. package/dist/src/abstract-stream.js.map +1 -1
  12. package/dist/src/array-equals.d.ts +24 -0
  13. package/dist/src/array-equals.d.ts.map +1 -0
  14. package/dist/src/array-equals.js +31 -0
  15. package/dist/src/array-equals.js.map +1 -0
  16. package/dist/src/close-source.d.ts +4 -0
  17. package/dist/src/close-source.d.ts.map +1 -0
  18. package/dist/src/close-source.js +11 -0
  19. package/dist/src/close-source.js.map +1 -0
  20. package/dist/src/close.d.ts +21 -0
  21. package/dist/src/close.d.ts.map +1 -0
  22. package/dist/src/close.js +49 -0
  23. package/dist/src/close.js.map +1 -0
  24. package/dist/src/errors.d.ts +0 -8
  25. package/dist/src/errors.d.ts.map +1 -1
  26. package/dist/src/errors.js +0 -8
  27. package/dist/src/errors.js.map +1 -1
  28. package/dist/src/get-thin-waist-addresses.browser.d.ts +1 -1
  29. package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -1
  30. package/dist/src/get-thin-waist-addresses.browser.js +3 -4
  31. package/dist/src/get-thin-waist-addresses.browser.js.map +1 -1
  32. package/dist/src/get-thin-waist-addresses.d.ts +1 -1
  33. package/dist/src/get-thin-waist-addresses.d.ts.map +1 -1
  34. package/dist/src/get-thin-waist-addresses.js +9 -7
  35. package/dist/src/get-thin-waist-addresses.js.map +1 -1
  36. package/dist/src/index.d.ts +1 -31
  37. package/dist/src/index.d.ts.map +1 -1
  38. package/dist/src/index.js +1 -31
  39. package/dist/src/index.js.map +1 -1
  40. package/dist/src/merge-options.d.ts +7 -0
  41. package/dist/src/merge-options.d.ts.map +1 -0
  42. package/dist/src/merge-options.js +128 -0
  43. package/dist/src/merge-options.js.map +1 -0
  44. package/dist/src/multiaddr/is-global-unicast.d.ts.map +1 -1
  45. package/dist/src/multiaddr/is-global-unicast.js +9 -8
  46. package/dist/src/multiaddr/is-global-unicast.js.map +1 -1
  47. package/dist/src/multiaddr/is-ip-based.d.ts +6 -0
  48. package/dist/src/multiaddr/is-ip-based.d.ts.map +1 -0
  49. package/dist/src/multiaddr/is-ip-based.js +18 -0
  50. package/dist/src/multiaddr/is-ip-based.js.map +1 -0
  51. package/dist/src/multiaddr/is-link-local.d.ts.map +1 -1
  52. package/dist/src/multiaddr/is-link-local.js +16 -11
  53. package/dist/src/multiaddr/is-link-local.js.map +1 -1
  54. package/dist/src/multiaddr/is-loopback.d.ts.map +1 -1
  55. package/dist/src/multiaddr/is-loopback.js +5 -12
  56. package/dist/src/multiaddr/is-loopback.js.map +1 -1
  57. package/dist/src/multiaddr/is-network-address.d.ts.map +1 -1
  58. package/dist/src/multiaddr/is-network-address.js +16 -4
  59. package/dist/src/multiaddr/is-network-address.js.map +1 -1
  60. package/dist/src/multiaddr/is-private.d.ts.map +1 -1
  61. package/dist/src/multiaddr/is-private.js +10 -9
  62. package/dist/src/multiaddr/is-private.js.map +1 -1
  63. package/dist/src/queue/index.d.ts +6 -3
  64. package/dist/src/queue/index.d.ts.map +1 -1
  65. package/dist/src/queue/index.js +4 -20
  66. package/dist/src/queue/index.js.map +1 -1
  67. package/dist/src/rate-limiter.d.ts +15 -1
  68. package/dist/src/rate-limiter.d.ts.map +1 -1
  69. package/dist/src/rate-limiter.js +14 -1
  70. package/dist/src/rate-limiter.js.map +1 -1
  71. package/dist/src/stream-to-ma-conn.d.ts +23 -0
  72. package/dist/src/stream-to-ma-conn.d.ts.map +1 -0
  73. package/dist/src/stream-to-ma-conn.js +75 -0
  74. package/dist/src/stream-to-ma-conn.js.map +1 -0
  75. package/package.json +162 -15
  76. package/src/abort-options.ts +20 -0
  77. package/src/abstract-stream.ts +464 -51
  78. package/src/array-equals.ts +34 -0
  79. package/src/close-source.ts +14 -0
  80. package/src/close.ts +65 -0
  81. package/src/errors.ts +0 -10
  82. package/src/get-thin-waist-addresses.browser.ts +4 -5
  83. package/src/get-thin-waist-addresses.ts +12 -8
  84. package/src/index.ts +1 -31
  85. package/src/merge-options.ts +161 -0
  86. package/src/multiaddr/is-global-unicast.ts +11 -8
  87. package/src/multiaddr/is-ip-based.ts +21 -0
  88. package/src/multiaddr/is-link-local.ts +20 -11
  89. package/src/multiaddr/is-loopback.ts +7 -12
  90. package/src/multiaddr/is-network-address.ts +19 -4
  91. package/src/multiaddr/is-private.ts +14 -9
  92. package/src/queue/index.ts +11 -24
  93. package/src/rate-limiter.ts +30 -3
  94. package/src/stream-to-ma-conn.ts +106 -0
  95. package/dist/src/abstract-message-stream.d.ts +0 -129
  96. package/dist/src/abstract-message-stream.d.ts.map +0 -1
  97. package/dist/src/abstract-message-stream.js +0 -393
  98. package/dist/src/abstract-message-stream.js.map +0 -1
  99. package/dist/src/abstract-multiaddr-connection.d.ts +0 -26
  100. package/dist/src/abstract-multiaddr-connection.d.ts.map +0 -1
  101. package/dist/src/abstract-multiaddr-connection.js +0 -66
  102. package/dist/src/abstract-multiaddr-connection.js.map +0 -1
  103. package/dist/src/abstract-stream-muxer.d.ts +0 -53
  104. package/dist/src/abstract-stream-muxer.d.ts.map +0 -1
  105. package/dist/src/abstract-stream-muxer.js +0 -169
  106. package/dist/src/abstract-stream-muxer.js.map +0 -1
  107. package/dist/src/length-prefixed-decoder.d.ts +0 -37
  108. package/dist/src/length-prefixed-decoder.d.ts.map +0 -1
  109. package/dist/src/length-prefixed-decoder.js +0 -64
  110. package/dist/src/length-prefixed-decoder.js.map +0 -1
  111. package/dist/src/message-queue.d.ts +0 -61
  112. package/dist/src/message-queue.d.ts.map +0 -1
  113. package/dist/src/message-queue.js +0 -93
  114. package/dist/src/message-queue.js.map +0 -1
  115. package/dist/src/mock-muxer.d.ts +0 -57
  116. package/dist/src/mock-muxer.d.ts.map +0 -1
  117. package/dist/src/mock-muxer.js +0 -204
  118. package/dist/src/mock-muxer.js.map +0 -1
  119. package/dist/src/mock-stream.d.ts +0 -31
  120. package/dist/src/mock-stream.d.ts.map +0 -1
  121. package/dist/src/mock-stream.js +0 -69
  122. package/dist/src/mock-stream.js.map +0 -1
  123. package/dist/src/multiaddr/get-net-config.d.ts +0 -55
  124. package/dist/src/multiaddr/get-net-config.d.ts.map +0 -1
  125. package/dist/src/multiaddr/get-net-config.js +0 -54
  126. package/dist/src/multiaddr/get-net-config.js.map +0 -1
  127. package/dist/src/multiaddr/index.d.ts +0 -7
  128. package/dist/src/multiaddr/index.d.ts.map +0 -1
  129. package/dist/src/multiaddr/index.js +0 -7
  130. package/dist/src/multiaddr/index.js.map +0 -1
  131. package/dist/src/multiaddr/utils.d.ts +0 -5
  132. package/dist/src/multiaddr/utils.d.ts.map +0 -1
  133. package/dist/src/multiaddr/utils.js +0 -32
  134. package/dist/src/multiaddr/utils.js.map +0 -1
  135. package/dist/src/multiaddr-connection-pair.d.ts +0 -25
  136. package/dist/src/multiaddr-connection-pair.d.ts.map +0 -1
  137. package/dist/src/multiaddr-connection-pair.js +0 -103
  138. package/dist/src/multiaddr-connection-pair.js.map +0 -1
  139. package/dist/src/stream-pair.d.ts +0 -42
  140. package/dist/src/stream-pair.d.ts.map +0 -1
  141. package/dist/src/stream-pair.js +0 -40
  142. package/dist/src/stream-pair.js.map +0 -1
  143. package/dist/src/stream-utils.d.ts +0 -191
  144. package/dist/src/stream-utils.d.ts.map +0 -1
  145. package/dist/src/stream-utils.js +0 -370
  146. package/dist/src/stream-utils.js.map +0 -1
  147. package/src/abstract-message-stream.ts +0 -553
  148. package/src/abstract-multiaddr-connection.ts +0 -93
  149. package/src/abstract-stream-muxer.ts +0 -239
  150. package/src/length-prefixed-decoder.ts +0 -98
  151. package/src/message-queue.ts +0 -156
  152. package/src/mock-muxer.ts +0 -304
  153. package/src/mock-stream.ts +0 -101
  154. package/src/multiaddr/get-net-config.ts +0 -112
  155. package/src/multiaddr/index.ts +0 -6
  156. package/src/multiaddr/utils.ts +0 -46
  157. package/src/multiaddr-connection-pair.ts +0 -147
  158. package/src/stream-pair.ts +0 -90
  159. package/src/stream-utils.ts +0 -865
@@ -0,0 +1,106 @@
1
+ import forEach from 'it-foreach'
2
+ import { pipe } from 'it-pipe'
3
+ import type { Logger, MultiaddrConnection, Stream } from '@libp2p/interface'
4
+ import type { Multiaddr } from '@multiformats/multiaddr'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
6
+
7
+ export interface StreamProperties {
8
+ stream: Stream
9
+ remoteAddr: Multiaddr
10
+ localAddr: Multiaddr
11
+ log: Logger
12
+
13
+ /**
14
+ * A callback invoked when data is read from the stream
15
+ */
16
+ onDataRead?(buf: Uint8ArrayList | Uint8Array): void
17
+
18
+ /**
19
+ * A callback invoked when data is written to the stream
20
+ */
21
+ onDataWrite?(buf: Uint8ArrayList | Uint8Array): void
22
+ }
23
+
24
+ /**
25
+ * Convert a duplex iterable into a MultiaddrConnection.
26
+ * https://github.com/libp2p/interface-transport#multiaddrconnection
27
+ */
28
+ export function streamToMaConnection (props: StreamProperties): MultiaddrConnection {
29
+ const { stream, remoteAddr, log, onDataRead, onDataWrite } = props
30
+
31
+ let closedRead = false
32
+ let closedWrite = false
33
+
34
+ // piggyback on `stream.close` invocations to close multiaddr connection
35
+ const streamClose = stream.close.bind(stream)
36
+ stream.close = async (options): Promise<void> => {
37
+ await streamClose(options)
38
+ close(true)
39
+ }
40
+
41
+ // piggyback on `stream.abort` invocations to close multiaddr connection
42
+ const streamAbort = stream.abort.bind(stream)
43
+ stream.abort = (err): void => {
44
+ streamAbort(err)
45
+ close(true)
46
+ }
47
+
48
+ // piggyback on `stream.sink` invocations to close multiaddr connection
49
+ const streamSink = stream.sink.bind(stream)
50
+ stream.sink = async (source): Promise<void> => {
51
+ try {
52
+ await streamSink(
53
+ pipe(
54
+ source,
55
+ (source) => forEach(source, buf => onDataWrite?.(buf))
56
+ )
57
+ )
58
+ } catch (err: any) {
59
+ maConn.log.error('errored - %e', err)
60
+
61
+ // If aborted we can safely ignore
62
+ if (err.type !== 'aborted') {
63
+ // If the source errored the socket will already have been destroyed by
64
+ // toIterable.duplex(). If the socket errored it will already be
65
+ // destroyed. There's nothing to do here except log the error & return.
66
+ maConn.log.error('%s error in sink - %e', remoteAddr, err)
67
+ }
68
+ } finally {
69
+ closedWrite = true
70
+ close()
71
+ }
72
+ }
73
+
74
+ const maConn: MultiaddrConnection = {
75
+ log: log.newScope('stream-to-maconn'),
76
+ sink: stream.sink,
77
+ source: (async function * (): AsyncGenerator<Uint8ArrayList> {
78
+ try {
79
+ for await (const buf of stream.source) {
80
+ onDataRead?.(buf)
81
+ yield buf
82
+ }
83
+ } finally {
84
+ closedRead = true
85
+ close()
86
+ }
87
+ }()),
88
+ remoteAddr,
89
+ timeline: { open: Date.now(), close: undefined },
90
+ close: stream.close,
91
+ abort: stream.abort
92
+ }
93
+
94
+ function close (force?: boolean): void {
95
+ if (force === true) {
96
+ closedRead = true
97
+ closedWrite = true
98
+ }
99
+
100
+ if (closedRead && closedWrite && maConn.timeline.close == null) {
101
+ maConn.timeline.close = Date.now()
102
+ }
103
+ }
104
+
105
+ return maConn
106
+ }
@@ -1,129 +0,0 @@
1
- import { TypedEventEmitter } from '@libp2p/interface';
2
- import { Uint8ArrayList } from 'uint8arraylist';
3
- import type { MessageStreamEvents, MessageStreamStatus, MessageStream, AbortOptions, MessageStreamTimeline, MessageStreamDirection, EventHandler, StreamOptions, MessageStreamReadStatus, MessageStreamWriteStatus } from '@libp2p/interface';
4
- import type { Logger } from '@libp2p/logger';
5
- export interface MessageStreamInit extends StreamOptions {
6
- /**
7
- * A Logger implementation used to log stream-specific information
8
- */
9
- log: Logger;
10
- /**
11
- * The stream direction
12
- */
13
- direction?: MessageStreamDirection;
14
- /**
15
- * By default all available bytes are passed to the `sendData` method of
16
- * extending classes, if smaller chunks are required, pass a value here.
17
- */
18
- maxMessageSize?: number;
19
- }
20
- export interface SendResult {
21
- /**
22
- * The number of bytes from the passed buffer that were sent
23
- */
24
- sentBytes: number;
25
- /**
26
- * If the underlying resource can accept more data immediately. If `true`,
27
- * `sent` must equal the `.byteLength` of the buffer passed to `sendData`.
28
- */
29
- canSendMore: boolean;
30
- }
31
- export declare abstract class AbstractMessageStream<Timeline extends MessageStreamTimeline = MessageStreamTimeline> extends TypedEventEmitter<MessageStreamEvents> implements MessageStream {
32
- status: MessageStreamStatus;
33
- readonly timeline: Timeline;
34
- inactivityTimeout: number;
35
- maxReadBufferLength: number;
36
- maxWriteBufferLength?: number;
37
- readonly log: Logger;
38
- direction: MessageStreamDirection;
39
- maxMessageSize?: number;
40
- readStatus: MessageStreamReadStatus;
41
- writeStatus: MessageStreamWriteStatus;
42
- remoteReadStatus: MessageStreamReadStatus;
43
- remoteWriteStatus: MessageStreamWriteStatus;
44
- writableNeedsDrain: boolean;
45
- /**
46
- * Any data stored here is emitted before any new incoming data.
47
- *
48
- * This is used when the stream is paused or if data is pushed onto the stream
49
- */
50
- protected readonly readBuffer: Uint8ArrayList;
51
- protected readonly writeBuffer: Uint8ArrayList;
52
- protected sendingData: boolean;
53
- constructor(init: MessageStreamInit);
54
- [Symbol.asyncIterator](): AsyncGenerator<Uint8Array | Uint8ArrayList>;
55
- isReadable(): boolean;
56
- send(data: Uint8Array | Uint8ArrayList): boolean;
57
- /**
58
- * Close immediately for reading and writing and send a reset message (local
59
- * error)
60
- */
61
- abort(err: Error): void;
62
- pause(): void;
63
- resume(): void;
64
- push(data: Uint8Array | Uint8ArrayList): void;
65
- /**
66
- * When an extending class reads data from it's implementation-specific source,
67
- * call this method to allow the stream consumer to read the data.
68
- */
69
- onData(data: Uint8Array | Uint8ArrayList): void;
70
- addEventListener<K extends keyof MessageStreamEvents>(type: K, listener: EventHandler<MessageStreamEvents[K]> | null, options?: boolean | AddEventListenerOptions): void;
71
- addEventListener(type: string, listener: EventHandler<Event>, options?: boolean | AddEventListenerOptions): void;
72
- /**
73
- * Receive a reset message - close immediately for reading and writing (remote
74
- * error)
75
- */
76
- onRemoteReset(): void;
77
- /**
78
- * The underlying resource or transport this stream uses has closed - it is
79
- * not possible to send any more messages though any data still in the read
80
- * buffer may still be read
81
- */
82
- onTransportClosed(err?: Error): void;
83
- /**
84
- * Called by extending classes when the remote closes its writable end
85
- */
86
- onRemoteCloseWrite(): void;
87
- /**
88
- * Called by extending classes when the remote closes its readable end
89
- */
90
- onRemoteCloseRead(): void;
91
- protected processSendQueue(): boolean;
92
- protected dispatchReadBuffer(): void;
93
- private checkReadBufferLength;
94
- private checkWriteBufferLength;
95
- onMuxerNeedsDrain(): void;
96
- onMuxerDrain(): void;
97
- /**
98
- * Send a data message to the remote end of the stream. Implementations of
99
- * this method should return the number of bytes from the passed buffer that
100
- * were sent successfully and if the underlying resource can accept more data.
101
- *
102
- * The implementation should always attempt to send the maximum amount of data
103
- * possible.
104
- *
105
- * Returning a result that means the data was only partially sent but that the
106
- * underlying resource can accept more data is invalid.
107
- */
108
- abstract sendData(data: Uint8ArrayList): SendResult;
109
- /**
110
- * Send a reset message to the remote end of the stream
111
- */
112
- abstract sendReset(err: Error): void;
113
- /**
114
- * If supported, instruct the remote end of the stream to temporarily stop
115
- * sending data messages
116
- */
117
- abstract sendPause(): void;
118
- /**
119
- * If supported, inform the remote end of the stream they may resume sending
120
- * data messages
121
- */
122
- abstract sendResume(): void;
123
- /**
124
- * Stop accepting new data to send and return a promise that resolves when any
125
- * unsent data has been written into the underlying resource.
126
- */
127
- abstract close(options?: AbortOptions): Promise<void>;
128
- }
129
- //# sourceMappingURL=abstract-message-stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-message-stream.d.ts","sourceRo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,SAAS,CAAC,kBAAkB,IAAK,IAAI;IAuCrC,OAAO,CAAC,qBAAqB;IAM7B,OAAO,CAAC,sBAAsB;IAUvB,iBAAiB,IAAK,IAAI;IAI1B,YAAY,IAAK,IAAI;IAI5B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,CAAE,IAAI,EAAE,cAAc,GAAG,UAAU;IAEpD;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAE,GAAG,EAAE,KAAK,GAAG,IAAI;IAErC;;;OAGG;IACH,QAAQ,CAAC,SAAS,IAAK,IAAI;IAE3B;;;OAGG;IACH,QAAQ,CAAC,UAAU,IAAK,IAAI;IAE5B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CACvD"}
@@ -1,393 +0,0 @@
1
- import { StreamResetError, TypedEventEmitter, StreamMessageEvent, StreamBufferError, StreamResetEvent, StreamAbortEvent, StreamCloseEvent, StreamStateError } from '@libp2p/interface';
2
- import { pushable } from 'it-pushable';
3
- import { Uint8ArrayList } from 'uint8arraylist';
4
- const DEFAULT_MAX_READ_BUFFER_LENGTH = Math.pow(2, 20) * 4; // 4MB
5
- export class AbstractMessageStream extends TypedEventEmitter {
6
- status;
7
- timeline;
8
- inactivityTimeout;
9
- maxReadBufferLength;
10
- maxWriteBufferLength;
11
- log;
12
- direction;
13
- maxMessageSize;
14
- readStatus;
15
- writeStatus;
16
- remoteReadStatus;
17
- remoteWriteStatus;
18
- writableNeedsDrain;
19
- /**
20
- * Any data stored here is emitted before any new incoming data.
21
- *
22
- * This is used when the stream is paused or if data is pushed onto the stream
23
- */
24
- readBuffer;
25
- writeBuffer;
26
- sendingData;
27
- constructor(init) {
28
- super();
29
- this.status = 'open';
30
- this.log = init.log;
31
- this.direction = init.direction ?? 'outbound';
32
- this.inactivityTimeout = init.inactivityTimeout ?? 120_000;
33
- this.maxReadBufferLength = init.maxReadBufferLength ?? DEFAULT_MAX_READ_BUFFER_LENGTH;
34
- this.maxWriteBufferLength = init.maxWriteBufferLength;
35
- this.maxMessageSize = init.maxMessageSize;
36
- this.readBuffer = new Uint8ArrayList();
37
- this.writeBuffer = new Uint8ArrayList();
38
- this.readStatus = 'readable';
39
- this.remoteReadStatus = 'readable';
40
- this.writeStatus = 'writable';
41
- this.remoteWriteStatus = 'writable';
42
- this.sendingData = false;
43
- this.writableNeedsDrain = false;
44
- // @ts-expect-error type could have required fields other than 'open'
45
- this.timeline = {
46
- open: Date.now()
47
- };
48
- this.processSendQueue = this.processSendQueue.bind(this);
49
- const continueSendingOnDrain = () => {
50
- if (this.writableNeedsDrain) {
51
- this.log.trace('drain event received, continue sending data');
52
- this.writableNeedsDrain = false;
53
- this.processSendQueue();
54
- }
55
- };
56
- this.addEventListener('drain', continueSendingOnDrain);
57
- }
58
- async *[Symbol.asyncIterator]() {
59
- if (this.readStatus !== 'readable' && this.readStatus !== 'paused') {
60
- return;
61
- }
62
- const output = pushable();
63
- const streamAsyncIterableOnMessageListener = (evt) => {
64
- output.push(evt.data);
65
- };
66
- this.addEventListener('message', streamAsyncIterableOnMessageListener);
67
- const streamAsyncIterableOnCloseListener = (evt) => {
68
- output.end(evt.error);
69
- };
70
- this.addEventListener('close', streamAsyncIterableOnCloseListener);
71
- const streamAsyncIterableOnRemoteCloseWriteListener = () => {
72
- output.end();
73
- };
74
- this.addEventListener('remoteCloseWrite', streamAsyncIterableOnRemoteCloseWriteListener);
75
- try {
76
- yield* output;
77
- }
78
- finally {
79
- this.removeEventListener('message', streamAsyncIterableOnMessageListener);
80
- this.removeEventListener('close', streamAsyncIterableOnCloseListener);
81
- this.removeEventListener('remoteCloseWrite', streamAsyncIterableOnRemoteCloseWriteListener);
82
- }
83
- }
84
- isReadable() {
85
- return this.status === 'open';
86
- }
87
- send(data) {
88
- if (this.writeStatus === 'closed' || this.writeStatus === 'closing') {
89
- throw new StreamStateError(`Cannot write to a stream that is ${this.writeStatus}`);
90
- }
91
- this.log.trace('append %d bytes to write buffer', data.byteLength);
92
- this.writeBuffer.append(data);
93
- return this.processSendQueue();
94
- }
95
- /**
96
- * Close immediately for reading and writing and send a reset message (local
97
- * error)
98
- */
99
- abort(err) {
100
- if (this.status === 'aborted' || this.status === 'reset' || this.status === 'closed') {
101
- return;
102
- }
103
- this.log.error('abort with error - %e', err);
104
- this.status = 'aborted';
105
- // throw away unread data
106
- if (this.readBuffer.byteLength > 0) {
107
- this.readBuffer.consume(this.readBuffer.byteLength);
108
- }
109
- // throw away unsent data
110
- if (this.writeBuffer.byteLength > 0) {
111
- this.writeBuffer.consume(this.writeBuffer.byteLength);
112
- this.safeDispatchEvent('idle');
113
- }
114
- this.writeStatus = 'closed';
115
- this.remoteWriteStatus = 'closed';
116
- this.readStatus = 'closed';
117
- this.remoteReadStatus = 'closed';
118
- this.timeline.close = Date.now();
119
- try {
120
- this.sendReset(err);
121
- }
122
- catch (err) {
123
- this.log('failed to send reset to remote - %e', err);
124
- }
125
- this.dispatchEvent(new StreamAbortEvent(err));
126
- }
127
- pause() {
128
- if (this.readStatus === 'closed' || this.readStatus === 'closing') {
129
- throw new StreamStateError('Cannot pause a stream that is closing/closed');
130
- }
131
- if (this.readStatus === 'paused') {
132
- return;
133
- }
134
- this.readStatus = 'paused';
135
- this.sendPause();
136
- }
137
- resume() {
138
- if (this.readStatus === 'closed' || this.readStatus === 'closing') {
139
- throw new StreamStateError('Cannot resume a stream that is closing/closed');
140
- }
141
- if (this.readStatus === 'readable') {
142
- return;
143
- }
144
- this.readStatus = 'readable';
145
- // emit any data that accumulated while we were paused
146
- this.dispatchReadBuffer();
147
- this.sendResume();
148
- }
149
- push(data) {
150
- if (this.readStatus === 'closed' || this.readStatus === 'closing') {
151
- throw new StreamStateError(`Cannot push data onto a stream that is ${this.readStatus}`);
152
- }
153
- if (data.byteLength === 0) {
154
- return;
155
- }
156
- this.readBuffer.append(data);
157
- if (this.readStatus === 'paused' || this.listenerCount('message') === 0) {
158
- // abort if the read buffer is too large
159
- this.checkReadBufferLength();
160
- return;
161
- }
162
- // TODO: use a microtask instead?
163
- setTimeout(() => {
164
- this.dispatchReadBuffer();
165
- }, 0);
166
- }
167
- /**
168
- * When an extending class reads data from it's implementation-specific source,
169
- * call this method to allow the stream consumer to read the data.
170
- */
171
- onData(data) {
172
- if (data.byteLength === 0) {
173
- // this.log('ignoring empty data')
174
- return;
175
- }
176
- // discard the data if our readable end is closed
177
- if (this.readStatus === 'closing' || this.readStatus === 'closed') {
178
- this.log('ignoring data - read status %s', this.readStatus);
179
- return;
180
- }
181
- this.readBuffer.append(data);
182
- this.dispatchReadBuffer();
183
- }
184
- addEventListener(...args) {
185
- // @ts-expect-error cannot ensure args has enough members
186
- super.addEventListener.apply(this, args);
187
- // if a 'message' listener is being added and we have queued data, dispatch
188
- // the data
189
- if (args[0] === 'message' && this.readBuffer.byteLength > 0) {
190
- // event listeners can be added in constructors and often use object
191
- // properties - if this the case we can access a class member before it
192
- // has been initialized so dispatch the message in the microtask queue
193
- queueMicrotask(() => {
194
- this.dispatchReadBuffer();
195
- });
196
- }
197
- }
198
- /**
199
- * Receive a reset message - close immediately for reading and writing (remote
200
- * error)
201
- */
202
- onRemoteReset() {
203
- this.log('remote reset');
204
- this.status = 'reset';
205
- this.writeStatus = 'closed';
206
- this.remoteWriteStatus = 'closed';
207
- this.remoteReadStatus = 'closed';
208
- this.timeline.close = Date.now();
209
- if (this.readBuffer.byteLength === 0) {
210
- this.readStatus = 'closed';
211
- }
212
- const err = new StreamResetError();
213
- this.dispatchEvent(new StreamResetEvent(err));
214
- }
215
- /**
216
- * The underlying resource or transport this stream uses has closed - it is
217
- * not possible to send any more messages though any data still in the read
218
- * buffer may still be read
219
- */
220
- onTransportClosed(err) {
221
- this.log('transport closed');
222
- if (this.readStatus === 'readable' && this.readBuffer.byteLength === 0) {
223
- this.log('close readable end after transport closed and read buffer is empty');
224
- this.readStatus = 'closed';
225
- }
226
- if (this.remoteReadStatus !== 'closed') {
227
- this.remoteReadStatus = 'closed';
228
- }
229
- if (this.remoteWriteStatus !== 'closed') {
230
- this.remoteWriteStatus = 'closed';
231
- }
232
- if (this.writeStatus !== 'closed') {
233
- this.writeStatus = 'closed';
234
- }
235
- if (err != null) {
236
- this.abort(err);
237
- }
238
- else {
239
- if (this.status === 'open' || this.status === 'closing') {
240
- this.timeline.close = Date.now();
241
- this.status = 'closed';
242
- this.writeStatus = 'closed';
243
- this.remoteWriteStatus = 'closed';
244
- this.remoteReadStatus = 'closed';
245
- this.dispatchEvent(new StreamCloseEvent());
246
- }
247
- }
248
- }
249
- /**
250
- * Called by extending classes when the remote closes its writable end
251
- */
252
- onRemoteCloseWrite() {
253
- if (this.remoteWriteStatus === 'closed') {
254
- return;
255
- }
256
- this.log.trace('on remote close write');
257
- this.remoteWriteStatus = 'closed';
258
- this.safeDispatchEvent('remoteCloseWrite');
259
- if (this.writeStatus === 'closed') {
260
- this.onTransportClosed();
261
- }
262
- }
263
- /**
264
- * Called by extending classes when the remote closes its readable end
265
- */
266
- onRemoteCloseRead() {
267
- this.log.trace('on remote close read');
268
- this.remoteReadStatus = 'closed';
269
- // throw away any unsent bytes if the remote closes it's readable end
270
- if (this.writeBuffer.byteLength > 0) {
271
- this.writeBuffer.consume(this.writeBuffer.byteLength);
272
- this.safeDispatchEvent('idle');
273
- }
274
- }
275
- processSendQueue() {
276
- // bail if the underlying transport is full
277
- if (this.writableNeedsDrain) {
278
- this.log.trace('not processing send queue as drain is required');
279
- this.checkWriteBufferLength();
280
- return false;
281
- }
282
- // bail if there is no data to send
283
- if (this.writeBuffer.byteLength === 0) {
284
- this.log.trace('not processing send queue as no bytes to send');
285
- return true;
286
- }
287
- // bail if we are already sending data
288
- if (this.sendingData) {
289
- this.log.trace('not processing send queue as already sending data');
290
- return true;
291
- }
292
- this.sendingData = true;
293
- this.log.trace('processing send queue with %d queued bytes', this.writeBuffer.byteLength);
294
- try {
295
- let canSendMore = true;
296
- const totalBytes = this.writeBuffer.byteLength;
297
- let sentBytes = 0;
298
- // send as much data as possible while we have data to send and the
299
- // underlying muxer can still accept data
300
- while (this.writeBuffer.byteLength > 0) {
301
- const end = Math.min(this.maxMessageSize ?? this.writeBuffer.byteLength, this.writeBuffer.byteLength);
302
- // this can happen if a subclass changes the max message size dynamically
303
- if (end === 0) {
304
- canSendMore = false;
305
- break;
306
- }
307
- // chunk to send to the remote end
308
- const toSend = this.writeBuffer.sublist(0, end);
309
- // copy toSend in case the extending class modifies the list
310
- const willSend = new Uint8ArrayList(toSend);
311
- this.writeBuffer.consume(toSend.byteLength);
312
- // sending data can cause buffers to fill up, events to be emitted and
313
- // this method to be invoked again
314
- const sendResult = this.sendData(toSend);
315
- canSendMore = sendResult.canSendMore;
316
- sentBytes += sendResult.sentBytes;
317
- if (sendResult.sentBytes !== willSend.byteLength) {
318
- willSend.consume(sendResult.sentBytes);
319
- this.writeBuffer.prepend(willSend);
320
- }
321
- if (!canSendMore) {
322
- break;
323
- }
324
- }
325
- if (!canSendMore) {
326
- this.log.trace('sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer', sentBytes, totalBytes, this.writeBuffer.byteLength);
327
- this.writableNeedsDrain = true;
328
- this.checkWriteBufferLength();
329
- }
330
- // we processed all bytes in the queue, resolve the write queue idle promise
331
- if (this.writeBuffer.byteLength === 0) {
332
- this.safeDispatchEvent('idle');
333
- }
334
- return canSendMore;
335
- }
336
- finally {
337
- this.sendingData = false;
338
- }
339
- }
340
- dispatchReadBuffer() {
341
- try {
342
- if (this.listenerCount('message') === 0) {
343
- this.log.trace('not dispatching pause buffer as there are no listeners for the message event');
344
- return;
345
- }
346
- if (this.readBuffer.byteLength === 0) {
347
- this.log.trace('not dispatching pause buffer as there is no data to dispatch');
348
- return;
349
- }
350
- if (this.readStatus === 'paused') {
351
- this.log.trace('not dispatching pause buffer we are paused');
352
- return;
353
- }
354
- // discard the pause buffer if our readable end is closed
355
- if (this.readStatus === 'closing' || this.readStatus === 'closed') {
356
- this.log('dropping %d bytes because the readable end is %s', this.readBuffer.byteLength, this.readStatus);
357
- this.readBuffer.consume(this.readBuffer.byteLength);
358
- return;
359
- }
360
- const buf = this.readBuffer.sublist();
361
- this.readBuffer.consume(buf.byteLength);
362
- this.dispatchEvent(new StreamMessageEvent(buf));
363
- }
364
- finally {
365
- if (this.readBuffer.byteLength === 0 && this.remoteWriteStatus === 'closed') {
366
- this.log('close readable end after dispatching read buffer and remote writable end is closed');
367
- this.readStatus = 'closed';
368
- }
369
- // abort if we failed to consume the read buffer and it is too large
370
- this.checkReadBufferLength();
371
- }
372
- }
373
- checkReadBufferLength() {
374
- if (this.readBuffer.byteLength > this.maxReadBufferLength) {
375
- this.abort(new StreamBufferError(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`));
376
- }
377
- }
378
- checkWriteBufferLength() {
379
- if (this.maxWriteBufferLength == null) {
380
- return;
381
- }
382
- if (this.writeBuffer.byteLength > this.maxWriteBufferLength) {
383
- this.abort(new StreamBufferError(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`));
384
- }
385
- }
386
- onMuxerNeedsDrain() {
387
- this.writableNeedsDrain = true;
388
- }
389
- onMuxerDrain() {
390
- this.safeDispatchEvent('drain');
391
- }
392
- }
393
- //# sourceMappingURL=abstract-message-stream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract-message-stream.js","sourceRoot":"","sources":["../../src/abstract-message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACtL,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAI/C,MAAM,8BAA8B,G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