@cryptotaxi247 / kubo / commits / f805b9fcd

feat: allow users to optin again into mplex

This is a partial revert of 7220409394005c85509448217686e79b1779554b. Closes #9958

Jorropo committed Aug 15, 2023 at 14:29 UTC f805b9fcda91d7f0ab11f930c30ab10a17fd048d
9 files changed +84 -26
config/swarm.go
+1 -1
@@ -122,7 +122,7 @@ type Transports struct {
122 Multiplexers struct {
123 // Defaults to 100.
124 Yamux Priority `json:",omitempty"`
125 - // Defaults to 200.
125 + // Defaults to -1.
126 Mplex Priority `json:",omitempty"`
127 }
128 }
core/node/libp2p/smux.go
+36 -19
@@ -3,35 +3,52 @@ package libp2p
3 import (
4 "fmt"
5 "os"
6 + "strings"
7
8 "github.com/ipfs/kubo/config"
9
10 "github.com/libp2p/go-libp2p"
10 - "github.com/libp2p/go-libp2p/core/network"
11 + "github.com/libp2p/go-libp2p/p2p/muxer/mplex"
12 "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
13 )
14
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 -
15 func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
16 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))
22
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 + }
52 }
53
54 func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) {
docs/changelogs/v0.23.md
+14 -5
@@ -6,7 +6,7 @@
6
7 - [Overview](#overview)
8 - [🔦 Highlights](#-highlights)
9 - - [Mplex removal](#mplex-removal)
9 + - [Mplex deprecation](#mplex-deprecation)
10 - [📝 Changelog](#-changelog)
11 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
12
@@ -14,14 +14,23 @@
14
15 ### 🔦 Highlights
16
17 -#### Mplex removal
17 +#### Mplex deprecation
18
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*.
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.
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.
34
35 ### 📝 Changelog
36
docs/config.md
+13 -1
@@ -2118,7 +2118,19 @@ Type: `priority`
2118
2119 **DEPRECATED**: See https://github.com/ipfs/kubo/issues/9958
2120
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`
2134
2135 ## `DNS`
2136
docs/examples/kubo-as-a-library/go.mod
+1
@@ -110,6 +110,7 @@ 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
114 github.com/libp2p/go-msgio v0.3.0 // indirect
115 github.com/libp2p/go-nat v0.2.0 // indirect
116 github.com/libp2p/go-netroute v0.2.1 // indirect
docs/examples/kubo-as-a-library/go.sum
+2
@@ -482,6 +482,8 @@ 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=
487 github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
488 github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
489 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
go.mod
+1
@@ -158,6 +158,7 @@ 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
162 github.com/libp2p/go-msgio v0.3.0 // indirect
163 github.com/libp2p/go-nat v0.2.0 // indirect
164 github.com/libp2p/go-netroute v0.2.1 // indirect
go.sum
+2
@@ -545,6 +545,8 @@ 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=
550 github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
551 github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
552 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
test/cli/transports_test.go
+14
@@ -71,6 +71,20 @@ func TestTransports(t *testing.T) {
71 runTests(nodes)
72 })
73
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 +
88 t.Run("tcp with NOISE", func(t *testing.T) {
89 t.Parallel()
90 nodes := tcpNodes(t)