Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move go-libp2p-yamux here #1439

Merged
merged 41 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
62cf611
extracted from go-peerstream
jbenet Jul 12, 2015
de05b59
fixed urls
jbenet Jul 12, 2015
59832ab
links fix
jbenet Jul 12, 2015
d42b661
implement AcceptStream
jbenet Jul 12, 2015
4332c8d
gxify and update deps
whyrusleeping May 2, 2016
3a964c3
rewrite paths to gx versions
whyrusleeping May 4, 2016
c6d96a9
gx publish version 1.0.0
whyrusleeping May 13, 2016
2fc370b
add deadline methods to stream
whyrusleeping Nov 7, 2016
bae0cbc
cleanup and change import
whyrusleeping Jul 16, 2017
3576d5e
go-stream-muxer has moved to libp2p
Stebalien Aug 18, 2017
8ae55cf
Merge pull request #6 from Stebalien/fix/stream-muxer-owner
Stebalien Aug 18, 2017
a258c50
remove conn.Serve
marten-seemann Jul 19, 2017
5ee63c6
Merge pull request #5 from marten-seemann/master
Stebalien Aug 24, 2017
c31fdfd
bump the stream window size to 1MiB
Stebalien Sep 25, 2018
556a36a
Merge pull request #9 from whyrusleeping/fix/increase-stream-window
Stebalien Sep 26, 2018
444e14b
bump window size to 16MiB
vyzo Mar 5, 2019
7a70e76
copy default config, initialize coalesce delay
vyzo May 21, 2019
aaa6b59
Merge pull request #12 from vyzo/feat/write-coalesce-delay
Stebalien May 21, 2019
88c1e0e
fix: unused import
Stebalien May 21, 2019
c35c511
migrate to libp2p org
Stebalien May 22, 2019
a59b684
fix: don't buffer reads
Stebalien May 22, 2019
f73d3f6
Merge pull request #1 from libp2p/fix/no-read-buffer
Stebalien May 22, 2019
cb81de4
migrate to consolidated types; add travis config. (#2)
raulk May 26, 2019
2a0c987
restructure files layout
Wondertan Feb 28, 2020
df4c879
redefine yamux stream to implement mux.MuxedStream and to respect mux…
Wondertan Feb 28, 2020
f5d58ef
revert Multiplexer name back to Transport
Wondertan Feb 28, 2020
3416b29
use explicit return values
Wondertan Mar 2, 2020
846e4ef
update go-yamux
Wondertan Mar 3, 2020
aa1de9a
feat: update to new stream interfaces
Stebalien Sep 2, 2020
f47682a
Merge pull request #27 from libp2p/feat/update-stream-interface
Stebalien Sep 2, 2020
d916bc6
change OpenStream to accept a context
marten-seemann Dec 17, 2020
6d4f899
Merge pull request #29 from libp2p/open-stream-context
marten-seemann Dec 19, 2020
07602f6
update go-yamux to v2.0.0, use context passed to OpenStream
marten-seemann Dec 19, 2020
f3029b6
Merge pull request #31 from libp2p/update-yamux
marten-seemann Dec 19, 2020
6f15910
reduce the number of max incoming stream to 256
marten-seemann Dec 10, 2021
090ba44
disable the 1000 streams test
marten-seemann Dec 10, 2021
c0a8ac8
Merge pull request #41 from libp2p/reduce-streams
marten-seemann Dec 12, 2021
ba15ca1
pass the PeerScope to yamux (satifiying its MemoryManger interface) (…
marten-seemann Jan 17, 2022
af478a9
disable the incoming streams limit (#49)
marten-seemann Feb 8, 2022
24e313b
move go-lipbp2-yamux here
marten-seemann Apr 22, 2022
f3bdb4b
switch from github.com/libp2p/go-libp2p-yamux to p2p/muxer/yamux
marten-seemann Apr 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/muxer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"testing"

bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"

yamux "github.com/libp2p/go-libp2p-yamux"
)

func TestMuxerSimple(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package libp2p
import (
"crypto/rand"

yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
tls "github.com/libp2p/go-libp2p-tls"
yamux "github.com/libp2p/go-libp2p-yamux"
"github.com/multiformats/go-multiaddr"
)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ require (
github.com/libp2p/go-libp2p-testing v0.9.2
github.com/libp2p/go-libp2p-tls v0.4.1
github.com/libp2p/go-libp2p-transport-upgrader v0.7.1
github.com/libp2p/go-libp2p-yamux v0.9.1
github.com/libp2p/go-msgio v0.2.0
github.com/libp2p/go-netroute v0.2.0
github.com/libp2p/go-reuseport v0.1.0
github.com/libp2p/go-reuseport-transport v0.1.0
github.com/libp2p/go-stream-muxer-multistream v0.4.0
github.com/libp2p/go-yamux/v3 v3.1.1
github.com/libp2p/zeroconf/v2 v2.1.1
github.com/lucas-clemente/quic-go v0.27.0
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
Expand Down Expand Up @@ -85,11 +85,11 @@ require (
github.com/libp2p/go-libp2p-pnet v0.2.0 // indirect
github.com/libp2p/go-libp2p-quic-transport v0.17.0 // indirect
github.com/libp2p/go-libp2p-swarm v0.10.2 // indirect
github.com/libp2p/go-libp2p-yamux v0.9.1 // indirect
github.com/libp2p/go-mplex v0.4.0 // indirect
github.com/libp2p/go-nat v0.1.0 // indirect
github.com/libp2p/go-openssl v0.0.7 // indirect
github.com/libp2p/go-tcp-transport v0.5.1 // indirect
github.com/libp2p/go-yamux/v3 v3.1.1 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.1 // indirect
Expand Down
44 changes: 44 additions & 0 deletions p2p/muxer/yamux/conn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package sm_yamux

import (
"context"

"github.com/libp2p/go-libp2p-core/network"

"github.com/libp2p/go-yamux/v3"
)

// conn implements mux.MuxedConn over yamux.Session.
type conn yamux.Session

var _ network.MuxedConn = &conn{}

// Close closes underlying yamux
func (c *conn) Close() error {
return c.yamux().Close()
}

// IsClosed checks if yamux.Session is in closed state.
func (c *conn) IsClosed() bool {
return c.yamux().IsClosed()
}

// OpenStream creates a new stream.
func (c *conn) OpenStream(ctx context.Context) (network.MuxedStream, error) {
s, err := c.yamux().OpenStream(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.yamux().AcceptStream()
return (*stream)(s), err
}

func (c *conn) yamux() *yamux.Session {
return (*yamux.Session)(c)
}
64 changes: 64 additions & 0 deletions p2p/muxer/yamux/stream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package sm_yamux

import (
"time"

"github.com/libp2p/go-libp2p-core/network"

"github.com/libp2p/go-yamux/v3"
)

// stream implements mux.MuxedStream over yamux.Stream.
type stream yamux.Stream

var _ network.MuxedStream = &stream{}

func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.yamux().Read(b)
if err == yamux.ErrStreamReset {
err = network.ErrReset
}

return n, err
}

func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.yamux().Write(b)
if err == yamux.ErrStreamReset {
err = network.ErrReset
}

return n, err
}

func (s *stream) Close() error {
return s.yamux().Close()
}

func (s *stream) Reset() error {
return s.yamux().Reset()
}

func (s *stream) CloseRead() error {
return s.yamux().CloseRead()
}

func (s *stream) CloseWrite() error {
return s.yamux().CloseWrite()
}

func (s *stream) SetDeadline(t time.Time) error {
return s.yamux().SetDeadline(t)
}

func (s *stream) SetReadDeadline(t time.Time) error {
return s.yamux().SetReadDeadline(t)
}

func (s *stream) SetWriteDeadline(t time.Time) error {
return s.yamux().SetWriteDeadline(t)
}

func (s *stream) yamux() *yamux.Stream {
return (*yamux.Stream)(s)
}
53 changes: 53 additions & 0 deletions p2p/muxer/yamux/transport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package sm_yamux

import (
"io/ioutil"
"math"
"net"

"github.com/libp2p/go-libp2p-core/network"

"github.com/libp2p/go-yamux/v3"
)

var DefaultTransport *Transport

func init() {
config := yamux.DefaultConfig()
// We've bumped this to 16MiB as this critically limits throughput.
//
// 1MiB means a best case of 10MiB/s (83.89Mbps) on a connection with
// 100ms latency. The default gave us 2.4MiB *best case* which was
// totally unacceptable.
config.MaxStreamWindowSize = uint32(16 * 1024 * 1024)
// don't spam
config.LogOutput = ioutil.Discard
// We always run over a security transport that buffers internally
// (i.e., uses a block cipher).
config.ReadBufSize = 0
// Effectively disable the incoming streams limit.
// This is now dynamically limited by the resource manager.
config.MaxIncomingStreams = math.MaxUint32
DefaultTransport = (*Transport)(config)
}

// Transport implements mux.Multiplexer that constructs
// yamux-backed muxed connections.
type Transport yamux.Config

var _ network.Multiplexer = &Transport{}

func (t *Transport) NewConn(nc net.Conn, isServer bool, scope network.PeerScope) (network.MuxedConn, error) {
var s *yamux.Session
var err error
if isServer {
s, err = yamux.Server(nc, t.Config(), scope)
} else {
s, err = yamux.Client(nc, t.Config(), scope)
}
return (*conn)(s), err
}

func (t *Transport) Config() *yamux.Config {
return (*yamux.Config)(t)
}
15 changes: 15 additions & 0 deletions p2p/muxer/yamux/transport_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sm_yamux

import (
"testing"

tmux "github.com/libp2p/go-libp2p-testing/suites/mux"
)

func TestDefaultTransport(t *testing.T) {
// Yamux doesn't have any backpressure when it comes to opening streams.
// If the peer opens too many streams, those are just reset.
delete(tmux.Subtests, "github.com/libp2p/go-libp2p-testing/suites/mux.SubtestStress1Conn1000Stream10Msg")

tmux.SubtestAll(t, DefaultTransport)
}
2 changes: 1 addition & 1 deletion p2p/net/swarm/dial_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"

Expand All @@ -19,7 +20,6 @@ import (
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
tnet "github.com/libp2p/go-libp2p-testing/net"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
yamux "github.com/libp2p/go-libp2p-yamux"
msmux "github.com/libp2p/go-stream-muxer-multistream"
ma "github.com/multiformats/go-multiaddr"

Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

yamux "github.com/libp2p/go-libp2p/p2p/muxer/yamux"
"github.com/libp2p/go-libp2p/p2p/net/swarm"
quic "github.com/libp2p/go-libp2p/p2p/transport/quic"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
tnet "github.com/libp2p/go-libp2p-testing/net"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
yamux "github.com/libp2p/go-libp2p-yamux"
msmux "github.com/libp2p/go-stream-muxer-multistream"
ma "github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
Expand Down