From 40bea0e311789662fb00f79237793b16dab68af4 Mon Sep 17 00:00:00 2001 From: Vlad <13818348+walldiss@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:42:15 +0700 Subject: [PATCH] disable quic --- nodebuilder/p2p/addrs.go | 17 ++++++++++++++--- nodebuilder/p2p/host.go | 24 +++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/nodebuilder/p2p/addrs.go b/nodebuilder/p2p/addrs.go index 1a928e3be2..607d63c2bd 100644 --- a/nodebuilder/p2p/addrs.go +++ b/nodebuilder/p2p/addrs.go @@ -2,6 +2,7 @@ package p2p import ( "fmt" + "slices" p2pconfig "github.com/libp2p/go-libp2p/config" hst "github.com/libp2p/go-libp2p/core/host" @@ -11,12 +12,22 @@ import ( // Listen returns invoke function that starts listening for inbound connections with libp2p.Host. func Listen(cfg *Config) func(h hst.Host) (err error) { return func(h hst.Host) (err error) { - maListen := make([]ma.Multiaddr, len(cfg.ListenAddresses)) - for i, addr := range cfg.ListenAddresses { - maListen[i], err = ma.NewMultiaddr(addr) + maListen := make([]ma.Multiaddr, 0, len(cfg.ListenAddresses)) + for _, addr := range cfg.ListenAddresses { + maddr, err := ma.NewMultiaddr(addr) if err != nil { return fmt.Errorf("failure to parse config.P2P.ListenAddresses: %w", err) } + if !enableQUIC { + // TODO(@walldiss): Remove this check when QUIC is stable + if slices.ContainsFunc(maddr.Protocols(), func(p ma.Protocol) bool { + return p.Code == ma.P_QUIC_V1 || p.Code == ma.P_WEBTRANSPORT + }) { + continue + } + } + + maListen = append(maListen, maddr) } return h.Network().Listen(maListen...) } diff --git a/nodebuilder/p2p/host.go b/nodebuilder/p2p/host.go index 1003970199..c38713f6a3 100644 --- a/nodebuilder/p2p/host.go +++ b/nodebuilder/p2p/host.go @@ -3,6 +3,7 @@ package p2p import ( "context" "fmt" + "os" "strings" "github.com/libp2p/go-libp2p" @@ -27,6 +28,8 @@ import ( "github.com/celestiaorg/celestia-node/nodebuilder/node" ) +var enableQUIC = os.Getenv("CELESTIA_ENABLE_QUIC") == "1" + // routedHost constructs a wrapped Host that may fallback to address discovery, // if any top-level operation on the Host is provided with PeerID(Hash(PbK)) only. func routedHost(base HostBase, r routing.PeerRouting) hst.Host { @@ -80,6 +83,19 @@ func host(params hostParams) (HostBase, error) { params.Cfg.Upgrade() } + transports := []libp2p.Option{ + libp2p.Transport(tcp.NewTCPTransport), + libp2p.Transport(libp2pwebrtc.New), + wsTransport(tlsCfg), + } + + // disable quic and webtransport client support until it is stable + if enableQUIC { + transports = append(transports, + libp2p.Transport(quic.NewTransport), + libp2p.Transport(webtransport.New)) + } + opts := []libp2p.Option{ libp2p.NoListenAddrs, // do not listen automatically libp2p.AddrsFactory(params.AddrF), @@ -92,13 +108,7 @@ func host(params hostParams) (HostBase, error) { libp2p.DisableRelay(), libp2p.BandwidthReporter(params.Bandwidth), libp2p.ResourceManager(params.ResourceManager), - libp2p.ChainOptions( - libp2p.Transport(tcp.NewTCPTransport), - libp2p.Transport(quic.NewTransport), - libp2p.Transport(webtransport.New), - libp2p.Transport(libp2pwebrtc.New), - wsTransport(tlsCfg), - ), + libp2p.ChainOptions(transports...), // to clearly define what defaults we rely upon libp2p.DefaultSecurity, libp2p.DefaultMuxers,