Merge pull request #7689 from filecoin-project/disable-mplex

disable mplex stream muxer
This commit is contained in:
Steven Allen 2021-11-29 09:46:24 -08:00 committed by GitHub
commit 797147097c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 32 deletions

1
go.mod
View File

@ -110,7 +110,6 @@ require (
github.com/libp2p/go-libp2p-core v0.9.0 github.com/libp2p/go-libp2p-core v0.9.0
github.com/libp2p/go-libp2p-discovery v0.5.1 github.com/libp2p/go-libp2p-discovery v0.5.1
github.com/libp2p/go-libp2p-kad-dht v0.13.0 github.com/libp2p/go-libp2p-kad-dht v0.13.0
github.com/libp2p/go-libp2p-mplex v0.4.1
github.com/libp2p/go-libp2p-noise v0.2.2 github.com/libp2p/go-libp2p-noise v0.2.2
github.com/libp2p/go-libp2p-peerstore v0.3.0 github.com/libp2p/go-libp2p-peerstore v0.3.0
github.com/libp2p/go-libp2p-pubsub v0.5.6 github.com/libp2p/go-libp2p-pubsub v0.5.6

View File

@ -177,7 +177,7 @@ var LibP2P = Options(
// Host settings // Host settings
Override(DefaultTransportsKey, lp2p.DefaultTransports), Override(DefaultTransportsKey, lp2p.DefaultTransports),
Override(AddrsFactoryKey, lp2p.AddrsFactory(nil, nil)), Override(AddrsFactoryKey, lp2p.AddrsFactory(nil, nil)),
Override(SmuxTransportKey, lp2p.SmuxTransport(true)), Override(SmuxTransportKey, lp2p.SmuxTransport()),
Override(RelayKey, lp2p.NoRelay()), Override(RelayKey, lp2p.NoRelay()),
Override(SecurityKey, lp2p.Security(true, false)), Override(SecurityKey, lp2p.Security(true, false)),

View File

@ -2,17 +2,13 @@ package lp2p
import ( import (
"os" "os"
"strings"
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
smux "github.com/libp2p/go-libp2p-core/mux"
mplex "github.com/libp2p/go-libp2p-mplex"
yamux "github.com/libp2p/go-libp2p-yamux" yamux "github.com/libp2p/go-libp2p-yamux"
) )
func makeSmuxTransportOption(mplexExp bool) libp2p.Option { func makeSmuxTransportOption() libp2p.Option {
const yamuxID = "/yamux/1.0.0" const yamuxID = "/yamux/1.0.0"
const mplexID = "/mplex/6.7.0"
ymxtpt := *yamux.DefaultTransport ymxtpt := *yamux.DefaultTransport
ymxtpt.AcceptBacklog = 512 ymxtpt.AcceptBacklog = 512
@ -21,34 +17,12 @@ func makeSmuxTransportOption(mplexExp bool) libp2p.Option {
ymxtpt.LogOutput = os.Stderr ymxtpt.LogOutput = os.Stderr
} }
muxers := map[string]smux.Multiplexer{yamuxID: &ymxtpt} return libp2p.Muxer(yamuxID, &ymxtpt)
if mplexExp {
muxers[mplexID] = mplex.DefaultTransport
}
// Allow muxer preference order overriding
order := []string{yamuxID, mplexID}
if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
order = strings.Fields(prefs)
}
opts := make([]libp2p.Option, 0, len(order))
for _, id := range order {
tpt, ok := muxers[id]
if !ok {
log.Warnf("unknown or duplicate muxer in LIBP2P_MUX_PREFS: %s", id)
continue
}
delete(muxers, id)
opts = append(opts, libp2p.Muxer(id, tpt))
}
return libp2p.ChainOptions(opts...)
} }
func SmuxTransport(mplex bool) func() (opts Libp2pOpts, err error) { func SmuxTransport() func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) { return func() (opts Libp2pOpts, err error) {
opts.Opts = append(opts.Opts, makeSmuxTransportOption(mplex)) opts.Opts = append(opts.Opts, makeSmuxTransportOption())
return return
} }
} }