kubo/core/node/libp2p/smux.go
Andi 642e58ef3b
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Build / docker-build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / go-test (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
chore: use errors.New to replace fmt.Errorf with no parameters (#10617)
2024-12-10 13:50:35 -08:00

34 lines
926 B
Go

package libp2p
import (
"errors"
"os"
"github.com/ipfs/kubo/config"
"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 != "" {
return nil, errors.New("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers")
}
if tptConfig.Multiplexers.Yamux < 0 {
return nil, errors.New("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) {
return func() (opts Libp2pOpts, err error) {
res, err := makeSmuxTransportOption(tptConfig)
if err != nil {
return opts, err
}
opts.Opts = append(opts.Opts, res)
return opts, nil
}
}