package dms3p2p import ( "fmt" quic "github.com/lucas-clemente/quic-go" config "gitlab.dms3.io/dms3/go-dms3-config" p2p "gitlab.dms3.io/p2p/go-p2p" metrics "gitlab.dms3.io/p2p/go-p2p-core/metrics" p2pquic "gitlab.dms3.io/p2p/go-p2p-quic-transport" tcp "gitlab.dms3.io/p2p/go-tcp-transport" websocket "gitlab.dms3.io/p2p/go-ws-transport" "go.uber.org/fx" ) // See https://gitlab.dms3.io/dms3/go-dms3/issues/7526 and // https://github.com/lucas-clemente/quic-go/releases/tag/v0.17.3. // TODO: remove this once the network has upgraded to > v0.6.0. func init() { quic.RetireBugBackwardsCompatibilityMode = true } func Transports(tptConfig config.Transports) interface{} { return func(pnet struct { fx.In Fprint PNetFingerprint `optional:"true"` }) (opts P2pOpts, err error) { privateNetworkEnabled := pnet.Fprint != nil if tptConfig.Network.TCP.WithDefault(true) { opts.Opts = append(opts.Opts, p2p.Transport(tcp.NewTCPTransport)) } if tptConfig.Network.Websocket.WithDefault(true) { opts.Opts = append(opts.Opts, p2p.Transport(websocket.New)) } if tptConfig.Network.QUIC.WithDefault(!privateNetworkEnabled) { if privateNetworkEnabled { // QUIC was force enabled while the private network was turned on. // Fail and tell the user. return opts, fmt.Errorf( "The QUIC transport does not support private networks. " + "Please disable Swarm.Transports.Network.QUIC.", ) } opts.Opts = append(opts.Opts, p2p.Transport(p2pquic.NewTransport)) } return opts, nil } } func BandwidthCounter() (opts P2pOpts, reporter *metrics.BandwidthCounter) { reporter = metrics.NewBandwidthCounter() opts.Opts = append(opts.Opts, p2p.BandwidthReporter(reporter)) return opts, reporter }