@cryptotaxi247 / kubo / commits / 722040939

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

Jorropo committed Feb 9, 2023 at 16:43 UTC 7220409394005c85509448217686e79b1779554b
8 files changed +27 -74
core/node/libp2p/smux.go
+9 -39
@@ -3,13 +3,11 @@ package libp2p
3 import (
4 "fmt"
5 "os"
6 - "strings"
6
7 "github.com/ipfs/kubo/config"
8
9 "github.com/libp2p/go-libp2p"
10 "github.com/libp2p/go-libp2p/core/network"
12 - "github.com/libp2p/go-libp2p/p2p/muxer/mplex"
11 "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
12 )
13
@@ -23,45 +21,17 @@ func yamuxTransport() network.Multiplexer {
21 }
22
23 func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
26 - const yamuxID = "/yamux/1.0.0"
27 - const mplexID = "/mplex/6.7.0"
28 -
24 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")
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 + }
33 +
34 + return libp2p.Muxer(yamux.ID, yamuxTransport()), nil
35 }
36
37 func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) {
docs/changelogs/v0.23.md
+10 -1
@@ -6,6 +6,7 @@
6
7 - [Overview](#overview)
8 - [🔦 Highlights](#-highlights)
9 + - [Mplex removal](#mplex-removal)
10 - [📝 Changelog](#-changelog)
11 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
12
@@ -13,7 +14,15 @@
14
15 ### 🔦 Highlights
16
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 +
26 ### 📝 Changelog
27
28 ### 👨‍👩‍👧‍👦 Contributors
19 -
docs/config.md
+8 -16
@@ -2052,6 +2052,8 @@ Type: `flag`
2052 Configuration section for libp2p _security_ transports. Transports enabled in
2053 this section will be used to secure unencrypted connections.
2054
2055 +This does not concern all the QUIC transports which use QUIC's builtin encryption.
2056 +
2057 Security transports are configured with the `priority` type.
2058
2059 When establishing an _outbound_ connection, Kubo will try each security
@@ -2094,11 +2096,13 @@ Type: `priority`
2096 Configuration section for libp2p _multiplexer_ transports. Transports enabled in
2097 this section will be used to multiplex duplex connections.
2098
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
2102 the `priority` type. Like with security transports, the initiator gets their
2103 first choice.
2104
2101 -Supported transports are: Yamux (priority 100) and Mplex (priority 200)
2105 +Supported transport is only: Yamux (priority 100)
2106
2107 No default priority will ever be less than 100.
2108
@@ -2112,21 +2116,9 @@ Type: `priority`
2116
2117 ### `Swarm.Transports.Multiplexers.Mplex`
2118
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
2120
2127 -Default: `200`
2128 -
2129 -Type: `priority`
2121 +Support for Mplex has been removed. Please remove this option from your config.
2122
2123 ## `DNS`
2124
docs/examples/kubo-as-a-library/go.mod
-1
@@ -110,7 +110,6 @@ require (
110 github.com/libp2p/go-libp2p-record v0.2.0 // indirect
111 github.com/libp2p/go-libp2p-routing-helpers v0.7.1 // indirect
112 github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
113 - github.com/libp2p/go-mplex v0.7.0 // indirect
113 github.com/libp2p/go-msgio v0.3.0 // indirect
114 github.com/libp2p/go-nat v0.2.0 // indirect
115 github.com/libp2p/go-netroute v0.2.1 // indirect
docs/examples/kubo-as-a-library/go.sum
-2
@@ -482,8 +482,6 @@ github.com/libp2p/go-libp2p-routing-helpers v0.7.1/go.mod h1:cHStPSRC/wgbfpb5jYd
482 github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
483 github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
484 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=
485 github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
486 github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
487 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
go.mod
-1
@@ -158,7 +158,6 @@ require (
158 github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
159 github.com/libp2p/go-libp2p-gostream v0.6.0 // indirect
160 github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
161 - github.com/libp2p/go-mplex v0.7.0 // indirect
161 github.com/libp2p/go-msgio v0.3.0 // indirect
162 github.com/libp2p/go-nat v0.2.0 // indirect
163 github.com/libp2p/go-netroute v0.2.1 // indirect
go.sum
-2
@@ -545,8 +545,6 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI
545 github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
546 github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
547 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=
548 github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
549 github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
550 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
test/cli/transports_test.go
-12
@@ -71,18 +71,6 @@ func TestTransports(t *testing.T) {
71 runTests(nodes)
72 })
73
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 -
74 t.Run("tcp with NOISE", func(t *testing.T) {
75 t.Parallel()
76 nodes := tcpNodes(t)