@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/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
- * ```js
24
+ * ```typescript
23
25
  * import { yamux } from '@libp2p/yamux'
24
- * import { pipe } from 'it-pipe'
25
- * import { duplexPair } from 'it-pair/duplex'
26
- * import all from 'it-all'
27
- *
28
- * // Connect two yamux muxers to demo basic stream multiplexing functionality
29
- *
30
- * const clientMuxer = yamux({
31
- * client: true,
32
- * onIncomingStream: stream => {
33
- * // echo data on incoming streams
34
- * pipe(stream, stream)
35
- * },
36
- * onStreamEnd: stream => {
37
- * // do nothing
38
- * }
39
- * })()
40
- *
41
- * const serverMuxer = yamux({
42
- * client: false,
43
- * onIncomingStream: stream => {
44
- * // echo data on incoming streams
45
- * pipe(stream, stream)
46
- * },
47
- * onStreamEnd: stream => {
48
- * // do nothing
49
- * }
50
- * })()
51
- *
52
- * // `p` is our "connections", what we use to connect the two sides
53
- * // In a real application, a connection is usually to a remote computer
54
- * const p = duplexPair()
55
- *
56
- * // connect the muxers together
57
- * pipe(p[0], clientMuxer, p[0])
58
- * pipe(p[1], serverMuxer, p[1])
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.js'
81
- import type { YamuxMuxer, YamuxMuxerInit } from './muxer.js'
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.js'
85
- export type { FrameHeader, FrameType } from './frame.js'
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.js'
6
- import { Decoder } from './decode.js'
7
- import { encodeHeader } from './encode.js'
8
- import { InvalidFrameError, isProtocolError, NotMatchingPingError, UnRequestedPingError } from './errors.js'
9
- import { Flag, FrameType, GoAwayCode } from './frame.js'
10
- import { StreamState, YamuxStream } from './stream.js'
11
- import type { Config } from './config.js'
12
- import type { Frame } from './decode.js'
13
- import type { FrameHeader } from './frame.js'
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.js'
3
+ import { INITIAL_STREAM_WINDOW, MAX_STREAM_WINDOW } from './constants.ts'
4
4
  import { isDataFrame } from './decode.ts'
5
- import { InvalidFrameError, ReceiveWindowExceededError } from './errors.js'
6
- import { Flag, FrameType, HEADER_LENGTH } from './frame.js'
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.js'
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
- async sendReset (): Promise<void> {
130
+ sendReset (): void {
131
131
  this.sendFrame({
132
132
  type: FrameType.WindowUpdate,
133
133
  flag: Flag.RST,
@@ -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
- }