| 1 | package libp2p |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "os" |
| 6 | |
| 7 | "github.com/ipfs/kubo/config" |
| 8 | |
| 9 | "github.com/libp2p/go-libp2p" |
| 10 | "github.com/libp2p/go-libp2p/p2p/muxer/yamux" |
| 11 | ) |
| 12 | |
| 13 | func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) { |
| 14 | if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" { |
| 15 | return nil, errors.New("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers") |
| 16 | } |
| 17 | if tptConfig.Multiplexers.Yamux < 0 { |
| 18 | return nil, errors.New("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported") |
| 19 | } |
| 20 | |
| 21 | return libp2p.Muxer(yamux.ID, yamux.DefaultTransport), nil |
| 22 | } |
| 23 | |
| 24 | func SmuxTransport(tptConfig config.Transports) func() (opts Libp2pOpts, err error) { |
| 25 | return func() (opts Libp2pOpts, err error) { |
| 26 | res, err := makeSmuxTransportOption(tptConfig) |
| 27 | if err != nil { |
| 28 | return opts, err |
| 29 | } |
| 30 | opts.Opts = append(opts.Opts, res) |
| 31 | return opts, nil |
| 32 | } |
| 33 | } |