diff --git a/.aegir.js b/.aegir.js index 678bffee11..e006da5444 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 { @@ -36,6 +37,7 @@ export default { webSockets() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index f0a2daf302..35317593fc 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -245,13 +245,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: [yamux(), mplex()], connectionEncryption: [noise()], peerDiscovery: [MulticastDNS], services: { @@ -267,13 +268,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: [yamux(), mplex()], connectionEncryption: [noise()], peerDiscovery: [ mdns({ @@ -284,8 +286,7 @@ const node = await createLibp2p({ "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", - ], - interval: 2000 + ] ) ] }) @@ -298,6 +299,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() @@ -311,6 +313,7 @@ const node = await createLibp2p({ webRtc.discovery ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -325,6 +328,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' @@ -334,6 +338,7 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -363,6 +368,7 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -383,6 +389,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' @@ -404,23 +411,23 @@ const delegatedContentRouting = new DelegatedContentRouting(peerId, ipfsHttpClie })) const node = await createLibp2p({ - transports: [tcp()], - streamMuxers: [mplex()], - connectionEncryption: [noise()], + transports: [ + tcp() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], contentRouting: [ delegatedContentRouting ], peerRouting: [ delegatedPeerRouting ], - peerId, - peerRouting: { // Peer routing configuration - refreshManager: { // Refresh known and connected closest peers - enabled: true, // Should find the closest peers. - interval: 6e5, // Interval for getting the new for closest peers of 10min - bootDelay: 10e3 // Delay for the initial query for closest peers - } - } + peerId }) ``` @@ -430,6 +437,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 { circuitRelayTransport, circuitRelayServer } from 'libp2p/circuit-relay' @@ -441,8 +449,13 @@ const node = await createLibp2p({ reservationConcurrency: 1 // how many relays to attempt to reserve slots on at once }) ], - streamMuxers: [mplex()], - connectionEncryption: [noise()], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], connectionGater: { // used by the server - return true to deny a reservation to the remote peer denyInboundRelayReservation: (source: PeerId) => Promise @@ -481,6 +494,7 @@ In this configuration the libp2p node will search the network for one relay 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 { circuitRelayTransport } from 'libp2p/circuit-relay' @@ -491,8 +505,13 @@ const node = await createLibp2p({ discoverRelays: 1 }) ], - streamMuxers: [mplex()], - connectionEncryption: [noise()] + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ] }) ``` @@ -517,8 +536,13 @@ const node = await createLibp2p({ '/ip4/123.123.123.123/p2p/QmRelay/p2p-circuit' // a known relay node with reservation slots available ] }, - streamMuxers: [mplex()], - connectionEncryption: [noise()] + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ] }) ``` @@ -526,15 +550,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' @@ -542,9 +567,16 @@ const datastore = new LevelDatastore('path/to/store') await datastore.open() const node = await createLibp2p({ - transports: [tcp()], - streamMuxers: [mplex()], - connectionEncryption: [noise()], + transports: [ + tcp() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], keychain: { pass: 'notsafepassword123456789', datastore: dsInstant, @@ -563,12 +595,20 @@ See the [API docs](https://libp2p.github.io/js-libp2p/interfaces/index._internal 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()], - connectionEncryption: [noise()], + transports: [ + tcp() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], connectionManager: { maxConnections: Infinity, minConnections: 0 @@ -705,13 +745,21 @@ 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()], - connectionEncryption: [noise()], + transports: [ + tcp() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], transportManager: { faultTolerance: FaultTolerance.NO_FATAL } @@ -722,13 +770,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: @@ -736,12 +784,20 @@ 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()], - connectionEncryption: [noise()] + transports: [ + tcp() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], metrics: { enabled: true, computeThrottleMaxQueueSize: 1000, @@ -762,10 +818,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: @@ -773,6 +829,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' @@ -781,9 +838,16 @@ await datastore.open() // level database must be ready before node boot const node = await createLibp2p({ datastore, // pass the opened datastore - transports: [tcp()], - streamMuxers: [mplex()], - connectionEncryption: [noise()], + transports: [ + tcp() + ], + streamMuxers: [ + yamux(), + mplex() + ], + connectionEncryption: [ + noise() + ], peerStore: { persistence: true, threshold: 5 @@ -799,6 +863,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' @@ -814,6 +879,7 @@ const node = await createLibp2p({ webRTC.discovery ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -843,6 +909,7 @@ const node = await createLibp2p({ webRTC.discovery ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -864,11 +931,11 @@ If your router supports this, libp2p can be configured to use it as follows: ```js import { createLibp2p } from 'libp2p' -import { uPnPNAT } from 'libp2p/upnp-nat' +import { uPnPNATService } from 'libp2p/upnp-nat' const node = await createLibp2p({ services: { - nat: uPnPNAT({ + nat: uPnPNATService({ description: 'my-node', // set as the port mapping description on the router, defaults the current libp2p version and your peer id gateway: '192.168.1.1', // leave unset to auto-discover externalIp: '80.1.1.1', // leave unset to auto-discover diff --git a/doc/GETTING_STARTED.md b/doc/GETTING_STARTED.md index 3a349ab30c..93f2142113 100644 --- a/doc/GETTING_STARTED.md +++ b/doc/GETTING_STARTED.md @@ -112,11 +112,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: [yamux(), mplex()] }) ``` @@ -146,7 +147,7 @@ const node = await createLibp2p({ }, transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [yamux(), mplex()] }) // start libp2p @@ -192,6 +193,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' @@ -204,7 +206,7 @@ const bootstrapMultiaddrs = [ const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], peerDiscovery: [ bootstrap({ list: bootstrapMultiaddrs, // provide array of multiaddrs diff --git a/examples/auto-relay/README.md b/examples/auto-relay/README.md index 51d541459c..3e987685fa 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: [yamux(), mplex()], 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: [yamux(), mplex()], relay: { enabled: true, autoRelay: { @@ -133,6 +134,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) { @@ -142,7 +144,7 @@ if (!autoRelayNodeAddr) { const node = await createLibp2p({ transports: [webSockets()], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [yamux(), mplex()] }) console.log(`Node started with id ${node.peerId.toString()}`) diff --git a/examples/auto-relay/dialer.js b/examples/auto-relay/dialer.js index 08f4aaafb7..207aa7e7d1 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' import { circuitRelayTransport } from 'libp2p/circuit-relay' import { identifyService } from 'libp2p/identify' @@ -21,6 +22,7 @@ async function main () { noise() ], streamMuxers: [ + yamux(), mplex() ], services: { diff --git a/examples/auto-relay/listener.js b/examples/auto-relay/listener.js index 0b3ed17452..864a5e8f73 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' import { circuitRelayTransport } from 'libp2p/circuit-relay' import { identifyService } from 'libp2p/identify' @@ -23,6 +24,7 @@ async function main () { noise() ], streamMuxers: [ + yamux(), mplex() ], services: { diff --git a/examples/auto-relay/relay.js b/examples/auto-relay/relay.js index 5633668dcd..de0400ab49 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' import { circuitRelayServer } from 'libp2p/circuit-relay' import { identifyService } from 'libp2p/identify' @@ -19,7 +20,7 @@ async function main () { noise() ], streamMuxers: [ - mplex() + yamux(),mplex() ], services: { identify: identifyService(), diff --git a/examples/chat/src/libp2p.js b/examples/chat/src/libp2p.js index c7ba20148b..09b31e8e54 100644 --- a/examples/chat/src/libp2p.js +++ b/examples/chat/src/libp2p.js @@ -1,18 +1,19 @@ 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() + yamux(),mplex() ], connectionEncryption: [ noise() diff --git a/examples/connection-encryption/1.js b/examples/connection-encryption/1.js index 2aae533f5b..fab21cb575 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: [yamux(), mplex()], connectionEncryption: [noise()] }) @@ -46,4 +47,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 900b385f02..fa57b412fe 100644 --- a/examples/delegated-routing/src/libp2p-bundle.js +++ b/examples/delegated-routing/src/libp2p-bundle.js @@ -5,13 +5,14 @@ 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' import { circuitRelayTransport } from 'libp2p/circuit-relay' -export default function Libp2pBundle ({peerInfo, peerBook}) { +export default function Libp2pBundle ({ peerInfo, peerBook }) { const wrtcstar = new webRTCStar() const client = createIpfsHttpClient({ host: '0.0.0.0', @@ -38,7 +39,7 @@ export default function Libp2pBundle ({peerInfo, peerBook}) { circuitRelayTransport() ], streamMuxers: [ - mplex() + yamux(), mplex() ], peerDiscovery: [ wrtcstar.discovery diff --git a/examples/discovery-mechanisms/1.js b/examples/discovery-mechanisms/1.js index abba6d8ddc..8291da4d51 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 bootstrappers from './bootstrappers.js' -;(async () => { +(async () => { const node = await createLibp2p({ addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], peerDiscovery: [ bootstrap({ @@ -32,4 +33,4 @@ import bootstrappers from './bootstrappers.js' console.log('Discovered:', peerInfo.id.toString()) }) -})(); +})() diff --git a/examples/discovery-mechanisms/2.js b/examples/discovery-mechanisms/2.js index 81f162d8ac..bcc2ddf320 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,7 @@ const createNode = async () => { tcp() ], streamMuxers: [ - mplex() + yamux(),mplex() ], connectionEncryption: [ noise() @@ -38,4 +39,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 f181b16814..e0452f7c73 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' @@ -16,7 +17,7 @@ const createNode = async (bootstrappers) => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], peerDiscovery: [ bootstrap({ @@ -43,7 +44,7 @@ const createNode = async (bootstrappers) => { ] }, transports: [tcp(), circuitRelayTransport()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], peerDiscovery: [ pubsubPeerDiscovery({ diff --git a/examples/discovery-mechanisms/README.md b/examples/discovery-mechanisms/README.md index 17650373d5..b11f13d48f 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,6 +25,7 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -63,6 +65,7 @@ const node = await createLibp2p({ tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -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,7 @@ const createNode = () => { tcp() ], streamMuxers: [ - mplex() + yamux(),mplex() ], connectionEncryption: [ noise() @@ -188,7 +192,7 @@ const createNode = async (bootstrapers) => { tcp() ], streamMuxers: [ - mplex() + yamux(),mplex() ], connectionEncryption: [ noise() @@ -219,7 +223,7 @@ const relay = await createLibp2p({ ] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], pubsub: gossipsub({ allowPublishToZeroPeers: true }), peerDiscovery: [ diff --git a/examples/echo/src/libp2p.js b/examples/echo/src/libp2p.js index 628e0b96f3..a639019ddc 100644 --- a/examples/echo/src/libp2p.js +++ b/examples/echo/src/libp2p.js @@ -1,18 +1,19 @@ 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() + yamux(),mplex() ], connectionEncryption: [ noise() diff --git a/examples/libp2p-in-the-browser/index.js b/examples/libp2p-in-the-browser/index.js index 08d73ce64b..2394bb86ee 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: [yamux(), mplex()], peerDiscovery: [ wrtcStar.discovery, bootstrap({ diff --git a/examples/peer-and-content-routing/1.js b/examples/peer-and-content-routing/1.js index ae1f5e699d..dfd2a18c88 100644 --- a/examples/peer-and-content-routing/1.js +++ b/examples/peer-and-content-routing/1.js @@ -4,6 +4,7 @@ import { createLibp2p } from 'libp2p' import { identifyService } from 'libp2p/identify' 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' @@ -14,7 +15,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], services: { dht: kadDHT({ @@ -55,4 +56,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 c335055ea9..efd52525dd 100644 --- a/examples/peer-and-content-routing/2.js +++ b/examples/peer-and-content-routing/2.js @@ -4,6 +4,7 @@ import { createLibp2p } from 'libp2p' import { identifyService } from 'libp2p/identify' 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' @@ -16,7 +17,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], services: { dht: kadDHT({ @@ -64,4 +65,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 23c7b3fe20..a2364d34a1 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: [yamux(), mplex()], connectionEncryption: [noise()], dht: kadDHT() }) diff --git a/examples/pnet/libp2p-node.js b/examples/pnet/libp2p-node.js index 1a19bf701e..f1e08aa714 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: [yamux(), mplex()], // 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 be22a717c3..e40daba690 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: [yamux(), mplex()], connectionEncryption: [noise()] }) @@ -74,4 +75,4 @@ const createNode = async () => { stream ) */ -})(); +})() diff --git a/examples/protocol-and-stream-muxing/2.js b/examples/protocol-and-stream-muxing/2.js index 3f2d1f2f7e..791552a2eb 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: [yamux(), mplex()], connectionEncryption: [noise()] }) @@ -61,4 +62,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 abd3ad1cc9..a034f32ba2 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: [yamux(), mplex()], connectionEncryption: [noise()] }) @@ -65,4 +66,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 ae05c63405..902b3ef5c1 100644 --- a/examples/protocol-and-stream-muxing/README.md +++ b/examples/protocol-and-stream-muxing/README.md @@ -111,6 +111,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({ @@ -119,6 +121,7 @@ createLibp2p({ tcp() ], streamMuxers: [ + yamux(), mplex() ] }) @@ -183,7 +186,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], }) diff --git a/examples/pubsub/1.js b/examples/pubsub/1.js index 883439fa8d..dd0ffff9bc 100644 --- a/examples/pubsub/1.js +++ b/examples/pubsub/1.js @@ -4,6 +4,7 @@ import { createLibp2p } from 'libp2p' import { identifyService } from 'libp2p/identify' 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' @@ -15,7 +16,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], services: { pubsub: floodsub(), diff --git a/examples/pubsub/README.md b/examples/pubsub/README.md index d5e7ea1da5..723e0dc67b 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: [yamux(), mplex()], 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 d919b5197e..03f7cff285 100644 --- a/examples/pubsub/message-filtering/1.js +++ b/examples/pubsub/message-filtering/1.js @@ -4,6 +4,7 @@ import { createLibp2p } from 'libp2p' import { identifyService } from 'libp2p/identify' 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' @@ -15,7 +16,7 @@ const createNode = async () => { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp()], - streamMuxers: [mplex()], + streamMuxers: [yamux(), mplex()], connectionEncryption: [noise()], services: { pubsub: floodsub(), @@ -32,7 +33,7 @@ const createNode = async () => { const [node1, node2, node3] = await Promise.all([ createNode(), createNode(), - createNode(), + createNode() ]) // node1 conect to node2 and node2 conect to node3 @@ -46,7 +47,7 @@ const createNode = async () => { }) await node2.dial(node3.peerId) - //subscribe + // subscribe node1.services.pubsub.addEventListener('message', (evt) => { if (evt.detail.topic !== topic) { return @@ -89,7 +90,7 @@ const createNode = async () => { } } - //validate fruit + // validate fruit node1.services.pubsub.topicValidators.set(topic, validateFruit) node2.services.pubsub.topicValidators.set(topic, validateFruit) node3.services.pubsub.topicValidators.set(topic, validateFruit) @@ -111,6 +112,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 88008cd54d..ee9a301530 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: [yamux(), mplex()], 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 4a0ceea20a..0ddcf58c5b 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: [yamux(), mplex()] }) 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() @@ -60,4 +61,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 197f190963..4d4392e759 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: [yamux(), mplex()] }) return node diff --git a/examples/transports/4.js b/examples/transports/4.js index 07fedaddf3..76695006bd 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' @@ -13,8 +14,8 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' const httpServer = https.createServer({ cert: fs.readFileSync('./test_certs/cert.pem'), - key: fs.readFileSync('./test_certs/key.pem'), -}); + key: fs.readFileSync('./test_certs/key.pem') +}) const createNode = async (addresses = []) => { if (!Array.isArray(addresses)) { @@ -35,13 +36,13 @@ const createNode = async (addresses = []) => { }) ], connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [mplex(), yamux()] }) return node } -function printAddrs(node, number) { +function printAddrs (node, number) { console.log('node %s is listening on:', number) node.getMultiaddrs().forEach((ma) => console.log(ma.toString())) } @@ -57,7 +58,7 @@ function print ({ stream }) { ) } -;(async () => { +(async () => { const [node1, node2] = await Promise.all([ createNode('/ip4/127.0.0.1/tcp/10000/wss'), createNode([]) @@ -69,7 +70,7 @@ function print ({ stream }) { node1.handle('/print', print) node2.handle('/print', print) - const targetAddr = node1.getMultiaddrs()[0]; + const targetAddr = node1.getMultiaddrs()[0] // node 2 (Secure WebSockets) dials to node 1 (Secure Websockets) const stream = await node2.dialProtocol(targetAddr, '/print') @@ -77,4 +78,4 @@ function print ({ stream }) { [uint8ArrayFromString('node 2 dialed to node 1 successfully')], stream ) -})(); +})() diff --git a/examples/transports/README.md b/examples/transports/README.md index fb8ca0239a..7da2d2c086 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: [yamux(), mplex()] // <--- Add this line }) return node @@ -191,7 +192,7 @@ const createNode = async (transports, addresses = []) => { }, transports: transports, connectionEncryption: [noise()], - streamMuxers: [mplex()] + streamMuxers: [yamux(), mplex()] }) return node diff --git a/examples/webrtc-direct/dialer.js b/examples/webrtc-direct/dialer.js index 071e07b263..7bf887a4a4 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: [yamux(), mplex()], connectionEncryption: [noise()], peerDiscovery: [ bootstrap({ diff --git a/examples/webrtc-direct/listener.js b/examples/webrtc-direct/listener.js index 6f9ee030a9..685b431f15 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: [yamux(), mplex()], connectionEncryption: [noise()] }) diff --git a/package.json b/package.json index bc885ffc31..a0e30802f3 100644 --- a/package.json +++ b/package.json @@ -188,7 +188,7 @@ "devDependencies": { "@chainsafe/libp2p-gossipsub": "^7.0.0", "@chainsafe/libp2p-noise": "^11.0.0", - "@chainsafe/libp2p-yamux": "^4.0.0", + "@chainsafe/libp2p-yamux": "^4.0.1", "@libp2p/bootstrap": "^8.0.0", "@libp2p/daemon-client": "^6.0.2", "@libp2p/daemon-server": "^5.0.2", diff --git a/src/index.ts b/src/index.ts index ff8828efd8..d2d956f95f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -128,11 +128,12 @@ export type Libp2pOptions = RecursivePartial { describe('flows with 1 listener', () => { @@ -42,6 +43,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -62,6 +64,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -83,6 +86,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -104,6 +108,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -351,6 +356,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -371,6 +377,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -391,6 +398,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -412,6 +420,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -433,6 +442,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -624,6 +634,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -644,6 +655,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -664,6 +676,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -752,6 +765,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -772,6 +786,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -792,6 +807,7 @@ describe('circuit-relay', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -876,6 +892,7 @@ describe('circuit-relay', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -897,6 +914,7 @@ describe('circuit-relay', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -917,6 +935,7 @@ describe('circuit-relay', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -960,6 +979,7 @@ describe('circuit-relay', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -981,6 +1001,7 @@ describe('circuit-relay', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -1001,6 +1022,7 @@ describe('circuit-relay', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ diff --git a/test/configuration/utils.ts b/test/configuration/utils.ts index fafd199c2d..9b09c9222d 100644 --- a/test/configuration/utils.ts +++ b/test/configuration/utils.ts @@ -1,6 +1,5 @@ import { PubSubBaseProtocol, PubSubComponents } from '@libp2p/pubsub' import { plaintext } from '../../src/insecure/index.js' -import { mplex } from '@libp2p/mplex' import { webSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' import { MULTIADDRS_WEBSOCKETS } from '../fixtures/browser.js' @@ -10,6 +9,7 @@ import type { Libp2pInit, Libp2pOptions } from '../../src/index.js' import type { PeerId } from '@libp2p/interface-peer-id' import * as cborg from 'cborg' import { circuitRelayTransport } from '../../src/circuit-relay/index.js' +import { yamux } from '@chainsafe/libp2p-yamux' import { mockConnectionGater } from '@libp2p/interface-mocks' const relayAddr = MULTIADDRS_WEBSOCKETS[0] @@ -26,7 +26,7 @@ export const baseOptions: Partial> = { }), circuitRelayTransport() ], - streamMuxers: [mplex()], + streamMuxers: [yamux()], connectionEncryption: [plaintext()] } diff --git a/test/connection-manager/direct.node.ts b/test/connection-manager/direct.node.ts index 245422d49f..98b493e6fd 100644 --- a/test/connection-manager/direct.node.ts +++ b/test/connection-manager/direct.node.ts @@ -36,6 +36,7 @@ import fs from 'node:fs' import { peerIdFromString } from '@libp2p/peer-id' import { stubInterface } from 'sinon-ts' import type { TransportManager } from '@libp2p/interface-transport' +import { yamux } from '@chainsafe/libp2p-yamux' import { EventEmitter } from '@libp2p/interfaces/events' import { createLibp2pNode, Libp2pNode } from '../../src/libp2p.js' @@ -316,6 +317,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -349,6 +351,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -377,6 +380,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -443,6 +447,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -469,6 +474,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -496,6 +502,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -526,6 +533,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -565,6 +573,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -623,6 +632,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -640,6 +650,7 @@ describe('libp2p.dialer (direct, TCP)', () => { tcp() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ diff --git a/test/connection-manager/direct.spec.ts b/test/connection-manager/direct.spec.ts index 65ee548bfc..7b371fc890 100644 --- a/test/connection-manager/direct.spec.ts +++ b/test/connection-manager/direct.spec.ts @@ -30,6 +30,7 @@ import type { PeerId } from '@libp2p/interface-peer-id' import { pEvent } from 'p-event' import { defaultComponents, Components } from '../../src/components.js' import { stubInterface } from 'sinon-ts' +import { yamux } from '@chainsafe/libp2p-yamux' import { EventEmitter } from '@libp2p/interfaces/events' import type { Libp2p } from '@libp2p/interface-libp2p' import { IdentifyService, identifyService } from '../../src/identify/index.js' @@ -366,6 +367,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -410,6 +412,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -439,6 +442,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -459,6 +463,7 @@ describe('libp2p.dialer (direct, WebSockets)', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ diff --git a/test/connection-manager/resolver.spec.ts b/test/connection-manager/resolver.spec.ts index 05d02e5b33..b935dd6988 100644 --- a/test/connection-manager/resolver.spec.ts +++ b/test/connection-manager/resolver.spec.ts @@ -19,6 +19,7 @@ import { webSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' import { mplex } from '@libp2p/mplex' import { plaintext } from '../../src/insecure/index.js' +import { yamux } from '@chainsafe/libp2p-yamux' const relayAddr = MULTIADDRS_WEBSOCKETS[0] @@ -57,6 +58,7 @@ describe('dialing (resolvable addresses)', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionManager: { @@ -80,6 +82,7 @@ describe('dialing (resolvable addresses)', () => { }) ], streamMuxers: [ + yamux(), mplex() ], connectionManager: { diff --git a/test/content-routing/dht/operation.node.ts b/test/content-routing/dht/operation.node.ts index 776134eb2a..884c849c3c 100644 --- a/test/content-routing/dht/operation.node.ts +++ b/test/content-routing/dht/operation.node.ts @@ -15,6 +15,7 @@ import { kadDHT } from '@libp2p/kad-dht' import { tcp } from '@libp2p/tcp' import { plaintext } from '../../../src/insecure/index.js' import { mplex } from '@libp2p/mplex' +import { yamux } from '@chainsafe/libp2p-yamux' const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/8000') const remoteListenAddr = multiaddr('/ip4/127.0.0.1/tcp/8001') @@ -59,6 +60,7 @@ describe('DHT subsystem operates correctly', () => { plaintext() ], streamMuxers: [ + yamux(), mplex() ], services: { @@ -80,6 +82,7 @@ describe('DHT subsystem operates correctly', () => { plaintext() ], streamMuxers: [ + yamux(), mplex() ], services: { diff --git a/test/fetch/fetch.node.ts b/test/fetch/fetch.node.ts index 8173b0dac4..77f86b1f2d 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' import { FetchService, fetchService } from '../../src/fetch/index.js' import type { Libp2p } from '@libp2p/interface-libp2p' @@ -23,6 +24,7 @@ async function createNode (peerId: PeerId): Promise { webSockets() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ diff --git a/test/upgrading/upgrader.spec.ts b/test/upgrading/upgrader.spec.ts index c70ab46c57..549597a0ca 100644 --- a/test/upgrading/upgrader.spec.ts +++ b/test/upgrading/upgrader.spec.ts @@ -31,6 +31,7 @@ import { PersistentPeerStore } from '@libp2p/peer-store' import { MemoryDatastore } from 'datastore-core' import { Components, defaultComponents } from '../../src/components.js' import { StubbedInstance, stubInterface } from 'sinon-ts' +import { yamux } from '@chainsafe/libp2p-yamux' import { EventEmitter } from '@libp2p/interfaces/events' import { createLibp2p } from '../../src/index.js' import type { Libp2p } from '@libp2p/interface-libp2p' @@ -45,10 +46,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 @@ -79,13 +82,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 }) @@ -104,13 +109,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 }) @@ -313,6 +320,7 @@ describe('Upgrader', () => { plaintext()() ], muxers: [ + yamux()(), mplex()() ], inboundUpgradeTimeout: 1000 @@ -575,6 +583,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -607,6 +616,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -627,6 +637,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -651,10 +662,10 @@ describe('libp2p.upgrader', () => { const remoteLibp2pUpgraderOnStreamSpy = sinon.spy(remoteComponents.upgrader as DefaultUpgrader, '_onStream') const stream = await localConnection.newStream(['/echo/1.0.0']) - expect(stream).to.include.keys(['id', 'close', 'reset', 'stat']) + expect(stream).to.include.keys(['id', 'recvWindowCapacity', 'sendWindowCapacity', 'sourceInput']) const [arg0] = remoteLibp2pUpgraderOnStreamSpy.getCall(0).args - expect(arg0.stream).to.include.keys(['id', 'close', 'reset', 'stat']) + expect(arg0.stream).to.include.keys(['id', 'recvWindowCapacity', 'sendWindowCapacity', 'sourceInput']) }) it('should emit connect and disconnect events', async () => { @@ -673,6 +684,7 @@ describe('libp2p.upgrader', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -691,6 +703,7 @@ describe('libp2p.upgrader', () => { circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ @@ -738,7 +751,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + yamux() ], connectionEncryption: [ plaintext() @@ -757,7 +770,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + yamux() ], connectionEncryption: [ plaintext() @@ -815,7 +828,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + yamux() ], connectionEncryption: [ plaintext() @@ -834,7 +847,7 @@ describe('libp2p.upgrader', () => { webSockets() ], streamMuxers: [ - mplex() + yamux() ], connectionEncryption: [ plaintext() diff --git a/test/utils/base-options.browser.ts b/test/utils/base-options.browser.ts index dfcd782ecc..eddd1b445a 100644 --- a/test/utils/base-options.browser.ts +++ b/test/utils/base-options.browser.ts @@ -6,6 +6,7 @@ import { plaintext } from '../../src/insecure/index.js' import type { Libp2pOptions } from '../../src/index.js' import mergeOptions from 'merge-options' import { circuitRelayTransport } from '../../src/circuit-relay/index.js' +import { yamux } from '@chainsafe/libp2p-yamux' import type { ServiceMap } from '@libp2p/interface-libp2p' import { mockConnectionGater } from '@libp2p/interface-mocks' @@ -18,6 +19,7 @@ export function createBaseOptions (overrides?: Libp2 circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [ diff --git a/test/utils/base-options.ts b/test/utils/base-options.ts index 9c3a147481..8292884bd1 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' import type { ServiceMap } from '@libp2p/interface-libp2p' import { webSockets } from '@libp2p/websockets' import * as filters from '@libp2p/websockets/filters' @@ -22,6 +23,7 @@ export function createBaseOptions (...overrides: Arr circuitRelayTransport() ], streamMuxers: [ + yamux(), mplex() ], connectionEncryption: [