@libp2p/multistream-select 1.0.6 → 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 +22 -33
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -8
- package/dist/src/index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +0 -9
- package/dist/src/ls.d.ts +0 -7
- package/dist/src/ls.d.ts.map +0 -1
- package/dist/src/ls.js +0 -32
- package/dist/src/ls.js.map +0 -1
- package/src/ls.ts +0 -45
package/README.md
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
# js-multistream-select <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
-
[](https://github.com/multiformats/multiformats)
|
|
5
|
-
[](https://webchat.freenode.net/?channels=%23ipfs)
|
|
6
|
-
[](https://codecov.io/gh/multiformats/js-multistream-select)
|
|
7
|
-
[](https://travis-ci.com/multiformats/js-multistream-select)
|
|
8
|
-
[](https://david-dm.org/multiformats/js-multistream-select)
|
|
9
|
-
[](https://github.com/feross/standard)
|
|
3
|
+
[](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
|
|
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
|
|
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
|
-
|
|
73
|
+
import { Dialer, Listener } from '@libp2p/multistream-select'
|
|
84
74
|
// You can now use
|
|
85
|
-
//
|
|
86
|
-
//
|
|
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
|
-
|
|
94
|
-
|
|
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
|
|
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
|
-
|
|
132
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
##
|
|
281
|
-
|
|
282
|
-
Contributions welcome. Please check out [the issues](https://github.com/multiformats/js-multistream-select/issues).
|
|
270
|
+
## License
|
|
283
271
|
|
|
284
|
-
|
|
272
|
+
Licensed under either of
|
|
285
273
|
|
|
286
|
-
|
|
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
|
-
|
|
277
|
+
### Contribution
|
|
289
278
|
|
|
290
|
-
|
|
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.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -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>;
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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) {
|
package/dist/src/index.js.map
CHANGED
|
@@ -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,
|
|
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": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "JavaScript implementation of multistream-select",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p-
|
|
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-
|
|
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-
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p-multistream-select/issues"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"ipfs",
|
|
@@ -137,15 +137,14 @@
|
|
|
137
137
|
"release": "aegir release"
|
|
138
138
|
},
|
|
139
139
|
"dependencies": {
|
|
140
|
-
"@libp2p/interfaces": "^2.0.0",
|
|
141
140
|
"@libp2p/logger": "^1.1.0",
|
|
142
141
|
"abortable-iterator": "^4.0.2",
|
|
143
142
|
"err-code": "^3.0.1",
|
|
144
143
|
"it-first": "^1.0.6",
|
|
145
|
-
"it-handshake": "^
|
|
144
|
+
"it-handshake": "^4.0.0",
|
|
146
145
|
"it-length-prefixed": "^7.0.1",
|
|
147
146
|
"it-pipe": "^2.0.3",
|
|
148
|
-
"it-pushable": "^
|
|
147
|
+
"it-pushable": "^3.0.0",
|
|
149
148
|
"it-reader": "^5.0.0",
|
|
150
149
|
"it-stream-types": "^1.0.4",
|
|
151
150
|
"p-defer": "^4.0.0",
|
|
@@ -153,7 +152,8 @@
|
|
|
153
152
|
"uint8arrays": "^3.0.0"
|
|
154
153
|
},
|
|
155
154
|
"devDependencies": {
|
|
156
|
-
"
|
|
155
|
+
"@types/varint": "^6.0.0",
|
|
156
|
+
"aegir": "^37.2.0",
|
|
157
157
|
"iso-random-stream": "^2.0.2",
|
|
158
158
|
"it-all": "^1.0.6",
|
|
159
159
|
"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
|
package/dist/src/ls.d.ts.map
DELETED
|
@@ -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
|
package/dist/src/ls.js.map
DELETED
|
@@ -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
|
-
}
|