From 637f2d2159a7cc6a3d5860d67307e464e4a30104 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 3 Feb 2023 22:52:21 -0500 Subject: [PATCH] chore: support yamux to wherever mplex is supported (#1578) --- .aegir.js | 4 +- doc/CONFIGURATION.md | 94 +++++++++++-------- doc/GETTING_STARTED.md | 8 +- examples/auto-relay/README.md | 8 +- examples/auto-relay/dialer.js | 4 +- examples/auto-relay/listener.js | 4 +- examples/auto-relay/relay.js | 6 +- examples/chat/src/libp2p.js | 6 +- examples/connection-encryption/1.js | 5 +- examples/connection-encryption/README.md | 3 +- .../delegated-routing/src/libp2p-bundle.js | 9 +- examples/discovery-mechanisms/1.js | 7 +- examples/discovery-mechanisms/2.js | 6 +- examples/discovery-mechanisms/3.js | 5 +- examples/discovery-mechanisms/README.md | 16 +++- examples/echo/src/libp2p.js | 6 +- examples/libp2p-in-the-browser/index.js | 3 +- examples/peer-and-content-routing/1.js | 5 +- examples/peer-and-content-routing/2.js | 5 +- examples/peer-and-content-routing/README.md | 3 +- examples/pnet/libp2p-node.js | 5 +- examples/protocol-and-stream-muxing/1.js | 5 +- examples/protocol-and-stream-muxing/2.js | 5 +- examples/protocol-and-stream-muxing/3.js | 5 +- examples/protocol-and-stream-muxing/README.md | 7 +- examples/pubsub/1.js | 3 +- examples/pubsub/README.md | 3 +- examples/pubsub/message-filtering/1.js | 13 ++- examples/pubsub/message-filtering/README.md | 3 +- examples/transports/2.js | 7 +- examples/transports/3.js | 3 +- examples/transports/4.js | 3 +- examples/transports/README.md | 5 +- examples/webrtc-direct/dialer.js | 3 +- examples/webrtc-direct/listener.js | 3 +- package.json | 2 +- src/circuit/README.md | 4 +- src/index.ts | 3 +- test/configuration/utils.ts | 3 +- test/dialing/direct.node.ts | 31 ++++-- test/dialing/direct.spec.ts | 25 +++-- test/fetch/fetch.node.ts | 4 +- test/registrar/registrar.spec.ts | 4 +- test/upgrading/upgrader.spec.ts | 41 +++++--- test/utils/base-options.browser.ts | 4 +- test/utils/base-options.ts | 4 +- 46 files changed, 263 insertions(+), 142 deletions(-) diff --git a/.aegir.js b/.aegir.js index 437b9f5ff3..2ea078b1c4 100644 --- a/.aegir.js +++ b/.aegir.js @@ -3,6 +3,7 @@ import { mplex } from '@libp2p/mplex' import { noise } from '@chainsafe/libp2p-noise' import { pipe } from 'it-pipe' import { createFromJSON } from '@libp2p/peer-id-factory' +import { yamux } from '@chainsafe/libp2p-yamux' /** @type {import('aegir').PartialOptions} */ export default { @@ -31,7 +32,8 @@ export default { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise(), diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index 78c09f84a7..4782fe1b8b 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -243,13 +243,14 @@ import { noise } from '@chainsafe/libp2p-noise' import { mdns } from '@libp2p/mdns' import { kadDHT } from '@libp2p/kad-dht' import { gossipsub } from 'libp2p-gossipsub' +import { yamux } from '@chainsafe/libp2p-yamux' const node = await createLibp2p({ transports: [ tcp(), webSockets() ], - streamMuxers: [mplex()], + streamMuxers: [mplex(),yamux()], connectionEncryption: [noise()], peerDiscovery: [MulticastDNS], dht: kadDHT(), @@ -263,13 +264,14 @@ const node = await createLibp2p({ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { mdns } from '@libp2p/mdns' import { bootstrap } from '@libp2p/bootstrap' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(),yamux()], connectionEncryption: [noise()], peerDiscovery: [ mdns({ @@ -299,6 +301,7 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { webRTCStar } from '@libp2p/webrtc-star' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const webRtc = webRTCStar() @@ -312,7 +315,8 @@ const node = await createLibp2p({ webRtc.discovery ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -326,6 +330,7 @@ const node = await createLibp2p({ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { gossipsub } from 'libp2p-gossipsub' import { SignaturePolicy } from '@libp2p/interface-pubsub' @@ -335,7 +340,8 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -380,6 +386,7 @@ const node = await createLibp2p({ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { create as ipfsHttpClient } from 'ipfs-http-client' import { DelegatedPeerRouting } from '@libp2p/delegated-peer-routing' @@ -402,7 +409,7 @@ const delegatedContentRouting = new DelegatedContentRouting(peerId, ipfsHttpClie const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], contentRouting: [ delegatedContentRouting @@ -427,11 +434,12 @@ const node = await createLibp2p({ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], relay: { // Circuit Relay options (this config is part of libp2p core configurations) enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay. @@ -454,11 +462,12 @@ const node = await createLibp2p({ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] relay: { // Circuit Relay options (this config is part of libp2p core configurations) enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay. @@ -474,15 +483,16 @@ const node = await createLibp2p({ Libp2p allows you to setup a secure keychain to manage your keys. The keychain configuration object should have the following properties: -| Name | Type | Description | -|------|------|-------------| -| pass | `string` | Passphrase to use in the keychain (minimum of 20 characters). | +| Name | Type | Description | +| --------- | -------- | -------------------------------------------------------------------------------------- | +| pass | `string` | Passphrase to use in the keychain (minimum of 20 characters). | | datastore | `object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) | ```js import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { LevelDatastore } from 'datastore-level' @@ -491,7 +501,7 @@ await datastore.open() const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], keychain: { pass: 'notsafepassword123456789', @@ -504,15 +514,15 @@ const node = await createLibp2p({ Dialing in libp2p can be configured to limit the rate of dialing, and how long dials are allowed to take. The dialer configuration object should have the following properties: -| Name | Type | Description | -|------|------|-------------| -| maxParallelDials | `number` | How many multiaddrs we can dial in parallel. | -| maxAddrsToDial | `number` | How many multiaddrs is the dial allowed to dial for a single peer. | -| maxDialsPerPeer | `number` | How many multiaddrs we can dial per peer, in parallel. | -| dialTimeout | `number` | Second dial timeout per peer in ms. | -| resolvers | `object` | Dial [Resolvers](https://github.com/multiformats/js-multiaddr/blob/master/src/resolvers/index.js) for resolving multiaddrs | -| addressSorter | `(Array
) => Array
` | Sort the known addresses of a peer before trying to dial. | -| startupReconnectTimeout | `number` | When a node is restarted, we try to connect to any peers marked with the `keep-alive` tag up until to this timeout in ms is reached (default: 60000) | +| Name | Type | Description | +| ----------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | +| maxParallelDials | `number` | How many multiaddrs we can dial in parallel. | +| maxAddrsToDial | `number` | How many multiaddrs is the dial allowed to dial for a single peer. | +| maxDialsPerPeer | `number` | How many multiaddrs we can dial per peer, in parallel. | +| dialTimeout | `number` | Second dial timeout per peer in ms. | +| resolvers | `object` | Dial [Resolvers](https://github.com/multiformats/js-multiaddr/blob/master/src/resolvers/index.js) for resolving multiaddrs | +| addressSorter | `(Array
) => Array
` | Sort the known addresses of a peer before trying to dial. | +| startupReconnectTimeout | `number` | When a node is restarted, we try to connect to any peers marked with the `keep-alive` tag up until to this timeout in ms is reached (default: 60000) | The below configuration example shows how the dialer should be configured, with the current defaults: @@ -520,6 +530,7 @@ The below configuration example shows how the dialer should be configured, with import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' @@ -527,7 +538,7 @@ import { publicAddressesFirst } from '@libp2p-utils/address-sort' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], dialer: { maxParallelDials: 100, @@ -549,11 +560,12 @@ The Connection Manager prunes Connections in libp2p whenever certain limits are import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], connectionManager: { maxConnections: Infinity, @@ -698,12 +710,13 @@ The Transport Manager is responsible for managing the libp2p transports life cyc import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { FaultTolerance } from '@libp2p/interface-transport' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], transportManager: { faultTolerance: FaultTolerance.NO_FATAL @@ -715,13 +728,13 @@ const node = await createLibp2p({ Metrics are disabled in libp2p by default. You can enable and configure them as follows: -| Name | Type | Description | -|------|------|-------------| -| enabled | `boolean` | Enabled metrics collection. | -| computeThrottleMaxQueueSize | `number` | How many messages a stat will queue before processing. | -| computeThrottleTimeout | `number` | Time in milliseconds a stat will wait, after the last item was added, before processing. | -| movingAverageIntervals | `Array` | The moving averages that will be computed. | -| maxOldPeersRetention | `number` | How many disconnected peers we will retain stats for. | +| Name | Type | Description | +| --------------------------- | --------------- | ---------------------------------------------------------------------------------------- | +| enabled | `boolean` | Enabled metrics collection. | +| computeThrottleMaxQueueSize | `number` | How many messages a stat will queue before processing. | +| computeThrottleTimeout | `number` | Time in milliseconds a stat will wait, after the last item was added, before processing. | +| movingAverageIntervals | `Array` | The moving averages that will be computed. | +| maxOldPeersRetention | `number` | How many disconnected peers we will retain stats for. | The below configuration example shows how the metrics should be configured. Aside from enabled being `false` by default, the following default configuration options are listed below: @@ -729,11 +742,12 @@ The below configuration example shows how the metrics should be configured. Asid import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const node = await createLibp2p({ transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] metrics: { enabled: true, @@ -755,10 +769,10 @@ PeerStore persistence is disabled in libp2p by default. You can enable and confi The threshold number represents the maximum number of "dirty peers" allowed in the PeerStore, i.e. peers that are not updated in the datastore. In this context, browser nodes should use a threshold of 1, since they might not "stop" properly in several scenarios and the PeerStore might end up with unflushed records when the window is closed. -| Name | Type | Description | -|------|------|-------------| -| persistence | `boolean` | Is persistence enabled. | -| threshold | `number` | Number of dirty peers allowed. | +| Name | Type | Description | +| ----------- | --------- | ------------------------------ | +| persistence | `boolean` | Is persistence enabled. | +| threshold | `number` | Number of dirty peers allowed. | The below configuration example shows how the PeerStore should be configured. Aside from persistence being `false` by default, the following default configuration options are listed below: @@ -766,6 +780,7 @@ The below configuration example shows how the PeerStore should be configured. As import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { LevelDatastore } from 'datastore-level' @@ -775,7 +790,7 @@ await datastore.open() // level database must be ready before node boot const node = await createLibp2p({ datastore, // pass the opened datastore transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], peerStore: { persistence: true, @@ -792,6 +807,7 @@ Some Transports can be passed additional options when they are created. For exam import { createLibp2p } from 'libp2p' import { webRTCStar } from '@libp2p/webrtc-star' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import wrtc from 'wrtc' @@ -807,7 +823,8 @@ const node = await createLibp2p({ webRTC.discovery ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -836,7 +853,8 @@ const node = await createLibp2p({ webRTC.discovery ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() diff --git a/doc/GETTING_STARTED.md b/doc/GETTING_STARTED.md index cf5986aaf7..1ecb75b614 100644 --- a/doc/GETTING_STARTED.md +++ b/doc/GETTING_STARTED.md @@ -109,11 +109,12 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux', const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) ``` @@ -143,7 +144,7 @@ const node = await createLibp2p({ }, transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) // start libp2p @@ -189,6 +190,7 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux', import { bootstrap } from '@libp2p/bootstrap' @@ -201,7 +203,7 @@ const bootstrapMultiaddrs = [ const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], peerDiscovery: [ bootstrap({ list: bootstrapMultiaddrs, // provide array of multiaddrs diff --git a/examples/auto-relay/README.md b/examples/auto-relay/README.md index da3100d5e8..505b139f8f 100644 --- a/examples/auto-relay/README.md +++ b/examples/auto-relay/README.md @@ -20,11 +20,12 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux', const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] // TODO check "What is next?" section @@ -81,7 +82,7 @@ if (!relayAddr) { const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], relay: { enabled: true, autoRelay: { @@ -135,6 +136,7 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux', const autoRelayNodeAddr = process.argv[2] if (!autoRelayNodeAddr) { @@ -144,7 +146,7 @@ if (!autoRelayNodeAddr) { const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) console.log(`Node started with id ${node.peerId.toString()}`) diff --git a/examples/auto-relay/dialer.js b/examples/auto-relay/dialer.js index 9f1a761769..85efdc4371 100644 --- a/examples/auto-relay/dialer.js +++ b/examples/auto-relay/dialer.js @@ -3,6 +3,7 @@ import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' import { multiaddr } from '@multiformats/multiaddr' +import { yamux } from '@chainsafe/libp2p-yamux/dist/src' async function main () { const autoRelayNodeAddr = process.argv[2] @@ -18,7 +19,8 @@ async function main () { noise() ], streamMuxers: [ - mplex() + mplex(), + yamux() ] }) diff --git a/examples/auto-relay/listener.js b/examples/auto-relay/listener.js index 1e2adbc5d2..d2a2bc8716 100644 --- a/examples/auto-relay/listener.js +++ b/examples/auto-relay/listener.js @@ -3,6 +3,7 @@ import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' import { multiaddr } from '@multiformats/multiaddr' +import { yamux } from '@chainsafe/libp2p-yamux/dist/src' async function main () { const relayAddr = process.argv[2] @@ -18,7 +19,8 @@ async function main () { noise() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], relay: { enabled: true, diff --git a/examples/auto-relay/relay.js b/examples/auto-relay/relay.js index 93205e73a6..f1e5d078c5 100644 --- a/examples/auto-relay/relay.js +++ b/examples/auto-relay/relay.js @@ -2,6 +2,7 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' async function main () { const node = await createLibp2p({ @@ -17,7 +18,8 @@ async function main () { noise() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], relay: { enabled: true, @@ -25,7 +27,7 @@ async function main () { enabled: true }, advertise: { - enabled: true, + enabled: true } } }) diff --git a/examples/chat/src/libp2p.js b/examples/chat/src/libp2p.js index c7ba20148b..f730aa9f9e 100644 --- a/examples/chat/src/libp2p.js +++ b/examples/chat/src/libp2p.js @@ -1,18 +1,20 @@ import { tcp } from '@libp2p/tcp' import { webSockets } from '@libp2p/websockets' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import defaultsDeep from '@nodeutils/defaults-deep' import { createLibp2p as create } from 'libp2p' -export async function createLibp2p(_options) { +export async function createLibp2p (_options) { const defaults = { transports: [ tcp(), webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() diff --git a/examples/connection-encryption/1.js b/examples/connection-encryption/1.js index b662d88a4c..1d58a48e63 100644 --- a/examples/connection-encryption/1.js +++ b/examples/connection-encryption/1.js @@ -1,6 +1,7 @@ import { createLibp2p } from '../../dist/src/index.js' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { pipe } from 'it-pipe' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' @@ -12,7 +13,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] }) @@ -44,4 +45,4 @@ const createNode = async () => { [uint8ArrayFromString('This information is sent out encrypted to the other peer')], stream ) -})(); +})() diff --git a/examples/connection-encryption/README.md b/examples/connection-encryption/README.md index 02b04891e1..5af36a474b 100644 --- a/examples/connection-encryption/README.md +++ b/examples/connection-encryption/README.md @@ -16,12 +16,13 @@ To add them to your libp2p configuration, all you have to do is: import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux', import { noise } from '@chainsafe/libp2p-noise' const createNode = async () => { return await createLibp2p({ transports: [ tcp() ], - streamMuxers: [ mplex() ], + streamMuxers: [ mplex(, yamux() ], // Attach noise as the crypto channel to use conectionEncrypters: [ noise() ] }) diff --git a/examples/delegated-routing/src/libp2p-bundle.js b/examples/delegated-routing/src/libp2p-bundle.js index e7c6beab9c..2b5c364268 100644 --- a/examples/delegated-routing/src/libp2p-bundle.js +++ b/examples/delegated-routing/src/libp2p-bundle.js @@ -5,12 +5,13 @@ import { createLibp2p } from 'libp2p' import { webSockets } from '@libp2p/websockets' import { webRTCStar } from '@libp2p/webrtc-star' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { delegatedPeerRouting } from '@libp2p/delegated-peer-routing' import { delegatedContentRouting } from '@libp2p/delegated-content-routing' import { create as createIpfsHttpClient } from 'ipfs-http-client' -export default function Libp2pBundle ({peerInfo, peerBook}) { +export default function Libp2pBundle ({ peerInfo, peerBook }) { const wrtcstar = new webRTCStar() const client = createIpfsHttpClient({ host: '0.0.0.0', @@ -23,6 +24,7 @@ export default function Libp2pBundle ({peerInfo, peerBook}) { peerBook, // Lets limit the connection managers peers and have it check peer health less frequently connectionManager: { + autoDial: false, maxPeers: 10, pollInterval: 5000 }, @@ -37,7 +39,7 @@ export default function Libp2pBundle ({peerInfo, peerBook}) { webSockets() ], streamMuxers: [ - mplex() + mplex(), yamux() ], peerDiscovery: [ wrtcstar.discovery @@ -45,9 +47,6 @@ export default function Libp2pBundle ({peerInfo, peerBook}) { connectionEncryption: [ noise() ], - connectionManager: { - autoDial: false - }, relay: { enabled: true, hop: { diff --git a/examples/discovery-mechanisms/1.js b/examples/discovery-mechanisms/1.js index 00015dfd8d..fa4f387947 100644 --- a/examples/discovery-mechanisms/1.js +++ b/examples/discovery-mechanisms/1.js @@ -3,17 +3,18 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { bootstrap } from '@libp2p/bootstrap' import bootstrapers from './bootstrappers.js' -;(async () => { +(async () => { const node = await createLibp2p({ addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], peerDiscovery: [ bootstrap({ @@ -33,4 +34,4 @@ import bootstrapers from './bootstrappers.js' // No need to dial, autoDial is on console.log('Discovered:', peer.id.toString()) }) -})(); +})() diff --git a/examples/discovery-mechanisms/2.js b/examples/discovery-mechanisms/2.js index 81f162d8ac..b4edb905c2 100644 --- a/examples/discovery-mechanisms/2.js +++ b/examples/discovery-mechanisms/2.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { mdns } from '@libp2p/mdns' @@ -15,7 +16,8 @@ const createNode = async () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -38,4 +40,4 @@ const createNode = async () => { node1.addEventListener('peer:discovery', (evt) => console.log('Discovered:', evt.detail.id.toString())) node2.addEventListener('peer:discovery', (evt) => console.log('Discovered:', evt.detail.id.toString())) -})(); +})() diff --git a/examples/discovery-mechanisms/3.js b/examples/discovery-mechanisms/3.js index edee24de80..90242ce8f8 100644 --- a/examples/discovery-mechanisms/3.js +++ b/examples/discovery-mechanisms/3.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { floodsub } from '@libp2p/floodsub' import { bootstrap } from '@libp2p/bootstrap' @@ -14,7 +15,7 @@ const createNode = async (bootstrappers) => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], pubsub: floodsub(), peerDiscovery: [ @@ -38,7 +39,7 @@ const createNode = async (bootstrappers) => { ] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], pubsub: floodsub(), peerDiscovery: [ diff --git a/examples/discovery-mechanisms/README.md b/examples/discovery-mechanisms/README.md index eead89fca3..ad29ffdd1f 100644 --- a/examples/discovery-mechanisms/README.md +++ b/examples/discovery-mechanisms/README.md @@ -17,6 +17,7 @@ import { createLibp2p } from 'libp2p' import { bootstrap } from '@libp2p/bootstrap' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const node = await createLibp2p({ @@ -24,7 +25,8 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -63,7 +65,8 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -117,6 +120,7 @@ import { createLibp2p } from 'libp2p' import { mdns } from '@libp2p/mdns' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const createNode = () => { @@ -128,7 +132,8 @@ const createNode = () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -188,7 +193,8 @@ const createNode = async (bootstrapers) => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() @@ -219,7 +225,7 @@ const relay = await createLibp2p({ ] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], pubsub: gossipsub({ allowPublishToZeroPeers: true }), peerDiscovery: [ diff --git a/examples/echo/src/libp2p.js b/examples/echo/src/libp2p.js index 628e0b96f3..3b2032beec 100644 --- a/examples/echo/src/libp2p.js +++ b/examples/echo/src/libp2p.js @@ -1,18 +1,20 @@ import { tcp } from '@libp2p/tcp' import { webSockets } from '@libp2p/websockets' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import defaultsDeep from '@nodeutils/defaults-deep' import { createLibp2p as createNode } from 'libp2p' -export async function createLibp2p(_options) { +export async function createLibp2p (_options) { const defaults = { transports: [ tcp(), webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() diff --git a/examples/libp2p-in-the-browser/index.js b/examples/libp2p-in-the-browser/index.js index 82551fd20f..b0ac3afa9e 100644 --- a/examples/libp2p-in-the-browser/index.js +++ b/examples/libp2p-in-the-browser/index.js @@ -3,6 +3,7 @@ import { webSockets } from '@libp2p/websockets' import { webRTCStar } from '@libp2p/webrtc-star' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { bootstrap } from '@libp2p/bootstrap' document.addEventListener('DOMContentLoaded', async () => { @@ -24,7 +25,7 @@ document.addEventListener('DOMContentLoaded', async () => { wrtcStar.transport ], connectionEncryption: [noise()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], peerDiscovery: [ wrtcStar.discovery, bootstrap({ diff --git a/examples/peer-and-content-routing/1.js b/examples/peer-and-content-routing/1.js index 22f477d344..453ca00eac 100644 --- a/examples/peer-and-content-routing/1.js +++ b/examples/peer-and-content-routing/1.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { kadDHT } from '@libp2p/kad-dht' import delay from 'delay' @@ -13,7 +14,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], dht: kadDHT() }) @@ -43,4 +44,4 @@ const createNode = async () => { console.log('Found it, multiaddrs are:') peer.multiaddrs.forEach((ma) => console.log(ma.toString())) -})(); +})() diff --git a/examples/peer-and-content-routing/2.js b/examples/peer-and-content-routing/2.js index a4ff651dbb..0610cd91bb 100644 --- a/examples/peer-and-content-routing/2.js +++ b/examples/peer-and-content-routing/2.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { CID } from 'multiformats/cid' import { kadDHT } from '@libp2p/kad-dht' @@ -15,7 +16,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], dht: kadDHT() }) @@ -52,4 +53,4 @@ const createNode = async () => { const providers = await all(node3.contentRouting.findProviders(cid, { timeout: 3000 })) console.log('Found provider:', providers[0].id.toString()) -})(); +})() diff --git a/examples/peer-and-content-routing/README.md b/examples/peer-and-content-routing/README.md index 7d3351d885..d54b3dd0fd 100644 --- a/examples/peer-and-content-routing/README.md +++ b/examples/peer-and-content-routing/README.md @@ -17,6 +17,7 @@ import { createLibp2p } from 'libp2p' import { kadDHT } from '@libp2p/kad-dht' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const createNode = async () => { @@ -25,7 +26,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], dht: kadDHT() }) diff --git a/examples/pnet/libp2p-node.js b/examples/pnet/libp2p-node.js index 1a19bf701e..0caac84b74 100644 --- a/examples/pnet/libp2p-node.js +++ b/examples/pnet/libp2p-node.js @@ -1,12 +1,15 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { preSharedKey } from 'libp2p/pnet' /** * privateLibp2pNode returns a libp2p node function that will use the swarm * key with the given `swarmKey` to create the Protector + * + * @param swarmKey */ export async function privateLibp2pNode (swarmKey) { const node = await createLibp2p({ @@ -14,7 +17,7 @@ export async function privateLibp2pNode (swarmKey) { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], // We're only using the TCP transport for this example - streamMuxers: [mplex()], // We're only using mplex muxing + streamMuxers: [mplex(), yamux()], // We're only using mplex muxing // Let's make sure to use identifying crypto in our pnet since the protector doesn't // care about node identity, and only the presence of private keys connectionEncryption: [noise()], diff --git a/examples/protocol-and-stream-muxing/1.js b/examples/protocol-and-stream-muxing/1.js index d43a0e1869..bcd09df844 100644 --- a/examples/protocol-and-stream-muxing/1.js +++ b/examples/protocol-and-stream-muxing/1.js @@ -1,6 +1,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { pipe } from 'it-pipe' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -12,7 +13,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] }) @@ -72,4 +73,4 @@ const createNode = async () => { stream ) */ -})(); +})() diff --git a/examples/protocol-and-stream-muxing/2.js b/examples/protocol-and-stream-muxing/2.js index a9c93b0fb4..1752b71182 100644 --- a/examples/protocol-and-stream-muxing/2.js +++ b/examples/protocol-and-stream-muxing/2.js @@ -1,6 +1,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { pipe } from 'it-pipe' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -12,7 +13,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] }) @@ -59,4 +60,4 @@ const createNode = async () => { [uint8ArrayFromString('another stream on protocol (b)')], stream3 ) -})(); +})() diff --git a/examples/protocol-and-stream-muxing/3.js b/examples/protocol-and-stream-muxing/3.js index 438ff7a406..d9b8ee23ad 100644 --- a/examples/protocol-and-stream-muxing/3.js +++ b/examples/protocol-and-stream-muxing/3.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { pipe } from 'it-pipe' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -14,7 +15,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] }) @@ -63,4 +64,4 @@ const createNode = async () => { [uint8ArrayFromString('from 2 to 1')], stream2 ) -})(); +})() diff --git a/examples/protocol-and-stream-muxing/README.md b/examples/protocol-and-stream-muxing/README.md index 0060690c5b..0072c01e9e 100644 --- a/examples/protocol-and-stream-muxing/README.md +++ b/examples/protocol-and-stream-muxing/README.md @@ -109,6 +109,8 @@ Currently, we have [libp2p-mplex](https://github.com/libp2p/js-libp2p-mplex) and import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' + //... createLibp2p({ @@ -117,7 +119,8 @@ createLibp2p({ tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ] }) @@ -181,7 +184,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], }) diff --git a/examples/pubsub/1.js b/examples/pubsub/1.js index 9cb49fcb0b..d449a663e1 100644 --- a/examples/pubsub/1.js +++ b/examples/pubsub/1.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { floodsub } from '@libp2p/floodsub' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -14,7 +15,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], pubsub: floodsub() }) diff --git a/examples/pubsub/README.md b/examples/pubsub/README.md index e3ea9bb86d..a5dc37287e 100644 --- a/examples/pubsub/README.md +++ b/examples/pubsub/README.md @@ -25,6 +25,7 @@ import { createLibp2p } from 'libp2p' import { GossipSub } from '@chainsafe/libp2p-gossipsub' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const createNode = async () => { @@ -33,7 +34,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], // we add the Pubsub module we want pubsub: gossipsub({ allowPublishToZeroPeers: true }) diff --git a/examples/pubsub/message-filtering/1.js b/examples/pubsub/message-filtering/1.js index c0e1540847..1e9d734786 100644 --- a/examples/pubsub/message-filtering/1.js +++ b/examples/pubsub/message-filtering/1.js @@ -3,6 +3,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { floodsub } from '@libp2p/floodsub' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -14,7 +15,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], pubsub: floodsub() }) @@ -28,7 +29,7 @@ const createNode = async () => { const [node1, node2, node3] = await Promise.all([ createNode(), createNode(), - createNode(), + createNode() ]) // node1 conect to node2 and node2 conect to node3 @@ -38,7 +39,7 @@ const createNode = async () => { await node2.peerStore.addressBook.set(node3.peerId, node3.getMultiaddrs()) await node2.dial(node3.peerId) - //subscribe + // subscribe node1.pubsub.addEventListener('message', (evt) => { if (evt.detail.topic !== topic) { return @@ -81,7 +82,7 @@ const createNode = async () => { } } - //validate fruit + // validate fruit node1.pubsub.topicValidators.set(topic, validateFruit) node2.pubsub.topicValidators.set(topic, validateFruit) node3.pubsub.topicValidators.set(topic, validateFruit) @@ -103,6 +104,10 @@ async function delay (ms) { /** * Wait for node1 to see that node2 has subscribed to the topic + * + * @param node1 + * @param node2 + * @param topic */ async function hasSubscription (node1, node2, topic) { while (true) { diff --git a/examples/pubsub/message-filtering/README.md b/examples/pubsub/message-filtering/README.md index 4fa61e273a..9bc217805f 100644 --- a/examples/pubsub/message-filtering/README.md +++ b/examples/pubsub/message-filtering/README.md @@ -11,6 +11,7 @@ import { createLibp2p } from 'libp2p' import { GossipSub } from '@chainsafe/libp2p-gossipsub' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const createNode = async () => { @@ -19,7 +20,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], // we add the Pubsub module we want pubsub: gossipsub({ allowPublishToZeroPeers: true }) diff --git a/examples/transports/2.js b/examples/transports/2.js index a23931d18d..180a7dd1e7 100644 --- a/examples/transports/2.js +++ b/examples/transports/2.js @@ -4,6 +4,7 @@ import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { pipe } from 'it-pipe' @@ -18,7 +19,7 @@ const createNode = async () => { }, transports: [tcp()], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) return node @@ -29,7 +30,7 @@ function printAddrs (node, number) { node.getMultiaddrs().forEach((ma) => console.log(ma.toString())) } -;(async () => { +(async () => { const [node1, node2] = await Promise.all([ createNode(), createNode() @@ -58,4 +59,4 @@ function printAddrs (node, number) { ['Hello', ' ', 'p2p', ' ', 'world', '!'].map(str => uint8ArrayFromString(str)), stream ) -})(); +})() diff --git a/examples/transports/3.js b/examples/transports/3.js index 400a5e5621..8748181afe 100644 --- a/examples/transports/3.js +++ b/examples/transports/3.js @@ -5,6 +5,7 @@ import { tcp } from '@libp2p/tcp' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { pipe } from 'it-pipe' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -20,7 +21,7 @@ const createNode = async (transports, addresses = []) => { }, transports: transports, connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) return node diff --git a/examples/transports/4.js b/examples/transports/4.js index 07496f70be..06bc5931c7 100644 --- a/examples/transports/4.js +++ b/examples/transports/4.js @@ -5,6 +5,7 @@ import { tcp } from '@libp2p/tcp' import { webSockets } from '@libp2p/websockets' import { noise } from '@chainsafe/libp2p-noise' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import fs from 'fs' import https from 'https' import { pipe } from 'it-pipe' @@ -35,7 +36,7 @@ const createNode = async (addresses = []) => { }) ], connectionEncryption: [noise()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionManager: { // Disable autoDial as it would fail because we are using a self-signed cert. // `dialProtocol` does not fail because we pass `rejectUnauthorized: false`. diff --git a/examples/transports/README.md b/examples/transports/README.md index 4ee963e950..b3c3809a7b 100644 --- a/examples/transports/README.md +++ b/examples/transports/README.md @@ -87,6 +87,7 @@ And we also need to import the modules on our .js file: ```js import { pipe } from 'it-pipe' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import all from 'it-all' ``` @@ -101,7 +102,7 @@ const createNode = async () => { }, transports: [tcp()], connectionEncryption: [noise()], - streamMuxers: [mplex()] // <--- Add this line + streamMuxers: [mplex(), yamux()] // <--- Add this line }) return node @@ -189,7 +190,7 @@ const createNode = async (transports, addresses = []) => { }, transports: transports, connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) return node diff --git a/examples/webrtc-direct/dialer.js b/examples/webrtc-direct/dialer.js index 9c50a23b45..7d365390a1 100644 --- a/examples/webrtc-direct/dialer.js +++ b/examples/webrtc-direct/dialer.js @@ -1,6 +1,7 @@ import { createLibp2p } from 'libp2p' import { webRTCDirect } from '@libp2p/webrtc-direct' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { bootstrap } from '@libp2p/bootstrap' @@ -9,7 +10,7 @@ document.addEventListener('DOMContentLoaded', async () => { const hardcodedPeerId = '12D3KooWCuo3MdXfMgaqpLC5Houi1TRoFqgK9aoxok4NK5udMu8m' const libp2p = await createLibp2p({ transports: [webRTCDirect()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()], peerDiscovery: [ bootstrap({ diff --git a/examples/webrtc-direct/listener.js b/examples/webrtc-direct/listener.js index 014ea0f96b..611d96fdd6 100644 --- a/examples/webrtc-direct/listener.js +++ b/examples/webrtc-direct/listener.js @@ -1,6 +1,7 @@ import { createLibp2p } from 'libp2p' import { webRTCDirect } from '@libp2p/webrtc-direct' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { createFromJSON } from '@libp2p/peer-id-factory' import wrtc from 'wrtc' @@ -19,7 +20,7 @@ import wrtc from 'wrtc' listen: ['/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct'] }, transports: [webRTCDirect({ wrtc })], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [noise()] }) diff --git a/package.json b/package.json index 8f340b2262..e7f36e0cb8 100644 --- a/package.json +++ b/package.json @@ -165,7 +165,7 @@ }, "devDependencies": { "@chainsafe/libp2p-noise": "^11.0.0", - "@chainsafe/libp2p-yamux": "^3.0.3", + "@chainsafe/libp2p-yamux": "^3.0.5", "@libp2p/bootstrap": "^6.0.0", "@libp2p/daemon-client": "^4.0.1", "@libp2p/daemon-server": "^4.0.1", diff --git a/src/circuit/README.md b/src/circuit/README.md index 712640e3c3..d126c4e2d1 100644 --- a/src/circuit/README.md +++ b/src/circuit/README.md @@ -41,6 +41,7 @@ import { multiaddr } from '@multiformats/multiaddr' import Libp2p from 'libp2p' import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' const relayAddr = ... @@ -53,7 +54,8 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ noise() diff --git a/src/index.ts b/src/index.ts index cd0ee8992a..69d50f834a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -185,11 +185,12 @@ export type Libp2pOptions = RecursivePartial & { start?: boolean } * import { tcp } from '@libp2p/tcp' * import { mplex } from '@libp2p/mplex' * import { noise } from '@chainsafe/libp2p-noise' + * import { yamux } from '@chainsafe/libp2p-yamux' * * // specify options * const options = { * transports: [tcp()], - * streamMuxers: [mplex()], + * streamMuxers: [mplex(), yamux()], * connectionEncryption: [noise()] * } * diff --git a/test/configuration/utils.ts b/test/configuration/utils.ts index d1983f9a26..141f4c9a30 100644 --- a/test/configuration/utils.ts +++ b/test/configuration/utils.ts @@ -9,12 +9,13 @@ import type { Message, PublishResult, PubSubInit, PubSubRPC, PubSubRPCMessage } import type { Libp2pInit, Libp2pOptions } from '../../src/index.js' import type { PeerId } from '@libp2p/interface-peer-id' import * as cborg from 'cborg' +import { yamux } from '@chainsafe/libp2p-yamux' const relayAddr = MULTIADDRS_WEBSOCKETS[0] export const baseOptions: Partial = { transports: [webSockets()], - streamMuxers: [mplex()], + streamMuxers: [mplex(), yamux()], connectionEncryption: [plaintext()] } diff --git a/test/dialing/direct.node.ts b/test/dialing/direct.node.ts index 86ff236db8..23c3791764 100644 --- a/test/dialing/direct.node.ts +++ b/test/dialing/direct.node.ts @@ -36,6 +36,7 @@ import os from 'node:os' import path from 'node:path' import fs from 'node:fs' import { peerIdFromString } from '@libp2p/peer-id' +import { yamux } from '@chainsafe/libp2p-yamux' const swarmKeyBuffer = uint8ArrayFromString(swarmKey) const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0') @@ -254,7 +255,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -287,7 +289,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -314,7 +317,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -343,7 +347,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -407,7 +412,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -456,7 +462,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -494,7 +501,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -531,7 +539,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -592,7 +601,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -609,7 +619,8 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/dialing/direct.spec.ts b/test/dialing/direct.spec.ts index 1084db1270..5eb979bcaf 100644 --- a/test/dialing/direct.spec.ts +++ b/test/dialing/direct.spec.ts @@ -31,6 +31,7 @@ import { MULTIADDRS_WEBSOCKETS } from '../fixtures/browser.js' import type { PeerId } from '@libp2p/interface-peer-id' import { pEvent } from 'p-event' import { DefaultComponents } from '../../src/components.js' +import { yamux } from '@chainsafe/libp2p-yamux' const unsupportedAddr = multiaddr('/ip4/127.0.0.1/tcp/9999') @@ -407,7 +408,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -461,7 +463,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -494,7 +497,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -534,7 +538,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -562,7 +567,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -583,7 +589,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -625,7 +632,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -651,7 +659,8 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/fetch/fetch.node.ts b/test/fetch/fetch.node.ts index 574e581ae1..be81badf11 100644 --- a/test/fetch/fetch.node.ts +++ b/test/fetch/fetch.node.ts @@ -8,6 +8,7 @@ import { plaintext } from '../../src/insecure/index.js' import { createPeerId } from '../utils/creators/peer.js' import { codes } from '../../src/errors.js' import type { PeerId } from '@libp2p/interface-peer-id' +import { yamux } from '@chainsafe/libp2p-yamux' async function createNode (peerId: PeerId) { return await createLibp2pNode({ @@ -21,7 +22,8 @@ async function createNode (peerId: PeerId) { tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/registrar/registrar.spec.ts b/test/registrar/registrar.spec.ts index d9fac96a4f..1578f191a2 100644 --- a/test/registrar/registrar.spec.ts +++ b/test/registrar/registrar.spec.ts @@ -21,6 +21,7 @@ import { webSockets } from '@libp2p/websockets' import { mplex } from '@libp2p/mplex' import type { PeerProtocolsChangeData } from '@libp2p/interface-peer-store' import { DefaultComponents } from '../../src/components.js' +import { yamux } from '@chainsafe/libp2p-yamux' const protocol = '/test/1.0.0' @@ -215,7 +216,8 @@ describe('registrar', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/upgrading/upgrader.spec.ts b/test/upgrading/upgrader.spec.ts index c2c813aea2..91a8486c92 100644 --- a/test/upgrading/upgrader.spec.ts +++ b/test/upgrading/upgrader.spec.ts @@ -33,6 +33,7 @@ import { PersistentPeerStore } from '@libp2p/peer-store' import { MemoryDatastore } from 'datastore-core' import { DefaultComponents } from '../../src/components.js' import { StubbedInstance, stubInterface } from 'sinon-ts' +import { yamux } from '@chainsafe/libp2p-yamux' const addrs = [ multiaddr('/ip4/127.0.0.1/tcp/0'), @@ -42,10 +43,12 @@ const addrs = [ describe('Upgrader', () => { let localUpgrader: Upgrader let localMuxerFactory: StreamMuxerFactory + let localYamuxerFactory: StreamMuxerFactory let localConnectionEncrypter: ConnectionEncrypter let localConnectionProtector: StubbedInstance let remoteUpgrader: Upgrader let remoteMuxerFactory: StreamMuxerFactory + let remotreYamuxerFactory: StreamMuxerFactory let remoteConnectionEncrypter: ConnectionEncrypter let remoteConnectionProtector: StubbedInstance let localPeer: PeerId @@ -75,13 +78,15 @@ describe('Upgrader', () => { localComponents.peerStore = new PersistentPeerStore(localComponents) localComponents.connectionManager = mockConnectionManager(localComponents) localMuxerFactory = mplex()() + localYamuxerFactory = yamux()() localConnectionEncrypter = plaintext()() localUpgrader = new DefaultUpgrader(localComponents, { connectionEncryption: [ localConnectionEncrypter ], muxers: [ - localMuxerFactory + localMuxerFactory, + localYamuxerFactory ], inboundUpgradeTimeout: 1000 }) @@ -99,13 +104,15 @@ describe('Upgrader', () => { remoteComponents.peerStore = new PersistentPeerStore(remoteComponents) remoteComponents.connectionManager = mockConnectionManager(remoteComponents) remoteMuxerFactory = mplex()() + remotreYamuxerFactory = yamux()() remoteConnectionEncrypter = plaintext()() remoteUpgrader = new DefaultUpgrader(remoteComponents, { connectionEncryption: [ remoteConnectionEncrypter ], muxers: [ - remoteMuxerFactory + remoteMuxerFactory, + remotreYamuxerFactory ], inboundUpgradeTimeout: 1000 }) @@ -305,7 +312,8 @@ describe('Upgrader', () => { plaintext()() ], muxers: [ - mplex()() + mplex()(), + yamux()() ], inboundUpgradeTimeout: 1000 }) @@ -565,7 +573,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -587,7 +596,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -603,7 +613,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -634,7 +645,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -648,7 +660,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -693,7 +706,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -707,7 +721,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -755,7 +770,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() @@ -769,7 +785,8 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/utils/base-options.browser.ts b/test/utils/base-options.browser.ts index 882d1ab1f7..ae5b5d9273 100644 --- a/test/utils/base-options.browser.ts +++ b/test/utils/base-options.browser.ts @@ -5,6 +5,7 @@ import { mplex } from '@libp2p/mplex' import { plaintext } from '../../src/insecure/index.js' import type { Libp2pOptions } from '../../src' import mergeOptions from 'merge-options' +import { yamux } from '@chainsafe/libp2p-yamux' export function createBaseOptions (overrides?: Libp2pOptions): Libp2pOptions { const options: Libp2pOptions = { @@ -14,7 +15,8 @@ export function createBaseOptions (overrides?: Libp2pOptions): Libp2pOptions { }) ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/utils/base-options.ts b/test/utils/base-options.ts index 41c91405f1..737d021e48 100644 --- a/test/utils/base-options.ts +++ b/test/utils/base-options.ts @@ -3,6 +3,7 @@ import { mplex } from '@libp2p/mplex' import { plaintext } from '../../src/insecure/index.js' import type { Libp2pOptions } from '../../src' import mergeOptions from 'merge-options' +import { yamux } from '@chainsafe/libp2p-yamux' export function createBaseOptions (...overrides: Libp2pOptions[]): Libp2pOptions { const options: Libp2pOptions = { @@ -10,7 +11,8 @@ export function createBaseOptions (...overrides: Libp2pOptions[]): Libp2pOptions tcp() ], streamMuxers: [ - mplex() + mplex(), + yamux() ], connectionEncryption: [ plaintext()