Skip to content

Commit 7220409

Browse files
Jorropohacdias
authored andcommitted
feat: remove Mplex
Mplex does not implement backpressure, our implementation will randomly reset streams if buffers overflow instead of risking deadlocks. In the past we had a bug where kubo nodes would prefer mplex over yamux. Turning off mplex make our connections to thoses nodes negociate yamux. Closes #9958
1 parent 0c57a4f commit 7220409

File tree

8 files changed

+27
-74
lines changed

8 files changed

+27
-74
lines changed

core/node/libp2p/smux.go

+9-39
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ package libp2p
33
import (
44
"fmt"
55
"os"
6-
"strings"
76

87
"github.com/ipfs/kubo/config"
98

109
"github.com/libp2p/go-libp2p"
1110
"github.com/libp2p/go-libp2p/core/network"
12-
"github.com/libp2p/go-libp2p/p2p/muxer/mplex"
1311
"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
1412
)
1513

@@ -23,45 +21,17 @@ func yamuxTransport() network.Multiplexer {
2321
}
2422

2523
func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
26-
const yamuxID = "/yamux/1.0.0"
27-
const mplexID = "/mplex/6.7.0"
28-
2924
if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
30-
// Using legacy LIBP2P_MUX_PREFS variable.
31-
log.Error("LIBP2P_MUX_PREFS is now deprecated.")
32-
log.Error("Use the `Swarm.Transports.Multiplexers' config field.")
33-
muxers := strings.Fields(prefs)
34-
enabled := make(map[string]bool, len(muxers))
35-
36-
var opts []libp2p.Option
37-
for _, tpt := range muxers {
38-
if enabled[tpt] {
39-
return nil, fmt.Errorf(
40-
"duplicate muxer found in LIBP2P_MUX_PREFS: %s",
41-
tpt,
42-
)
43-
}
44-
switch tpt {
45-
case yamuxID:
46-
opts = append(opts, libp2p.Muxer(tpt, yamuxTransport()))
47-
case mplexID:
48-
opts = append(opts, libp2p.Muxer(tpt, mplex.DefaultTransport))
49-
default:
50-
return nil, fmt.Errorf("unknown muxer: %s", tpt)
51-
}
52-
}
53-
return libp2p.ChainOptions(opts...), nil
54-
} else {
55-
return prioritizeOptions([]priorityOption{{
56-
priority: tptConfig.Multiplexers.Yamux,
57-
defaultPriority: 100,
58-
opt: libp2p.Muxer(yamuxID, yamuxTransport()),
59-
}, {
60-
priority: tptConfig.Multiplexers.Mplex,
61-
defaultPriority: 200,
62-
opt: libp2p.Muxer(mplexID, mplex.DefaultTransport),
63-
}}), nil
25+
return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported")
6426
}
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+
}
33+
34+
return libp2p.Muxer(yamux.ID, yamuxTransport()), nil
6535
}
6636

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

docs/changelogs/v0.23.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@
66

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

1213
### Overview
1314

1415
### 🔦 Highlights
1516

17+
#### Mplex removal
18+
19+
Support for Mplex was removed, this is because it is unreliable and would
20+
randomly drop streams when sending data too fast.
21+
22+
New pieces of code rely on backpressure, that means the stream will dynamicaly
23+
slow down the sending rate if data is getting backed up.
24+
Backpressure is provided by Yamux and QUIC.
25+
1626
### 📝 Changelog
1727

1828
### 👨‍👩‍👧‍👦 Contributors
19-

docs/config.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,8 @@ Type: `flag`
20522052
Configuration section for libp2p _security_ transports. Transports enabled in
20532053
this section will be used to secure unencrypted connections.
20542054

2055+
This does not concern all the QUIC transports which use QUIC's builtin encryption.
2056+
20552057
Security transports are configured with the `priority` type.
20562058

20572059
When establishing an _outbound_ connection, Kubo will try each security
@@ -2094,11 +2096,13 @@ Type: `priority`
20942096
Configuration section for libp2p _multiplexer_ transports. Transports enabled in
20952097
this section will be used to multiplex duplex connections.
20962098

2097-
Multiplexer transports are secured the same way security transports are, with
2099+
This does not concern all the QUIC transports which use QUIC's builtin muxing.
2100+
2101+
Multiplexer transports are configured the same way security transports are, with
20982102
the `priority` type. Like with security transports, the initiator gets their
20992103
first choice.
21002104

2101-
Supported transports are: Yamux (priority 100) and Mplex (priority 200)
2105+
Supported transport is only: Yamux (priority 100)
21022106

21032107
No default priority will ever be less than 100.
21042108

@@ -2112,21 +2116,9 @@ Type: `priority`
21122116

21132117
### `Swarm.Transports.Multiplexers.Mplex`
21142118

2115-
Mplex is the default multiplexer used when communicating between Kubo and all
2116-
other IPFS and libp2p implementations. Unlike Yamux:
2117-
2118-
* Mplex is a simpler protocol.
2119-
* Mplex is more efficient.
2120-
* Mplex does not have built-in keepalives.
2121-
* Mplex does not support backpressure. Unfortunately, this means that, if a
2122-
single stream to a peer gets backed up for a period of time, the mplex
2123-
transport will kill the stream to allow the others to proceed. On the other
2124-
hand, the lack of backpressure means mplex can be significantly faster on some
2125-
high-latency connections.
2119+
**DEPRECATED**: See https://github.com/ipfs/kubo/issues/9958
21262120

2127-
Default: `200`
2128-
2129-
Type: `priority`
2121+
Support for Mplex has been removed. Please remove this option from your config.
21302122

21312123
## `DNS`
21322124

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

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ 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
114113
github.com/libp2p/go-msgio v0.3.0 // indirect
115114
github.com/libp2p/go-nat v0.2.0 // indirect
116115
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,8 +482,6 @@ 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=
487485
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
488486
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
489487
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,7 +158,6 @@ 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
162161
github.com/libp2p/go-msgio v0.3.0 // indirect
163162
github.com/libp2p/go-nat v0.2.0 // indirect
164163
github.com/libp2p/go-netroute v0.2.1 // indirect

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,6 @@ 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=
550548
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
551549
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
552550
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=

test/cli/transports_test.go

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

74-
t.Run("tcp with mplex", func(t *testing.T) {
75-
t.Parallel()
76-
nodes := tcpNodes(t)
77-
nodes.ForEachPar(func(n *harness.Node) {
78-
n.UpdateConfig(func(cfg *config.Config) {
79-
cfg.Swarm.Transports.Multiplexers.Yamux = config.Disabled
80-
})
81-
})
82-
nodes.StartDaemons().Connect()
83-
runTests(nodes)
84-
})
85-
8674
t.Run("tcp with NOISE", func(t *testing.T) {
8775
t.Parallel()
8876
nodes := tcpNodes(t)

0 commit comments

Comments
 (0)