Skip to content

Commit

Permalink
Expose muxer ids (#2012)
Browse files Browse the repository at this point in the history
* docs: remove documentation indicating that mplex is enabled by default

* feat: expose yamux ID as a constant

* feat: expose mplex ID as a constant

* reword muxer config documentation

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
  • Loading branch information
aschmahmann and marten-seemann committed Jan 25, 2023
1 parent 084de06 commit d5a280e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var DefaultSecurity = ChainOptions(
//
// Use this option when you want to *extend* the set of multiplexers used by
// libp2p instead of replacing them.
var DefaultMuxers = Muxer("/yamux/1.0.0", yamux.DefaultTransport)
var DefaultMuxers = Muxer(yamux.ID, yamux.DefaultTransport)

// DefaultTransports are the default libp2p transports.
//
Expand Down
3 changes: 1 addition & 2 deletions libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func ChainOptions(opts ...Option) Option {
// transport protocols;
//
// - If no multiplexer configuration is provided, the node is configured by
// default to use the "yamux/1.0.0" and "mplux/6.7.0" stream connection
// multiplexers;
// default to use yamux;
//
// - If no security transport is provided, the host uses the go-libp2p's noise
// and/or tls encrypted transport to encrypt all traffic;
Expand Down
2 changes: 2 additions & 0 deletions p2p/muxer/mplex/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
// 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
Expand Down
2 changes: 2 additions & 0 deletions p2p/muxer/yamux/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

var DefaultTransport *Transport

const ID = "/yamux/1.0.0"

func init() {
config := yamux.DefaultConfig()
// We've bumped this to 16MiB as this critically limits throughput.
Expand Down
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 @@ -82,7 +82,7 @@ func makeUpgrader(t *testing.T, n *Swarm) transport.Upgrader {
pk := n.Peerstore().PrivKey(id)
st := insecure.NewWithIdentity(insecure.ID, id, pk)

u, err := tptu.New([]sec.SecureTransport{st}, []tptu.StreamMuxer{{ID: "/yamux/1.0.0", Muxer: yamux.DefaultTransport}}, nil, nil, nil)
u, err := tptu.New([]sec.SecureTransport{st}, []tptu.StreamMuxer{{ID: yamux.ID, Muxer: yamux.DefaultTransport}}, nil, nil, nil)
require.NoError(t, err)
return u
}
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 @@ -105,7 +105,7 @@ func GenUpgrader(t *testing.T, n *swarm.Swarm, connGater connmgr.ConnectionGater
pk := n.Peerstore().PrivKey(id)
st := insecure.NewWithIdentity(insecure.ID, id, pk)

u, err := tptu.New([]sec.SecureTransport{st}, []tptu.StreamMuxer{{ID: "/yamux/1.0.0", Muxer: yamux.DefaultTransport}}, nil, nil, connGater, opts...)
u, err := tptu.New([]sec.SecureTransport{st}, []tptu.StreamMuxer{{ID: yamux.ID, Muxer: yamux.DefaultTransport}}, nil, nil, connGater, opts...)
require.NoError(t, err)
return u
}
Expand Down
4 changes: 2 additions & 2 deletions test-plans/cmd/ping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func main() {

switch muxer {
case "yamux":
options = append(options, libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport))
options = append(options, libp2p.Muxer(yamux.ID, yamux.DefaultTransport))
case "mplex":
options = append(options, libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport))
options = append(options, libp2p.Muxer(mplex.ID, mplex.DefaultTransport))
case "quic":
default:
log.Fatalf("Unsupported muxer: %s", muxer)
Expand Down

0 comments on commit d5a280e

Please sign in to comment.