Skip to content

Commit f805b9f

Browse files
committed
feat: allow users to optin again into mplex
This is a partial revert of 7220409. Closes #9958
1 parent 7220409 commit f805b9f

File tree

9 files changed

+84
-26
lines changed

9 files changed

+84
-26
lines changed

config/swarm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type Transports struct {
122122
Multiplexers struct {
123123
// Defaults to 100.
124124
Yamux Priority `json:",omitempty"`
125-
// Defaults to 200.
125+
// Defaults to -1.
126126
Mplex Priority `json:",omitempty"`
127127
}
128128
}

core/node/libp2p/smux.go

+36-19
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,52 @@ package libp2p
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
"github.com/ipfs/kubo/config"
89

910
"github.com/libp2p/go-libp2p"
10-
"github.com/libp2p/go-libp2p/core/network"
11+
"github.com/libp2p/go-libp2p/p2p/muxer/mplex"
1112
"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
1213
)
1314

14-
func yamuxTransport() network.Multiplexer {
15-
tpt := *yamux.DefaultTransport
16-
tpt.AcceptBacklog = 512
17-
if os.Getenv("YAMUX_DEBUG") != "" {
18-
tpt.LogOutput = os.Stderr
19-
}
20-
return &tpt
21-
}
22-
2315
func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
2416
if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
25-
return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported")
26-
}
27-
if tptConfig.Multiplexers.Mplex != 0 {
28-
return nil, fmt.Errorf("Swarm.Transports.Multiplexers.Mplex is no longer supported")
29-
}
30-
if tptConfig.Multiplexers.Yamux < 0 {
31-
return nil, fmt.Errorf("Swarm.Transports.Multiplexers.Yamux is disabled even tho it is the only multiplexer available")
32-
}
17+
// Using legacy LIBP2P_MUX_PREFS variable.
18+
log.Error("LIBP2P_MUX_PREFS is now deprecated.")
19+
log.Error("Use the `Swarm.Transports.Multiplexers' config field.")
20+
muxers := strings.Fields(prefs)
21+
enabled := make(map[string]bool, len(muxers))
3322

34-
return libp2p.Muxer(yamux.ID, yamuxTransport()), nil
23+
var opts []libp2p.Option
24+
for _, tpt := range muxers {
25+
if enabled[tpt] {
26+
return nil, fmt.Errorf(
27+
"duplicate muxer found in LIBP2P_MUX_PREFS: %s",
28+
tpt,
29+
)
30+
}
31+
switch tpt {
32+
case yamux.ID:
33+
opts = append(opts, libp2p.Muxer(tpt, yamux.DefaultTransport))
34+
case mplex.ID:
35+
opts = append(opts, libp2p.Muxer(tpt, mplex.DefaultTransport))
36+
default:
37+
return nil, fmt.Errorf("unknown muxer: %s", tpt)
38+
}
39+
}
40+
return libp2p.ChainOptions(opts...), nil
41+
} else {
42+
return prioritizeOptions([]priorityOption{{
43+
priority: tptConfig.Multiplexers.Yamux,
44+
defaultPriority: 100,
45+
opt: libp2p.Muxer(yamux.ID, yamux.DefaultTransport),
46+
}, {
47+
priority: tptConfig.Multiplexers.Mplex,
48+
defaultPriority: config.Disabled,
49+
opt: libp2p.Muxer(mplex.ID, mplex.DefaultTransport),
50+
}}), nil
51+
}
3552
}
3653

3754
func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) {

docs/changelogs/v0.23.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,31 @@
66

77
- [Overview](#overview)
88
- [🔦 Highlights](#-highlights)
9-
- [Mplex removal](#mplex-removal)
9+
- [Mplex deprecation](#mplex-deprecation)
1010
- [📝 Changelog](#-changelog)
1111
- [👨‍👩‍👧‍👦 Contributors](#-contributors)
1212

1313
### Overview
1414

1515
### 🔦 Highlights
1616

17-
#### Mplex removal
17+
#### Mplex deprecation
1818

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

2222
New pieces of code rely on backpressure, that means the stream will dynamicaly
2323
slow down the sending rate if data is getting backed up.
24-
Backpressure is provided by Yamux and QUIC.
24+
Backpressure is provided by **Yamux** and **QUIC**.
25+
26+
In case you need compatibility with older implementations that do not ship with
27+
Yamux (like default's JS-IPFS) you can turned it back ON in the config with:
28+
```console
29+
$ ipfs config --json Swarm.Transports.Multiplexers.Mplex 200
30+
```
31+
32+
We will completely remove Mplex in v0.24 as it makes protocols very bad to implement,
33+
if you are in this situation you need to add yamux support to your other implementation.
2534

2635
### 📝 Changelog
2736

docs/config.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,19 @@ Type: `priority`
21182118

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

2121-
Support for Mplex has been removed. Please remove this option from your config.
2121+
Mplex is deprecated, this is because it is unreliable and
2122+
randomly drop streams when sending data *too fast*.
2123+
2124+
New pieces of code rely on backpressure, that means the stream will dynamicaly
2125+
slow down the sending rate if data is getting backed up.
2126+
Backpressure is provided by **Yamux** and **QUIC**.
2127+
2128+
If you want to turn it back on make sure to have a higher (lower is better)
2129+
priority than `Yamux`, you don't want your Kubo to start defaulting to Mplex.
2130+
2131+
Default: `200`
2132+
2133+
Type: `priority`
21222134

21232135
## `DNS`
21242136

docs/examples/kubo-as-a-library/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ require (
110110
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
111111
github.com/libp2p/go-libp2p-routing-helpers v0.7.1 // indirect
112112
github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
113+
github.com/libp2p/go-mplex v0.7.0 // indirect
113114
github.com/libp2p/go-msgio v0.3.0 // indirect
114115
github.com/libp2p/go-nat v0.2.0 // indirect
115116
github.com/libp2p/go-netroute v0.2.1 // indirect

docs/examples/kubo-as-a-library/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ github.com/libp2p/go-libp2p-routing-helpers v0.7.1/go.mod h1:cHStPSRC/wgbfpb5jYd
482482
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
483483
github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
484484
github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY=
485+
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
486+
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
485487
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
486488
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
487489
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ require (
158158
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
159159
github.com/libp2p/go-libp2p-gostream v0.6.0 // indirect
160160
github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
161+
github.com/libp2p/go-mplex v0.7.0 // indirect
161162
github.com/libp2p/go-msgio v0.3.0 // indirect
162163
github.com/libp2p/go-nat v0.2.0 // indirect
163164
github.com/libp2p/go-netroute v0.2.1 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI
545545
github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
546546
github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
547547
github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY=
548+
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
549+
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
548550
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
549551
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
550552
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=

test/cli/transports_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ func TestTransports(t *testing.T) {
7171
runTests(nodes)
7272
})
7373

74+
t.Run("tcp with mplex", func(t *testing.T) {
75+
// FIXME(#10069): we don't want this to exists anymore
76+
t.Parallel()
77+
nodes := tcpNodes(t)
78+
nodes.ForEachPar(func(n *harness.Node) {
79+
n.UpdateConfig(func(cfg *config.Config) {
80+
cfg.Swarm.Transports.Multiplexers.Yamux = config.Disabled
81+
cfg.Swarm.Transports.Multiplexers.Mplex = 200
82+
})
83+
})
84+
nodes.StartDaemons().Connect()
85+
runTests(nodes)
86+
})
87+
7488
t.Run("tcp with NOISE", func(t *testing.T) {
7589
t.Parallel()
7690
nodes := tcpNodes(t)

0 commit comments

Comments
 (0)