From 5da84975bf609d81bb0dac8335083e87e03c9571 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 3 Feb 2023 17:13:56 -0800 Subject: [PATCH] quic: disable sending of Version Negotiation packets (#2015) --- p2p/test/quic/quic_test.go | 11 ++++++++--- p2p/transport/quicreuse/config.go | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/p2p/test/quic/quic_test.go b/p2p/test/quic/quic_test.go index 1806fa6d7e..57c28be369 100644 --- a/p2p/test/quic/quic_test.go +++ b/p2p/test/quic/quic_test.go @@ -3,6 +3,7 @@ package quic_test import ( "context" "testing" + "time" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/network" @@ -99,9 +100,13 @@ func TestDisableQUICDraft29(t *testing.T) { ) require.NoError(t, err) defer h2.Close() - require.ErrorContains(t, - h2.Connect(context.Background(), peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/udp/12346/quic")}}), - "no compatible QUIC version found", + // We disabled QUIC Version Negotiation, so we will _not_ receive a Version Negotiation packet. + // Instead, the connection will run into the context timeout. + ctx, cancel := context.WithTimeout(context.Background(), 300*time.Microsecond) + defer cancel() + require.ErrorIs(t, + h2.Connect(ctx, peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/udp/12346/quic")}}), + context.DeadlineExceeded, ) // make sure that dialing QUIC v1 works require.NoError(t, h2.Connect(context.Background(), peer.AddrInfo{ID: h1.ID(), Addrs: []ma.Multiaddr{addrs[0]}})) diff --git a/p2p/transport/quicreuse/config.go b/p2p/transport/quicreuse/config.go index a57cbd13ac..76a2c8cc44 100644 --- a/p2p/transport/quicreuse/config.go +++ b/p2p/transport/quicreuse/config.go @@ -20,4 +20,6 @@ var quicConfig = &quic.Config{ Versions: []quic.VersionNumber{quic.VersionDraft29, quic.Version1}, // We don't use datagrams (yet), but this is necessary for WebTransport EnableDatagrams: true, + // The multiaddress encodes the QUIC version, thus there's no need to send Version Negotiation packets. + DisableVersionNegotiationPackets: true, }