diff --git a/core/node/libp2p/internal/mplex/conn.go b/core/node/libp2p/internal/mplex/conn.go deleted file mode 100644 index 4a6ca87c389f..000000000000 --- a/core/node/libp2p/internal/mplex/conn.go +++ /dev/null @@ -1,49 +0,0 @@ -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/conn.go -package mplex - -import ( - "context" - - "github.com/libp2p/go-libp2p/core/network" - - mp "github.com/libp2p/go-mplex" -) - -type conn mp.Multiplex - -var _ network.MuxedConn = &conn{} - -// NewMuxedConn constructs a new Conn from a *mp.Multiplex. -func NewMuxedConn(m *mp.Multiplex) network.MuxedConn { - return (*conn)(m) -} - -func (c *conn) Close() error { - return c.mplex().Close() -} - -func (c *conn) IsClosed() bool { - return c.mplex().IsClosed() -} - -// OpenStream creates a new stream. -func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) { - s, err := c.mplex().NewStream(ctx) - if err != nil { - return nil, err - } - return (*stream)(s), nil -} - -// AcceptStream accepts a stream opened by the other side. -func (c *conn) AcceptStream() (network.MuxedStream, error) { - s, err := c.mplex().Accept() - if err != nil { - return nil, err - } - return (*stream)(s), nil -} - -func (c *conn) mplex() *mp.Multiplex { - return (*mp.Multiplex)(c) -} diff --git a/core/node/libp2p/internal/mplex/stream.go b/core/node/libp2p/internal/mplex/stream.go deleted file mode 100644 index 34d9cfb14afb..000000000000 --- a/core/node/libp2p/internal/mplex/stream.go +++ /dev/null @@ -1,65 +0,0 @@ -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/stream.go -package mplex - -import ( - "time" - - "github.com/libp2p/go-libp2p/core/network" - - mp "github.com/libp2p/go-mplex" -) - -// stream implements network.MuxedStream over mplex.Stream. -type stream mp.Stream - -var _ network.MuxedStream = &stream{} - -func (s *stream) Read(b []byte) (n int, err error) { - n, err = s.mplex().Read(b) - if err == mp.ErrStreamReset { - err = network.ErrReset - } - - return n, err -} - -func (s *stream) Write(b []byte) (n int, err error) { - n, err = s.mplex().Write(b) - if err == mp.ErrStreamReset { - err = network.ErrReset - } - - return n, err -} - -func (s *stream) Close() error { - return s.mplex().Close() -} - -func (s *stream) CloseWrite() error { - return s.mplex().CloseWrite() -} - -func (s *stream) CloseRead() error { - return s.mplex().CloseRead() -} - -func (s *stream) Reset() error { - return s.mplex().Reset() -} - -func (s *stream) SetDeadline(t time.Time) error { - return s.mplex().SetDeadline(t) -} - -func (s *stream) SetReadDeadline(t time.Time) error { - return s.mplex().SetReadDeadline(t) -} - -func (s *stream) SetWriteDeadline(t time.Time) error { - return s.mplex().SetWriteDeadline(t) -} - -func (s *stream) mplex() *mp.Stream { - return (*mp.Stream)(s) -} diff --git a/core/node/libp2p/internal/mplex/transport.go b/core/node/libp2p/internal/mplex/transport.go deleted file mode 100644 index e7df384b9ded..000000000000 --- a/core/node/libp2p/internal/mplex/transport.go +++ /dev/null @@ -1,29 +0,0 @@ -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/transport.go -package mplex - -import ( - "net" - - "github.com/libp2p/go-libp2p/core/network" - - mp "github.com/libp2p/go-mplex" -) - -// DefaultTransport has default settings for Transport -var DefaultTransport = &Transport{} - -const ID = "/mplex/6.7.0" - -var _ network.Multiplexer = &Transport{} - -// Transport implements mux.Multiplexer that constructs -// mplex-backed muxed connections. -type Transport struct{} - -func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) { - m, err := mp.NewMultiplex(nc, isServer, scope) - if err != nil { - return nil, err - } - return NewMuxedConn(m), nil -} diff --git a/core/node/libp2p/internal/mplex/transport_test.go b/core/node/libp2p/internal/mplex/transport_test.go deleted file mode 100644 index 1e3a1dec9e8b..000000000000 --- a/core/node/libp2p/internal/mplex/transport_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// Code copied from https://github.com/libp2p/go-libp2p/blob/9bd85029550a084fca63ec6ff9184122cdf06591/p2p/muxer/mplex/transport_test.go -package mplex - -import ( - "errors" - "net" - "testing" - - "github.com/libp2p/go-libp2p/core/network" - test "github.com/libp2p/go-libp2p/p2p/muxer/testsuite" -) - -func TestDefaultTransport(t *testing.T) { - test.SubtestAll(t, DefaultTransport) -} - -type memoryScope struct { - network.PeerScope - limit int - reserved int -} - -func (m *memoryScope) ReserveMemory(size int, prio uint8) error { - if m.reserved+size > m.limit { - return errors.New("too much") - } - m.reserved += size - return nil -} - -func (m *memoryScope) ReleaseMemory(size int) { - m.reserved -= size - if m.reserved < 0 { - panic("too much memory released") - } -} - -type memoryLimitedTransport struct { - Transport -} - -func (t *memoryLimitedTransport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) { - return t.Transport.NewConn(nc, isServer, &memoryScope{ - limit: 3 * 1 << 20, - PeerScope: scope, - }) -} - -func TestDefaultTransportWithMemoryLimit(t *testing.T) { - test.SubtestAll(t, &memoryLimitedTransport{ - Transport: *DefaultTransport, - }) -} diff --git a/core/node/libp2p/smux.go b/core/node/libp2p/smux.go index 0966dfaf2564..a276b5ddc163 100644 --- a/core/node/libp2p/smux.go +++ b/core/node/libp2p/smux.go @@ -3,51 +3,25 @@ package libp2p import ( "fmt" "os" - "strings" "github.com/ipfs/kubo/config" - "github.com/ipfs/kubo/core/node/libp2p/internal/mplex" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/p2p/muxer/yamux" ) func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) { if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" { - // Using legacy LIBP2P_MUX_PREFS variable. - log.Error("LIBP2P_MUX_PREFS is now deprecated.") - log.Error("Use the `Swarm.Transports.Multiplexers' config field.") - muxers := strings.Fields(prefs) - enabled := make(map[string]bool, len(muxers)) - - var opts []libp2p.Option - for _, tpt := range muxers { - if enabled[tpt] { - return nil, fmt.Errorf( - "duplicate muxer found in LIBP2P_MUX_PREFS: %s", - tpt, - ) - } - switch tpt { - case yamux.ID: - opts = append(opts, libp2p.Muxer(tpt, yamux.DefaultTransport)) - case mplex.ID: - opts = append(opts, libp2p.Muxer(tpt, mplex.DefaultTransport)) - default: - return nil, fmt.Errorf("unknown muxer: %s", tpt) - } - } - return libp2p.ChainOptions(opts...), nil + return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers") + } + if tptConfig.Multiplexers.Mplex != 0 { + 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") } - return prioritizeOptions([]priorityOption{{ - priority: tptConfig.Multiplexers.Yamux, - defaultPriority: 100, - opt: libp2p.Muxer(yamux.ID, yamux.DefaultTransport), - }, { - priority: tptConfig.Multiplexers.Mplex, - defaultPriority: config.Disabled, - opt: libp2p.Muxer(mplex.ID, mplex.DefaultTransport), - }}), nil + if tptConfig.Multiplexers.Yamux < 0 { + return nil, fmt.Errorf("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported") + } + + return libp2p.Muxer(yamux.ID, yamux.DefaultTransport), nil } func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) { diff --git a/docs/changelogs/v0.25.md b/docs/changelogs/v0.25.md index 98e2a04f9d4b..b4945758a1c7 100644 --- a/docs/changelogs/v0.25.md +++ b/docs/changelogs/v0.25.md @@ -7,6 +7,7 @@ - [Overview](#overview) - [๐Ÿ”ฆ Highlights](#-highlights) - [RPC `API.Authorizations`](#rpc-apiauthorizations) + - [MPLEX removal](#mplex-removal) - [Graphsync Experiment Removal](#graphsync-experiment-removal) - [๐Ÿ“ Changelog](#-changelog) - [๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors](#-contributors) @@ -28,6 +29,16 @@ This feature is opt-in. By default, no authorization is set up. For configuration instructions, refer to the [documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#apiauthorizations). +#### MPLEX Removal + +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). + +We now fully removed it. If you still need mplex support to talk with other pieces of software, +please try updating them, and if they don't support yamux or QUIC talk to us about it. + +Mplex is unreliable by design, it will drop data and generete errors when sending data *too fast*, +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. + #### Graphsync Experiment Removal Currently the Graphsync server is to our knowledge not used diff --git a/docs/config.md b/docs/config.md index 0b33fa3fdcf8..df35d2ce87ee 100644 --- a/docs/config.md +++ b/docs/config.md @@ -2253,21 +2253,10 @@ Type: `priority` ### `Swarm.Transports.Multiplexers.Mplex` -**DEPRECATED**: See https://github.com/ipfs/kubo/issues/9958 +**REMOVED**: See https://github.com/ipfs/kubo/issues/9958 -Mplex is deprecated, this is because it is unreliable and -randomly drop streams when sending data *too fast*. - -New pieces of code rely on backpressure, that means the stream will dynamically -slow down the sending rate if data is getting backed up. -Backpressure is provided by **Yamux** and **QUIC**. - -If you want to turn it back on make sure to have a higher (lower is better) -priority than `Yamux`, you don't want your Kubo to start defaulting to Mplex. - -Default: `200` - -Type: `priority` +Support for Mplex has been [removed from Kubo and go-libp2p](https://github.com/libp2p/specs/issues/553). +Please remove this option from your config. ## `DNS` diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index d930f99fbf8f..7b2e4e1bdd8e 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -108,7 +108,6 @@ require ( github.com/libp2p/go-libp2p-record v0.2.0 // indirect github.com/libp2p/go-libp2p-routing-helpers v0.7.3 // indirect github.com/libp2p/go-libp2p-xor v0.1.0 // indirect - github.com/libp2p/go-mplex v0.7.0 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index 1dc80d229728..a15178ee24ed 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -476,8 +476,6 @@ github.com/libp2p/go-libp2p-routing-helpers v0.7.3/go.mod h1:cN4mJAD/7zfPKXBcs9z github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA= github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY= -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY= -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= diff --git a/go.mod b/go.mod index 6b114c9f75f7..6832b4091fed 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,6 @@ require ( github.com/libp2p/go-libp2p-record v0.2.0 github.com/libp2p/go-libp2p-routing-helpers v0.7.3 github.com/libp2p/go-libp2p-testing v0.12.0 - github.com/libp2p/go-mplex v0.7.0 github.com/libp2p/go-socket-activation v0.1.0 github.com/mitchellh/go-homedir v1.1.0 github.com/multiformats/go-multiaddr v0.12.0 diff --git a/go.sum b/go.sum index a28c6ab3b030..fbf947edc471 100644 --- a/go.sum +++ b/go.sum @@ -539,8 +539,6 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA= github.com/libp2p/go-libp2p-xor v0.1.0/go.mod h1:LSTM5yRnjGZbWNTA/hRwq2gGFrvRIbQJscoIL/u6InY= -github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY= -github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM= diff --git a/test/cli/transports_test.go b/test/cli/transports_test.go index c1642c602cdd..a523351816da 100644 --- a/test/cli/transports_test.go +++ b/test/cli/transports_test.go @@ -72,20 +72,6 @@ func TestTransports(t *testing.T) { runTests(nodes) }) - t.Run("tcp with mplex", func(t *testing.T) { - // FIXME(#10069): we don't want this to exists anymore - t.Parallel() - nodes := tcpNodes(t) - nodes.ForEachPar(func(n *harness.Node) { - n.UpdateConfig(func(cfg *config.Config) { - cfg.Swarm.Transports.Multiplexers.Yamux = config.Disabled - cfg.Swarm.Transports.Multiplexers.Mplex = 200 - }) - }) - nodes.StartDaemons().Connect() - runTests(nodes) - }) - t.Run("tcp with NOISE", func(t *testing.T) { t.Parallel() nodes := tcpNodes(t)