@libp2p/multistream-select 1.0.5 → 2.0.1

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 CHANGED
@@ -1,19 +1,9 @@
1
1
  # js-multistream-select <!-- omit in toc -->
2
2
 
3
- [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
4
- [![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats)
5
- [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
6
- [![](https://img.shields.io/codecov/c/github/multiformats/js-multistream-select.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multistream-select)
7
- [![](https://img.shields.io/travis/multiformats/js-multistream-select.svg?style=flat-square)](https://travis-ci.com/multiformats/js-multistream-select)
8
- [![Dependency Status](https://david-dm.org/multiformats/js-multistream-select.svg?style=flat-square)](https://david-dm.org/multiformats/js-multistream-select)
9
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
3
+ [![test & maybe release](https://github.com/libp2p/js-libp2p-multistream-select/actions/workflows/js-test-and-release.yml/badge.svg)](https://github.com/libp2p/js-libp2p-multistream-select/actions/workflows/js-test-and-release.yml)
10
4
 
11
5
  > JavaScript implementation of [multistream-select](https://github.com/multiformats/multistream-select)
12
6
 
13
- ## Lead Maintainer <!-- omit in toc -->
14
-
15
- [Jacob Heun](https://github.com/jacobheun)
16
-
17
7
  ## Table of Contents <!-- omit in toc -->
18
8
 
19
9
  - [Background](#background)
@@ -24,7 +14,7 @@
24
14
  - [Dialer](#dialer)
25
15
  - [Listener](#listener)
26
16
  - [API](#api)
27
- - [`new MSS.Dialer(duplex)`](#new-mssdialerduplex)
17
+ - [`new Dialer(duplex)`](#new-dialerduplex)
28
18
  - [Parameters](#parameters)
29
19
  - [Returns](#returns)
30
20
  - [Examples](#examples)
@@ -36,7 +26,7 @@
36
26
  - [Parameters](#parameters-2)
37
27
  - [Returns](#returns-2)
38
28
  - [Examples](#examples-2)
39
- - [`new MSS.Listener(duplex)`](#new-msslistenerduplex)
29
+ - [`new Listener(duplex)`](#new-listenerduplex)
40
30
  - [Parameters](#parameters-3)
41
31
  - [Returns](#returns-3)
42
32
  - [Examples](#examples-3)
@@ -44,8 +34,8 @@
44
34
  - [Parameters](#parameters-4)
45
35
  - [Returns](#returns-4)
46
36
  - [Examples](#examples-4)
47
- - [Contribute](#contribute)
48
37
  - [License](#license)
38
+ - [Contribution](#contribution)
49
39
 
50
40
  ## Background
51
41
 
@@ -74,29 +64,29 @@ This mode also packs a `ls` option, so that the callee can list the protocols it
74
64
  ## Install
75
65
 
76
66
  ```sh
77
- npm i multistream-select
67
+ npm i @libp2p/multistream-select
78
68
  ```
79
69
 
80
70
  ## Usage
81
71
 
82
72
  ```js
83
- const MSS = require('multistream-select')
73
+ import { Dialer, Listener } from '@libp2p/multistream-select'
84
74
  // You can now use
85
- // MSS.Dialer - actively select a protocol with a remote
86
- // MSS.Listener - handle a protocol with a remote
75
+ // Dialer - actively select a protocol with a remote
76
+ // Listener - handle a protocol with a remote
87
77
  ```
88
78
 
89
79
  ### Dialer
90
80
 
91
81
  ```js
92
82
  import { pipe } from 'it-pipe'
93
- const MSS = require('multistream-select')
94
- const Mplex = require('libp2p-mplex')
83
+ import { Dialer } from '@libp2p/multistream-select'
84
+ import { Mplex } from '@libp2p/mplex'
95
85
 
96
86
  const muxer = new Mplex()
97
87
  const muxedStream = muxer.newStream()
98
88
 
99
- const mss = new MSS.Dialer(muxedStream)
89
+ const mss = new Dialer(muxedStream)
100
90
 
101
91
  // mss.select(protocol(s))
102
92
  // Select from one of the passed protocols (in priority order)
@@ -128,12 +118,12 @@ const { stream: dhtStream, protocol } = await mss.select([
128
118
 
129
119
  ```js
130
120
  import { pipe } from 'it-pipe'
131
- const MSS = require('multistream-select')
132
- const Mplex = require('libp2p-mplex')
121
+ import { Listener } from '@libp2p/multistream-select'
122
+ import { Mplex } from '@libp2p/mplex'
133
123
 
134
124
  const muxer = new Mplex({
135
125
  async onStream (muxedStream) {
136
- const mss = new MSS.Listener(muxedStream)
126
+ const mss = new Listener(muxedStream)
137
127
 
138
128
  // mss.handle(handledProtocols)
139
129
  // Returns selected stream and protocol
@@ -165,7 +155,7 @@ const muxer = new Mplex({
165
155
 
166
156
  ## API
167
157
 
168
- ### `new MSS.Dialer(duplex)`
158
+ ### `new Dialer(duplex)`
169
159
 
170
160
  Create a new multistream select "dialer" instance which can be used to negotiate a protocol to use, list all available protocols the remote supports, or do both.
171
161
 
@@ -234,7 +224,7 @@ if (!protocols.includes(wantedProto)) {
234
224
  // Now use dialer.select to use wantedProto, safe in the knowledge it is supported
235
225
  ```
236
226
 
237
- ### `new MSS.Listener(duplex)`
227
+ ### `new Listener(duplex)`
238
228
 
239
229
  Construct a new multistream select "listener" instance which can be used to handle multistream protocol selections for particular protocols.
240
230
 
@@ -277,14 +267,13 @@ const { stream, protocol } = await listener.handle([
277
267
  // Remote wants to speak `protocol`
278
268
  ```
279
269
 
280
- ## Contribute
281
-
282
- Contributions welcome. Please check out [the issues](https://github.com/multiformats/js-multistream-select/issues).
270
+ ## License
283
271
 
284
- Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
272
+ Licensed under either of
285
273
 
286
- Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
274
+ * Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
275
+ * MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
287
276
 
288
- ## License
277
+ ### Contribution
289
278
 
290
- [MIT](LICENSE)
279
+ 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.
@@ -19,7 +19,6 @@ declare class MultistreamSelect {
19
19
  }
20
20
  export declare class Dialer extends MultistreamSelect {
21
21
  select(protocols: string | string[], options?: AbortOptions): Promise<ProtocolStream>;
22
- ls(options?: AbortOptions): Promise<string[]>;
23
22
  }
24
23
  export declare class Listener extends MultistreamSelect {
25
24
  handle(protocols: string | string[], options?: AbortOptions): Promise<ProtocolStream>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IAC1B,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,cAAM,iBAAiB;IACrB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IACpC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAA;gBAEZ,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC;IAKvC;;;;OAIG;IACG,UAAU,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CASzD;AAED,qBAAa,MAAO,SAAQ,iBAAiB;IACrC,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAItF,EAAE,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAOrD;AAED,qBAAa,QAAS,SAAQ,iBAAiB;IACvC,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;CAG7F"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IAC1B,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,cAAM,iBAAiB;IACrB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IACpC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAA;gBAEZ,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC;IAKvC;;;;OAIG;IACG,UAAU,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CASzD;AAED,qBAAa,MAAO,SAAQ,iBAAiB;IACrC,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;CAG7F;AAED,qBAAa,QAAS,SAAQ,iBAAiB;IACvC,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;CAG7F"}
package/dist/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { select } from './select.js';
2
2
  import { handle } from './handle.js';
3
- import { ls } from './ls.js';
4
3
  import { PROTOCOL_ID } from './constants.js';
5
4
  export { PROTOCOL_ID };
6
5
  class MultistreamSelect {
@@ -26,13 +25,6 @@ export class Dialer extends MultistreamSelect {
26
25
  async select(protocols, options) {
27
26
  return await select(this.stream, protocols, this.shaken ? undefined : PROTOCOL_ID, options);
28
27
  }
29
- async ls(options) {
30
- await this._handshake(options);
31
- const res = await ls(this.stream, options);
32
- const { stream, protocols } = res;
33
- this.stream = stream;
34
- return protocols;
35
- }
36
28
  }
37
29
  export class Listener extends MultistreamSelect {
38
30
  async handle(protocols, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAI5C,OAAO,EAAE,WAAW,EAAE,CAAA;AAOtB,MAAM,iBAAiB;IAIrB,YAAa,MAA0B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAE,OAAsB;QACtC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAM;SACP;QAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAC7E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACpB,CAAC;CACF;AAED,MAAM,OAAO,MAAO,SAAQ,iBAAiB;IAC3C,KAAK,CAAC,MAAM,CAAE,SAA4B,EAAE,OAAsB;QAChE,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;IAC7F,CAAC;IAED,KAAK,CAAC,EAAE,CAAE,OAAsB;QAC9B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QAC9B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC1C,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,CAAA;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AAED,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAC7C,KAAK,CAAC,MAAM,CAAE,SAA4B,EAAE,OAAsB;QAChE,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;CACF"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAI5C,OAAO,EAAE,WAAW,EAAE,CAAA;AAOtB,MAAM,iBAAiB;IAIrB,YAAa,MAA0B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAE,OAAsB;QACtC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAM;SACP;QAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAC7E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACpB,CAAC;CACF;AAED,MAAM,OAAO,MAAO,SAAQ,iBAAiB;IAC3C,KAAK,CAAC,MAAM,CAAE,SAA4B,EAAE,OAAsB;QAChE,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;IAC7F,CAAC;CACF;AAED,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAC7C,KAAK,CAAC,MAAM,CAAE,SAA4B,EAAE,OAAsB;QAChE,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@libp2p/multistream-select",
3
- "version": "1.0.5",
3
+ "version": "2.0.1",
4
4
  "description": "JavaScript implementation of multistream-select",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-multistream-select#readme",
6
+ "homepage": "https://github.com/libp2p/js-libp2p-multistream-select#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
9
+ "url": "git+https://github.com/libp2p/js-libp2p-multistream-select.git"
10
10
  },
11
11
  "bugs": {
12
- "url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
12
+ "url": "https://github.com/libp2p/js-libp2p-multistream-select/issues"
13
13
  },
14
14
  "keywords": [
15
15
  "ipfs",
@@ -137,23 +137,24 @@
137
137
  "release": "aegir release"
138
138
  },
139
139
  "dependencies": {
140
- "@libp2p/interfaces": "^2.0.0",
141
- "@libp2p/logger": "^1.1.0",
140
+ "@libp2p/interfaces": "^3.0.2",
141
+ "@libp2p/logger": "^2.0.0",
142
142
  "abortable-iterator": "^4.0.2",
143
143
  "err-code": "^3.0.1",
144
144
  "it-first": "^1.0.6",
145
- "it-handshake": "^3.0.1",
145
+ "it-handshake": "^4.0.0",
146
146
  "it-length-prefixed": "^7.0.1",
147
147
  "it-pipe": "^2.0.3",
148
- "it-pushable": "^2.0.1",
148
+ "it-pushable": "^3.0.0",
149
149
  "it-reader": "^5.0.0",
150
150
  "it-stream-types": "^1.0.4",
151
151
  "p-defer": "^4.0.0",
152
- "uint8arraylist": "^1.4.0",
152
+ "uint8arraylist": "^1.5.1",
153
153
  "uint8arrays": "^3.0.0"
154
154
  },
155
155
  "devDependencies": {
156
- "aegir": "^37.0.7",
156
+ "@types/varint": "^6.0.0",
157
+ "aegir": "^37.2.0",
157
158
  "iso-random-stream": "^2.0.2",
158
159
  "it-all": "^1.0.6",
159
160
  "it-map": "^1.0.6",
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { select } from './select.js'
2
2
  import { handle } from './handle.js'
3
- import { ls } from './ls.js'
4
3
  import { PROTOCOL_ID } from './constants.js'
5
4
  import type { Duplex } from 'it-stream-types'
6
5
  import type { AbortOptions } from '@libp2p/interfaces'
@@ -41,14 +40,6 @@ export class Dialer extends MultistreamSelect {
41
40
  async select (protocols: string | string[], options?: AbortOptions): Promise<ProtocolStream> {
42
41
  return await select(this.stream, protocols, this.shaken ? undefined : PROTOCOL_ID, options)
43
42
  }
44
-
45
- async ls (options?: AbortOptions): Promise<string[]> {
46
- await this._handshake(options)
47
- const res = await ls(this.stream, options)
48
- const { stream, protocols } = res
49
- this.stream = stream
50
- return protocols
51
- }
52
43
  }
53
44
 
54
45
  export class Listener extends MultistreamSelect {
package/dist/src/ls.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { Duplex } from 'it-stream-types';
2
- import type { AbortOptions } from '@libp2p/interfaces';
3
- export declare function ls(stream: Duplex<Uint8Array>, options?: AbortOptions): Promise<{
4
- stream: Duplex<Uint8Array>;
5
- protocols: string[];
6
- }>;
7
- //# sourceMappingURL=ls.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../src/ls.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD,wBAAsB,EAAE,CAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA+B1I"}
package/dist/src/ls.js DELETED
@@ -1,32 +0,0 @@
1
- import { reader as createReader } from 'it-reader';
2
- import { logger } from '@libp2p/logger';
3
- import * as multistream from './multistream.js';
4
- import { handshake } from 'it-handshake';
5
- import * as lp from 'it-length-prefixed';
6
- import { pipe } from 'it-pipe';
7
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
8
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
9
- const log = logger('libp2p:mss:ls');
10
- export async function ls(stream, options) {
11
- const { reader, writer, rest, stream: shakeStream } = handshake(stream);
12
- log('write "ls"');
13
- multistream.write(writer, uint8ArrayFromString('ls'));
14
- rest();
15
- // Next message from remote will be (e.g. for 2 protocols):
16
- // <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n
17
- const res = await multistream.read(reader, options);
18
- // After reading response we have:
19
- // <varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n
20
- const protocolsReader = createReader([res]);
21
- const protocols = [];
22
- // Decode each of the protocols from the reader
23
- await pipe(protocolsReader, lp.decode(), async (source) => {
24
- for await (const protocol of source) {
25
- // Remove the newline
26
- protocols.push(uint8ArrayToString(protocol.slice(0, -1)));
27
- }
28
- });
29
- const output = { stream: shakeStream, protocols };
30
- return output;
31
- }
32
- //# sourceMappingURL=ls.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ls.js","sourceRoot":"","sources":["../../src/ls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAI5E,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;AAEnC,MAAM,CAAC,KAAK,UAAU,EAAE,CAAE,MAA0B,EAAE,OAAsB;IAC1E,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IAEvE,GAAG,CAAC,YAAY,CAAC,CAAA;IACjB,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAA;IACrD,IAAI,EAAE,CAAA;IAEN,2DAA2D;IAC3D,6FAA6F;IAC7F,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEnD,kCAAkC;IAClC,6EAA6E;IAC7E,MAAM,eAAe,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAC3C,MAAM,SAAS,GAAa,EAAE,CAAA;IAE9B,+CAA+C;IAC/C,MAAM,IAAI,CACR,eAAe,EACf,EAAE,CAAC,MAAM,EAAE,EACX,KAAK,EAAE,MAAM,EAAE,EAAE;QACf,IAAI,KAAK,EAAE,MAAM,QAAQ,IAAI,MAAM,EAAE;YACnC,qBAAqB;YACrB,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;SAC1D;IACH,CAAC,CACF,CAAA;IAED,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;IAEjD,OAAO,MAAM,CAAA;AACf,CAAC"}
package/src/ls.ts DELETED
@@ -1,45 +0,0 @@
1
- import { reader as createReader } from 'it-reader'
2
- import { logger } from '@libp2p/logger'
3
- import * as multistream from './multistream.js'
4
- import { handshake } from 'it-handshake'
5
- import * as lp from 'it-length-prefixed'
6
- import { pipe } from 'it-pipe'
7
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
8
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
- import type { Duplex } from 'it-stream-types'
10
- import type { AbortOptions } from '@libp2p/interfaces'
11
-
12
- const log = logger('libp2p:mss:ls')
13
-
14
- export async function ls (stream: Duplex<Uint8Array>, options?: AbortOptions): Promise<{ stream: Duplex<Uint8Array>, protocols: string[] }> {
15
- const { reader, writer, rest, stream: shakeStream } = handshake(stream)
16
-
17
- log('write "ls"')
18
- multistream.write(writer, uint8ArrayFromString('ls'))
19
- rest()
20
-
21
- // Next message from remote will be (e.g. for 2 protocols):
22
- // <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n
23
- const res = await multistream.read(reader, options)
24
-
25
- // After reading response we have:
26
- // <varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n
27
- const protocolsReader = createReader([res])
28
- const protocols: string[] = []
29
-
30
- // Decode each of the protocols from the reader
31
- await pipe(
32
- protocolsReader,
33
- lp.decode(),
34
- async (source) => {
35
- for await (const protocol of source) {
36
- // Remove the newline
37
- protocols.push(uint8ArrayToString(protocol.slice(0, -1)))
38
- }
39
- }
40
- )
41
-
42
- const output = { stream: shakeStream, protocols }
43
-
44
- return output
45
- }