@libp2p/multistream-select 4.0.9-f537b3731 → 4.0.10

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.
@@ -1,12 +1,6 @@
1
- import type { MultistreamSelectInit, ProtocolStream } from './index.js';
2
- import type { AbortOptions } from '@libp2p/interface';
3
- import type { Duplex } from 'it-stream-types';
4
- export interface SelectStream extends Duplex<any, any, any> {
5
- readStatus?: string;
6
- closeWrite?(options?: AbortOptions): Promise<void>;
7
- closeRead?(options?: AbortOptions): Promise<void>;
8
- close?(options?: AbortOptions): Promise<void>;
9
- }
1
+ import { Uint8ArrayList } from 'uint8arraylist';
2
+ import type { ByteArrayInit, ByteListInit, ProtocolStream } from './index.js';
3
+ import type { Duplex, Source } from 'it-stream-types';
10
4
  /**
11
5
  * Negotiate a protocol to use from a list of protocols.
12
6
  *
@@ -50,5 +44,16 @@ export interface SelectStream extends Duplex<any, any, any> {
50
44
  * // }
51
45
  * ```
52
46
  */
53
- export declare function select<Stream extends SelectStream>(stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>>;
47
+ export declare function select(stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>>, protocols: string | string[], options: ByteArrayInit): Promise<ProtocolStream<Uint8Array>>;
48
+ export declare function select(stream: Duplex<AsyncGenerator<Uint8ArrayList | Uint8Array>, Source<Uint8ArrayList | Uint8Array>>, protocols: string | string[], options?: ByteListInit): Promise<ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>>;
49
+ /**
50
+ * Lazily negotiates a protocol.
51
+ *
52
+ * It *does not* block writes waiting for the other end to respond. Instead, it
53
+ * simply assumes the negotiation went successfully and starts writing data.
54
+ *
55
+ * Use when it is known that the receiver supports the desired protocol.
56
+ */
57
+ export declare function lazySelect(stream: Duplex<Source<Uint8Array>, Source<Uint8Array>>, protocol: string): ProtocolStream<Uint8Array>;
58
+ export declare function lazySelect(stream: Duplex<Source<Uint8ArrayList | Uint8Array>, Source<Uint8ArrayList | Uint8Array>>, protocol: string): ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>;
54
59
  //# sourceMappingURL=select.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACzD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClD,SAAS,CAAC,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,MAAM,CAAE,MAAM,SAAS,YAAY,EAAG,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAoDzK"}
1
+ {"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAI/C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAyB,cAAc,EAAE,MAAM,YAAY,CAAA;AACpG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAIrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,MAAM,CAAE,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAA;AACxL,wBAAsB,MAAM,CAAE,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,cAAc,GAAG,UAAU,CAAC,EAAE,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,cAAc,GAAG,UAAU,CAAC,CAAC,CAAA;AAgD3P;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAA;AACjI,wBAAgB,UAAU,CAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,EAAE,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,cAAc,EAAE,cAAc,GAAG,UAAU,CAAC,CAAA"}
@@ -1,278 +1,95 @@
1
- import { CodeError } from '@libp2p/interface';
2
- import { lpStream } from 'it-length-prefixed-stream';
3
- import pDefer from 'p-defer';
4
- import * as varint from 'uint8-varint';
1
+ import { CodeError } from '@libp2p/interface/errors';
2
+ import { logger } from '@libp2p/logger';
3
+ import { handshake } from 'it-handshake';
4
+ import merge from 'it-merge';
5
+ import { pushable } from 'it-pushable';
6
+ import { reader } from 'it-reader';
5
7
  import { Uint8ArrayList } from 'uint8arraylist';
6
8
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
7
- import { MAX_PROTOCOL_LENGTH } from './constants.js';
8
9
  import * as multistream from './multistream.js';
9
10
  import { PROTOCOL_ID } from './index.js';
10
- /**
11
- * Negotiate a protocol to use from a list of protocols.
12
- *
13
- * @param stream - A duplex iterable stream to dial on
14
- * @param protocols - A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made.
15
- * @param options - An options object containing an AbortSignal and an optional boolean `writeBytes` - if this is true, `Uint8Array`s will be written into `duplex`, otherwise `Uint8ArrayList`s will
16
- * @returns A stream for the selected protocol and the protocol that was selected from the list of protocols provided to `select`.
17
- * @example
18
- *
19
- * ```js
20
- * import { pipe } from 'it-pipe'
21
- * import * as mss from '@libp2p/multistream-select'
22
- * import { Mplex } from '@libp2p/mplex'
23
- *
24
- * const muxer = new Mplex()
25
- * const muxedStream = muxer.newStream()
26
- *
27
- * // mss.select(protocol(s))
28
- * // Select from one of the passed protocols (in priority order)
29
- * // Returns selected stream and protocol
30
- * const { stream: dhtStream, protocol } = await mss.select(muxedStream, [
31
- * // This might just be different versions of DHT, but could be different impls
32
- * '/ipfs-dht/2.0.0', // Most of the time this will probably just be one item.
33
- * '/ipfs-dht/1.0.0'
34
- * ])
35
- *
36
- * // Typically this stream will be passed back to the caller of libp2p.dialProtocol
37
- * //
38
- * // ...it might then do something like this:
39
- * // try {
40
- * // await pipe(
41
- * // [uint8ArrayFromString('Some DHT data')]
42
- * // dhtStream,
43
- * // async source => {
44
- * // for await (const chunk of source)
45
- * // // DHT response data
46
- * // }
47
- * // )
48
- * // } catch (err) {
49
- * // // Error in stream
50
- * // }
51
- * ```
52
- */
53
- export async function select(stream, protocols, options) {
11
+ const log = logger('libp2p:mss:select');
12
+ export async function select(stream, protocols, options = {}) {
54
13
  protocols = Array.isArray(protocols) ? [...protocols] : [protocols];
55
- if (protocols.length === 1) {
56
- return optimisticSelect(stream, protocols[0], options);
57
- }
58
- const lp = lpStream(stream, {
59
- ...options,
60
- maxDataLength: MAX_PROTOCOL_LENGTH
61
- });
14
+ const { reader, writer, rest, stream: shakeStream } = handshake(stream);
62
15
  const protocol = protocols.shift();
63
16
  if (protocol == null) {
64
17
  throw new Error('At least one protocol must be specified');
65
18
  }
66
- options?.log?.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol);
67
- const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`);
68
- const p2 = uint8ArrayFromString(`${protocol}\n`);
69
- await multistream.writeAll(lp, [p1, p2], options);
70
- options?.log?.trace('select: reading multistream-select header');
71
- let response = await multistream.readString(lp, options);
72
- options?.log?.trace('select: read "%s"', response);
19
+ log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol);
20
+ const p1 = uint8ArrayFromString(PROTOCOL_ID);
21
+ const p2 = uint8ArrayFromString(protocol);
22
+ multistream.writeAll(writer, [p1, p2], options);
23
+ let response = await multistream.readString(reader, options);
24
+ log.trace('select: read "%s"', response);
73
25
  // Read the protocol response if we got the protocolId in return
74
26
  if (response === PROTOCOL_ID) {
75
- options?.log?.trace('select: reading protocol response');
76
- response = await multistream.readString(lp, options);
77
- options?.log?.trace('select: read "%s"', response);
27
+ response = await multistream.readString(reader, options);
28
+ log.trace('select: read "%s"', response);
78
29
  }
79
30
  // We're done
80
31
  if (response === protocol) {
81
- return { stream: lp.unwrap(), protocol };
32
+ rest();
33
+ return { stream: shakeStream, protocol };
82
34
  }
83
35
  // We haven't gotten a valid ack, try the other protocols
84
36
  for (const protocol of protocols) {
85
- options?.log?.trace('select: write "%s"', protocol);
86
- await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options);
87
- options?.log?.trace('select: reading protocol response');
88
- const response = await multistream.readString(lp, options);
89
- options?.log?.trace('select: read "%s" for "%s"', response, protocol);
37
+ log.trace('select: write "%s"', protocol);
38
+ multistream.write(writer, uint8ArrayFromString(protocol), options);
39
+ const response = await multistream.readString(reader, options);
40
+ log.trace('select: read "%s" for "%s"', response, protocol);
90
41
  if (response === protocol) {
91
- return { stream: lp.unwrap(), protocol };
42
+ rest(); // End our writer so others can start writing to stream
43
+ return { stream: shakeStream, protocol };
92
44
  }
93
45
  }
46
+ rest();
94
47
  throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL');
95
48
  }
96
- /**
97
- * Optimistically negotiates a protocol.
98
- *
99
- * It *does not* block writes waiting for the other end to respond. Instead, it
100
- * simply assumes the negotiation went successfully and starts writing data.
101
- *
102
- * Use when it is known that the receiver supports the desired protocol.
103
- */
104
- function optimisticSelect(stream, protocol, options) {
105
- const originalSink = stream.sink.bind(stream);
106
- const originalSource = stream.source;
49
+ export function lazySelect(stream, protocol) {
50
+ // This is a signal to write the multistream headers if the consumer tries to
51
+ // read from the source
52
+ const negotiateTrigger = pushable();
107
53
  let negotiated = false;
108
- let negotiating = false;
109
- const doneNegotiating = pDefer();
110
- let sentProtocol = false;
111
- let sendingProtocol = false;
112
- const doneSendingProtocol = pDefer();
113
- let readProtocol = false;
114
- let readingProtocol = false;
115
- const doneReadingProtocol = pDefer();
116
- const lp = lpStream({
117
- sink: originalSink,
118
- source: originalSource
119
- }, {
120
- ...options,
121
- maxDataLength: MAX_PROTOCOL_LENGTH
122
- });
123
- stream.sink = async (source) => {
124
- const { sink } = lp.unwrap();
125
- await sink(async function* () {
126
- let sentData = false;
127
- for await (const buf of source) {
128
- // started reading before the source yielded, wait for protocol send
129
- if (sendingProtocol) {
130
- await doneSendingProtocol.promise;
54
+ return {
55
+ stream: {
56
+ sink: async (source) => {
57
+ await stream.sink((async function* () {
58
+ let first = true;
59
+ for await (const chunk of merge(source, negotiateTrigger)) {
60
+ if (first) {
61
+ first = false;
62
+ negotiated = true;
63
+ negotiateTrigger.end();
64
+ const p1 = uint8ArrayFromString(PROTOCOL_ID);
65
+ const p2 = uint8ArrayFromString(protocol);
66
+ const list = new Uint8ArrayList(multistream.encode(p1), multistream.encode(p2));
67
+ if (chunk.length > 0)
68
+ list.append(chunk);
69
+ yield* list;
70
+ }
71
+ else {
72
+ yield chunk;
73
+ }
74
+ }
75
+ })());
76
+ },
77
+ source: (async function* () {
78
+ if (!negotiated)
79
+ negotiateTrigger.push(new Uint8Array());
80
+ const byteReader = reader(stream.source);
81
+ let response = await multistream.readString(byteReader);
82
+ if (response === PROTOCOL_ID) {
83
+ response = await multistream.readString(byteReader);
131
84
  }
132
- // writing before reading, send the protocol and the first chunk of data
133
- if (!sentProtocol) {
134
- sendingProtocol = true;
135
- options?.log?.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
136
- const protocolString = `${protocol}\n`;
137
- // send protocols in first chunk of data written to transport
138
- yield new Uint8ArrayList(Uint8Array.from([19]), // length of PROTOCOL_ID plus newline
139
- uint8ArrayFromString(`${PROTOCOL_ID}\n`), varint.encode(protocolString.length), uint8ArrayFromString(protocolString), buf).subarray();
140
- options?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
141
- sentProtocol = true;
142
- sendingProtocol = false;
143
- doneSendingProtocol.resolve();
85
+ if (response !== protocol) {
86
+ throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL');
144
87
  }
145
- else {
146
- yield buf;
88
+ for await (const chunk of byteReader) {
89
+ yield* chunk;
147
90
  }
148
- sentData = true;
149
- }
150
- // special case - the source passed to the sink has ended but we didn't
151
- // negotiated the protocol yet so do it now
152
- if (!sentData) {
153
- await negotiate();
154
- }
155
- }());
156
- };
157
- async function negotiate() {
158
- if (negotiating) {
159
- options?.log?.trace('optimistic: already negotiating %s stream', protocol);
160
- await doneNegotiating.promise;
161
- return;
162
- }
163
- negotiating = true;
164
- try {
165
- // we haven't sent the protocol yet, send it now
166
- if (!sentProtocol) {
167
- options?.log?.trace('optimistic: doing send protocol for %s stream', protocol);
168
- await doSendProtocol();
169
- }
170
- // if we haven't read the protocol response yet, do it now
171
- if (!readProtocol) {
172
- options?.log?.trace('optimistic: doing read protocol for %s stream', protocol);
173
- await doReadProtocol();
174
- }
175
- }
176
- finally {
177
- negotiating = false;
178
- negotiated = true;
179
- doneNegotiating.resolve();
180
- }
181
- }
182
- async function doSendProtocol() {
183
- if (sendingProtocol) {
184
- await doneSendingProtocol.promise;
185
- return;
186
- }
187
- sendingProtocol = true;
188
- try {
189
- options?.log?.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
190
- await lp.writeV([
191
- uint8ArrayFromString(`${PROTOCOL_ID}\n`),
192
- uint8ArrayFromString(`${protocol}\n`)
193
- ]);
194
- options?.log?.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
195
- }
196
- finally {
197
- sentProtocol = true;
198
- sendingProtocol = false;
199
- doneSendingProtocol.resolve();
200
- }
201
- }
202
- async function doReadProtocol() {
203
- if (readingProtocol) {
204
- await doneReadingProtocol.promise;
205
- return;
206
- }
207
- readingProtocol = true;
208
- try {
209
- options?.log?.trace('optimistic: reading multistream select header');
210
- let response = await multistream.readString(lp, options);
211
- options?.log?.trace('optimistic: read multistream select header "%s"', response);
212
- if (response === PROTOCOL_ID) {
213
- response = await multistream.readString(lp, options);
214
- }
215
- options?.log?.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol);
216
- if (response !== protocol) {
217
- throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL');
218
- }
219
- }
220
- finally {
221
- readProtocol = true;
222
- readingProtocol = false;
223
- doneReadingProtocol.resolve();
224
- }
225
- }
226
- stream.source = (async function* () {
227
- // make sure we've done protocol negotiation before we read stream data
228
- await negotiate();
229
- options?.log?.trace('optimistic: reading data from "%s" stream', protocol);
230
- yield* lp.unwrap().source;
231
- })();
232
- if (stream.closeRead != null) {
233
- const originalCloseRead = stream.closeRead.bind(stream);
234
- stream.closeRead = async (opts) => {
235
- // we need to read & write to negotiate the protocol so ensure we've done
236
- // this before closing the readable end of the stream
237
- if (!negotiated) {
238
- await negotiate().catch(err => {
239
- options?.log?.error('could not negotiate protocol before close read', err);
240
- });
241
- }
242
- // protocol has been negotiated, ok to close the readable end
243
- await originalCloseRead(opts);
244
- };
245
- }
246
- if (stream.closeWrite != null) {
247
- const originalCloseWrite = stream.closeWrite.bind(stream);
248
- stream.closeWrite = async (opts) => {
249
- // we need to read & write to negotiate the protocol so ensure we've done
250
- // this before closing the writable end of the stream
251
- if (!negotiated) {
252
- await negotiate().catch(err => {
253
- options?.log?.error('could not negotiate protocol before close write', err);
254
- });
255
- }
256
- // protocol has been negotiated, ok to close the writable end
257
- await originalCloseWrite(opts);
258
- };
259
- }
260
- if (stream.close != null) {
261
- const originalClose = stream.close.bind(stream);
262
- stream.close = async (opts) => {
263
- // the stream is being closed, don't try to negotiate a protocol if we
264
- // haven't already
265
- if (!negotiated) {
266
- negotiated = true;
267
- negotiating = false;
268
- doneNegotiating.resolve();
269
- }
270
- // protocol has been negotiated, ok to close the writable end
271
- await originalClose(opts);
272
- };
273
- }
274
- return {
275
- stream,
91
+ })()
92
+ },
276
93
  protocol
277
94
  };
278
95
  }
@@ -1 +1 @@
1
- {"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,WAAW,MA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AAM,EAAE,CAAC,KAAK,SAAU,CAAC;gBACvB,IAAI,CAAC,UAAU;oBAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,CAAA;gBACxD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBACxC,IAAI,QAAQ,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;gBACvD,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;oBAC7B,QAAQ,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;gBACrD,CAAC;gBACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;oBAC1B,MAAM,IAAI,SAAS,CAAC,2BAA2B,EAAE,0BAA0B,CAAC,CAAA;gBAC9E,CAAC;gBACD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;oBACrC,KAAM,CAAC,CAAC,KAAK,CAAA;gBACf,CAAC;YACH,CAAC,CAAC,EAAE;SACL;QACD,QAAQ;KACT,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@libp2p/multistream-select",
3
- "version": "4.0.9-f537b3731",
3
+ "version": "4.0.10",
4
4
  "description": "JavaScript implementation of multistream-select",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/multistream-select#readme",
6
+ "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/multistream-select#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/libp2p/js-libp2p.git"
@@ -11,10 +11,6 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/libp2p/js-libp2p/issues"
13
13
  },
14
- "publishConfig": {
15
- "access": "public",
16
- "provenance": true
17
- },
18
14
  "keywords": [
19
15
  "ipfs",
20
16
  "libp2p",
@@ -57,22 +53,26 @@
57
53
  "test:electron-main": "aegir test -t electron-main"
58
54
  },
59
55
  "dependencies": {
60
- "@libp2p/interface": "1.0.1-f537b3731",
61
- "it-length-prefixed": "^9.0.3",
62
- "it-length-prefixed-stream": "^1.1.1",
56
+ "@libp2p/interface": "^0.1.6",
57
+ "@libp2p/logger": "^3.1.0",
58
+ "abortable-iterator": "^5.0.1",
59
+ "it-first": "^3.0.1",
60
+ "it-handshake": "^4.1.3",
61
+ "it-length-prefixed": "^9.0.1",
62
+ "it-merge": "^3.0.0",
63
63
  "it-pipe": "^3.0.1",
64
+ "it-pushable": "^3.2.0",
65
+ "it-reader": "^6.0.1",
64
66
  "it-stream-types": "^2.0.1",
65
- "p-defer": "^4.0.0",
66
- "uint8-varint": "^2.0.2",
67
+ "uint8-varint": "^2.0.0",
67
68
  "uint8arraylist": "^2.4.3",
68
69
  "uint8arrays": "^4.0.6"
69
70
  },
70
71
  "devDependencies": {
71
- "@libp2p/logger": "4.0.1-f537b3731",
72
72
  "aegir": "^41.0.2",
73
73
  "iso-random-stream": "^2.0.2",
74
- "it-all": "^3.0.3",
75
- "it-drain": "^3.0.5",
74
+ "it-all": "^3.0.1",
75
+ "it-map": "^3.0.3",
76
76
  "it-pair": "^2.0.6",
77
77
  "p-timeout": "^6.0.0"
78
78
  }
package/src/handle.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { encode } from 'it-length-prefixed'
2
- import { lpStream } from 'it-length-prefixed-stream'
1
+ import { logger } from '@libp2p/logger'
2
+ import { handshake } from 'it-handshake'
3
3
  import { Uint8ArrayList } from 'uint8arraylist'
4
4
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
5
- import { MAX_PROTOCOL_LENGTH, PROTOCOL_ID } from './constants.js'
5
+ import { PROTOCOL_ID } from './constants.js'
6
6
  import * as multistream from './multistream.js'
7
- import type { MultistreamSelectInit, ProtocolStream } from './index.js'
8
- import type { Duplex } from 'it-stream-types'
7
+ import type { ByteArrayInit, ByteListInit, MultistreamSelectInit, ProtocolStream } from './index.js'
8
+ import type { Duplex, Source } from 'it-stream-types'
9
+
10
+ const log = logger('libp2p:mss:handle')
9
11
 
10
12
  /**
11
13
  * Handle multistream protocol selections for the given list of protocols.
@@ -53,51 +55,38 @@ import type { Duplex } from 'it-stream-types'
53
55
  * })
54
56
  * ```
55
57
  */
56
- export async function handle <Stream extends Duplex<any, any, any>> (stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>> {
58
+ export async function handle (stream: Duplex<Source<Uint8Array>, Source<Uint8Array>>, protocols: string | string[], options: ByteArrayInit): Promise<ProtocolStream<Uint8Array>>
59
+ export async function handle (stream: Duplex<Source<Uint8ArrayList | Uint8Array>, Source<Uint8ArrayList | Uint8Array>>, protocols: string | string[], options?: ByteListInit): Promise<ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>>
60
+ export async function handle (stream: any, protocols: string | string[], options?: MultistreamSelectInit): Promise<ProtocolStream<any>> {
57
61
  protocols = Array.isArray(protocols) ? protocols : [protocols]
58
- options?.log?.trace('handle: available protocols %s', protocols)
59
-
60
- const lp = lpStream(stream, {
61
- ...options,
62
- maxDataLength: MAX_PROTOCOL_LENGTH,
63
- maxLengthLength: 2 // 2 bytes is enough to length-prefix MAX_PROTOCOL_LENGTH
64
- })
62
+ const { writer, reader, rest, stream: shakeStream } = handshake(stream)
65
63
 
66
64
  while (true) {
67
- options?.log?.trace('handle: reading incoming string')
68
- const protocol = await multistream.readString(lp, options)
69
- options?.log?.trace('handle: read "%s"', protocol)
65
+ const protocol = await multistream.readString(reader, options)
66
+ log.trace('read "%s"', protocol)
70
67
 
71
68
  if (protocol === PROTOCOL_ID) {
72
- options?.log?.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
73
- await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options)
74
- options?.log?.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
69
+ log.trace('respond with "%s" for "%s"', PROTOCOL_ID, protocol)
70
+ multistream.write(writer, uint8ArrayFromString(PROTOCOL_ID), options)
75
71
  continue
76
72
  }
77
73
 
78
74
  if (protocols.includes(protocol)) {
79
- options?.log?.trace('handle: respond with "%s" for "%s"', protocol, protocol)
80
- await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
81
- options?.log?.trace('handle: responded with "%s" for "%s"', protocol, protocol)
82
-
83
- return { stream: lp.unwrap(), protocol }
75
+ multistream.write(writer, uint8ArrayFromString(protocol), options)
76
+ log.trace('respond with "%s" for "%s"', protocol, protocol)
77
+ rest()
78
+ return { stream: shakeStream, protocol }
84
79
  }
85
80
 
86
81
  if (protocol === 'ls') {
87
82
  // <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n\n
88
- const protos = new Uint8ArrayList(
89
- ...protocols.map(p => encode.single(uint8ArrayFromString(`${p}\n`))),
90
- uint8ArrayFromString('\n')
91
- )
92
-
93
- options?.log?.trace('handle: respond with "%s" for %s', protocols, protocol)
94
- await multistream.write(lp, protos, options)
95
- options?.log?.trace('handle: responded with "%s" for %s', protocols, protocol)
83
+ multistream.write(writer, new Uint8ArrayList(...protocols.map(p => multistream.encode(uint8ArrayFromString(p)))), options)
84
+ // multistream.writeAll(writer, protocols.map(p => uint8ArrayFromString(p)))
85
+ log.trace('respond with "%s" for %s', protocols, protocol)
96
86
  continue
97
87
  }
98
88
 
99
- options?.log?.('handle: respond with "na" for "%s"', protocol)
100
- await multistream.write(lp, uint8ArrayFromString('na\n'), options)
101
- options?.log?.('handle: responded with "na" for "%s"', protocol)
89
+ multistream.write(writer, uint8ArrayFromString('na'), options)
90
+ log('respond with "na" for "%s"', protocol)
102
91
  }
103
92
  }
package/src/index.ts CHANGED
@@ -21,19 +21,27 @@
21
21
  */
22
22
 
23
23
  import { PROTOCOL_ID } from './constants.js'
24
- import type { AbortOptions, LoggerOptions } from '@libp2p/interface'
25
- import type { LengthPrefixedStreamOpts } from 'it-length-prefixed-stream'
24
+ import type { AbortOptions } from '@libp2p/interface'
25
+ import type { Duplex, Source } from 'it-stream-types'
26
26
 
27
27
  export { PROTOCOL_ID }
28
28
 
29
- export interface ProtocolStream<Stream> {
30
- stream: Stream
29
+ export interface ProtocolStream<TSource, TSink = TSource, RSink = Promise<void>> {
30
+ stream: Duplex<AsyncGenerator<TSource>, Source<TSink>, RSink>
31
31
  protocol: string
32
32
  }
33
33
 
34
- export interface MultistreamSelectInit extends AbortOptions, LoggerOptions, Partial<LengthPrefixedStreamOpts> {
34
+ export interface ByteArrayInit extends AbortOptions {
35
+ writeBytes: true
36
+ }
37
+
38
+ export interface ByteListInit extends AbortOptions {
39
+ writeBytes?: false
40
+ }
35
41
 
42
+ export interface MultistreamSelectInit extends AbortOptions {
43
+ writeBytes?: boolean
36
44
  }
37
45
 
38
- export { select } from './select.js'
46
+ export { select, lazySelect } from './select.js'
39
47
  export { handle } from './handle.js'