@libp2p/mplex 11.0.46-cf9aab5c8 → 11.0.47-a02cb0461
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/encode.d.ts +1 -2
- package/dist/src/encode.d.ts.map +1 -1
- package/dist/src/encode.js +4 -6
- package/dist/src/encode.js.map +1 -1
- package/dist/src/index.d.ts +5 -31
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/mplex.d.ts +11 -53
- package/dist/src/mplex.d.ts.map +1 -1
- package/dist/src/mplex.js +56 -222
- package/dist/src/mplex.js.map +1 -1
- package/dist/src/stream.d.ts +17 -23
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +56 -28
- package/dist/src/stream.js.map +1 -1
- package/package.json +12 -15
- package/src/encode.ts +5 -7
- package/src/index.ts +10 -43
- package/src/mplex.ts +58 -273
- package/src/stream.ts +78 -46
package/dist/src/mplex.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mplex.js","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"mplex.js","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAA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AAI,KAAK,CAAC,uCAAuC,CAAC,CAAC,CAAA;gBAC9D,OAAM;YACR,CAAC;YAED,OAAM;QACR,CAAC;QAED,IAAI,CAAC;YACH,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;gBACrB,KAAK,YAAY,CAAC,iBAAiB,CAAC;gBACpC,KAAK,YAAY,CAAC,gBAAgB;oBAChC,6DAA6D;oBAC7D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;oBAC3B,MAAK;gBACP,KAAK,YAAY,CAAC,eAAe,CAAC;gBAClC,KAAK,YAAY,CAAC,cAAc;oBAC9B,iCAAiC;oBACjC,MAAM,CAAC,kBAAkB,EAAE,CAAA;oBAC3B,MAAK;gBACP,KAAK,YAAY,CAAC,eAAe,CAAC;gBAClC,KAAK,YAAY,CAAC,cAAc;oBAC9B,6EAA6E;oBAC7E,MAAM,CAAC,aAAa,EAAE,CAAA;oBACtB,MAAK;gBACP;oBACE,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;YACpC,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAA;YAC1D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/stream.d.ts
CHANGED
@@ -1,39 +1,33 @@
|
|
1
|
-
import { AbstractStream } from '@libp2p/utils
|
1
|
+
import { AbstractStream } from '@libp2p/utils';
|
2
2
|
import { Uint8ArrayList } from 'uint8arraylist';
|
3
|
-
import type {
|
4
|
-
import type { Logger } from '@libp2p/interface';
|
5
|
-
import type { AbstractStreamInit } from '@libp2p/utils
|
3
|
+
import type { MplexStreamMuxer } from './mplex.ts';
|
4
|
+
import type { Logger, MessageStreamDirection } from '@libp2p/interface';
|
5
|
+
import type { AbstractStreamInit, SendResult } from '@libp2p/utils';
|
6
|
+
import type { AbortOptions } from 'it-pushable';
|
6
7
|
export interface Options {
|
7
8
|
id: number;
|
8
|
-
send(msg: Message): Promise<void>;
|
9
9
|
log: Logger;
|
10
|
-
|
11
|
-
onEnd?(err?: Error): void;
|
12
|
-
type?: 'initiator' | 'receiver';
|
10
|
+
direction: MessageStreamDirection;
|
13
11
|
maxMsgSize?: number;
|
12
|
+
muxer: MplexStreamMuxer;
|
14
13
|
}
|
15
14
|
interface MplexStreamInit extends AbstractStreamInit {
|
16
|
-
streamId: number;
|
17
|
-
name: string;
|
18
|
-
send(msg: Message): Promise<void>;
|
19
|
-
/**
|
20
|
-
* The maximum allowable data size, any data larger than this will be
|
21
|
-
* chunked and sent in multiple data messages
|
22
|
-
*/
|
23
15
|
maxDataSize: number;
|
16
|
+
muxer: MplexStreamMuxer;
|
17
|
+
direction: MessageStreamDirection;
|
24
18
|
}
|
25
19
|
export declare class MplexStream extends AbstractStream {
|
26
|
-
|
27
|
-
private readonly streamId;
|
28
|
-
private readonly send;
|
20
|
+
readonly streamId: number;
|
29
21
|
private readonly types;
|
30
22
|
private readonly maxDataSize;
|
23
|
+
private readonly muxer;
|
31
24
|
constructor(init: MplexStreamInit);
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
25
|
+
sendData(data: Uint8ArrayList): SendResult;
|
26
|
+
sendReset(): boolean;
|
27
|
+
sendCloseWrite(options?: AbortOptions): Promise<void>;
|
28
|
+
sendCloseRead(options?: AbortOptions): Promise<void>;
|
29
|
+
sendPause(): void;
|
30
|
+
sendResume(): void;
|
37
31
|
}
|
38
32
|
export declare function createStream(options: Options): MplexStream;
|
39
33
|
export {};
|
package/dist/src/stream.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../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,CAAE,OAAO,EAAE,OAAO,GAAG,WAAW,CAY3D"}
|
package/dist/src/stream.js
CHANGED
@@ -1,59 +1,87 @@
|
|
1
|
-
import { AbstractStream } from '@libp2p/utils
|
1
|
+
import { AbstractStream } from '@libp2p/utils';
|
2
2
|
import { Uint8ArrayList } from 'uint8arraylist';
|
3
3
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
4
4
|
import { MAX_MSG_SIZE } from './decode.js';
|
5
|
+
import { encode } from "./encode.js";
|
5
6
|
import { InitiatorMessageTypes, ReceiverMessageTypes } from './message-types.js';
|
6
7
|
export class MplexStream extends AbstractStream {
|
7
|
-
name;
|
8
8
|
streamId;
|
9
|
-
send;
|
10
9
|
types;
|
11
10
|
maxDataSize;
|
11
|
+
muxer;
|
12
12
|
constructor(init) {
|
13
13
|
super(init);
|
14
14
|
this.types = init.direction === 'outbound' ? InitiatorMessageTypes : ReceiverMessageTypes;
|
15
|
-
this.send = init.send;
|
16
|
-
this.name = init.name;
|
17
|
-
this.streamId = init.streamId;
|
18
15
|
this.maxDataSize = init.maxDataSize;
|
16
|
+
this.muxer = init.muxer;
|
17
|
+
this.streamId = parseInt(this.id.substring(1));
|
18
|
+
if (init.direction === 'outbound') {
|
19
|
+
// open the stream on the receiver end. do this in a microtask so the
|
20
|
+
// stream gets added to the streams array by the muxer superclass before
|
21
|
+
// we send the NEW_STREAM message, otherwise we create a race condition
|
22
|
+
// whereby we can receive the stream messages before the stream is added
|
23
|
+
// to the streams list
|
24
|
+
queueMicrotask(() => {
|
25
|
+
this.muxer.send(encode({
|
26
|
+
id: this.streamId,
|
27
|
+
type: InitiatorMessageTypes.NEW_STREAM,
|
28
|
+
data: new Uint8ArrayList(uint8ArrayFromString(this.id))
|
29
|
+
}));
|
30
|
+
});
|
31
|
+
}
|
19
32
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
async sendData(data) {
|
24
|
-
data = data.sublist();
|
33
|
+
sendData(data) {
|
34
|
+
const list = new Uint8ArrayList();
|
35
|
+
const sentBytes = data.byteLength;
|
25
36
|
while (data.byteLength > 0) {
|
26
37
|
const toSend = Math.min(data.byteLength, this.maxDataSize);
|
27
|
-
|
38
|
+
const slice = data.sublist(0, toSend);
|
39
|
+
data = data.sublist(toSend);
|
40
|
+
list.append(encode({
|
28
41
|
id: this.streamId,
|
29
42
|
type: this.types.MESSAGE,
|
30
|
-
data:
|
31
|
-
});
|
32
|
-
data.consume(toSend);
|
43
|
+
data: slice
|
44
|
+
}));
|
33
45
|
}
|
46
|
+
return {
|
47
|
+
sentBytes,
|
48
|
+
canSendMore: this.muxer.send(list)
|
49
|
+
};
|
34
50
|
}
|
35
|
-
|
36
|
-
|
51
|
+
sendReset() {
|
52
|
+
return this.muxer.send(encode({
|
53
|
+
id: this.streamId,
|
54
|
+
type: this.types.RESET
|
55
|
+
}));
|
37
56
|
}
|
38
|
-
async sendCloseWrite() {
|
39
|
-
|
57
|
+
async sendCloseWrite(options) {
|
58
|
+
this.muxer.send(encode({
|
59
|
+
id: this.streamId,
|
60
|
+
type: this.types.CLOSE
|
61
|
+
}));
|
62
|
+
options?.signal?.throwIfAborted();
|
40
63
|
}
|
41
|
-
async sendCloseRead() {
|
64
|
+
async sendCloseRead(options) {
|
65
|
+
options?.signal?.throwIfAborted();
|
42
66
|
// mplex does not support close read, only close write
|
43
67
|
}
|
68
|
+
sendPause() {
|
69
|
+
// mplex does not support backpressure
|
70
|
+
}
|
71
|
+
sendResume() {
|
72
|
+
// mplex does not support backpressure
|
73
|
+
}
|
44
74
|
}
|
45
75
|
export function createStream(options) {
|
46
|
-
const { id,
|
47
|
-
const direction = type === 'initiator' ? 'outbound' : 'inbound';
|
76
|
+
const { id, muxer, direction, maxMsgSize = MAX_MSG_SIZE } = options;
|
48
77
|
return new MplexStream({
|
49
|
-
|
50
|
-
|
51
|
-
name: `${name ?? id}`,
|
78
|
+
...options,
|
79
|
+
id: direction === 'outbound' ? (`i${id}`) : `r${id}`,
|
52
80
|
direction,
|
53
81
|
maxDataSize: maxMsgSize,
|
54
|
-
|
55
|
-
|
56
|
-
|
82
|
+
muxer,
|
83
|
+
log: options.log.newScope(`${direction}:${id}`),
|
84
|
+
protocol: ''
|
57
85
|
});
|
58
86
|
}
|
59
87
|
//# sourceMappingURL=stream.js.map
|
package/dist/src/stream.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAoBhF,MAAM,OAAO,WAAY,SAAQ,cAAc;IAC7B,QAAQ,CAAQ;IACf,KAAK,CAAwB;IAC7B,WAAW,CAAQ;IACnB,KAAK,CAAkB;IAExC,YAAa,IAAqB;QAChC,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,oBAAoB,CAAA;QACzF,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;QACnC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,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M,CAAC;YACL,EAAE,EAAE,IAAI,CAAC,QAAQ;YACjB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;SACvB,CAAC,CACH,CAAA;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAE,OAAsB;QAC1C,IAAI,CAAC,KAAK,CAAC,IAAI,CACb,MAAM,CAAC;YACL,EAAE,EAAE,IAAI,CAAC,QAAQ;YACjB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;SACvB,CAAC,CACH,CAAA;QACD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;IACnC,CAAC;IAED,KAAK,CAAC,aAAa,CAAE,OAAsB;QACzC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QACjC,sDAAsD;IACxD,CAAC;IAED,SAAS;QACP,sCAAsC;IACxC,CAAC;IAED,UAAU;QACR,sCAAsC;IACxC,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAE,OAAgB;IAC5C,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,GAAG,YAAY,EAAE,GAAG,OAAO,CAAA;IAEnE,OAAO,IAAI,WAAW,CAAC;QACrB,GAAG,OAAO;QACV,EAAE,EAAE,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE;QACpD,SAAS;QACT,WAAW,EAAE,UAAU;QACvB,KAAK;QACL,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,SAAS,IAAI,EAAE,EAAE,CAAC;QAC/C,QAAQ,EAAE,EAAE;KACb,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/mplex",
|
3
|
-
"version": "11.0.
|
3
|
+
"version": "11.0.47-a02cb0461",
|
4
4
|
"description": "JavaScript implementation of https://github.com/libp2p/mplex",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex#readme",
|
@@ -55,29 +55,26 @@
|
|
55
55
|
"test:electron-main": "aegir test -t electron-main"
|
56
56
|
},
|
57
57
|
"dependencies": {
|
58
|
-
"@libp2p/interface": "2.
|
59
|
-
"@libp2p/utils": "6.7.
|
60
|
-
"it-pipe": "^3.0.1",
|
58
|
+
"@libp2p/interface": "2.11.0-a02cb0461",
|
59
|
+
"@libp2p/utils": "6.7.2-a02cb0461",
|
61
60
|
"it-pushable": "^3.2.3",
|
62
|
-
"it-stream-types": "^2.0.2",
|
63
61
|
"uint8-varint": "^2.0.4",
|
64
62
|
"uint8arraylist": "^2.4.8",
|
65
63
|
"uint8arrays": "^5.1.0"
|
66
64
|
},
|
67
65
|
"devDependencies": {
|
68
|
-
"@libp2p/interface-compliance-tests": "6.
|
69
|
-
"@libp2p/logger": "5.
|
70
|
-
"aegir": "^47.0.
|
66
|
+
"@libp2p/interface-compliance-tests": "6.5.0-a02cb0461",
|
67
|
+
"@libp2p/logger": "5.2.0-a02cb0461",
|
68
|
+
"aegir": "^47.0.21",
|
71
69
|
"benchmark": "^2.1.4",
|
72
|
-
"cborg": "^4.2.11",
|
73
|
-
"delay": "^6.0.0",
|
74
70
|
"iso-random-stream": "^2.0.2",
|
75
|
-
"it-all": "^3.0.
|
76
|
-
"it-drain": "^3.0.
|
77
|
-
"it-foreach": "^2.1.
|
78
|
-
"it-map": "^3.1.3",
|
71
|
+
"it-all": "^3.0.9",
|
72
|
+
"it-drain": "^3.0.10",
|
73
|
+
"it-foreach": "^2.1.4",
|
79
74
|
"it-pair": "^2.0.6",
|
80
|
-
"
|
75
|
+
"it-pipe": "^3.0.1",
|
76
|
+
"it-stream-types": "^2.0.2",
|
77
|
+
"p-event": "^6.0.1",
|
81
78
|
"random-int": "^3.0.0"
|
82
79
|
},
|
83
80
|
"sideEffects": false
|
package/src/encode.ts
CHANGED
@@ -3,7 +3,6 @@ import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
3
|
import { allocUnsafe } from 'uint8arrays/alloc'
|
4
4
|
import { MessageTypes } from './message-types.js'
|
5
5
|
import type { Message } from './message-types.js'
|
6
|
-
import type { Source } from 'it-stream-types'
|
7
6
|
|
8
7
|
const POOL_SIZE = 10 * 1024
|
9
8
|
|
@@ -56,10 +55,9 @@ const encoder = new Encoder()
|
|
56
55
|
/**
|
57
56
|
* Encode and yield one or more messages
|
58
57
|
*/
|
59
|
-
export
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
}
|
58
|
+
export function encode (message: Message): Uint8ArrayList {
|
59
|
+
const list = new Uint8ArrayList()
|
60
|
+
encoder.write(message, list)
|
61
|
+
|
62
|
+
return list
|
65
63
|
}
|
package/src/index.ts
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
*
|
4
4
|
* This is a [simple stream multiplexer(https://docs.libp2p.io/concepts/multiplex/mplex/) that has been deprecated.
|
5
5
|
*
|
6
|
-
* Please use [@
|
6
|
+
* Please use [@libp2p/yamux](https://www.npmjs.com/package/@libp2p/yamux) instead.
|
7
7
|
*
|
8
8
|
* @example
|
9
9
|
*
|
@@ -33,10 +33,7 @@
|
|
33
33
|
|
34
34
|
import { serviceCapabilities } from '@libp2p/interface'
|
35
35
|
import { MplexStreamMuxer } from './mplex.js'
|
36
|
-
import type {
|
37
|
-
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface'
|
38
|
-
|
39
|
-
export type { MplexComponents }
|
36
|
+
import type { MultiaddrConnection, StreamMuxer, StreamMuxerFactory } from '@libp2p/interface'
|
40
37
|
|
41
38
|
export interface MplexInit {
|
42
39
|
/**
|
@@ -45,9 +42,9 @@ export interface MplexInit {
|
|
45
42
|
* messages. If we receive a message larger than this an error will
|
46
43
|
* be thrown and the connection closed.
|
47
44
|
*
|
48
|
-
* @default
|
45
|
+
* @default 1_048_576
|
49
46
|
*/
|
50
|
-
|
47
|
+
maxMessageSize?: number
|
51
48
|
|
52
49
|
/**
|
53
50
|
* Constrains the size of the unprocessed message queue buffer.
|
@@ -55,37 +52,10 @@ export interface MplexInit {
|
|
55
52
|
* we have the complete message to deserialized. If the queue gets longer
|
56
53
|
* than this value an error will be thrown and the connection closed.
|
57
54
|
*
|
58
|
-
* @default
|
55
|
+
* @default 4_194_304
|
59
56
|
*/
|
60
57
|
maxUnprocessedMessageQueueSize?: number
|
61
58
|
|
62
|
-
/**
|
63
|
-
* The maximum number of multiplexed streams that can be open at any
|
64
|
-
* one time. A request to open more than this will have a stream
|
65
|
-
* reset message sent immediately as a response for the newly opened
|
66
|
-
* stream id
|
67
|
-
*
|
68
|
-
* @default 1024
|
69
|
-
*/
|
70
|
-
maxInboundStreams?: number
|
71
|
-
|
72
|
-
/**
|
73
|
-
* The maximum number of multiplexed streams that can be open at any
|
74
|
-
* one time. An attempt to open more than this will throw
|
75
|
-
*
|
76
|
-
* @default 1024
|
77
|
-
*/
|
78
|
-
maxOutboundStreams?: number
|
79
|
-
|
80
|
-
/**
|
81
|
-
* Incoming stream messages are buffered until processed by the stream
|
82
|
-
* handler. If the buffer reaches this size in bytes the stream will
|
83
|
-
* be reset
|
84
|
-
*
|
85
|
-
* @default 4194304
|
86
|
-
*/
|
87
|
-
maxStreamBufferSize?: number
|
88
|
-
|
89
59
|
/**
|
90
60
|
* When `maxInboundStreams` is hit, if the remote continues try to open
|
91
61
|
* more than this many new multiplexed streams per second the connection
|
@@ -99,10 +69,8 @@ export interface MplexInit {
|
|
99
69
|
class Mplex implements StreamMuxerFactory {
|
100
70
|
public protocol = '/mplex/6.7.0'
|
101
71
|
private readonly _init: MplexInit
|
102
|
-
private readonly components: MplexComponents
|
103
72
|
|
104
|
-
constructor (
|
105
|
-
this.components = components
|
73
|
+
constructor (init: MplexInit = {}) {
|
106
74
|
this._init = init
|
107
75
|
}
|
108
76
|
|
@@ -112,9 +80,8 @@ class Mplex implements StreamMuxerFactory {
|
|
112
80
|
'@libp2p/stream-multiplexing'
|
113
81
|
]
|
114
82
|
|
115
|
-
createStreamMuxer (
|
116
|
-
return new MplexStreamMuxer(
|
117
|
-
...init,
|
83
|
+
createStreamMuxer (maConn: MultiaddrConnection): StreamMuxer {
|
84
|
+
return new MplexStreamMuxer(maConn, {
|
118
85
|
...this._init
|
119
86
|
})
|
120
87
|
}
|
@@ -123,6 +90,6 @@ class Mplex implements StreamMuxerFactory {
|
|
123
90
|
/**
|
124
91
|
* @deprecated mplex is deprecated as it has no flow control. Please use yamux instead.
|
125
92
|
*/
|
126
|
-
export function mplex (init: MplexInit = {}): (
|
127
|
-
return (
|
93
|
+
export function mplex (init: MplexInit = {}): () => StreamMuxerFactory {
|
94
|
+
return () => new Mplex(init)
|
128
95
|
}
|