From 9a2559af390875d575b58de2943c4064b903d9b3 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 7 Feb 2024 16:57:13 +0100 Subject: [PATCH 1/2] chore: update aegir to 42.x.x Updates project config and fixes deps. --- .github/dependabot.yml | 2 +- .github/workflows/js-test-and-release.yml | 195 +--------------------- README.md | 77 +++++++++ package.json | 6 +- 4 files changed, 90 insertions(+), 190 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0bc3b42..d401a77 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,7 @@ updates: schedule: interval: daily time: "10:00" - open-pull-requests-limit: 10 + open-pull-requests-limit: 20 commit-message: prefix: "deps" prefix-development: "deps(dev)" diff --git a/.github/workflows/js-test-and-release.yml b/.github/workflows/js-test-and-release.yml index 1462739..359eb97 100644 --- a/.github/workflows/js-test-and-release.yml +++ b/.github/workflows/js-test-and-release.yml @@ -9,196 +9,19 @@ on: permissions: contents: write + id-token: write packages: write + pull-requests: write concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} cancel-in-progress: true jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present lint - - run: npm run --if-present dep-check - - run: npm run --if-present doc-check - - test-node: - needs: check - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - node: [lts/*] - fail-fast: true - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node }} - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:node - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: node - files: .coverage/*,packages/*/.coverage/* - - test-chrome: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:chrome - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: chrome - files: .coverage/*,packages/*/.coverage/* - - test-chrome-webworker: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:chrome-webworker - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: chrome-webworker - files: .coverage/*,packages/*/.coverage/* - - test-firefox: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:firefox - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: firefox - files: .coverage/*,packages/*/.coverage/* - - test-firefox-webworker: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:firefox-webworker - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: firefox-webworker - files: .coverage/*,packages/*/.coverage/* - - test-webkit: - needs: check - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - node: [lts/*] - fail-fast: true - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:webkit - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: webkit - files: .coverage/*,packages/*/.coverage/* - - test-webkit-webworker: - needs: check - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - node: [lts/*] - fail-fast: true - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npm run --if-present test:webkit-webworker - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: webkit-webworker - files: .coverage/*,packages/*/.coverage/* - - test-electron-main: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npx xvfb-maybe npm run --if-present test:electron-main - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: electron-main - files: .coverage/*,packages/*/.coverage/* - - test-electron-renderer: - needs: check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - run: npx xvfb-maybe npm run --if-present test:electron-renderer - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: electron-renderer - files: .coverage/*,packages/*/.coverage/* - - release: - needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-webkit, test-webkit-webworker, test-electron-main, test-electron-renderer] - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - permissions: - id-token: write - contents: write - pull-requests: write - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - - uses: ipfs/aegir/actions/docker-login@master - with: - docker-token: ${{ secrets.DOCKER_TOKEN }} - docker-username: ${{ secrets.DOCKER_USERNAME }} - - run: npm run --if-present release - env: - GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN || github.token }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + js-test-and-release: + uses: pl-strflt/uci/.github/workflows/js-test-and-release.yml@v0.0 + secrets: + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }} diff --git a/README.md b/README.md index 511f613..f836f1b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,83 @@ > Yamux stream multiplexer for libp2p +# About + +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). + +## Example - Configure libp2p with Yamux + +```typescript +import { createLibp2p } from 'libp2p' +import { yamux } from '@chainsafe/libp2p-yamux' + +const node = await createLibp2p({ + // ... other options + streamMuxers: [ + yamux() + ] +}) +``` + +## Example - Using the low-level API + +```js +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 ```console diff --git a/package.json b/package.json index 9de8003..8f712b2 100644 --- a/package.json +++ b/package.json @@ -176,8 +176,8 @@ "@libp2p/utils": "^5.0.0", "get-iterator": "^2.0.1", "it-foreach": "^2.0.3", - "it-pipe": "^3.0.1", "it-pushable": "^3.2.0", + "it-stream-types": "^2.0.1", "uint8arraylist": "^2.4.3" }, "devDependencies": { @@ -185,9 +185,9 @@ "@libp2p/interface-compliance-tests": "^5.0.0", "@libp2p/logger": "^4.0.0", "@libp2p/mplex": "^10.0.0", - "aegir": "^41.1.10", + "aegir": "^42.2.3", "it-drain": "^3.0.2", "it-pair": "^2.0.6", - "it-stream-types": "^2.0.1" + "it-pipe": "^3.0.1" } } From 2fd6a6cad37bfe6955d7ccc5654df806f514e566 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 8 Feb 2024 09:15:23 +0100 Subject: [PATCH 2/2] chore: fix deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3111ac7..a468da7 100644 --- a/package.json +++ b/package.json @@ -176,8 +176,8 @@ "@libp2p/utils": "^5.2.5", "get-iterator": "^2.0.1", "it-foreach": "^2.0.6", - "it-pipe": "^3.0.1", "it-pushable": "^3.2.3", + "it-stream-types": "^2.0.1", "uint8arraylist": "^2.4.8" }, "devDependencies": {