diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 015bb9122d..d265878deb 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -19,38 +19,38 @@ jobs: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - test-examples: - name: Test example ${{ matrix.example.name }} - runs-on: ubuntu-latest - needs: build - continue-on-error: true - strategy: - matrix: - example: - - name: js-libp2p-example-chat - repo: https://github.com/libp2p/js-libp2p-example-chat.git - deps: - - '@libp2p/peer-id-factory@$PWD/packages/peer-id-factory' - - '@libp2p/tcp@$PWD/packages/transport-tcp' - - '@libp2p/websockets@$PWD/packages/transport-websockets' - - 'libp2p@$PWD/packages/libp2p' - # disabled until @libp2p/identify and @libp2p/circuit-relay are published - # - name: js-libp2p-example-circuit-relay - # repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git - # deps: - # - '@libp2p/circuit-relay@$PWD/packages/transport-circuit-relay' - # - '@libp2p/identify@$PWD/packages/protocol-identify' - # - '@libp2p/websockets@$PWD/packages/transport-websockets' - # - 'libp2p@$PWD/packages/libp2p' - - name: js-libp2p-example-connection-encryption - repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git - deps: - - '@libp2p/tcp@$PWD/packages/transport-tcp' - - 'libp2p@$PWD/packages/libp2p' - 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 aegir test-dependant ${{ matrix.example.repo }} --deps ${{ join(matrix.example.deps, ',') }} + # test-examples: + # name: Test example ${{ matrix.example.name }} + # runs-on: ubuntu-latest + # needs: build + # continue-on-error: true + # strategy: + # matrix: + # example: + # - name: js-libp2p-example-chat + # repo: https://github.com/libp2p/js-libp2p-example-chat.git + # deps: + # - '@libp2p/peer-id-factory@$PWD/packages/peer-id-factory' + # - '@libp2p/tcp@$PWD/packages/transport-tcp' + # - '@libp2p/websockets@$PWD/packages/transport-websockets' + # - 'libp2p@$PWD/packages/libp2p' + # # disabled until @libp2p/identify and @libp2p/circuit-relay are published + # # - name: js-libp2p-example-circuit-relay + # # repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git + # # deps: + # # - '@libp2p/circuit-relay@$PWD/packages/transport-circuit-relay' + # # - '@libp2p/identify@$PWD/packages/protocol-identify' + # # - '@libp2p/websockets@$PWD/packages/transport-websockets' + # # - 'libp2p@$PWD/packages/libp2p' + # - name: js-libp2p-example-connection-encryption + # repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git + # deps: + # - '@libp2p/tcp@$PWD/packages/transport-tcp' + # - 'libp2p@$PWD/packages/libp2p' + # 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 aegir test-dependant ${{ matrix.example.repo }} --deps ${{ join(matrix.example.deps, ',') }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 85418fe171..d0558d033e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,222 +9,221 @@ on: jobs: - build: - 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 - with: - directories: | - ./interop/dist - ./interop/node_modules + # build: + # 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 + # with: + # directories: | + # ./interop/dist + # ./interop/node_modules - check: - needs: build - 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 + # check: + # needs: build + # 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: build - 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-node: + # needs: build + # 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: build - 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: + # needs: build + # 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: build - 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-chrome-webworker: + # needs: build + # 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: build - 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: + # needs: build + # 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: build - 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-firefox-webworker: + # needs: build + # 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: build - 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 playwright install-deps - - run: npm run --if-present test:webkit - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 - with: - flags: webkit - files: .coverage/*,packages/*/.coverage/* + # test-webkit: + # needs: build + # 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 playwright install-deps + # - run: npm run --if-present test:webkit + # - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + # with: + # flags: webkit + # files: .coverage/*,packages/*/.coverage/* - test-electron-main: - needs: build - 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-main: + # needs: build + # 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: build - 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/* + # test-electron-renderer: + # needs: build + # 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/* - test-interop: - needs: build - 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 test:interop -- --bail + # test-interop: + # needs: build + # 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 test:interop -- --bail - transport-interop: - needs: build - runs-on: ${{ fromJSON(github.repository == 'libp2p/js-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }} - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - with: - directories: | - ./interop/dist - ./interop/node_modules - - name: Build images - run: (cd interop && make -j 4) - - name: Save package-lock.json as artifact - uses: actions/upload-artifact@v2 - with: - name: package locks - path: | - package-lock.json - interop/package-lock.json - - uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master - with: - test-filter: js-libp2p-head - test-ignore: nim - extra-versions: ${{ github.workspace }}/interop/node-version.json ${{ github.workspace }}/interop/chromium-version.json ${{ github.workspace }}/interop/firefox-version.json - s3-cache-bucket: ${{ vars.S3_LIBP2P_BUILD_CACHE_BUCKET_NAME }} - s3-access-key-id: ${{ vars.S3_LIBP2P_BUILD_CACHE_AWS_ACCESS_KEY_ID }} - s3-secret-access-key: ${{ secrets.S3_LIBP2P_BUILD_CACHE_AWS_SECRET_ACCESS_KEY }} - worker-count: 16 + # transport-interop: + # needs: build + # runs-on: ${{ fromJSON(github.repository == 'libp2p/js-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }} + # steps: + # - uses: actions/checkout@v3 + # - uses: actions/setup-node@v3 + # with: + # node-version: lts/* + # - uses: ipfs/aegir/actions/cache-node-modules@master + # with: + # directories: | + # ./interop/dist + # ./interop/node_modules + # - name: Build images + # run: (cd interop && make -j 4) + # - name: Save package-lock.json as artifact + # uses: actions/upload-artifact@v2 + # with: + # name: package locks + # path: | + # package-lock.json + # interop/package-lock.json + # - uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master + # with: + # test-filter: js-libp2p-head + # test-ignore: nim + # extra-versions: ${{ github.workspace }}/interop/node-version.json ${{ github.workspace }}/interop/chromium-version.json ${{ github.workspace }}/interop/firefox-version.json + # s3-cache-bucket: ${{ vars.S3_LIBP2P_BUILD_CACHE_BUCKET_NAME }} + # s3-access-key-id: ${{ vars.S3_LIBP2P_BUILD_CACHE_AWS_ACCESS_KEY_ID }} + # s3-secret-access-key: ${{ secrets.S3_LIBP2P_BUILD_CACHE_AWS_SECRET_ACCESS_KEY }} + # worker-count: 16 release: if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest - needs: [ - test-node, - test-chrome, - test-chrome-webworker, - test-firefox, - test-firefox-webworker, - test-electron-main, - test-electron-renderer, - test-interop, - transport-interop - ] - # https://docs.npmjs.com/generating-provenance-statements + # needs: [ + # test-node, + # test-chrome, + # test-chrome-webworker, + # test-firefox, + # test-firefox-webworker, + # test-electron-main, + # test-electron-renderer, + # test-interop, + # transport-interop + # ] permissions: id-token: write contents: write pull-requests: write steps: - - uses: GoogleCloudPlatform/release-please-action@v2 + - uses: google-github-actions/release-please-action@v3 id: release with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.release-please.json b/.release-please.json index 6a23611c5e..97634acd93 100644 --- a/.release-please.json +++ b/.release-please.json @@ -1,6 +1,6 @@ { + "last-release-sha": "a7eb258e0ef2147671acba73d9febc2f882a484a", "plugins": ["node-workspace"], - "group-pull-request-title-pattern": "chore: release ${component}", "packages": { "interop": {}, "packages/connection-encrypter-plaintext": {}, diff --git a/packages/multistream-select/src/handle.ts b/packages/multistream-select/src/handle.ts index dc375f2cc8..2a21b2e174 100644 --- a/packages/multistream-select/src/handle.ts +++ b/packages/multistream-select/src/handle.ts @@ -55,7 +55,7 @@ import type { Duplex } from 'it-stream-types' */ export async function handle > (stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise> { protocols = Array.isArray(protocols) ? protocols : [protocols] - options.log.trace('handle: available protocols %s', protocols) + options?.log?.trace('handle: available protocols %s', protocols) const lp = lpStream(stream, { ...options, @@ -64,21 +64,21 @@ export async function handle > (stream: Str }) while (true) { - options?.log.trace('handle: reading incoming string') + options?.log?.trace('handle: reading incoming string') const protocol = await multistream.readString(lp, options) - options.log.trace('handle: read "%s"', protocol) + options?.log?.trace('handle: read "%s"', protocol) if (protocol === PROTOCOL_ID) { - options.log.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol) + options?.log?.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol) await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options) - options.log.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol) + options?.log?.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol) continue } if (protocols.includes(protocol)) { - options.log.trace('handle: respond with "%s" for "%s"', protocol, protocol) + options?.log?.trace('handle: respond with "%s" for "%s"', protocol, protocol) await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options) - options.log.trace('handle: responded with "%s" for "%s"', protocol, protocol) + options?.log?.trace('handle: responded with "%s" for "%s"', protocol, protocol) return { stream: lp.unwrap(), protocol } } @@ -90,14 +90,14 @@ export async function handle > (stream: Str uint8ArrayFromString('\n') ) - options.log.trace('handle: respond with "%s" for %s', protocols, protocol) + options?.log?.trace('handle: respond with "%s" for %s', protocols, protocol) await multistream.write(lp, protos, options) - options.log.trace('handle: responded with "%s" for %s', protocols, protocol) + options?.log?.trace('handle: responded with "%s" for %s', protocols, protocol) continue } - options.log('handle: respond with "na" for "%s"', protocol) + options?.log?.('handle: respond with "na" for "%s"', protocol) await multistream.write(lp, uint8ArrayFromString('na\n'), options) - options.log('handle: responded with "na" for "%s"', protocol) + options?.log?.('handle: responded with "na" for "%s"', protocol) } } diff --git a/packages/multistream-select/src/multistream.ts b/packages/multistream-select/src/multistream.ts index c1f9930015..9a00bfac0b 100644 --- a/packages/multistream-select/src/multistream.ts +++ b/packages/multistream-select/src/multistream.ts @@ -30,7 +30,7 @@ export async function read (reader: LengthPrefixedStream (stream: Stream, prot throw new Error('At least one protocol must be specified') } - options?.log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol) + options?.log?.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol) const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`) const p2 = uint8ArrayFromString(`${protocol}\n`) await multistream.writeAll(lp, [p1, p2], options) - options?.log.trace('select: reading multistream-select header') + options?.log?.trace('select: reading multistream-select header') let response = await multistream.readString(lp, options) - options?.log.trace('select: read "%s"', response) + options?.log?.trace('select: read "%s"', response) // Read the protocol response if we got the protocolId in return if (response === PROTOCOL_ID) { - options?.log.trace('select: reading protocol response') + options?.log?.trace('select: reading protocol response') response = await multistream.readString(lp, options) - options?.log.trace('select: read "%s"', response) + options?.log?.trace('select: read "%s"', response) } // We're done @@ -101,11 +101,11 @@ export async function select (stream: Stream, prot // We haven't gotten a valid ack, try the other protocols for (const protocol of protocols) { - options?.log.trace('select: write "%s"', protocol) + options?.log?.trace('select: write "%s"', protocol) await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options) - options?.log.trace('select: reading protocol response') + options?.log?.trace('select: reading protocol response') const response = await multistream.readString(lp, options) - options?.log.trace('select: read "%s" for "%s"', response, protocol) + options?.log?.trace('select: read "%s" for "%s"', response, protocol) if (response === protocol) { return { stream: lp.unwrap(), protocol } @@ -163,7 +163,7 @@ function optimisticSelect (stream: Stream, protoco if (!sentProtocol) { sendingProtocol = true - options?.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength) + options?.log?.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength) const protocolString = `${protocol}\n` @@ -176,7 +176,7 @@ function optimisticSelect (stream: Stream, protoco buf ).subarray() - options?.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength) + options?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength) sentProtocol = true sendingProtocol = false @@ -198,7 +198,7 @@ function optimisticSelect (stream: Stream, protoco async function negotiate (): Promise { if (negotiating) { - options?.log.trace('optimistic: already negotiating %s stream', protocol) + options?.log?.trace('optimistic: already negotiating %s stream', protocol) await doneNegotiating.promise return } @@ -208,13 +208,13 @@ function optimisticSelect (stream: Stream, protoco try { // we haven't sent the protocol yet, send it now if (!sentProtocol) { - options?.log.trace('optimistic: doing send protocol for %s stream', protocol) + options?.log?.trace('optimistic: doing send protocol for %s stream', protocol) await doSendProtocol() } // if we haven't read the protocol response yet, do it now if (!readProtocol) { - options?.log.trace('optimistic: doing read protocol for %s stream', protocol) + options?.log?.trace('optimistic: doing read protocol for %s stream', protocol) await doReadProtocol() } } finally { @@ -233,12 +233,12 @@ function optimisticSelect (stream: Stream, protoco sendingProtocol = true try { - options?.log.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol) + options?.log?.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol) await lp.writeV([ uint8ArrayFromString(`${PROTOCOL_ID}\n`), uint8ArrayFromString(`${protocol}\n`) ]) - options?.log.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol) + options?.log?.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol) } finally { sentProtocol = true sendingProtocol = false @@ -255,15 +255,15 @@ function optimisticSelect (stream: Stream, protoco readingProtocol = true try { - options?.log.trace('optimistic: reading multistream select header') + options?.log?.trace('optimistic: reading multistream select header') let response = await multistream.readString(lp, options) - options?.log.trace('optimistic: read multistream select header "%s"', response) + options?.log?.trace('optimistic: read multistream select header "%s"', response) if (response === PROTOCOL_ID) { response = await multistream.readString(lp, options) } - options?.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol) + options?.log?.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol) if (response !== protocol) { throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL') @@ -279,7 +279,7 @@ function optimisticSelect (stream: Stream, protoco // make sure we've done protocol negotiation before we read stream data await negotiate() - options?.log.trace('optimistic: reading data from "%s" stream', protocol) + options?.log?.trace('optimistic: reading data from "%s" stream', protocol) yield * lp.unwrap().source })() @@ -291,7 +291,7 @@ function optimisticSelect (stream: Stream, protoco // this before closing the readable end of the stream if (!negotiated) { await negotiate().catch(err => { - options?.log.error('could not negotiate protocol before close read', err) + options?.log?.error('could not negotiate protocol before close read', err) }) } @@ -308,7 +308,7 @@ function optimisticSelect (stream: Stream, protoco // this before closing the writable end of the stream if (!negotiated) { await negotiate().catch(err => { - options?.log.error('could not negotiate protocol before close write', err) + options?.log?.error('could not negotiate protocol before close write', err) }) }