7.0.1 • Published 1 year ago

@chainsafe/libp2p-yamux v7.0.1

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
1 year ago

@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.

@infinitebrahmanuniverse/nolb-_chai@everything-registry/sub-chunk-164electron-forge-react-typescript-boilerplatewalletdropstarpcthld-explorer-componentsipfs-nodejs-cmnctrajs-cmnctrjs-ds-crdtipdwhelialibp2p_kit_jslibp2p-ts@windingtree/sdk-server@windingtree/sdk@windingtree/sdk-client@windingtree/sdk-node@turbo-ing/edge-v0@ts-drp/network@topology-foundation/networkchaintalk-utilsdaguladecontactdebeem-utilsdebeem-libdebeem-p2p-relaydenetwork-libdenetwork-utilsrivalz-client-node-librivalz-client-nodejs-chaintalk-utilschaintalk-libchaintalk-relaydenetwork-relaywebpeerjszkdatabasemoonbase-jsp4podulpeerbitpipe-protocolplugin-payairivalz-node-clientrivalz-client-lib@fluencelabs/js-client@helia/cli-utils@futureverse/sylo-protocol-sdk@krypton-js/sdk@libp2p/amino-dht-bootstrapper@libp2p/protocol-adventure@libp2p/multidim-interop@le-space/voyager@nhtio/p2pbus@olptools/node@peerbit/react@peer-ai/peer-ai@othentic/othentic-cli@othentic/othentic-cli-sepolia@abaxx/sdk@aldea/mocknet@bitxenia/astradb@blockless/browser-node@carmel/node@autismjs/protocol@aztec/p2p@badaimweeb/js-protov2@canvas-js/gossiplog@sinugrepo/rivalz-mod-cli@questflow/deworker-cli@djack-sdk/signal@djack-sdk/network@rosen-bridge/rosenet-node@rosen-bridge/rosenet-relay@constl/ipa@dao-xyz/app-sdk@debros/network@riffcc/constl-ipa-fork@deworker/deworker-cli@saonetwork/sao-client-js@dwn-protocol/dwn@dwn-protocol/id-sdk@drtc/bootstrap@drtc/bootstrap-node@drtc/create@drtc/relay@drtc/relay-node@drtc/tests@sfroment/network@nabladelta/lambdadelta@fatduckai/ai
7.0.2-rc.0

1 year ago

7.0.1

1 year ago

7.0.0

1 year ago

6.0.2

2 years ago

5.0.4

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.1

3 years ago

4.0.2

3 years ago

3.0.10

3 years ago

3.0.8

3 years ago

4.0.0

3 years ago

3.0.9

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.4

3 years ago

3.0.5

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.0

3 years ago