Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support yamux to wherever mplex is supported #1579

Merged
merged 18 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -31,6 +32,7 @@ export default {
webSockets()
],
streamMuxers: [
yamux(),
mplex()
],
connectionEncryption: [
Expand Down
92 changes: 55 additions & 37 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [yamux(), mplex()],
connectionEncryption: [noise()],
peerDiscovery: [MulticastDNS],
dht: kadDHT(),
Expand All @@ -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: [yamux(), mplex()],
connectionEncryption: [noise()],
peerDiscovery: [
mdns({
Expand Down Expand Up @@ -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()
Expand All @@ -312,6 +315,7 @@ const node = await createLibp2p({
webRtc.discovery
],
streamMuxers: [
yamux(),
mplex()
],
connectionEncryption: [
Expand All @@ -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'
Expand All @@ -335,7 +340,7 @@ const node = await createLibp2p({
tcp()
],
streamMuxers: [
mplex()
yamux(),mplex()
],
connectionEncryption: [
noise()
Expand All @@ -362,6 +367,7 @@ const node = await createLibp2p({
tcp()
],
streamMuxers: [
yamux(),
mplex()
],
connectionEncryption: [
Expand All @@ -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'
Expand All @@ -402,7 +409,7 @@ const delegatedContentRouting = new DelegatedContentRouting(peerId, ipfsHttpClie

const node = await createLibp2p({
transports: [tcp()],
streamMuxers: [mplex()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()],
contentRouting: [
delegatedContentRouting
Expand All @@ -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: [yamux(), mplex()],
connectionEncryption: [noise()],
relay: { // Circuit Relay options
enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay.
Expand Down Expand Up @@ -463,11 +471,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: [yamux(), mplex()],
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.
Expand All @@ -483,15 +492,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'

Expand All @@ -500,7 +510,7 @@ await datastore.open()

const node = await createLibp2p({
transports: [tcp()],
streamMuxers: [mplex()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()],
keychain: {
pass: 'notsafepassword123456789',
Expand All @@ -513,30 +523,31 @@ 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<Address>) => Array<Address>` | 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<Address>) => Array<Address>` | 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:

```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 { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
import { publicAddressesFirst } from '@libp2p-utils/address-sort'

const node = await createLibp2p({
transports: [tcp()],
streamMuxers: [mplex()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()],
dialer: {
maxParallelDials: 100,
Expand All @@ -558,11 +569,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: [yamux(), mplex()],
connectionEncryption: [noise()],
connectionManager: {
maxConnections: Infinity,
Expand Down Expand Up @@ -707,12 +719,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: [yamux(), mplex()],
connectionEncryption: [noise()],
transportManager: {
faultTolerance: FaultTolerance.NO_FATAL
Expand All @@ -724,25 +737,26 @@ 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<number>` | 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<number>` | 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:

```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'

const node = await createLibp2p({
transports: [tcp()],
streamMuxers: [mplex()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()]
metrics: {
enabled: true,
Expand All @@ -764,17 +778,18 @@ 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:

```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'

Expand All @@ -784,7 +799,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: [yamux(), mplex()],
connectionEncryption: [noise()],
peerStore: {
persistence: true,
Expand All @@ -801,6 +816,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'

Expand All @@ -816,7 +832,8 @@ const node = await createLibp2p({
webRTC.discovery
],
streamMuxers: [
mplex()
yamux(), mplex()

],
connectionEncryption: [
noise()
Expand Down Expand Up @@ -845,7 +862,8 @@ const node = await createLibp2p({
webRTC.discovery
],
streamMuxers: [
mplex()
yamux(), mplex()

],
connectionEncryption: [
noise()
Expand Down
8 changes: 5 additions & 3 deletions doc/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [yamux(), mplex()]
})
```

Expand Down Expand Up @@ -143,7 +144,7 @@ const node = await createLibp2p({
},
transports: [webSockets()],
connectionEncryption: [noise()],
streamMuxers: [mplex()]
streamMuxers: [yamux(), mplex()]
})

// start libp2p
Expand Down Expand Up @@ -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'

Expand All @@ -201,7 +203,7 @@ const bootstrapMultiaddrs = [
const node = await createLibp2p({
transports: [webSockets()],
connectionEncryption: [noise()],
streamMuxers: [mplex()],
streamMuxers: [yamux(), mplex()],
peerDiscovery: [
bootstrap({
list: bootstrapMultiaddrs, // provide array of multiaddrs
Expand Down
Loading