Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@chainsafe/libp2p-yamux

ChainSafe88.7kApache-2.0 OR MIT7.0.1TypeScript support: included

Yamux stream multiplexer for libp2p

IPFS, libp2p, multiplexer, muxer, stream

readme

@chainsafe/libp2p-yamux

codecov CI

Yamux stream multiplexer for libp2p

About

This module is a JavaScript implementation of Yamux from Hashicorp designed to be used with js-libp2p.

Example - Configure libp2p with Yamux

import { createLibp2p } from 'libp2p'
import { yamux } from '@chainsafe/libp2p-yamux'

const node = await createLibp2p({
  // ... other options
  streamMuxers: [
    yamux()
  ]
})

Example - Using the low-level API

import { yamux } from '@chainsafe/libp2p-yamux'
import { pipe } from 'it-pipe'
import { duplexPair } from 'it-pair/duplex'
import all from 'it-all'

// Connect two yamux muxers to demo basic stream multiplexing functionality

const clientMuxer = yamux({
  client: true,
  onIncomingStream: stream => {
    // echo data on incoming streams
    pipe(stream, stream)
  },
  onStreamEnd: stream => {
    // do nothing
  }
})()

const serverMuxer = yamux({
  client: false,
  onIncomingStream: stream => {
    // echo data on incoming streams
    pipe(stream, stream)
  },
  onStreamEnd: stream => {
    // do nothing
  }
})()

// `p` is our "connections", what we use to connect the two sides
// In a real application, a connection is usually to a remote computer
const p = duplexPair()

// connect the muxers together
pipe(p[0], clientMuxer, p[0])
pipe(p[1], serverMuxer, p[1])

// now either side can open streams
const stream0 = clientMuxer.newStream()
const stream1 = serverMuxer.newStream()

// Send some data to the other side
const encoder = new TextEncoder()
const data = [encoder.encode('hello'), encoder.encode('world')]
pipe(data, stream0)

// Receive data back
const result = await pipe(stream0, all)

// close a stream
stream1.close()

// close the muxer
clientMuxer.close()

Install

$ npm i @chainsafe/libp2p-yamux

Browser <script> tag

Loading this module through a script tag will make its exports available as ChainsafeLibp2pYamux in the global namespace.

<script src="https://unpkg.com/@chainsafe/libp2p-yamux/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribution

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.

changelog

7.0.1 (2024-09-25)

Bug Fixes

  • switch missing stream log to trace (#90) (96bfe96)

7.0.0 (2024-09-11)

⚠ BREAKING CHANGES

Features

  • add service capabilities definition (#79) (0aff43d)

Bug Fixes

Trivial Changes

Dependencies

  • dev: bump aegir from 43.0.3 to 44.1.1 (#83) (0a8b06f)

6.0.2 (2024-02-08)

Bug Fixes

6.0.1 (2023-11-30)

Bug Fixes

6.0.0 (2023-11-29)

⚠ BREAKING CHANGES

  • yield uint8arraylists (#65)

Features

5.0.4 (2023-11-29)

Dependencies

5.0.3 (2023-11-14)

Bug Fixes

  • establish RTT at start of connection (#64) (672523b)

5.0.2 (2023-11-12)

Bug Fixes

  • remove abortable iterator from muxer (#63) (064bf1c)

5.0.1 (2023-11-12)

Bug Fixes

  • do not stringify headers for logging (#61) (59e73d8)
  • silence max listeners exceeded warning (#62) (cce9446)

5.0.0 (2023-08-03)

⚠ BREAKING CHANGES

  • stream close methods are now asyc, requires libp2p@0.46.x or later

  • chore: pr comments

  • chore: remove readState/writeState as they are not used any more

Features

4.0.2 (2023-05-17)

Bug Fixes

  • improve decode performance with subarray (#49) (684de7c)

Dependencies

4.0.1 (2023-05-01)

Bug Fixes

  • updated reset for abort controller (#26) (6fc5ebd)

4.0.0 (2023-04-19)

⚠ BREAKING CHANGES

  • the type of the source/sink properties have changed

Dependencies

3.0.10 (2023-04-16)

Bug Fixes

  • use trace logging for happy paths (#35) (2c64584)

3.0.9 (2023-04-13)

Dependencies

  • bump @libp2p/interface-connection from 3.1.1 to 4.0.0 (#32) (e8ac91d)
  • bump it-pipe from 2.0.5 to 3.0.1 (#30) (e396e6e)

3.0.8 (2023-04-13)

Dependencies

3.0.7 (2023-03-01)

Bug Fixes

3.0.6 (2023-02-24)

Dependencies

  • dev: bump it-pair from 2.0.3 to 2.0.4 (#22) (f908735)

3.0.5 (2023-01-16)

Dependencies

  • dev: bump aegir from 37.12.1 to 38.1.0 (#20) (0cf9a86)

Trivial Changes

3.0.4 (2023-01-06)

Bug Fixes

3.0.3 (2022-11-05)

Bug Fixes

3.0.2 (2022-10-17)

Dependencies

  • dev: bump @libp2p/mplex from 6.0.2 to 7.0.0 (#14) (4085a05)

3.0.1 (2022-10-17)

Dependencies

  • dev: bump @libp2p/interface-stream-muxer-compliance-tests from 5.0.0 to 6.0.0 (#15) (b6a02d1)
  • dev: bump it-drain from 1.0.5 to 2.0.0 (#16) (399a49c)

3.0.0 (2022-10-12)

⚠ BREAKING CHANGES

  • modules no longer implement Initializable instead switching to constructor injection

Bug Fixes

2.0.0 (2022-10-07)

⚠ BREAKING CHANGES

  • deps: bump @libp2p/interface-stream-muxer from 2.0.2 to 3.0.0 (#9)
  • deps: bump @libp2p/components from 2.1.1 to 3.0.0 (#7)

Bug Fixes

Trivial Changes

  • deps-dev: bump @libp2p/interface-stream-muxer-compliance-tests from 4.0.0 to 5.0.0 (#8) (af8c3ae)
  • deps: bump @libp2p/components from 2.1.1 to 3.0.0 (#7) (2c31bce)
  • deps: bump @libp2p/interface-stream-muxer from 2.0.2 to 3.0.0 (#9) (3235d5f)