@libp2p/utils 6.7.2 → 7.0.0-55b7e5fea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/index.min.js +7 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/abstract-message-stream.d.ts +129 -0
- package/dist/src/abstract-message-stream.d.ts.map +1 -0
- package/dist/src/abstract-message-stream.js +393 -0
- package/dist/src/abstract-message-stream.js.map +1 -0
- package/dist/src/abstract-multiaddr-connection.d.ts +26 -0
- package/dist/src/abstract-multiaddr-connection.d.ts.map +1 -0
- package/dist/src/abstract-multiaddr-connection.js +66 -0
- package/dist/src/abstract-multiaddr-connection.js.map +1 -0
- package/dist/src/abstract-stream-muxer.d.ts +53 -0
- package/dist/src/abstract-stream-muxer.d.ts.map +1 -0
- package/dist/src/abstract-stream-muxer.js +169 -0
- package/dist/src/abstract-stream-muxer.js.map +1 -0
- package/dist/src/abstract-stream.d.ts +14 -130
- package/dist/src/abstract-stream.d.ts.map +1 -1
- package/dist/src/abstract-stream.js +39 -321
- package/dist/src/abstract-stream.js.map +1 -1
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +8 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/get-thin-waist-addresses.browser.d.ts +1 -1
- package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -1
- package/dist/src/get-thin-waist-addresses.browser.js +4 -3
- package/dist/src/get-thin-waist-addresses.browser.js.map +1 -1
- package/dist/src/get-thin-waist-addresses.d.ts +1 -1
- package/dist/src/get-thin-waist-addresses.d.ts.map +1 -1
- package/dist/src/get-thin-waist-addresses.js +7 -9
- package/dist/src/get-thin-waist-addresses.js.map +1 -1
- package/dist/src/index.d.ts +31 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +31 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/length-prefixed-decoder.d.ts +37 -0
- package/dist/src/length-prefixed-decoder.d.ts.map +1 -0
- package/dist/src/length-prefixed-decoder.js +64 -0
- package/dist/src/length-prefixed-decoder.js.map +1 -0
- package/dist/src/message-queue.d.ts +61 -0
- package/dist/src/message-queue.d.ts.map +1 -0
- package/dist/src/message-queue.js +93 -0
- package/dist/src/message-queue.js.map +1 -0
- package/dist/src/mock-muxer.d.ts +57 -0
- package/dist/src/mock-muxer.d.ts.map +1 -0
- package/dist/src/mock-muxer.js +204 -0
- package/dist/src/mock-muxer.js.map +1 -0
- package/dist/src/mock-stream.d.ts +31 -0
- package/dist/src/mock-stream.d.ts.map +1 -0
- package/dist/src/mock-stream.js +69 -0
- package/dist/src/mock-stream.js.map +1 -0
- package/dist/src/multiaddr/get-net-config.d.ts +55 -0
- package/dist/src/multiaddr/get-net-config.d.ts.map +1 -0
- package/dist/src/multiaddr/get-net-config.js +54 -0
- package/dist/src/multiaddr/get-net-config.js.map +1 -0
- package/dist/src/multiaddr/index.d.ts +7 -0
- package/dist/src/multiaddr/index.d.ts.map +1 -0
- package/dist/src/multiaddr/index.js +7 -0
- package/dist/src/multiaddr/index.js.map +1 -0
- package/dist/src/multiaddr/is-global-unicast.d.ts.map +1 -1
- package/dist/src/multiaddr/is-global-unicast.js +8 -9
- package/dist/src/multiaddr/is-global-unicast.js.map +1 -1
- package/dist/src/multiaddr/is-link-local.d.ts.map +1 -1
- package/dist/src/multiaddr/is-link-local.js +11 -16
- package/dist/src/multiaddr/is-link-local.js.map +1 -1
- package/dist/src/multiaddr/is-loopback.d.ts.map +1 -1
- package/dist/src/multiaddr/is-loopback.js +12 -5
- package/dist/src/multiaddr/is-loopback.js.map +1 -1
- package/dist/src/multiaddr/is-network-address.d.ts.map +1 -1
- package/dist/src/multiaddr/is-network-address.js +4 -16
- package/dist/src/multiaddr/is-network-address.js.map +1 -1
- package/dist/src/multiaddr/is-private.d.ts.map +1 -1
- package/dist/src/multiaddr/is-private.js +9 -10
- package/dist/src/multiaddr/is-private.js.map +1 -1
- package/dist/src/multiaddr/utils.d.ts +5 -0
- package/dist/src/multiaddr/utils.d.ts.map +1 -0
- package/dist/src/multiaddr/utils.js +32 -0
- package/dist/src/multiaddr/utils.js.map +1 -0
- package/dist/src/multiaddr-connection-pair.d.ts +25 -0
- package/dist/src/multiaddr-connection-pair.d.ts.map +1 -0
- package/dist/src/multiaddr-connection-pair.js +103 -0
- package/dist/src/multiaddr-connection-pair.js.map +1 -0
- package/dist/src/queue/index.d.ts +3 -6
- package/dist/src/queue/index.d.ts.map +1 -1
- package/dist/src/queue/index.js +20 -4
- package/dist/src/queue/index.js.map +1 -1
- package/dist/src/rate-limiter.d.ts +1 -15
- package/dist/src/rate-limiter.d.ts.map +1 -1
- package/dist/src/rate-limiter.js +1 -14
- package/dist/src/rate-limiter.js.map +1 -1
- package/dist/src/stream-pair.d.ts +42 -0
- package/dist/src/stream-pair.d.ts.map +1 -0
- package/dist/src/stream-pair.js +40 -0
- package/dist/src/stream-pair.js.map +1 -0
- package/dist/src/stream-utils.d.ts +191 -0
- package/dist/src/stream-utils.d.ts.map +1 -0
- package/dist/src/stream-utils.js +371 -0
- package/dist/src/stream-utils.js.map +1 -0
- package/package.json +15 -162
- package/src/abstract-message-stream.ts +553 -0
- package/src/abstract-multiaddr-connection.ts +93 -0
- package/src/abstract-stream-muxer.ts +239 -0
- package/src/abstract-stream.ts +51 -464
- package/src/errors.ts +10 -0
- package/src/get-thin-waist-addresses.browser.ts +5 -4
- package/src/get-thin-waist-addresses.ts +8 -12
- package/src/index.ts +31 -1
- package/src/length-prefixed-decoder.ts +98 -0
- package/src/message-queue.ts +156 -0
- package/src/mock-muxer.ts +304 -0
- package/src/mock-stream.ts +101 -0
- package/src/multiaddr/get-net-config.ts +112 -0
- package/src/multiaddr/index.ts +6 -0
- package/src/multiaddr/is-global-unicast.ts +8 -11
- package/src/multiaddr/is-link-local.ts +11 -20
- package/src/multiaddr/is-loopback.ts +12 -7
- package/src/multiaddr/is-network-address.ts +4 -19
- package/src/multiaddr/is-private.ts +9 -14
- package/src/multiaddr/utils.ts +46 -0
- package/src/multiaddr-connection-pair.ts +147 -0
- package/src/queue/index.ts +24 -11
- package/src/rate-limiter.ts +3 -30
- package/src/stream-pair.ts +90 -0
- package/src/stream-utils.ts +866 -0
- package/dist/src/abort-options.d.ts +0 -7
- package/dist/src/abort-options.d.ts.map +0 -1
- package/dist/src/abort-options.js +0 -14
- package/dist/src/abort-options.js.map +0 -1
- package/dist/src/array-equals.d.ts +0 -24
- package/dist/src/array-equals.d.ts.map +0 -1
- package/dist/src/array-equals.js +0 -31
- package/dist/src/array-equals.js.map +0 -1
- package/dist/src/close-source.d.ts +0 -4
- package/dist/src/close-source.d.ts.map +0 -1
- package/dist/src/close-source.js +0 -11
- package/dist/src/close-source.js.map +0 -1
- package/dist/src/close.d.ts +0 -21
- package/dist/src/close.d.ts.map +0 -1
- package/dist/src/close.js +0 -49
- package/dist/src/close.js.map +0 -1
- package/dist/src/merge-options.d.ts +0 -7
- package/dist/src/merge-options.d.ts.map +0 -1
- package/dist/src/merge-options.js +0 -128
- package/dist/src/merge-options.js.map +0 -1
- package/dist/src/multiaddr/is-ip-based.d.ts +0 -6
- package/dist/src/multiaddr/is-ip-based.d.ts.map +0 -1
- package/dist/src/multiaddr/is-ip-based.js +0 -18
- package/dist/src/multiaddr/is-ip-based.js.map +0 -1
- package/dist/src/stream-to-ma-conn.d.ts +0 -23
- package/dist/src/stream-to-ma-conn.d.ts.map +0 -1
- package/dist/src/stream-to-ma-conn.js +0 -75
- package/dist/src/stream-to-ma-conn.js.map +0 -1
- package/dist/typedoc-urls.json +0 -147
- package/src/abort-options.ts +0 -20
- package/src/array-equals.ts +0 -34
- package/src/close-source.ts +0 -14
- package/src/close.ts +0 -65
- package/src/merge-options.ts +0 -161
- package/src/multiaddr/is-ip-based.ts +0 -21
- package/src/stream-to-ma-conn.ts +0 -106
|
@@ -0,0 +1,129 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-message-stream.d.ts","sourceRoot":"","sources":["../../src/abstract-message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,iBAAiB,EAAiH,MAAM,mBAAmB,CAAA;AAEtL,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,aAAa,EAAE,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,YAAY,EAAE,aAAa,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAC7O,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAI5C,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAElC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,8BAAsB,qBAAqB,CAAC,QAAQ,SAAS,qBAAqB,GAAG,qBAAqB,CAAE,SAAQ,iBAAiB,CAAC,mBAAmB,CAAE,YAAW,aAAa;IAC1K,MAAM,EAAE,mBAAmB,CAAA;IAClC,SAAgB,QAAQ,EAAE,QAAQ,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IACpC,SAAgB,GAAG,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,sBAAsB,CAAA;IACjC,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,UAA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CrC;;OAEG;IACH,kBAAkB,IAAK,IAAI;IAgB3B;;OAEG;IACH,iBAAiB,IAAK,IAAI;IAY1B,SAAS,CAAC,gBAAgB,IAAK,OAAO;IAkFtC,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"}
|
|
@@ -0,0 +1,393 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA,CAAC,MAAM;AAiCjE,MAAM,OAAgB,qBAAsF,SAAQ,iBAAsC;IACjJ,MAAM,CAAqB;IAClB,QAAQ,CAAU;IAC3B,iBAAiB,CAAQ;IACzB,mBAAmB,CAAQ;IAC3B,oBAAoB,C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AI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAChL,CAAC;IACH,CAAC;IAEM,iBAAiB;QACtB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAA;IAChC,CAAC;IAEM,YAAY;QACjB,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;CAqCF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AbstractMessageStream } from './abstract-message-stream.ts';
|
|
2
|
+
import type { MessageStreamInit } from './abstract-message-stream.ts';
|
|
3
|
+
import type { CounterGroup, Logger, MultiaddrConnection, MessageStreamDirection, AbortOptions } from '@libp2p/interface';
|
|
4
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
5
|
+
export interface AbstractMultiaddrConnectionInit extends Omit<MessageStreamInit, 'log'> {
|
|
6
|
+
remoteAddr: Multiaddr;
|
|
7
|
+
direction: MessageStreamDirection;
|
|
8
|
+
log: Logger;
|
|
9
|
+
inactivityTimeout?: number;
|
|
10
|
+
localAddr?: Multiaddr;
|
|
11
|
+
metricPrefix?: string;
|
|
12
|
+
metrics?: CounterGroup;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class AbstractMultiaddrConnection extends AbstractMessageStream implements MultiaddrConnection {
|
|
15
|
+
remoteAddr: Multiaddr;
|
|
16
|
+
private metricPrefix;
|
|
17
|
+
private metrics?;
|
|
18
|
+
constructor(init: AbstractMultiaddrConnectionInit);
|
|
19
|
+
close(options?: AbortOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Wait for any unsent data to be written to the underlying resource, then
|
|
22
|
+
* close the resource and resolve the returned promise
|
|
23
|
+
*/
|
|
24
|
+
abstract sendClose(options?: AbortOptions): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=abstract-multiaddr-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-multiaddr-connection.d.ts","sourceRoot":"","sources":["../../src/abstract-multiaddr-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,+BAAgC,SAAQ,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC;IACrF,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,sBAAsB,CAAA;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,8BAAsB,2BAA4B,SAAQ,qBAAsB,YAAW,mBAAmB;IACrG,UAAU,EAAE,SAAS,CAAA;IAE5B,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,OAAO,CAAC,CAAc;gBAEjB,IAAI,EAAE,+BAA+B;IA0B5C,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAuCnD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAC3D"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { pEvent } from 'p-event';
|
|
2
|
+
import { AbstractMessageStream } from "./abstract-message-stream.js";
|
|
3
|
+
export class AbstractMultiaddrConnection extends AbstractMessageStream {
|
|
4
|
+
remoteAddr;
|
|
5
|
+
metricPrefix;
|
|
6
|
+
metrics;
|
|
7
|
+
constructor(init) {
|
|
8
|
+
super(init);
|
|
9
|
+
this.metricPrefix = init.metricPrefix ?? '';
|
|
10
|
+
this.metrics = init.metrics;
|
|
11
|
+
this.remoteAddr = init.remoteAddr;
|
|
12
|
+
this.addEventListener('close', (evt) => {
|
|
13
|
+
this.metrics?.increment({ [`${this.metricPrefix}end`]: true });
|
|
14
|
+
if (evt.error != null) {
|
|
15
|
+
if (evt.local) {
|
|
16
|
+
this.metrics?.increment({ [`${this.metricPrefix}abort`]: true });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.metrics?.increment({ [`${this.metricPrefix}reset`]: true });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
if (evt.local) {
|
|
24
|
+
this.metrics?.increment({ [`${this.metricPrefix}_local_close`]: true });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.metrics?.increment({ [`${this.metricPrefix}_remote_close`]: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async close(options) {
|
|
33
|
+
if (this.status !== 'open') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.status = 'closing';
|
|
37
|
+
this.writeStatus = 'closing';
|
|
38
|
+
this.remoteWriteStatus = 'closing';
|
|
39
|
+
this.remoteReadStatus = 'closing';
|
|
40
|
+
// if we are currently sending data, wait for all the data to be written
|
|
41
|
+
// into the underlying transport
|
|
42
|
+
if (this.sendingData || this.writeBuffer.byteLength > 0) {
|
|
43
|
+
this.log('waiting for write queue to become idle before closing writable end of stream, %d unsent bytes', this.writeBuffer.byteLength);
|
|
44
|
+
await pEvent(this, 'idle', {
|
|
45
|
+
...options,
|
|
46
|
+
rejectionEvents: [
|
|
47
|
+
'close'
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// now that the underlying transport has all the data, if the buffer is full
|
|
52
|
+
// wait for it to be emptied
|
|
53
|
+
if (this.writableNeedsDrain) {
|
|
54
|
+
this.log('waiting for write queue to drain before closing writable end of stream, %d unsent bytes', this.writeBuffer.byteLength);
|
|
55
|
+
await pEvent(this, 'drain', {
|
|
56
|
+
...options,
|
|
57
|
+
rejectionEvents: [
|
|
58
|
+
'close'
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
await this.sendClose(options);
|
|
63
|
+
this.onTransportClosed();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=abstract-multiaddr-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-multiaddr-connection.js","sourceRoot":"","sources":["../../src/abstract-multiaddr-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAepE,MAAM,OAAgB,2BAA4B,SAAQ,qBAAqB;IACtE,UAAU,CAAW;IAEpB,YAAY,CAAQ;IACpB,OAAO,CAAe;IAE9B,YAAa,IAAqC;QAChD,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,EAAE,CAAA;QAC3C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QAEjC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACrC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;YAE9D,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;gBACtB,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;oBACd,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,CA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