@libp2p/multistream-select 6.0.29-6059227cb → 6.0.29-87bc8d4fb
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/dist/index.min.js +13 -9
- package/dist/index.min.js.map +4 -4
- package/dist/src/handle.d.ts +3 -3
- package/dist/src/handle.d.ts.map +1 -1
- package/dist/src/handle.js +20 -21
- package/dist/src/handle.js.map +1 -1
- package/dist/src/index.d.ts +8 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/multistream.d.ts +17 -3
- package/dist/src/multistream.d.ts.map +1 -1
- package/dist/src/multistream.js +24 -5
- package/dist/src/multistream.js.map +1 -1
- package/dist/src/select.d.ts +10 -3
- package/dist/src/select.d.ts.map +1 -1
- package/dist/src/select.js +237 -34
- package/dist/src/select.js.map +1 -1
- package/package.json +12 -7
- package/src/handle.ts +22 -25
- package/src/index.ts +9 -3
- package/src/multistream.ts +32 -7
- package/src/select.ts +299 -39
package/dist/src/handle.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MultistreamSelectInit } from './index.js';
|
|
2
|
-
import type {
|
|
1
|
+
import type { MultistreamSelectInit, ProtocolStream } from './index.js';
|
|
2
|
+
import type { Duplex } from 'it-stream-types';
|
|
3
3
|
/**
|
|
4
4
|
* Handle multistream protocol selections for the given list of protocols.
|
|
5
5
|
*
|
|
@@ -46,5 +46,5 @@ import type { MultiaddrConnection, MessageStream } from '@libp2p/interface';
|
|
|
46
46
|
* })
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
|
-
export declare function handle<Stream extends
|
|
49
|
+
export declare function handle<Stream extends Duplex<any, any, any>>(stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>>;
|
|
50
50
|
//# sourceMappingURL=handle.d.ts.map
|
package/dist/src/handle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAsB,MAAM,CAAE,MAAM,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAG,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CA+ClL"}
|
package/dist/src/handle.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { lpStream } from '@libp2p/utils';
|
|
2
1
|
import { encode } from 'it-length-prefixed';
|
|
2
|
+
import { lpStream } from 'it-length-prefixed-stream';
|
|
3
3
|
import { Uint8ArrayList } from 'uint8arraylist';
|
|
4
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
5
5
|
import { MAX_PROTOCOL_LENGTH, PROTOCOL_ID } from './constants.js';
|
|
6
|
-
import
|
|
6
|
+
import * as multistream from './multistream.js';
|
|
7
7
|
/**
|
|
8
8
|
* Handle multistream protocol selections for the given list of protocols.
|
|
9
9
|
*
|
|
@@ -50,42 +50,41 @@ import { readString } from './multistream.js';
|
|
|
50
50
|
* })
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
export async function handle(stream, protocols, options
|
|
53
|
+
export async function handle(stream, protocols, options) {
|
|
54
54
|
protocols = Array.isArray(protocols) ? protocols : [protocols];
|
|
55
|
-
|
|
55
|
+
options.log.trace('handle: available protocols %s', protocols);
|
|
56
56
|
const lp = lpStream(stream, {
|
|
57
57
|
...options,
|
|
58
58
|
maxDataLength: MAX_PROTOCOL_LENGTH,
|
|
59
59
|
maxLengthLength: 2 // 2 bytes is enough to length-prefix MAX_PROTOCOL_LENGTH
|
|
60
60
|
});
|
|
61
61
|
while (true) {
|
|
62
|
-
log.trace('reading incoming string');
|
|
63
|
-
const protocol = await readString(lp, options);
|
|
64
|
-
log.trace('read "%s"', protocol);
|
|
62
|
+
options.log.trace('handle: reading incoming string');
|
|
63
|
+
const protocol = await multistream.readString(lp, options);
|
|
64
|
+
options.log.trace('handle: read "%s"', protocol);
|
|
65
65
|
if (protocol === PROTOCOL_ID) {
|
|
66
|
-
log.trace('respond with "%s" for "%s"', PROTOCOL_ID, protocol);
|
|
67
|
-
await
|
|
68
|
-
log.trace('responded with "%s" for "%s"', PROTOCOL_ID, protocol);
|
|
66
|
+
options.log.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol);
|
|
67
|
+
await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options);
|
|
68
|
+
options.log.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol);
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
71
71
|
if (protocols.includes(protocol)) {
|
|
72
|
-
log.trace('respond with "%s" for "%s"', protocol, protocol);
|
|
73
|
-
await
|
|
74
|
-
log.trace('responded with "%s" for "%s"', protocol, protocol);
|
|
75
|
-
lp.unwrap();
|
|
76
|
-
return protocol;
|
|
72
|
+
options.log.trace('handle: respond with "%s" for "%s"', protocol, protocol);
|
|
73
|
+
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options);
|
|
74
|
+
options.log.trace('handle: responded with "%s" for "%s"', protocol, protocol);
|
|
75
|
+
return { stream: lp.unwrap(), protocol };
|
|
77
76
|
}
|
|
78
77
|
if (protocol === 'ls') {
|
|
79
78
|
// <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n\n
|
|
80
79
|
const protos = new Uint8ArrayList(...protocols.map(p => encode.single(uint8ArrayFromString(`${p}\n`))), uint8ArrayFromString('\n'));
|
|
81
|
-
log.trace('respond with "%s" for %s', protocols, protocol);
|
|
82
|
-
await
|
|
83
|
-
log.trace('responded with "%s" for %s', protocols, protocol);
|
|
80
|
+
options.log.trace('handle: respond with "%s" for %s', protocols, protocol);
|
|
81
|
+
await multistream.write(lp, protos, options);
|
|
82
|
+
options.log.trace('handle: responded with "%s" for %s', protocols, protocol);
|
|
84
83
|
continue;
|
|
85
84
|
}
|
|
86
|
-
log.trace('respond with "na" for "%s"', protocol);
|
|
87
|
-
await
|
|
88
|
-
log('responded with "na" for "%s"', protocol);
|
|
85
|
+
options.log.trace('handle: respond with "na" for "%s"', protocol);
|
|
86
|
+
await multistream.write(lp, uint8ArrayFromString('na\n'), options);
|
|
87
|
+
options.log('handle: responded with "na" for "%s"', protocol);
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
//# sourceMappingURL=handle.js.map
|
package/dist/src/handle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAI/C;;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TOCOL_ID } from './constants.js';
|
|
23
|
-
import type { AbortOptions } from '@libp2p/interface';
|
|
24
|
-
import type { LengthPrefixedStreamOpts } from '
|
|
23
|
+
import type { AbortOptions, LoggerOptions } from '@libp2p/interface';
|
|
24
|
+
import type { LengthPrefixedStreamOpts } from 'it-length-prefixed-stream';
|
|
25
25
|
export { PROTOCOL_ID };
|
|
26
|
-
export interface
|
|
26
|
+
export interface ProtocolStream<Stream> {
|
|
27
|
+
stream: Stream;
|
|
28
|
+
protocol: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MultistreamSelectInit extends AbortOptions, LoggerOptions, Partial<LengthPrefixedStreamOpts> {
|
|
27
31
|
/**
|
|
28
32
|
* When false, and only a single protocol is being negotiated, use optimistic
|
|
29
33
|
* select to send both the protocol name and the first data buffer in the
|
|
@@ -34,5 +38,6 @@ export interface MultistreamSelectInit extends AbortOptions, Partial<LengthPrefi
|
|
|
34
38
|
negotiateFully?: boolean;
|
|
35
39
|
}
|
|
36
40
|
export { select } from './select.js';
|
|
41
|
+
export type { SelectStream } from './select.js';
|
|
37
42
|
export { handle } from './handle.js';
|
|
38
43
|
//# 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;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAEzE,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,WAAW,cAAc,CAAC,MAAM;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,wBAAwB,CAAC;IAC3G;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAI5C,OAAO,EAAE,WAAW,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAI5C,OAAO,EAAE,WAAW,EAAE,CAAA;AAkBtB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import type { AbortOptions } from '@libp2p/interface';
|
|
2
|
-
import type { LengthPrefixedStream } from '
|
|
1
|
+
import type { AbortOptions, LoggerOptions } from '@libp2p/interface';
|
|
2
|
+
import type { LengthPrefixedStream } from 'it-length-prefixed-stream';
|
|
3
|
+
import type { Duplex, Source } from 'it-stream-types';
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
+
/**
|
|
6
|
+
* `write` encodes and writes a single buffer
|
|
7
|
+
*/
|
|
8
|
+
export declare function write(writer: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, buffer: Uint8Array | Uint8ArrayList, options?: AbortOptions): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* `writeAll` behaves like `write`, except it encodes an array of items as a single write
|
|
11
|
+
*/
|
|
12
|
+
export declare function writeAll(writer: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, buffers: Uint8Array[], options?: AbortOptions): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Read a length-prefixed buffer from the passed stream, stripping the final newline character
|
|
15
|
+
*/
|
|
16
|
+
export declare function read(reader: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, options: AbortOptions & LoggerOptions): Promise<Uint8ArrayList>;
|
|
3
17
|
/**
|
|
4
18
|
* Read a length-prefixed string from the passed stream, stripping the final newline character
|
|
5
19
|
*/
|
|
6
|
-
export declare function readString(reader: LengthPrefixedStream<
|
|
20
|
+
export declare function readString(reader: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, options: AbortOptions & LoggerOptions): Promise<string>;
|
|
7
21
|
//# sourceMappingURL=multistream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multistream.d.ts","sourceRoot":"","sources":["../../src/multistream.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"multistream.d.ts","sourceRoot":"","sources":["../../src/multistream.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA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8ArrayFromString } from 'uint8arrays/from-string';
|
|
|
3
3
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
4
4
|
const NewLine = uint8ArrayFromString('\n');
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* `write` encodes and writes a single buffer
|
|
7
7
|
*/
|
|
8
|
-
export async function
|
|
8
|
+
export async function write(writer, buffer, options) {
|
|
9
|
+
await writer.write(buffer, options);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `writeAll` behaves like `write`, except it encodes an array of items as a single write
|
|
13
|
+
*/
|
|
14
|
+
export async function writeAll(writer, buffers, options) {
|
|
15
|
+
await writer.writeV(buffers, options);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Read a length-prefixed buffer from the passed stream, stripping the final newline character
|
|
19
|
+
*/
|
|
20
|
+
export async function read(reader, options) {
|
|
9
21
|
const buf = await reader.read(options);
|
|
10
|
-
|
|
11
|
-
|
|
22
|
+
if (buf.byteLength === 0 || buf.get(buf.byteLength - 1) !== NewLine[0]) {
|
|
23
|
+
options.log.error('Invalid mss message - missing newline', buf);
|
|
12
24
|
throw new InvalidMessageError('Missing newline');
|
|
13
25
|
}
|
|
14
|
-
return
|
|
26
|
+
return buf.sublist(0, -1); // Remove newline
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read a length-prefixed string from the passed stream, stripping the final newline character
|
|
30
|
+
*/
|
|
31
|
+
export async function readString(reader, options) {
|
|
32
|
+
const buf = await read(reader, options);
|
|
33
|
+
return uint8ArrayToString(buf.subarray());
|
|
15
34
|
}
|
|
16
35
|
//# sourceMappingURL=multistream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multistream.js","sourceRoot":"","sources":["../../src/multistream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yB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AC,CAAA,CAAC,iBAAiB;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAE,MAAqG,EAAE,OAAqC;IAC5K,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEvC,OAAO,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;AAC3C,CAAC"}
|
package/dist/src/select.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import type { MultistreamSelectInit } from './index.js';
|
|
2
|
-
import type {
|
|
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
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Negotiate a protocol to use from a list of protocols.
|
|
5
12
|
*
|
|
@@ -43,5 +50,5 @@ import type { MessageStream } from '@libp2p/interface';
|
|
|
43
50
|
* // }
|
|
44
51
|
* ```
|
|
45
52
|
*/
|
|
46
|
-
export declare function select<Stream extends
|
|
53
|
+
export declare function select<Stream extends SelectStream>(stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>>;
|
|
47
54
|
//# sourceMappingURL=select.d.ts.map
|
package/dist/src/select.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAUA,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"}
|
package/dist/src/select.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { UnsupportedProtocolError } from '@libp2p/interface';
|
|
2
|
-
import { lpStream } from '
|
|
2
|
+
import { lpStream } from 'it-length-prefixed-stream';
|
|
3
|
+
import pDefer from 'p-defer';
|
|
4
|
+
import { raceSignal } from 'race-signal';
|
|
5
|
+
import * as varint from 'uint8-varint';
|
|
6
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
3
7
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
4
8
|
import { MAX_PROTOCOL_LENGTH } from './constants.js';
|
|
5
|
-
import
|
|
9
|
+
import * as multistream from './multistream.js';
|
|
6
10
|
import { PROTOCOL_ID } from './index.js';
|
|
7
11
|
/**
|
|
8
12
|
* Negotiate a protocol to use from a list of protocols.
|
|
@@ -47,48 +51,247 @@ import { PROTOCOL_ID } from './index.js';
|
|
|
47
51
|
* // }
|
|
48
52
|
* ```
|
|
49
53
|
*/
|
|
50
|
-
export async function select(stream, protocols, options
|
|
54
|
+
export async function select(stream, protocols, options) {
|
|
51
55
|
protocols = Array.isArray(protocols) ? [...protocols] : [protocols];
|
|
52
|
-
if (protocols.length ===
|
|
53
|
-
|
|
56
|
+
if (protocols.length === 1 && options.negotiateFully === false) {
|
|
57
|
+
return optimisticSelect(stream, protocols[0], options);
|
|
54
58
|
}
|
|
55
|
-
const log = stream.log.newScope('mss:select');
|
|
56
59
|
const lp = lpStream(stream, {
|
|
57
60
|
...options,
|
|
58
61
|
maxDataLength: MAX_PROTOCOL_LENGTH
|
|
59
62
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const protocol = protocols.shift();
|
|
64
|
+
if (protocol == null) {
|
|
65
|
+
throw new Error('At least one protocol must be specified');
|
|
66
|
+
}
|
|
67
|
+
options.log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol);
|
|
68
|
+
const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`);
|
|
69
|
+
const p2 = uint8ArrayFromString(`${protocol}\n`);
|
|
70
|
+
await multistream.writeAll(lp, [p1, p2], options);
|
|
71
|
+
options.log.trace('select: reading multistream-select header');
|
|
72
|
+
let response = await multistream.readString(lp, options);
|
|
73
|
+
options.log.trace('select: read "%s"', response);
|
|
74
|
+
// Read the protocol response if we got the protocolId in return
|
|
75
|
+
if (response === PROTOCOL_ID) {
|
|
76
|
+
options.log.trace('select: reading protocol response');
|
|
77
|
+
response = await multistream.readString(lp, options);
|
|
78
|
+
options.log.trace('select: read "%s"', response);
|
|
79
|
+
}
|
|
80
|
+
// We're done
|
|
81
|
+
if (response === protocol) {
|
|
82
|
+
return { stream: lp.unwrap(), protocol };
|
|
83
|
+
}
|
|
84
|
+
// We haven't gotten a valid ack, try the other protocols
|
|
85
|
+
for (const protocol of protocols) {
|
|
86
|
+
options.log.trace('select: write "%s"', protocol);
|
|
87
|
+
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options);
|
|
88
|
+
options.log.trace('select: reading protocol response');
|
|
89
|
+
const response = await multistream.readString(lp, options);
|
|
90
|
+
options.log.trace('select: read "%s" for "%s"', response, protocol);
|
|
91
|
+
if (response === protocol) {
|
|
92
|
+
return { stream: lp.unwrap(), protocol };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw new UnsupportedProtocolError('protocol selection failed');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Optimistically negotiates a protocol.
|
|
99
|
+
*
|
|
100
|
+
* It *does not* block writes waiting for the other end to respond. Instead, it
|
|
101
|
+
* simply assumes the negotiation went successfully and starts writing data.
|
|
102
|
+
*
|
|
103
|
+
* Use when it is known that the receiver supports the desired protocol.
|
|
104
|
+
*/
|
|
105
|
+
function optimisticSelect(stream, protocol, options) {
|
|
106
|
+
const originalSink = stream.sink.bind(stream);
|
|
107
|
+
const originalSource = stream.source;
|
|
108
|
+
let negotiated = false;
|
|
109
|
+
let negotiating = false;
|
|
110
|
+
const doneNegotiating = pDefer();
|
|
111
|
+
let sentProtocol = false;
|
|
112
|
+
let sendingProtocol = false;
|
|
113
|
+
const doneSendingProtocol = pDefer();
|
|
114
|
+
let readProtocol = false;
|
|
115
|
+
let readingProtocol = false;
|
|
116
|
+
const doneReadingProtocol = pDefer();
|
|
117
|
+
const lp = lpStream({
|
|
118
|
+
sink: originalSink,
|
|
119
|
+
source: originalSource
|
|
120
|
+
}, {
|
|
121
|
+
...options,
|
|
122
|
+
maxDataLength: MAX_PROTOCOL_LENGTH
|
|
123
|
+
});
|
|
124
|
+
stream.sink = async (source) => {
|
|
125
|
+
const { sink } = lp.unwrap();
|
|
126
|
+
await sink(async function* () {
|
|
127
|
+
let sentData = false;
|
|
128
|
+
for await (const buf of source) {
|
|
129
|
+
// started reading before the source yielded, wait for protocol send
|
|
130
|
+
if (sendingProtocol) {
|
|
131
|
+
await doneSendingProtocol.promise;
|
|
132
|
+
}
|
|
133
|
+
// writing before reading, send the protocol and the first chunk of data
|
|
134
|
+
if (!sentProtocol) {
|
|
135
|
+
sendingProtocol = true;
|
|
136
|
+
options.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
|
|
137
|
+
const protocolString = `${protocol}\n`;
|
|
138
|
+
// send protocols in first chunk of data written to transport
|
|
139
|
+
yield new Uint8ArrayList(Uint8Array.from([19]), // length of PROTOCOL_ID plus newline
|
|
140
|
+
uint8ArrayFromString(`${PROTOCOL_ID}\n`), varint.encode(protocolString.length), uint8ArrayFromString(protocolString), buf).subarray();
|
|
141
|
+
options.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength);
|
|
142
|
+
sentProtocol = true;
|
|
143
|
+
sendingProtocol = false;
|
|
144
|
+
doneSendingProtocol.resolve();
|
|
145
|
+
// read the negotiation response but don't block more sending
|
|
146
|
+
negotiate()
|
|
147
|
+
.catch(err => {
|
|
148
|
+
options.log.error('could not finish optimistic protocol negotiation of %s', protocol, err);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
yield buf;
|
|
153
|
+
}
|
|
154
|
+
sentData = true;
|
|
155
|
+
}
|
|
156
|
+
// special case - the source passed to the sink has ended but we didn't
|
|
157
|
+
// negotiated the protocol yet so do it now
|
|
158
|
+
if (!sentData) {
|
|
159
|
+
await negotiate();
|
|
76
160
|
}
|
|
161
|
+
}());
|
|
162
|
+
};
|
|
163
|
+
async function negotiate() {
|
|
164
|
+
if (negotiating) {
|
|
165
|
+
options.log.trace('optimistic: already negotiating %s stream', protocol);
|
|
166
|
+
await doneNegotiating.promise;
|
|
167
|
+
return;
|
|
77
168
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
169
|
+
negotiating = true;
|
|
170
|
+
try {
|
|
171
|
+
// we haven't sent the protocol yet, send it now
|
|
172
|
+
if (!sentProtocol) {
|
|
173
|
+
options.log.trace('optimistic: doing send protocol for %s stream', protocol);
|
|
174
|
+
await doSendProtocol();
|
|
175
|
+
}
|
|
176
|
+
// if we haven't read the protocol response yet, do it now
|
|
177
|
+
if (!readProtocol) {
|
|
178
|
+
options.log.trace('optimistic: doing read protocol for %s stream', protocol);
|
|
179
|
+
await doReadProtocol();
|
|
180
|
+
}
|
|
82
181
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
log.trace('selected "%s" after negotiation', response);
|
|
88
|
-
lp.unwrap();
|
|
89
|
-
return protocol;
|
|
182
|
+
finally {
|
|
183
|
+
negotiating = false;
|
|
184
|
+
negotiated = true;
|
|
185
|
+
doneNegotiating.resolve();
|
|
90
186
|
}
|
|
91
187
|
}
|
|
92
|
-
|
|
188
|
+
async function doSendProtocol() {
|
|
189
|
+
if (sendingProtocol) {
|
|
190
|
+
await doneSendingProtocol.promise;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
sendingProtocol = true;
|
|
194
|
+
try {
|
|
195
|
+
options.log.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
|
|
196
|
+
await lp.writeV([
|
|
197
|
+
uint8ArrayFromString(`${PROTOCOL_ID}\n`),
|
|
198
|
+
uint8ArrayFromString(`${protocol}\n`)
|
|
199
|
+
]);
|
|
200
|
+
options.log.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol);
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
sentProtocol = true;
|
|
204
|
+
sendingProtocol = false;
|
|
205
|
+
doneSendingProtocol.resolve();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function doReadProtocol() {
|
|
209
|
+
if (readingProtocol) {
|
|
210
|
+
await doneReadingProtocol.promise;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
readingProtocol = true;
|
|
214
|
+
try {
|
|
215
|
+
options.log.trace('optimistic: reading multistream select header');
|
|
216
|
+
let response = await multistream.readString(lp, options);
|
|
217
|
+
options.log.trace('optimistic: read multistream select header "%s"', response);
|
|
218
|
+
if (response === PROTOCOL_ID) {
|
|
219
|
+
response = await multistream.readString(lp, options);
|
|
220
|
+
}
|
|
221
|
+
options.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol);
|
|
222
|
+
if (response !== protocol) {
|
|
223
|
+
throw new UnsupportedProtocolError('protocol selection failed');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
readProtocol = true;
|
|
228
|
+
readingProtocol = false;
|
|
229
|
+
doneReadingProtocol.resolve();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
stream.source = (async function* () {
|
|
233
|
+
// make sure we've done protocol negotiation before we read stream data
|
|
234
|
+
await negotiate();
|
|
235
|
+
options.log.trace('optimistic: reading data from "%s" stream', protocol);
|
|
236
|
+
yield* lp.unwrap().source;
|
|
237
|
+
})();
|
|
238
|
+
if (stream.closeRead != null) {
|
|
239
|
+
const originalCloseRead = stream.closeRead.bind(stream);
|
|
240
|
+
stream.closeRead = async (opts) => {
|
|
241
|
+
// we need to read & write to negotiate the protocol so ensure we've done
|
|
242
|
+
// this before closing the readable end of the stream
|
|
243
|
+
if (!negotiated) {
|
|
244
|
+
await negotiate().catch(err => {
|
|
245
|
+
options.log.error('could not negotiate protocol before close read', err);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// protocol has been negotiated, ok to close the readable end
|
|
249
|
+
await originalCloseRead(opts);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (stream.closeWrite != null) {
|
|
253
|
+
const originalCloseWrite = stream.closeWrite.bind(stream);
|
|
254
|
+
stream.closeWrite = async (opts) => {
|
|
255
|
+
// we need to read & write to negotiate the protocol so ensure we've done
|
|
256
|
+
// this before closing the writable end of the stream
|
|
257
|
+
if (!negotiated) {
|
|
258
|
+
await negotiate().catch(err => {
|
|
259
|
+
options.log.error('could not negotiate protocol before close write', err);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
// protocol has been negotiated, ok to close the writable end
|
|
263
|
+
await originalCloseWrite(opts);
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (stream.close != null) {
|
|
267
|
+
const originalClose = stream.close.bind(stream);
|
|
268
|
+
stream.close = async (opts) => {
|
|
269
|
+
// if we are in the process of negotiation, let it finish before closing
|
|
270
|
+
// because we may have unsent early data
|
|
271
|
+
const tasks = [];
|
|
272
|
+
if (sendingProtocol) {
|
|
273
|
+
tasks.push(doneSendingProtocol.promise);
|
|
274
|
+
}
|
|
275
|
+
if (readingProtocol) {
|
|
276
|
+
tasks.push(doneReadingProtocol.promise);
|
|
277
|
+
}
|
|
278
|
+
if (tasks.length > 0) {
|
|
279
|
+
// let the in-flight protocol negotiation finish gracefully
|
|
280
|
+
await raceSignal(Promise.all(tasks), opts?.signal);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// no protocol negotiation attempt has occurred so don't start one
|
|
284
|
+
negotiated = true;
|
|
285
|
+
negotiating = false;
|
|
286
|
+
doneNegotiating.resolve();
|
|
287
|
+
}
|
|
288
|
+
// protocol has been negotiated, ok to close the writable end
|
|
289
|
+
await originalClose(opts);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
stream,
|
|
294
|
+
protocol
|
|
295
|
+
};
|
|
93
296
|
}
|
|
94
297
|
//# sourceMappingURL=select.js.map
|
package/dist/src/select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,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,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAYxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAgC,MAAc,EAAE,SAA4B,EAAE,OAA8B;IACtI,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEnE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,cAAc,KAAK,KAAK,EAAE,CAAC;QAC/D,OAAO,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;IACxD,CAA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M,aAAa,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC,CAAA;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/multistream-select",
|
|
3
|
-
"version": "6.0.29-
|
|
3
|
+
"version": "6.0.29-87bc8d4fb",
|
|
4
4
|
"description": "JavaScript implementation of multistream-select",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/multistream-select#readme",
|
|
@@ -51,19 +51,24 @@
|
|
|
51
51
|
"test:electron-main": "aegir test -t electron-main"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@libp2p/interface": "2.11.0-
|
|
55
|
-
"@libp2p/utils": "6.7.2-6059227cb",
|
|
54
|
+
"@libp2p/interface": "2.11.0-87bc8d4fb",
|
|
56
55
|
"it-length-prefixed": "^10.0.1",
|
|
56
|
+
"it-length-prefixed-stream": "^2.0.2",
|
|
57
|
+
"it-stream-types": "^2.0.2",
|
|
58
|
+
"p-defer": "^4.0.1",
|
|
59
|
+
"race-signal": "^1.1.3",
|
|
60
|
+
"uint8-varint": "^2.0.4",
|
|
57
61
|
"uint8arraylist": "^2.4.8",
|
|
58
62
|
"uint8arrays": "^5.1.0"
|
|
59
63
|
},
|
|
60
64
|
"devDependencies": {
|
|
61
|
-
"
|
|
65
|
+
"@libp2p/logger": "5.2.0-87bc8d4fb",
|
|
66
|
+
"aegir": "^47.0.14",
|
|
62
67
|
"iso-random-stream": "^2.0.2",
|
|
63
|
-
"it-all": "^3.0.
|
|
64
|
-
"it-drain": "^3.0.
|
|
68
|
+
"it-all": "^3.0.8",
|
|
69
|
+
"it-drain": "^3.0.9",
|
|
70
|
+
"it-pair": "^2.0.6",
|
|
65
71
|
"it-pipe": "^3.0.1",
|
|
66
|
-
"p-event": "^6.0.1",
|
|
67
72
|
"p-timeout": "^6.1.4"
|
|
68
73
|
},
|
|
69
74
|
"sideEffects": false
|