@libp2p/yamux 8.0.1 → 8.0.2-5cb617ae2
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 +49 -63
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/config.js +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/decode.d.ts +1 -1
- package/dist/src/decode.js +2 -2
- package/dist/src/encode.d.ts +1 -1
- package/dist/src/encode.js +1 -1
- package/dist/src/index.d.ts +41 -57
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +40 -56
- package/dist/src/index.js.map +1 -1
- package/dist/src/muxer.d.ts +3 -3
- package/dist/src/muxer.js +6 -6
- package/dist/src/stream.d.ts +2 -2
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +4 -4
- package/dist/src/stream.js.map +1 -1
- package/package.json +18 -15
- package/src/config.ts +1 -1
- package/src/constants.ts +1 -1
- package/src/decode.ts +3 -3
- package/src/encode.ts +2 -2
- package/src/index.ts +42 -58
- package/src/muxer.ts +9 -9
- package/src/stream.ts +5 -5
- package/dist/typedoc-urls.json +0 -22
package/src/index.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module is a JavaScript implementation of [Yamux from Hashicorp](https://github.com/hashicorp/yamux/blob/master/spec.md) designed to be used with [js-libp2p](https://github.com/libp2p/js-libp2p).
|
|
5
5
|
*
|
|
6
|
+
* Formerly published as [`@chainsafe/libp2p-yamux`](https://www.npmjs.com/package/@chainsafe/libp2p-yamux).
|
|
7
|
+
*
|
|
6
8
|
* @example Configure libp2p with Yamux
|
|
7
9
|
*
|
|
8
10
|
* ```typescript
|
|
@@ -19,70 +21,52 @@
|
|
|
19
21
|
*
|
|
20
22
|
* @example Using the low-level API
|
|
21
23
|
*
|
|
22
|
-
* ```
|
|
24
|
+
* ```typescript
|
|
23
25
|
* import { yamux } from '@libp2p/yamux'
|
|
24
|
-
* import {
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* const clientMuxer = yamux(
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* // now either side can open streams
|
|
61
|
-
* const stream0 = clientMuxer.newStream()
|
|
62
|
-
* const stream1 = serverMuxer.newStream()
|
|
63
|
-
*
|
|
64
|
-
* // Send some data to the other side
|
|
65
|
-
* const encoder = new TextEncoder()
|
|
66
|
-
* const data = [encoder.encode('hello'), encoder.encode('world')]
|
|
67
|
-
* pipe(data, stream0)
|
|
68
|
-
*
|
|
69
|
-
* // Receive data back
|
|
70
|
-
* const result = await pipe(stream0, all)
|
|
71
|
-
*
|
|
72
|
-
* // close a stream
|
|
73
|
-
* stream1.close()
|
|
74
|
-
*
|
|
75
|
-
* // close the muxer
|
|
76
|
-
* clientMuxer.close()
|
|
26
|
+
* import { multiaddrConnectionPair } from '@libp2p/utils'
|
|
27
|
+
*
|
|
28
|
+
* // a pair of connected multiaddr connections - in a real application these
|
|
29
|
+
* // would be the two ends of a network connection
|
|
30
|
+
* const [outboundConnection, inboundConnection] = multiaddrConnectionPair()
|
|
31
|
+
*
|
|
32
|
+
* const clientMuxer = yamux()().createStreamMuxer(outboundConnection)
|
|
33
|
+
* const serverMuxer = yamux()().createStreamMuxer(inboundConnection)
|
|
34
|
+
*
|
|
35
|
+
* // echo incoming data back on the server side
|
|
36
|
+
* serverMuxer.addEventListener('stream', (evt) => {
|
|
37
|
+
* const stream = evt.detail
|
|
38
|
+
*
|
|
39
|
+
* stream.addEventListener('message', (msg) => {
|
|
40
|
+
* stream.send(msg.data)
|
|
41
|
+
* })
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
44
|
+
* // open a stream from the client and send some data
|
|
45
|
+
* const stream = await clientMuxer.createStream()
|
|
46
|
+
*
|
|
47
|
+
* const received = new Promise<string>((resolve) => {
|
|
48
|
+
* stream.addEventListener('message', (msg) => {
|
|
49
|
+
* resolve(new TextDecoder().decode(msg.data.subarray()))
|
|
50
|
+
* })
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
53
|
+
* stream.send(new TextEncoder().encode('hello world'))
|
|
54
|
+
*
|
|
55
|
+
* console.info(await received)
|
|
56
|
+
* // -> hello world
|
|
57
|
+
*
|
|
58
|
+
* await stream.close()
|
|
59
|
+
* await clientMuxer.close()
|
|
60
|
+
* await serverMuxer.close()
|
|
77
61
|
* ```
|
|
78
62
|
*/
|
|
79
63
|
|
|
80
|
-
import { Yamux } from './muxer.
|
|
81
|
-
import type { YamuxMuxer, YamuxMuxerInit } from './muxer.
|
|
64
|
+
import { Yamux } from './muxer.ts'
|
|
65
|
+
import type { YamuxMuxer, YamuxMuxerInit } from './muxer.ts'
|
|
82
66
|
import type { StreamMuxerFactory } from '@libp2p/interface'
|
|
83
67
|
|
|
84
|
-
export { GoAwayCode } from './frame.
|
|
85
|
-
export type { FrameHeader, FrameType } from './frame.
|
|
68
|
+
export { GoAwayCode } from './frame.ts'
|
|
69
|
+
export type { FrameHeader, FrameType } from './frame.ts'
|
|
86
70
|
export type { YamuxMuxerInit }
|
|
87
71
|
|
|
88
72
|
export function yamux (init: YamuxMuxerInit = {}): () => StreamMuxerFactory<YamuxMuxer> {
|
package/src/muxer.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { InvalidParametersError, MuxerClosedError, TooManyOutboundProtocolStream
|
|
|
2
2
|
import { AbstractStreamMuxer, repeatingTask } from '@libp2p/utils'
|
|
3
3
|
import { raceSignal } from 'race-signal'
|
|
4
4
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
5
|
-
import { defaultConfig, verifyConfig } from './config.
|
|
6
|
-
import { Decoder } from './decode.
|
|
7
|
-
import { encodeHeader } from './encode.
|
|
8
|
-
import { InvalidFrameError, isProtocolError, NotMatchingPingError, UnRequestedPingError } from './errors.
|
|
9
|
-
import { Flag, FrameType, GoAwayCode } from './frame.
|
|
10
|
-
import { StreamState, YamuxStream } from './stream.
|
|
11
|
-
import type { Config } from './config.
|
|
12
|
-
import type { Frame } from './decode.
|
|
13
|
-
import type { FrameHeader } from './frame.
|
|
5
|
+
import { defaultConfig, verifyConfig } from './config.ts'
|
|
6
|
+
import { Decoder } from './decode.ts'
|
|
7
|
+
import { encodeHeader } from './encode.ts'
|
|
8
|
+
import { InvalidFrameError, isProtocolError, NotMatchingPingError, UnRequestedPingError } from './errors.ts'
|
|
9
|
+
import { Flag, FrameType, GoAwayCode } from './frame.ts'
|
|
10
|
+
import { StreamState, YamuxStream } from './stream.ts'
|
|
11
|
+
import type { Config } from './config.ts'
|
|
12
|
+
import type { Frame } from './decode.ts'
|
|
13
|
+
import type { FrameHeader } from './frame.ts'
|
|
14
14
|
import type { AbortOptions, MessageStream, StreamMuxerFactory } from '@libp2p/interface'
|
|
15
15
|
import type { RepeatingTask } from '@libp2p/utils'
|
|
16
16
|
|
package/src/stream.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AbstractStream } from '@libp2p/utils'
|
|
2
2
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
|
-
import { INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.
|
|
3
|
+
import { INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.ts'
|
|
4
4
|
import { isDataFrame } from './decode.ts'
|
|
5
|
-
import { InvalidFrameError, ReceiveWindowExceededError } from './errors.
|
|
6
|
-
import { Flag, FrameType, HEADER_LENGTH } from './frame.
|
|
5
|
+
import { InvalidFrameError, ReceiveWindowExceededError } from './errors.ts'
|
|
6
|
+
import { Flag, FrameType, HEADER_LENGTH } from './frame.ts'
|
|
7
7
|
import type { Frame } from './decode.ts'
|
|
8
|
-
import type { FrameHeader } from './frame.
|
|
8
|
+
import type { FrameHeader } from './frame.ts'
|
|
9
9
|
import type { AbortOptions } from '@libp2p/interface'
|
|
10
10
|
import type { AbstractStreamInit, SendResult } from '@libp2p/utils'
|
|
11
11
|
|
|
@@ -127,7 +127,7 @@ export class YamuxStream extends AbstractStream {
|
|
|
127
127
|
/**
|
|
128
128
|
* Send a reset message to the remote muxer
|
|
129
129
|
*/
|
|
130
|
-
|
|
130
|
+
sendReset (): void {
|
|
131
131
|
this.sendFrame({
|
|
132
132
|
type: FrameType.WindowUpdate,
|
|
133
133
|
flag: Flag.RST,
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Config": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.config.Config.html",
|
|
3
|
-
"./config:Config": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.config.Config.html",
|
|
4
|
-
"YamuxStreamOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.config.YamuxStreamOptions.html",
|
|
5
|
-
"./config:YamuxStreamOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.config.YamuxStreamOptions.html",
|
|
6
|
-
"defaultConfig": "https://libp2p.github.io/js-libp2p/variables/_libp2p_yamux.config.defaultConfig.html",
|
|
7
|
-
"./config:defaultConfig": "https://libp2p.github.io/js-libp2p/variables/_libp2p_yamux.config.defaultConfig.html",
|
|
8
|
-
"verifyConfig": "https://libp2p.github.io/js-libp2p/functions/_libp2p_yamux.config.verifyConfig.html",
|
|
9
|
-
"./config:verifyConfig": "https://libp2p.github.io/js-libp2p/functions/_libp2p_yamux.config.verifyConfig.html",
|
|
10
|
-
"FrameType": "https://libp2p.github.io/js-libp2p/enums/_libp2p_yamux.index.FrameType.html",
|
|
11
|
-
"GoAwayCode": "https://libp2p.github.io/js-libp2p/enums/_libp2p_yamux.index.GoAwayCode.html",
|
|
12
|
-
"FrameHeader": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.index.FrameHeader.html",
|
|
13
|
-
"YamuxMuxerInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.index.YamuxMuxerInit.html",
|
|
14
|
-
"yamux": "https://libp2p.github.io/js-libp2p/functions/_libp2p_yamux.index.yamux.html",
|
|
15
|
-
".:yamux": "https://libp2p.github.io/js-libp2p/functions/_libp2p_yamux.index.yamux.html",
|
|
16
|
-
"StreamState": "https://libp2p.github.io/js-libp2p/enums/_libp2p_yamux.stream.StreamState.html",
|
|
17
|
-
"./stream:StreamState": "https://libp2p.github.io/js-libp2p/enums/_libp2p_yamux.stream.StreamState.html",
|
|
18
|
-
"YamuxStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_yamux.stream.YamuxStream.html",
|
|
19
|
-
"./stream:YamuxStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_yamux.stream.YamuxStream.html",
|
|
20
|
-
"YamuxStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.stream.YamuxStreamInit.html",
|
|
21
|
-
"./stream:YamuxStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_yamux.stream.YamuxStreamInit.html"
|
|
22
|
-
}
|