@libp2p/mplex 9.0.12 → 10.0.0-06e6d235f
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 +6 -4
- package/dist/index.min.js +5 -5
- package/dist/src/decode.js.map +1 -1
- package/dist/src/encode.d.ts +2 -1
- package/dist/src/encode.d.ts.map +1 -1
- package/dist/src/encode.js +5 -21
- package/dist/src/encode.js.map +1 -1
- package/dist/src/index.d.ts +3 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/mplex.d.ts +8 -5
- package/dist/src/mplex.d.ts.map +1 -1
- package/dist/src/mplex.js +31 -25
- package/dist/src/mplex.js.map +1 -1
- package/dist/src/stream.d.ts +3 -1
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +2 -3
- package/dist/src/stream.js.map +1 -1
- package/package.json +14 -11
- package/src/encode.ts +5 -25
- package/src/index.ts +8 -18
- package/src/mplex.ts +39 -32
- package/src/stream.ts +4 -3
- package/dist/typedoc-urls.json +0 -6
package/dist/src/index.d.ts
CHANGED
@@ -30,7 +30,8 @@
|
|
30
30
|
* pipe([1, 2, 3], stream)
|
31
31
|
* ```
|
32
32
|
*/
|
33
|
-
import type
|
33
|
+
import { type MplexComponents } from './mplex.js';
|
34
|
+
import type { StreamMuxerFactory } from '@libp2p/interface';
|
34
35
|
export interface MplexInit {
|
35
36
|
/**
|
36
37
|
* The maximum size of message that can be sent in one go in bytes.
|
@@ -47,17 +48,6 @@ export interface MplexInit {
|
|
47
48
|
* (default: 4MB)
|
48
49
|
*/
|
49
50
|
maxUnprocessedMessageQueueSize?: number;
|
50
|
-
/**
|
51
|
-
* Each byte array written into a multiplexed stream is converted to one or
|
52
|
-
* more messages which are sent as byte arrays to the remote node. Sending
|
53
|
-
* lots of small messages can be expensive - use this setting to batch up
|
54
|
-
* the serialized bytes of all messages sent during the current tick up to
|
55
|
-
* this limit to send in one go similar to Nagle's algorithm. N.b. you
|
56
|
-
* should benchmark your application carefully when using this setting as it
|
57
|
-
* may cause the opposite of the desired effect. Omit this setting to send
|
58
|
-
* all messages as they become available. (default: undefined)
|
59
|
-
*/
|
60
|
-
minSendBytes?: number;
|
61
51
|
/**
|
62
52
|
* The maximum number of multiplexed streams that can be open at any
|
63
53
|
* one time. A request to open more than this will have a stream
|
@@ -83,5 +73,5 @@ export interface MplexInit {
|
|
83
73
|
*/
|
84
74
|
disconnectThreshold?: number;
|
85
75
|
}
|
86
|
-
export declare function mplex(init?: MplexInit): () => StreamMuxerFactory;
|
76
|
+
export declare function mplex(init?: MplexInit): (components: MplexComponents) => StreamMuxerFactory;
|
87
77
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,EAAe,kBAAkB,EAAmB,MAAM,mBAAmB,CAAA;AAEzF,MAAM,WAAW,SAAS;IACxB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;;;OAMG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAA;IAEvC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAE5B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAoBD,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,kBAAkB,CAEhG"}
|
package/dist/src/index.js
CHANGED
@@ -34,17 +34,19 @@ import { MplexStreamMuxer } from './mplex.js';
|
|
34
34
|
class Mplex {
|
35
35
|
protocol = '/mplex/6.7.0';
|
36
36
|
_init;
|
37
|
-
|
37
|
+
components;
|
38
|
+
constructor(components, init = {}) {
|
39
|
+
this.components = components;
|
38
40
|
this._init = init;
|
39
41
|
}
|
40
42
|
createStreamMuxer(init = {}) {
|
41
|
-
return new MplexStreamMuxer({
|
43
|
+
return new MplexStreamMuxer(this.components, {
|
42
44
|
...init,
|
43
45
|
...this._init
|
44
46
|
});
|
45
47
|
}
|
46
48
|
}
|
47
49
|
export function mplex(init = {}) {
|
48
|
-
return () => new Mplex(init);
|
50
|
+
return (components) => new Mplex(components, init);
|
49
51
|
}
|
50
52
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,gBAAgB,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAA;AAkDnE,MAAM,KAAK;IACF,QAAQ,GAAG,cAAc,CAAA;IACf,KAAK,CAAW;IAChB,UAAU,CAAiB;IAE5C,YAAa,UAA2B,EAAE,OAAkB,EAAE;QAC5D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,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;AAED,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACpD,CAAC"}
|
package/dist/src/mplex.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { type Message } from './message-types.js';
|
2
2
|
import { type MplexStream } from './stream.js';
|
3
3
|
import type { MplexInit } from './index.js';
|
4
|
-
import type { AbortOptions } from '@libp2p/interface';
|
5
|
-
import type { Stream } from '@libp2p/interface/connection';
|
6
|
-
import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface/stream-muxer';
|
4
|
+
import type { AbortOptions, ComponentLogger, Stream, StreamMuxer, StreamMuxerInit } from '@libp2p/interface';
|
7
5
|
import type { Sink, Source } from 'it-stream-types';
|
8
6
|
import type { Uint8ArrayList } from 'uint8arraylist';
|
7
|
+
export interface MplexComponents {
|
8
|
+
logger: ComponentLogger;
|
9
|
+
}
|
9
10
|
interface MplexStreamMuxerInit extends MplexInit, StreamMuxerInit {
|
10
11
|
/**
|
11
12
|
* The default timeout to use in ms when shutting down the muxer.
|
@@ -15,7 +16,8 @@ interface MplexStreamMuxerInit extends MplexInit, StreamMuxerInit {
|
|
15
16
|
export declare class MplexStreamMuxer implements StreamMuxer {
|
16
17
|
protocol: string;
|
17
18
|
sink: Sink<Source<Uint8ArrayList | Uint8Array>, Promise<void>>;
|
18
|
-
source: AsyncGenerator<Uint8Array>;
|
19
|
+
source: AsyncGenerator<Uint8ArrayList | Uint8Array>;
|
20
|
+
private readonly log;
|
19
21
|
private _streamId;
|
20
22
|
private readonly _streams;
|
21
23
|
private readonly _init;
|
@@ -23,7 +25,8 @@ export declare class MplexStreamMuxer implements StreamMuxer {
|
|
23
25
|
private readonly closeController;
|
24
26
|
private readonly rateLimiter;
|
25
27
|
private readonly closeTimeout;
|
26
|
-
|
28
|
+
private readonly logger;
|
29
|
+
constructor(components: MplexComponents, init?: MplexStreamMuxerInit);
|
27
30
|
/**
|
28
31
|
* Returns a Map of streams and their ids
|
29
32
|
*/
|
package/dist/src/mplex.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mplex.d.ts","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"mplex.d.ts","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AAQA,OAAO,EAAkC,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjF,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAU,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACpH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAyBpD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,UAAU,oBAAqB,SAAQ,SAAS,EAAE,eAAe;IAC/D;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,qBAAa,gBAAiB,YAAW,WAAW;IAC3C,QAAQ,SAAiB;IAEzB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9D,MAAM,EAAE,cAAc,CAAC,cAAc,GAAG,UAAU,CAAC,CAAA;IAE1D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B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,13 @@
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
2
|
-
import {
|
3
|
-
import { abortableSource } from 'abortable-iterator';
|
1
|
+
import { CodeError } from '@libp2p/interface';
|
2
|
+
import { closeSource } from '@libp2p/utils/close-source';
|
4
3
|
import { pipe } from 'it-pipe';
|
5
|
-
import {
|
4
|
+
import { pushable } from 'it-pushable';
|
6
5
|
import { RateLimiterMemory } from 'rate-limiter-flexible';
|
7
6
|
import { toString as uint8ArrayToString } from 'uint8arrays';
|
8
7
|
import { Decoder } from './decode.js';
|
9
8
|
import { encode } from './encode.js';
|
10
9
|
import { MessageTypes, MessageTypeNames } from './message-types.js';
|
11
10
|
import { createStream } from './stream.js';
|
12
|
-
const log = logger('libp2p:mplex');
|
13
11
|
const MAX_STREAMS_INBOUND_STREAMS_PER_CONNECTION = 1024;
|
14
12
|
const MAX_STREAMS_OUTBOUND_STREAMS_PER_CONNECTION = 1024;
|
15
13
|
const MAX_STREAM_BUFFER_SIZE = 1024 * 1024 * 4; // 4MB
|
@@ -32,6 +30,7 @@ export class MplexStreamMuxer {
|
|
32
30
|
protocol = '/mplex/6.7.0';
|
33
31
|
sink;
|
34
32
|
source;
|
33
|
+
log;
|
35
34
|
_streamId;
|
36
35
|
_streams;
|
37
36
|
_init;
|
@@ -39,8 +38,11 @@ export class MplexStreamMuxer {
|
|
39
38
|
closeController;
|
40
39
|
rateLimiter;
|
41
40
|
closeTimeout;
|
42
|
-
|
41
|
+
logger;
|
42
|
+
constructor(components, init) {
|
43
43
|
init = init ?? {};
|
44
|
+
this.log = components.logger.forComponent('libp2p:mplex');
|
45
|
+
this.logger = components.logger;
|
44
46
|
this._streamId = 0;
|
45
47
|
this._streams = {
|
46
48
|
/**
|
@@ -61,7 +63,7 @@ export class MplexStreamMuxer {
|
|
61
63
|
/**
|
62
64
|
* An iterable source
|
63
65
|
*/
|
64
|
-
this._source =
|
66
|
+
this._source = pushable({
|
65
67
|
objectMode: true,
|
66
68
|
onEnd: () => {
|
67
69
|
// the source has ended, we can't write any more messages to gracefully
|
@@ -74,7 +76,7 @@ export class MplexStreamMuxer {
|
|
74
76
|
}
|
75
77
|
}
|
76
78
|
});
|
77
|
-
this.source = pipe(this._source, source => encode(source
|
79
|
+
this.source = pipe(this._source, source => encode(source));
|
78
80
|
/**
|
79
81
|
* Close controller
|
80
82
|
*/
|
@@ -152,7 +154,7 @@ export class MplexStreamMuxer {
|
|
152
154
|
}
|
153
155
|
_newStream(options) {
|
154
156
|
const { id, name, type, registry } = options;
|
155
|
-
log('new %s stream %s', type, id);
|
157
|
+
this.log('new %s stream %s', type, id);
|
156
158
|
if (type === 'initiator' && this._streams.initiators.size === (this._init.maxOutboundStreams ?? MAX_STREAMS_OUTBOUND_STREAMS_PER_CONNECTION)) {
|
157
159
|
throw new CodeError('Too many outbound streams open', 'ERR_TOO_MANY_OUTBOUND_STREAMS');
|
158
160
|
}
|
@@ -160,19 +162,19 @@ export class MplexStreamMuxer {
|
|
160
162
|
throw new Error(`${type} stream ${id} already exists!`);
|
161
163
|
}
|
162
164
|
const send = async (msg) => {
|
163
|
-
if (log.enabled) {
|
164
|
-
log.trace('%s stream %s send', type, id, printMessage(msg));
|
165
|
+
if (this.log.enabled) {
|
166
|
+
this.log.trace('%s stream %s send', type, id, printMessage(msg));
|
165
167
|
}
|
166
168
|
this._source.push(msg);
|
167
169
|
};
|
168
170
|
const onEnd = () => {
|
169
|
-
log('%s stream with id %s and protocol %s ended', type, id, stream.protocol);
|
171
|
+
this.log('%s stream with id %s and protocol %s ended', type, id, stream.protocol);
|
170
172
|
registry.delete(id);
|
171
173
|
if (this._init.onStreamEnd != null) {
|
172
174
|
this._init.onStreamEnd(stream);
|
173
175
|
}
|
174
176
|
};
|
175
|
-
const stream = createStream({ id, name, send, type, onEnd, maxMsgSize: this._init.maxMsgSize });
|
177
|
+
const stream = createStream({ id, name, send, type, onEnd, maxMsgSize: this._init.maxMsgSize, logger: this.logger });
|
176
178
|
registry.set(id, stream);
|
177
179
|
return stream;
|
178
180
|
}
|
@@ -182,10 +184,11 @@ export class MplexStreamMuxer {
|
|
182
184
|
*/
|
183
185
|
_createSink() {
|
184
186
|
const sink = async (source) => {
|
187
|
+
const abortListener = () => {
|
188
|
+
closeSource(source, this.log);
|
189
|
+
};
|
190
|
+
this.closeController.signal.addEventListener('abort', abortListener);
|
185
191
|
try {
|
186
|
-
source = abortableSource(source, this.closeController.signal, {
|
187
|
-
returnOnAbort: true
|
188
|
-
});
|
189
192
|
const decoder = new Decoder(this._init.maxMsgSize, this._init.maxUnprocessedMessageQueueSize);
|
190
193
|
for await (const chunk of source) {
|
191
194
|
for (const msg of decoder.write(chunk)) {
|
@@ -195,21 +198,24 @@ export class MplexStreamMuxer {
|
|
195
198
|
this._source.end();
|
196
199
|
}
|
197
200
|
catch (err) {
|
198
|
-
log('error in sink', err);
|
201
|
+
this.log('error in sink', err);
|
199
202
|
this._source.end(err); // End the source with an error
|
200
203
|
}
|
204
|
+
finally {
|
205
|
+
this.closeController.signal.removeEventListener('abort', abortListener);
|
206
|
+
}
|
201
207
|
};
|
202
208
|
return sink;
|
203
209
|
}
|
204
210
|
async _handleIncoming(message) {
|
205
211
|
const { id, type } = message;
|
206
|
-
if (log.enabled) {
|
207
|
-
log.trace('incoming message', printMessage(message));
|
212
|
+
if (this.log.enabled) {
|
213
|
+
this.log.trace('incoming message', printMessage(message));
|
208
214
|
}
|
209
215
|
// Create a new stream?
|
210
216
|
if (message.type === MessageTypes.NEW_STREAM) {
|
211
217
|
if (this._streams.receivers.size === (this._init.maxInboundStreams ?? MAX_STREAMS_INBOUND_STREAMS_PER_CONNECTION)) {
|
212
|
-
log('too many inbound streams open');
|
218
|
+
this.log('too many inbound streams open');
|
213
219
|
// not going to allow this stream, send the reset message manually
|
214
220
|
// instead of setting it up just to tear it down
|
215
221
|
this._source.push({
|
@@ -223,7 +229,7 @@ export class MplexStreamMuxer {
|
|
223
229
|
await this.rateLimiter.consume('new-stream', 1);
|
224
230
|
}
|
225
231
|
catch {
|
226
|
-
log('rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection');
|
232
|
+
this.log('rate limit hit when opening too many new streams over the inbound stream limit - closing remote connection');
|
227
233
|
// since there's no backpressure in mplex, the only thing we can really do to protect ourselves is close the connection
|
228
234
|
this.abort(new Error('Too many open streams'));
|
229
235
|
return;
|
@@ -239,7 +245,7 @@ export class MplexStreamMuxer {
|
|
239
245
|
const list = (type & 1) === 1 ? this._streams.initiators : this._streams.receivers;
|
240
246
|
const stream = list.get(id);
|
241
247
|
if (stream == null) {
|
242
|
-
log('missing stream %s for message type %s', id, MessageTypeNames[type]);
|
248
|
+
this.log('missing stream %s for message type %s', id, MessageTypeNames[type]);
|
243
249
|
// if the remote keeps sending us messages for streams that have been
|
244
250
|
// closed or were never opened they may be attacking us so if they do
|
245
251
|
// this very quickly all we can do is close the connection
|
@@ -247,7 +253,7 @@ export class MplexStreamMuxer {
|
|
247
253
|
await this.rateLimiter.consume('missing-stream', 1);
|
248
254
|
}
|
249
255
|
catch {
|
250
|
-
log('rate limit hit when receiving messages for streams that do not exist - closing remote connection');
|
256
|
+
this.log('rate limit hit when receiving messages for streams that do not exist - closing remote connection');
|
251
257
|
// since there's no backpressure in mplex, the only thing we can really do to protect ourselves is close the connection
|
252
258
|
this.abort(new Error('Too many messages for missing streams'));
|
253
259
|
return;
|
@@ -282,11 +288,11 @@ export class MplexStreamMuxer {
|
|
282
288
|
stream.reset();
|
283
289
|
break;
|
284
290
|
default:
|
285
|
-
log('unknown message type %s', type);
|
291
|
+
this.log('unknown message type %s', type);
|
286
292
|
}
|
287
293
|
}
|
288
294
|
catch (err) {
|
289
|
-
log.error('error while processing message', err);
|
295
|
+
this.log.error('error while processing message', err);
|
290
296
|
stream.abort(err);
|
291
297
|
}
|
292
298
|
}
|
package/dist/src/mplex.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mplex.js","sourceRoot":"","sources":["../../src/mplex.ts"],"names":[],"mappings":"AAAA,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,CAAC;gBAClC,KAAK,YAAY,CAAC,cAAc;oBAC9B,yDAAyD;oBACzD,MAAM,CAAC,gBAAgB,EAAE,CAAA;oBACzB,MAAK;gBACP,KAAK,YAAY,CAAC,eAAe,CAAC;gBAClC,KAAK,YAAY,CAAC,cAAc;oBAC9B,6EAA6E;oBAC7E,MAAM,CAAC,KAAK,EAAE,CAAA;oBACd,MAAK;gBACP;oBACE,IAAI,CAAC,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;YAC7C,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;YACrD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/stream.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import { AbstractStream, type AbstractStreamInit } from '@libp2p/
|
1
|
+
import { AbstractStream, type AbstractStreamInit } from '@libp2p/utils/abstract-stream';
|
2
2
|
import { Uint8ArrayList } from 'uint8arraylist';
|
3
3
|
import type { Message } from './message-types.js';
|
4
|
+
import type { ComponentLogger } from '@libp2p/interface';
|
4
5
|
export interface Options {
|
5
6
|
id: number;
|
6
7
|
send(msg: Message): Promise<void>;
|
@@ -8,6 +9,7 @@ export interface Options {
|
|
8
9
|
onEnd?(err?: Error): void;
|
9
10
|
type?: 'initiator' | 'receiver';
|
10
11
|
maxMsgSize?: number;
|
12
|
+
logger: ComponentLogger;
|
11
13
|
}
|
12
14
|
interface MplexStreamInit extends AbstractStreamInit {
|
13
15
|
streamId: number;
|
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,KAAK,kBAAkB,EAAE,MAAM,
|
1
|
+
{"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AG,OAAO,CAAC,IAAI,CAAC;IAe9C,SAAS,IAAK,OAAO,CAAC,IAAI,CAAC;IAI3B,cAAc,IAAK,OAAO,CAAC,IAAI,CAAC;IAIhC,aAAa,IAAK,OAAO,CAAC,IAAI,CAAC;CAGtC;AAED,wBAAgB,YAAY,CAAE,OAAO,EAAE,OAAO,GAAG,WAAW,CAa3D"}
|
package/dist/src/stream.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import { AbstractStream } from '@libp2p/
|
2
|
-
import { logger } from '@libp2p/logger';
|
1
|
+
import { AbstractStream } from '@libp2p/utils/abstract-stream';
|
3
2
|
import { Uint8ArrayList } from 'uint8arraylist';
|
4
3
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
5
4
|
import { MAX_MSG_SIZE } from './decode.js';
|
@@ -53,7 +52,7 @@ export function createStream(options) {
|
|
53
52
|
maxDataSize: maxMsgSize,
|
54
53
|
onEnd,
|
55
54
|
send,
|
56
|
-
log: logger(`libp2p:mplex:stream:${type}:${id}`)
|
55
|
+
log: options.logger.forComponent(`libp2p:mplex:stream:${type}:${id}`)
|
57
56
|
});
|
58
57
|
}
|
59
58
|
//# 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,EAA2B,MAAM,
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA2B,MAAM,+BAA+B,CAAA;AACvF,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,qBAAqB,EAAE,oBAAoB,E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-1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/mplex",
|
3
|
-
"version": "
|
3
|
+
"version": "10.0.0-06e6d235f",
|
4
4
|
"description": "JavaScript implementation of https://github.com/libp2p/mplex",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p/tree/
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex#readme",
|
7
7
|
"repository": {
|
8
8
|
"type": "git",
|
9
9
|
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
@@ -11,6 +11,10 @@
|
|
11
11
|
"bugs": {
|
12
12
|
"url": "https://github.com/libp2p/js-libp2p/issues"
|
13
13
|
},
|
14
|
+
"publishConfig": {
|
15
|
+
"access": "public",
|
16
|
+
"provenance": true
|
17
|
+
},
|
14
18
|
"keywords": [
|
15
19
|
"IPFS",
|
16
20
|
"connection",
|
@@ -57,12 +61,10 @@
|
|
57
61
|
"test:electron-main": "aegir test -t electron-main"
|
58
62
|
},
|
59
63
|
"dependencies": {
|
60
|
-
"@libp2p/interface": "
|
61
|
-
"@libp2p/
|
62
|
-
"abortable-iterator": "^5.0.1",
|
64
|
+
"@libp2p/interface": "1.0.0-06e6d235f",
|
65
|
+
"@libp2p/utils": "5.0.0-06e6d235f",
|
63
66
|
"benchmark": "^2.1.4",
|
64
|
-
"it-
|
65
|
-
"it-pushable": "^3.2.0",
|
67
|
+
"it-pushable": "^3.2.1",
|
66
68
|
"it-stream-types": "^2.0.1",
|
67
69
|
"rate-limiter-flexible": "^3.0.0",
|
68
70
|
"uint8-varint": "^2.0.0",
|
@@ -70,17 +72,18 @@
|
|
70
72
|
"uint8arrays": "^4.0.6"
|
71
73
|
},
|
72
74
|
"devDependencies": {
|
73
|
-
"@libp2p/interface-compliance-tests": "
|
75
|
+
"@libp2p/interface-compliance-tests": "5.0.0-06e6d235f",
|
76
|
+
"@libp2p/logger": "4.0.0-06e6d235f",
|
74
77
|
"aegir": "^41.0.2",
|
75
78
|
"cborg": "^4.0.3",
|
76
79
|
"delay": "^6.0.0",
|
77
80
|
"iso-random-stream": "^2.0.2",
|
78
|
-
"it-all": "^3.0.
|
79
|
-
"it-drain": "^3.0.
|
81
|
+
"it-all": "^3.0.3",
|
82
|
+
"it-drain": "^3.0.3",
|
80
83
|
"it-foreach": "^2.0.2",
|
81
84
|
"it-map": "^3.0.3",
|
85
|
+
"it-pair": "^2.0.6",
|
82
86
|
"it-pipe": "^3.0.1",
|
83
|
-
"it-to-buffer": "^4.0.1",
|
84
87
|
"p-defer": "^4.0.0",
|
85
88
|
"random-int": "^3.0.0"
|
86
89
|
},
|
package/src/encode.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import batchedBytes from 'it-batched-bytes'
|
2
1
|
import * as varint from 'uint8-varint'
|
3
2
|
import { Uint8ArrayList } from 'uint8arraylist'
|
4
3
|
import { allocUnsafe } from './alloc-unsafe.js'
|
@@ -56,29 +55,10 @@ const encoder = new Encoder()
|
|
56
55
|
/**
|
57
56
|
* Encode and yield one or more messages
|
58
57
|
*/
|
59
|
-
export async function * encode (source: Source<Message
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
for (const msg of messages) {
|
66
|
-
encoder.write(msg, list)
|
67
|
-
}
|
68
|
-
|
69
|
-
yield list.subarray()
|
70
|
-
}
|
71
|
-
|
72
|
-
return
|
58
|
+
export async function * encode (source: Source<Message>): AsyncGenerator<Uint8Array | Uint8ArrayList, void, undefined> {
|
59
|
+
for await (const message of source) {
|
60
|
+
const list = new Uint8ArrayList()
|
61
|
+
encoder.write(message, list)
|
62
|
+
yield list
|
73
63
|
}
|
74
|
-
|
75
|
-
// batch messages up for sending
|
76
|
-
yield * batchedBytes(source, {
|
77
|
-
size: minSendBytes,
|
78
|
-
serialize: (obj, list) => {
|
79
|
-
for (const m of obj) {
|
80
|
-
encoder.write(m, list)
|
81
|
-
}
|
82
|
-
}
|
83
|
-
})
|
84
64
|
}
|
package/src/index.ts
CHANGED
@@ -31,8 +31,8 @@
|
|
31
31
|
* ```
|
32
32
|
*/
|
33
33
|
|
34
|
-
import { MplexStreamMuxer } from './mplex.js'
|
35
|
-
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface
|
34
|
+
import { MplexStreamMuxer, type MplexComponents } from './mplex.js'
|
35
|
+
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface'
|
36
36
|
|
37
37
|
export interface MplexInit {
|
38
38
|
/**
|
@@ -52,18 +52,6 @@ export interface MplexInit {
|
|
52
52
|
*/
|
53
53
|
maxUnprocessedMessageQueueSize?: number
|
54
54
|
|
55
|
-
/**
|
56
|
-
* Each byte array written into a multiplexed stream is converted to one or
|
57
|
-
* more messages which are sent as byte arrays to the remote node. Sending
|
58
|
-
* lots of small messages can be expensive - use this setting to batch up
|
59
|
-
* the serialized bytes of all messages sent during the current tick up to
|
60
|
-
* this limit to send in one go similar to Nagle's algorithm. N.b. you
|
61
|
-
* should benchmark your application carefully when using this setting as it
|
62
|
-
* may cause the opposite of the desired effect. Omit this setting to send
|
63
|
-
* all messages as they become available. (default: undefined)
|
64
|
-
*/
|
65
|
-
minSendBytes?: number
|
66
|
-
|
67
55
|
/**
|
68
56
|
* The maximum number of multiplexed streams that can be open at any
|
69
57
|
* one time. A request to open more than this will have a stream
|
@@ -96,19 +84,21 @@ export interface MplexInit {
|
|
96
84
|
class Mplex implements StreamMuxerFactory {
|
97
85
|
public protocol = '/mplex/6.7.0'
|
98
86
|
private readonly _init: MplexInit
|
87
|
+
private readonly components: MplexComponents
|
99
88
|
|
100
|
-
constructor (init: MplexInit = {}) {
|
89
|
+
constructor (components: MplexComponents, init: MplexInit = {}) {
|
90
|
+
this.components = components
|
101
91
|
this._init = init
|
102
92
|
}
|
103
93
|
|
104
94
|
createStreamMuxer (init: StreamMuxerInit = {}): StreamMuxer {
|
105
|
-
return new MplexStreamMuxer({
|
95
|
+
return new MplexStreamMuxer(this.components, {
|
106
96
|
...init,
|
107
97
|
...this._init
|
108
98
|
})
|
109
99
|
}
|
110
100
|
}
|
111
101
|
|
112
|
-
export function mplex (init: MplexInit = {}): () => StreamMuxerFactory {
|
113
|
-
return () => new Mplex(init)
|
102
|
+
export function mplex (init: MplexInit = {}): (components: MplexComponents) => StreamMuxerFactory {
|
103
|
+
return (components) => new Mplex(components, init)
|
114
104
|
}
|