@libp2p/mplex 1.2.1 → 2.0.0
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 +85 -70
- package/dist/src/index.d.ts +7 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/mplex.d.ts +3 -3
- package/dist/src/mplex.d.ts.map +1 -1
- package/dist/src/mplex.js +1 -1
- package/dist/src/mplex.js.map +1 -1
- package/package.json +7 -4
- package/src/index.ts +13 -8
- package/src/mplex.ts +4 -4
- package/src/stream.ts +1 -1
package/README.md
CHANGED
@@ -1,26 +1,41 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
[](http://libp2p.io/)
|
4
|
+
[](http://webchat.freenode.net/?channels=%23libp2p)
|
5
|
+
[](https://discuss.libp2p.io)
|
6
|
+
[](https://codecov.io/gh/libp2p/js-libp2p-mplex)
|
7
|
+
[](https://github.com/libp2p/js-libp2p-mplex/actions/workflows/js-test-and-release.yml)
|
8
|
+
|
9
|
+
> JavaScript implementation of <https://github.com/libp2p/mplex>
|
10
|
+
|
11
|
+
## Table of contents <!-- omit in toc -->
|
12
|
+
|
13
|
+
- [Install](#install)
|
14
|
+
- [Usage](#usage)
|
15
|
+
- [API](#api)
|
16
|
+
- [`const factory = new Mplex([options])`](#const-factory--new-mplexoptions)
|
17
|
+
- [`const muxer = factory.createStreamMuxer(components, [options])`](#const-muxer--factorycreatestreammuxercomponents-options)
|
18
|
+
- [`muxer.onStream`](#muxeronstream)
|
19
|
+
- [`muxer.onStreamEnd`](#muxeronstreamend)
|
20
|
+
- [`muxer.streams`](#muxerstreams)
|
21
|
+
- [`const stream = muxer.newStream([options])`](#const-stream--muxernewstreamoptions)
|
22
|
+
- [`stream.close()`](#streamclose)
|
23
|
+
- [`stream.abort([err])`](#streamaborterr)
|
24
|
+
- [`stream.reset()`](#streamreset)
|
25
|
+
- [`stream.timeline`](#streamtimeline)
|
26
|
+
- [`stream.id`](#streamid)
|
27
|
+
- [Contribute](#contribute)
|
28
|
+
- [License](#license)
|
29
|
+
- [Contribution](#contribution)
|
17
30
|
|
18
31
|
## Install
|
19
32
|
|
20
|
-
```
|
21
|
-
npm
|
33
|
+
```console
|
34
|
+
$ npm i @libp2p/mplex
|
22
35
|
```
|
23
36
|
|
37
|
+
[](https://github.com/libp2p/interface-stream-muxer)
|
38
|
+
|
24
39
|
## Usage
|
25
40
|
|
26
41
|
```js
|
@@ -54,13 +69,13 @@ Creates a factory that can be used to create new muxers.
|
|
54
69
|
|
55
70
|
`options` is an optional `Object` that may have the following properties:
|
56
71
|
|
57
|
-
|
58
|
-
|
59
|
-
|
72
|
+
- `maxMsgSize` - a number that defines how large mplex data messages can be in bytes, if messages are larger than this they will be sent as multiple messages (default: 1048576 - e.g. 1MB)
|
73
|
+
- `maxStreamsPerConnection` - a number that defines how many streams are allowed per connection (default: 1024)
|
74
|
+
- `maxStreamBufferSize` - a number that defines how large the message buffer is allowed to grow (default: 1024 \* 1024 \* 4 - e.g. 4MB)
|
60
75
|
|
61
76
|
### `const muxer = factory.createStreamMuxer(components, [options])`
|
62
77
|
|
63
|
-
Create a new
|
78
|
+
Create a new *duplex* stream that can be piped together with a connection in order to allow multiplexed communications.
|
64
79
|
|
65
80
|
e.g.
|
66
81
|
|
@@ -77,45 +92,45 @@ pipe(conn, muxer, conn) // conn is duplex connection to another peer
|
|
77
92
|
|
78
93
|
`options` is an optional `Object` that may have the following properties:
|
79
94
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
95
|
+
- `onStream` - A function called when receiving a new stream from the remote. e.g.
|
96
|
+
```js
|
97
|
+
// Receive a new stream on the muxed connection
|
98
|
+
const onStream = stream => {
|
99
|
+
// Read from this stream and write back to it (echo server)
|
100
|
+
pipe(
|
101
|
+
stream,
|
102
|
+
source => (async function * () {
|
103
|
+
for await (const data of source) yield data
|
104
|
+
})(),
|
105
|
+
stream
|
106
|
+
)
|
107
|
+
}
|
108
|
+
const muxer = new Mplex({ onStream })
|
109
|
+
// ...
|
110
|
+
```
|
111
|
+
**Note:** The `onStream` function can be passed in place of the `options` object. i.e.
|
112
|
+
```js
|
113
|
+
new Mplex(stream => { /* ... */ })
|
114
|
+
```
|
115
|
+
- `onStreamEnd` - A function called when a stream ends
|
116
|
+
```js
|
117
|
+
// Receive a notification when a stream ends
|
118
|
+
const onStreamEnd = stream => {
|
119
|
+
// Manage any tracking changes, etc
|
120
|
+
}
|
121
|
+
const muxer = new Mplex({ onStreamEnd })
|
122
|
+
// ...
|
123
|
+
```
|
124
|
+
- `signal` - An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which can be used to abort the muxer, *including* all of it's multiplexed connections. e.g.
|
125
|
+
```js
|
126
|
+
const controller = new AbortController()
|
127
|
+
const muxer = new Mplex({ signal: controller.signal })
|
128
|
+
|
129
|
+
pipe(conn, muxer, conn)
|
130
|
+
|
131
|
+
controller.abort()
|
132
|
+
```
|
133
|
+
- `maxMsgSize` - The maximum size in bytes the data field of multiplexed messages may contain (default 1MB)
|
119
134
|
|
120
135
|
### `muxer.onStream`
|
121
136
|
|
@@ -143,7 +158,7 @@ const stream = muxer.newStream()
|
|
143
158
|
pipe([1, 2, 3], stream, consume)
|
144
159
|
```
|
145
160
|
|
146
|
-
In addition to `sink` and `source` properties, this stream also has the following API, that will **normally
|
161
|
+
In addition to `sink` and `source` properties, this stream also has the following API, that will **normally *not* be used by stream consumers**.
|
147
162
|
|
148
163
|
#### `stream.close()`
|
149
164
|
|
@@ -155,17 +170,17 @@ The source will return normally, the sink will continue to consume.
|
|
155
170
|
|
156
171
|
#### `stream.abort([err])`
|
157
172
|
|
158
|
-
Closes the stream for **reading**
|
173
|
+
Closes the stream for **reading** *and* **writing**. This should be called when a *local error* has occurred.
|
159
174
|
|
160
175
|
Note, if called without an error any buffered data in the source can still be consumed and the stream will end normally.
|
161
176
|
|
162
|
-
This will cause a `RESET` message to be sent to the remote,
|
177
|
+
This will cause a `RESET` message to be sent to the remote, *unless* the sink has already ended.
|
163
178
|
|
164
179
|
The sink will return and the source will throw if an error is passed or return normally if not.
|
165
180
|
|
166
181
|
#### `stream.reset()`
|
167
182
|
|
168
|
-
Closes the stream
|
183
|
+
Closes the stream *immediately* for **reading** *and* **writing**. This should be called when a *remote error* has occurred.
|
169
184
|
|
170
185
|
This function is called automatically by the muxer when it receives a `RESET` message from the remote.
|
171
186
|
|
@@ -183,16 +198,16 @@ Returns a `string` with an identifier unique to **this** muxer. Identifiers are
|
|
183
198
|
|
184
199
|
The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
|
185
200
|
|
186
|
-
|
187
|
-
|
201
|
+
- Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
|
202
|
+
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
|
188
203
|
|
189
204
|
## License
|
190
205
|
|
191
206
|
Licensed under either of
|
192
207
|
|
193
|
-
|
194
|
-
|
208
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
209
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
195
210
|
|
196
|
-
|
211
|
+
## Contribution
|
197
212
|
|
198
213
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
package/dist/src/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import type { StreamMuxerFactory, StreamMuxerInit } from '@libp2p/
|
1
|
+
import { Components, Initializable } from '@libp2p/components';
|
2
|
+
import type { StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
|
3
3
|
import { MplexStreamMuxer } from './mplex.js';
|
4
4
|
export interface MplexInit {
|
5
5
|
/**
|
@@ -20,10 +20,12 @@ export interface MplexInit {
|
|
20
20
|
*/
|
21
21
|
maxStreamBufferSize?: number;
|
22
22
|
}
|
23
|
-
export declare class Mplex implements StreamMuxerFactory {
|
23
|
+
export declare class Mplex implements StreamMuxerFactory, Initializable {
|
24
24
|
protocol: string;
|
25
|
-
private readonly
|
25
|
+
private readonly _init;
|
26
|
+
private components;
|
26
27
|
constructor(init?: MplexInit);
|
27
|
-
|
28
|
+
init(components: Components): void;
|
29
|
+
createStreamMuxer(init?: StreamMuxerInit): MplexStreamMuxer;
|
28
30
|
}
|
29
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAEhC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,qBAAa,KAAM,YAAW,kBAAkB,EAAE,aAAa;IACtD,QAAQ,SAAiB;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,UAAU,CAA+B;gBAEpC,IAAI,GAAE,SAAc;IAIjC,IAAI,CAAE,UAAU,EAAE,UAAU;IAI5B,iBAAiB,CAAE,IAAI,GAAE,eAAoB;CAM9C"}
|
package/dist/src/index.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
+
import { Components } from '@libp2p/components';
|
1
2
|
import { MplexStreamMuxer } from './mplex.js';
|
2
3
|
export class Mplex {
|
3
4
|
constructor(init = {}) {
|
4
5
|
this.protocol = '/mplex/6.7.0';
|
5
|
-
this.
|
6
|
+
this.components = new Components();
|
7
|
+
this._init = init;
|
6
8
|
}
|
7
|
-
|
8
|
-
|
9
|
+
init(components) {
|
10
|
+
this.components = components;
|
11
|
+
}
|
12
|
+
createStreamMuxer(init = {}) {
|
13
|
+
return new MplexStreamMuxer(this.components, {
|
9
14
|
...init,
|
10
|
-
...this.
|
15
|
+
...this._init
|
11
16
|
});
|
12
17
|
}
|
13
18
|
}
|
package/dist/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAwB7C,MAAM,OAAO,KAAK;IAKhB,YAAa,OAAkB,EAAE;QAJ1B,aAAQ,GAAG,cAAc,CAAA;QAExB,eAAU,GAAe,IAAI,UAAU,EAAE,CAAA;QAG/C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IAED,IAAI,CAAE,UAAsB;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,iBAAiB,CAAE,OAAwB,EAAE;QAC3C,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE;YAC3C,GAAG,IAAI;YACP,GAAG,IAAI,CAAC,KAAK;SACd,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/src/mplex.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Pushable } from 'it-pushable';
|
2
2
|
import { Message } from './message-types.js';
|
3
|
-
import type { Components } from '@libp2p/
|
3
|
+
import type { Components } from '@libp2p/components';
|
4
4
|
import type { Sink } from 'it-stream-types';
|
5
|
-
import type { StreamMuxer, StreamMuxerInit } from '@libp2p/
|
6
|
-
import type { Stream } from '@libp2p/
|
5
|
+
import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
|
6
|
+
import type { Stream } from '@libp2p/interface-connection';
|
7
7
|
import type { MplexInit } from './index.js';
|
8
8
|
export interface MplexStream extends Stream {
|
9
9
|
source: Pushable<Uint8Array>;
|
package/dist/src/mplex.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mplex.d.ts","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAA;AAKjD,OAAO,EAAkC,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAM5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM
|
1
|
+
{"version":3,"file":"mplex.d.ts","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAA;AAKjD,OAAO,EAAkC,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAM5E,OAAO,KA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EAAE,WAAW,CAAC,CAAA;KAAE;IA6CrH;;;OAGG;IACH,WAAW;IA4BX;;;OAGG;IACH,aAAa;;;;;;;IA+Bb,eAAe,CAAE,OAAO,EAAE,OAAO;CA+DlC"}
|
package/dist/src/mplex.js
CHANGED
@@ -90,7 +90,7 @@ export class MplexStreamMuxer {
|
|
90
90
|
_newStream(options) {
|
91
91
|
const maxStreams = this._init.maxStreamsPerConnection ?? MAX_STREAMS_PER_CONNECTION;
|
92
92
|
if ((this._streams.initiators.size + this._streams.receivers.size) === maxStreams) {
|
93
|
-
throw errCode(new Error('
|
93
|
+
throw errCode(new Error('To many streams open'), 'ERR_TOO_MANY_STREAMS');
|
94
94
|
}
|
95
95
|
const { id, name, type, registry } = options;
|
96
96
|
log('new %s stream %s %s', type, id, name);
|
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,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAW,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAO9B,MAAM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d,MAAK;YACP;gBACE,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;SACvC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/mplex",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
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-mplex#readme",
|
@@ -35,6 +35,7 @@
|
|
35
35
|
],
|
36
36
|
"exports": {
|
37
37
|
".": {
|
38
|
+
"types": "./src/index.d.ts",
|
38
39
|
"import": "./dist/src/index.js"
|
39
40
|
}
|
40
41
|
},
|
@@ -140,6 +141,9 @@
|
|
140
141
|
"release": "aegir release"
|
141
142
|
},
|
142
143
|
"dependencies": {
|
144
|
+
"@libp2p/components": "^1.0.0",
|
145
|
+
"@libp2p/interface-connection": "^1.0.1",
|
146
|
+
"@libp2p/interface-stream-muxer": "^1.0.1",
|
143
147
|
"@libp2p/logger": "^1.1.3",
|
144
148
|
"@libp2p/tracked-map": "^1.0.5",
|
145
149
|
"abortable-iterator": "^4.0.2",
|
@@ -153,10 +157,9 @@
|
|
153
157
|
"varint": "^6.0.0"
|
154
158
|
},
|
155
159
|
"devDependencies": {
|
156
|
-
"@libp2p/interface-compliance-tests": "^
|
157
|
-
"@libp2p/interfaces": "^2.0.1",
|
160
|
+
"@libp2p/interface-stream-muxer-compliance-tests": "^1.0.2",
|
158
161
|
"@types/varint": "^6.0.0",
|
159
|
-
"aegir": "^37.0
|
162
|
+
"aegir": "^37.2.0",
|
160
163
|
"cborg": "^1.8.1",
|
161
164
|
"delay": "^5.0.0",
|
162
165
|
"iso-random-stream": "^2.0.2",
|
package/src/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import type { StreamMuxerFactory, StreamMuxerInit } from '@libp2p/
|
1
|
+
import { Components, Initializable } from '@libp2p/components'
|
2
|
+
import type { StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
|
3
3
|
import { MplexStreamMuxer } from './mplex.js'
|
4
4
|
|
5
5
|
export interface MplexInit {
|
@@ -24,18 +24,23 @@ export interface MplexInit {
|
|
24
24
|
maxStreamBufferSize?: number
|
25
25
|
}
|
26
26
|
|
27
|
-
export class Mplex implements StreamMuxerFactory {
|
27
|
+
export class Mplex implements StreamMuxerFactory, Initializable {
|
28
28
|
public protocol = '/mplex/6.7.0'
|
29
|
-
private readonly
|
29
|
+
private readonly _init: MplexInit
|
30
|
+
private components: Components = new Components()
|
30
31
|
|
31
32
|
constructor (init: MplexInit = {}) {
|
32
|
-
this.
|
33
|
+
this._init = init
|
33
34
|
}
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
init (components: Components) {
|
37
|
+
this.components = components
|
38
|
+
}
|
39
|
+
|
40
|
+
createStreamMuxer (init: StreamMuxerInit = {}) {
|
41
|
+
return new MplexStreamMuxer(this.components, {
|
37
42
|
...init,
|
38
|
-
...this.
|
43
|
+
...this._init
|
39
44
|
})
|
40
45
|
}
|
41
46
|
}
|
package/src/mplex.ts
CHANGED
@@ -10,10 +10,10 @@ import { toString as uint8ArrayToString } from 'uint8arrays'
|
|
10
10
|
import { trackedMap } from '@libp2p/tracked-map'
|
11
11
|
import { logger } from '@libp2p/logger'
|
12
12
|
import errCode from 'err-code'
|
13
|
-
import type { Components } from '@libp2p/
|
13
|
+
import type { Components } from '@libp2p/components'
|
14
14
|
import type { Sink } from 'it-stream-types'
|
15
|
-
import type { StreamMuxer, StreamMuxerInit } from '@libp2p/
|
16
|
-
import type { Stream } from '@libp2p/
|
15
|
+
import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
|
16
|
+
import type { Stream } from '@libp2p/interface-connection'
|
17
17
|
import type { MplexInit } from './index.js'
|
18
18
|
|
19
19
|
const log = logger('libp2p:mplex')
|
@@ -127,7 +127,7 @@ export class MplexStreamMuxer implements StreamMuxer {
|
|
127
127
|
const maxStreams = this._init.maxStreamsPerConnection ?? MAX_STREAMS_PER_CONNECTION
|
128
128
|
|
129
129
|
if ((this._streams.initiators.size + this._streams.receivers.size) === maxStreams) {
|
130
|
-
throw errCode(new Error('
|
130
|
+
throw errCode(new Error('To many streams open'), 'ERR_TOO_MANY_STREAMS')
|
131
131
|
}
|
132
132
|
|
133
133
|
const { id, name, type, registry } = options
|
package/src/stream.ts
CHANGED
@@ -8,7 +8,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
8
8
|
import { Uint8ArrayList } from 'uint8arraylist'
|
9
9
|
import { logger } from '@libp2p/logger'
|
10
10
|
import type { Message } from './message-types.js'
|
11
|
-
import type { Timeline } from '@libp2p/
|
11
|
+
import type { Timeline } from '@libp2p/interface-connection'
|
12
12
|
import type { Source } from 'it-stream-types'
|
13
13
|
import type { MplexStream } from './mplex.js'
|
14
14
|
|