@cryptotaxi247 / kubo / commits / 6a51849c2

libp2p: remove mplex

Fixes: #10069

Jorropo committed Aug 22, 2023 at 14:21 UTC 6a51849c299dd991eb566cab42da0f7e15817d3c
12 files changed +23 -265
core/node/libp2p/internal/mplex/conn.go deleted
-49
@@ -1,49 +0,0 @@
1 -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/conn.go
2 -package mplex
3 -
4 -import (
5 - "context"
6 -
7 - "github.com/libp2p/go-libp2p/core/network"
8 -
9 - mp "github.com/libp2p/go-mplex"
10 -)
11 -
12 -type conn mp.Multiplex
13 -
14 -var _ network.MuxedConn = &conn{}
15 -
16 -// NewMuxedConn constructs a new Conn from a *mp.Multiplex.
17 -func NewMuxedConn(m *mp.Multiplex) network.MuxedConn {
18 - return (*conn)(m)
19 -}
20 -
21 -func (c *conn) Close() error {
22 - return c.mplex().Close()
23 -}
24 -
25 -func (c *conn) IsClosed() bool {
26 - return c.mplex().IsClosed()
27 -}
28 -
29 -// OpenStream creates a new stream.
30 -func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) {
31 - s, err := c.mplex().NewStream(ctx)
32 - if err != nil {
33 - return nil, err
34 - }
35 - return (*stream)(s), nil
36 -}
37 -
38 -// AcceptStream accepts a stream opened by the other side.
39 -func (c *conn) AcceptStream() (network.MuxedStream, error) {
40 - s, err := c.mplex().Accept()
41 - if err != nil {
42 - return nil, err
43 - }
44 - return (*stream)(s), nil
45 -}
46 -
47 -func (c *conn) mplex() *mp.Multiplex {
48 - return (*mp.Multiplex)(c)
49 -}
core/node/libp2p/internal/mplex/stream.go deleted
-65
@@ -1,65 +0,0 @@
1 -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/stream.go
2 -package mplex
3 -
4 -import (
5 - "time"
6 -
7 - "github.com/libp2p/go-libp2p/core/network"
8 -
9 - mp "github.com/libp2p/go-mplex"
10 -)
11 -
12 -// stream implements network.MuxedStream over mplex.Stream.
13 -type stream mp.Stream
14 -
15 -var _ network.MuxedStream = &stream{}
16 -
17 -func (s *stream) Read(b []byte) (n int, err error) {
18 - n, err = s.mplex().Read(b)
19 - if err == mp.ErrStreamReset {
20 - err = network.ErrReset
21 - }
22 -
23 - return n, err
24 -}
25 -
26 -func (s *stream) Write(b []byte) (n int, err error) {
27 - n, err = s.mplex().Write(b)
28 - if err == mp.ErrStreamReset {
29 - err = network.ErrReset
30 - }
31 -
32 - return n, err
33 -}
34 -
35 -func (s *stream) Close() error {
36 - return s.mplex().Close()
37 -}
38 -
39 -func (s *stream) CloseWrite() error {
40 - return s.mplex().CloseWrite()
41 -}
42 -
43 -func (s *stream) CloseRead() error {
44 - return s.mplex().CloseRead()
45 -}
46 -
47 -func (s *stream) Reset() error {
48 - return s.mplex().Reset()
49 -}
50 -
51 -func (s *stream) SetDeadline(t time.Time) error {
52 - return s.mplex().SetDeadline(t)
53 -}
54 -
55 -func (s *stream) SetReadDeadline(t time.Time) error {
56 - return s.mplex().SetReadDeadline(t)
57 -}
58 -
59 -func (s *stream) SetWriteDeadline(t time.Time) error {
60 - return s.mplex().SetWriteDeadline(t)
61 -}
62 -
63 -func (s *stream) mplex() *mp.Stream {
64 - return (*mp.Stream)(s)
65 -}
core/node/libp2p/internal/mplex/transport.go deleted
-29
@@ -1,29 +0,0 @@
1 -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/transport.go
2 -package mplex
3 -
4 -import (
5 - "net"
6 -
7 - "github.com/libp2p/go-libp2p/core/network"
8 -
9 - mp "github.com/libp2p/go-mplex"
10 -)
11 -
12 -// DefaultTransport has default settings for Transport
13 -var DefaultTransport = &Transport{}
14 -
15 -const ID = "/mplex/6.7.0"
16 -
17 -var _ network.Multiplexer = &Transport{}
18 -
19 -// Transport implements mux.Multiplexer that constructs
20 -// mplex-backed muxed connections.
21 -type Transport struct{}
22 -
23 -func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
24 - m, err := mp.NewMultiplex(nc, isServer, scope)
25 - if err != nil {
26 - return nil, err
27 - }
28 - return NewMuxedConn(m), nil
29 -}
core/node/libp2p/internal/mplex/transport_test.go deleted
-53
@@ -1,53 +0,0 @@
1 -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/transport_test.go
2 -package mplex
3 -
4 -import (
5 - "errors"
6 - "net"
7 - "testing"
8 -
9 - "github.com/libp2p/go-libp2p/core/network"
10 - test "github.com/libp2p/go-libp2p/p2p/muxer/testsuite"
11 -)
12 -
13 -func TestDefaultTransport(t *testing.T) {
14 - test.SubtestAll(t, DefaultTransport)
15 -}
16 -
17 -type memoryScope struct {
18 - network.PeerScope
19 - limit int
20 - reserved int
21 -}
22 -
23 -func (m *memoryScope) ReserveMemory(size int, prio uint8) error {
24 - if m.reserved+size > m.limit {
25 - return errors.New("too much")
26 - }
27 - m.reserved += size
28 - return nil
29 -}
30 -
31 -func (m *memoryScope) ReleaseMemory(size int) {
32 - m.reserved -= size
33 - if m.reserved < 0 {
34 - panic("too much memory released")
35 - }
36 -}
37 -
38 -type memoryLimitedTransport struct {
39 - Transport
40 -}
41 -
42 -func (t *memoryLimitedTransport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
43 - return t.Transport.NewConn(nc, isServer, &memoryScope{
44 - limit: 3 * 1 << 20,
45 - PeerScope: scope,
46 - })
47 -}
48 -
49 -func TestDefaultTransportWithMemoryLimit(t *testing.T) {
50 - test.SubtestAll(t, &memoryLimitedTransport{
51 - Transport: *DefaultTransport,
52 - })
53 -}
core/node/libp2p/smux.go
+9 -35
@@ -3,51 +3,25 @@ package libp2p
3 import (
4 "fmt"
5 "os"
6 - "strings"
6
7 "github.com/ipfs/kubo/config"
8
10 - "github.com/ipfs/kubo/core/node/libp2p/internal/mplex"
9 "github.com/libp2p/go-libp2p"
10 "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
11 )
12
13 func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
14 if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
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 -
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
15 + return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers")
16 + }
17 + if tptConfig.Multiplexers.Mplex != 0 {
18 + return nil, fmt.Errorf("Swarm.Transports.Multiplexers.Mplex is no longer supported, remove it from your config, see https://github.com/libp2p/specs/issues/553")
19 }
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
20 + if tptConfig.Multiplexers.Yamux < 0 {
21 + return nil, fmt.Errorf("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported")
22 + }
23 +
24 + return libp2p.Muxer(yamux.ID, yamux.DefaultTransport), nil
25 }
26
27 func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) {
docs/changelogs/v0.25.md
+11
@@ -7,6 +7,7 @@
7 - [Overview](#overview)
8 - [🔦 Highlights](#-highlights)
9 - [RPC `API.Authorizations`](#rpc-apiauthorizations)
10 + - [MPLEX removal](#mplex-removal)
11 - [Graphsync Experiment Removal](#graphsync-experiment-removal)
12 - [📝 Changelog](#-changelog)
13 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
@@ -28,6 +29,16 @@ This feature is opt-in. By default, no authorization is set up.
29 For configuration instructions,
30 refer to the [documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#apiauthorizations).
31
32 +#### MPLEX Removal
33 +
34 +After deprecating and removing mplex support by default in [v0.23.0](https://github.com/ipfs/kubo/blob/master/docs/changelogs/v0.23.md#mplex-deprecation).
35 +
36 +We now fully removed it. If you still need mplex support to talk with other pieces of software,
37 +please try updating them, and if they don't support yamux or QUIC [talk to us about it](https://github.com/ipfs/kubo/issues/new/choose).
38 +
39 +Mplex is unreliable by design, it will drop data and generete errors when sending data *too fast*,
40 +yamux and QUIC support backpressure, that means if we send data faster than the remote machine can process it, we slows down to match the remote's speed.
41 +
42 #### Graphsync Experiment Removal
43
44 Currently the Graphsync server is to our knowledge not used
docs/config.md
+3 -14
@@ -2253,21 +2253,10 @@ Type: `priority`
2253
2254 ### `Swarm.Transports.Multiplexers.Mplex`
2255
2256 -**DEPRECATED**: See https://github.com/ipfs/kubo/issues/9958
2256 +**REMOVED**: See https://github.com/ipfs/kubo/issues/9958
2257
2258 -Mplex is deprecated, this is because it is unreliable and
2259 -randomly drop streams when sending data *too fast*.
2260 -
2261 -New pieces of code rely on backpressure, that means the stream will dynamically
2262 -slow down the sending rate if data is getting backed up.
2263 -Backpressure is provided by **Yamux** and **QUIC**.
2264 -
2265 -If you want to turn it back on make sure to have a higher (lower is better)
2266 -priority than `Yamux`, you don't want your Kubo to start defaulting to Mplex.
2267 -
2268 -Default: `200`
2269 -
2270 -Type: `priority`
2258 +Support for Mplex has been [removed from Kubo and go-libp2p](https://github.com/libp2p/specs/issues/553).
2259 +Please remove this option from your config.
2260
2261 ## `DNS`
2262
docs/examples/kubo-as-a-library/go.mod
-1
@@ -108,7 +108,6 @@ require (
108 github.com/libp2p/go-libp2p-record v0.2.0 // indirect
109 github.com/libp2p/go-libp2p-routing-helpers v0.7.3 // indirect
110 github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
111 - github.com/libp2p/go-mplex v0.7.0 // indirect
111 github.com/libp2p/go-msgio v0.3.0 // indirect
112 github.com/libp2p/go-nat v0.2.0 // indirect
113 github.com/libp2p/go-netroute v0.2.1 // indirect
docs/examples/kubo-as-a-library/go.sum
-2
@@ -476,8 +476,6 @@ github.com/libp2p/go-libp2p-routing-helpers v0.7.3/go.mod h1:cN4mJAD/7zfPKXBcs9z
476 github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
477 github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
478 github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY=
479 -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
480 -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
479 github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
480 github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
481 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
go.mod
-1
@@ -55,7 +55,6 @@ require (
55 github.com/libp2p/go-libp2p-record v0.2.0
56 github.com/libp2p/go-libp2p-routing-helpers v0.7.3
57 github.com/libp2p/go-libp2p-testing v0.12.0
58 - github.com/libp2p/go-mplex v0.7.0
58 github.com/libp2p/go-socket-activation v0.1.0
59 github.com/mitchellh/go-homedir v1.1.0
60 github.com/multiformats/go-multiaddr v0.12.0
go.sum
-2
@@ -539,8 +539,6 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI
539 github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
540 github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA=
541 github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY=
542 -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
543 -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
542 github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
543 github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
544 github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
test/cli/transports_test.go
-14
@@ -72,20 +72,6 @@ func TestTransports(t *testing.T) {
72 runTests(nodes)
73 })
74
75 - t.Run("tcp with mplex", func(t *testing.T) {
76 - // FIXME(#10069): we don't want this to exists anymore
77 - t.Parallel()
78 - nodes := tcpNodes(t)
79 - nodes.ForEachPar(func(n *harness.Node) {
80 - n.UpdateConfig(func(cfg *config.Config) {
81 - cfg.Swarm.Transports.Multiplexers.Yamux = config.Disabled
82 - cfg.Swarm.Transports.Multiplexers.Mplex = 200
83 - })
84 - })
85 - nodes.StartDaemons().Connect()
86 - runTests(nodes)
87 - })
88 -
75 t.Run("tcp with NOISE", func(t *testing.T) {
76 t.Parallel()
77 nodes := tcpNodes(t)