Skip to content

Commit

Permalink
feat: allow users to optin again into mplex
Browse files Browse the repository at this point in the history
This is a partial revert of 7220409.

Closes #9958
  • Loading branch information
Jorropo committed Aug 15, 2023
1 parent 7220409 commit f805b9f
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type Transports struct {
Multiplexers struct {
// Defaults to 100.
Yamux Priority `json:",omitempty"`
// Defaults to 200.
// Defaults to -1.
Mplex Priority `json:",omitempty"`
}
}
Expand Down
55 changes: 36 additions & 19 deletions core/node/libp2p/smux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,52 @@ package libp2p
import (
"fmt"
"os"
"strings"

"github.com/ipfs/kubo/config"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/p2p/muxer/mplex"
"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
)

func yamuxTransport() network.Multiplexer {
tpt := *yamux.DefaultTransport
tpt.AcceptBacklog = 512
if os.Getenv("YAMUX_DEBUG") != "" {
tpt.LogOutput = os.Stderr
}
return &tpt
}

func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported")
}
if tptConfig.Multiplexers.Mplex != 0 {
return nil, fmt.Errorf("Swarm.Transports.Multiplexers.Mplex is no longer supported")
}
if tptConfig.Multiplexers.Yamux < 0 {
return nil, fmt.Errorf("Swarm.Transports.Multiplexers.Yamux is disabled even tho it is the only multiplexer available")
}
// Using legacy LIBP2P_MUX_PREFS variable.
log.Error("LIBP2P_MUX_PREFS is now deprecated.")
log.Error("Use the `Swarm.Transports.Multiplexers' config field.")
muxers := strings.Fields(prefs)
enabled := make(map[string]bool, len(muxers))

return libp2p.Muxer(yamux.ID, yamuxTransport()), nil
var opts []libp2p.Option
for _, tpt := range muxers {
if enabled[tpt] {
return nil, fmt.Errorf(
"duplicate muxer found in LIBP2P_MUX_PREFS: %s",
tpt,
)
}
switch tpt {
case yamux.ID:
opts = append(opts, libp2p.Muxer(tpt, yamux.DefaultTransport))
case mplex.ID:
opts = append(opts, libp2p.Muxer(tpt, mplex.DefaultTransport))
default:
return nil, fmt.Errorf("unknown muxer: %s", tpt)
}
}
return libp2p.ChainOptions(opts...), nil
} else {
return prioritizeOptions([]priorityOption{{
priority: tptConfig.Multiplexers.Yamux,
defaultPriority: 100,
opt: libp2p.Muxer(yamux.ID, yamux.DefaultTransport),
}, {
priority: tptConfig.Multiplexers.Mplex,
defaultPriority: config.Disabled,
opt: libp2p.Muxer(mplex.ID, mplex.DefaultTransport),
}}), nil
}
}

func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) {
Expand Down
19 changes: 14 additions & 5 deletions docs/changelogs/v0.23.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@

- [Overview](#overview)
- [🔦 Highlights](#-highlights)
- [Mplex removal](#mplex-removal)
- [Mplex deprecation](#mplex-deprecation)
- [📝 Changelog](#-changelog)
- [👨‍👩‍👧‍👦 Contributors](#-contributors)

### Overview

### 🔦 Highlights

#### Mplex removal
#### Mplex deprecation

Support for Mplex was removed, this is because it is unreliable and would
randomly drop streams when sending data too fast.
Mplex is being deprecated, this is because it is unreliable and
randomly drop streams when sending data *too fast*.

New pieces of code rely on backpressure, that means the stream will dynamicaly
slow down the sending rate if data is getting backed up.
Backpressure is provided by Yamux and QUIC.
Backpressure is provided by **Yamux** and **QUIC**.

In case you need compatibility with older implementations that do not ship with
Yamux (like default's JS-IPFS) you can turned it back ON in the config with:
```console
$ ipfs config --json Swarm.Transports.Multiplexers.Mplex 200
```

We will completely remove Mplex in v0.24 as it makes protocols very bad to implement,
if you are in this situation you need to add yamux support to your other implementation.

### 📝 Changelog

Expand Down
14 changes: 13 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,19 @@ Type: `priority`

**DEPRECATED**: See https://github.com/ipfs/kubo/issues/9958

Support for Mplex has been removed. Please remove this option from your config.
Mplex is deprecated, this is because it is unreliable and
randomly drop streams when sending data *too fast*.

New pieces of code rely on backpressure, that means the stream will dynamicaly
slow down the sending rate if data is getting backed up.
Backpressure is provided by **Yamux** and **QUIC**.

If you want to turn it back on make sure to have a higher (lower is better)
priority than `Yamux`, you don't want your Kubo to start defaulting to Mplex.

Default: `200`

Type: `priority`

## `DNS`

Expand Down
1 change: 1 addition & 0 deletions docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ require (
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.1 // indirect
github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/kubo-as-a-library/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ github.com/libp2p/go-libp2p-routing-helpers v0.7.1/go.mod h1:cHStPSRC/wgbfpb5jYd
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY=
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ require (
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
github.com/libp2p/go-libp2p-gostream v0.6.0 // indirect
github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI
github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY=
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
Expand Down
14 changes: 14 additions & 0 deletions test/cli/transports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ func TestTransports(t *testing.T) {
runTests(nodes)
})

t.Run("tcp with mplex", func(t *testing.T) {
// FIXME(#10069): we don't want this to exists anymore
t.Parallel()
nodes := tcpNodes(t)
nodes.ForEachPar(func(n *harness.Node) {
n.UpdateConfig(func(cfg *config.Config) {
cfg.Swarm.Transports.Multiplexers.Yamux = config.Disabled
cfg.Swarm.Transports.Multiplexers.Mplex = 200
})
})
nodes.StartDaemons().Connect()
runTests(nodes)
})

t.Run("tcp with NOISE", func(t *testing.T) {
t.Parallel()
nodes := tcpNodes(t)
Expand Down

0 comments on commit f805b9f

Please sign in to comment.