From f16447cf6cc0d406a38d3fd21ce0c5bab9fdc9c7 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 30 May 2023 15:14:23 -0700 Subject: [PATCH] quic: add go1.21 build constraint This package will add on crypto/tls features added in Go 1.21, so use a build constraint to restrict ourselves to that version. Unlocks the ability to use other features from Go versions more recent than what's in x/net's go.mod file. For golang/go#58547 Change-Id: I14011c7506b047e389d9b3e995c0bafcd5e74d44 Reviewed-on: https://go-review.googlesource.com/c/net/+/499283 TryBot-Result: Gopher Robot Run-TryBot: Damien Neil Reviewed-by: Jonathan Amsterdam --- internal/quic/errors.go | 2 + internal/quic/files_test.go | 51 +++++++++++++++++++++++++ internal/quic/frame_debug.go | 2 + internal/quic/packet.go | 2 + internal/quic/packet_codec_test.go | 2 + internal/quic/packet_number.go | 2 + internal/quic/packet_number_test.go | 2 + internal/quic/packet_parser.go | 2 + internal/quic/packet_protection.go | 2 + internal/quic/packet_protection_test.go | 2 + internal/quic/packet_test.go | 2 + internal/quic/packet_writer.go | 2 + internal/quic/quic.go | 2 + internal/quic/rangeset.go | 2 + internal/quic/rangeset_test.go | 2 + internal/quic/sent_packet.go | 4 +- internal/quic/sent_packet_test.go | 4 +- internal/quic/sent_val.go | 2 + internal/quic/sent_val_test.go | 2 + internal/quic/wire.go | 2 + internal/quic/wire_test.go | 2 + 21 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 internal/quic/files_test.go diff --git a/internal/quic/errors.go b/internal/quic/errors.go index 725a7daaa2..a9ebbe4b74 100644 --- a/internal/quic/errors.go +++ b/internal/quic/errors.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/files_test.go b/internal/quic/files_test.go new file mode 100644 index 0000000000..8113109e75 --- /dev/null +++ b/internal/quic/files_test.go @@ -0,0 +1,51 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.21 + +package quic + +import ( + "bytes" + "os" + "strings" + "testing" +) + +// TestFiles checks that every file in this package has a build constraint on Go 1.21. +// +// The QUIC implementation depends on crypto/tls features added in Go 1.21, +// so there's no point in trying to build on anything older. +// +// Drop this test when the x/net go.mod depends on 1.21 or newer. +func TestFiles(t *testing.T) { + f, err := os.Open(".") + if err != nil { + t.Fatal(err) + } + names, err := f.Readdirnames(-1) + if err != nil { + t.Fatal(err) + } + for _, name := range names { + if !strings.HasSuffix(name, ".go") { + continue + } + b, err := os.ReadFile(name) + if err != nil { + t.Fatal(err) + } + // Check for copyright header while we're in here. + if !bytes.Contains(b, []byte("The Go Authors.")) { + t.Errorf("%v: missing copyright", name) + } + // doc.go doesn't need a build constraint. + if name == "doc.go" { + continue + } + if !bytes.Contains(b, []byte("//go:build go1.21")) { + t.Errorf("%v: missing constraint on go1.21", name) + } + } +} diff --git a/internal/quic/frame_debug.go b/internal/quic/frame_debug.go index fa9bdca061..34a0039ba8 100644 --- a/internal/quic/frame_debug.go +++ b/internal/quic/frame_debug.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet.go b/internal/quic/packet.go index 4645ae7091..93a9102e8d 100644 --- a/internal/quic/packet.go +++ b/internal/quic/packet.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic // packetType is a QUIC packet type. diff --git a/internal/quic/packet_codec_test.go b/internal/quic/packet_codec_test.go index ee533c8abf..2a2043b992 100644 --- a/internal/quic/packet_codec_test.go +++ b/internal/quic/packet_codec_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet_number.go b/internal/quic/packet_number.go index 9e9f0ad003..206053e581 100644 --- a/internal/quic/packet_number.go +++ b/internal/quic/packet_number.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic // A packetNumber is a QUIC packet number. diff --git a/internal/quic/packet_number_test.go b/internal/quic/packet_number_test.go index 7450e39881..4d8516ae6c 100644 --- a/internal/quic/packet_number_test.go +++ b/internal/quic/packet_number_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet_parser.go b/internal/quic/packet_parser.go index d06b601d8f..cc025b6f36 100644 --- a/internal/quic/packet_parser.go +++ b/internal/quic/packet_parser.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet_protection.go b/internal/quic/packet_protection.go index 7d96d69cd9..6969ad3a10 100644 --- a/internal/quic/packet_protection.go +++ b/internal/quic/packet_protection.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet_protection_test.go b/internal/quic/packet_protection_test.go index f1d353d8e7..6495360a3b 100644 --- a/internal/quic/packet_protection_test.go +++ b/internal/quic/packet_protection_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet_test.go b/internal/quic/packet_test.go index 3011dda1d4..b13a587e54 100644 --- a/internal/quic/packet_test.go +++ b/internal/quic/packet_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/packet_writer.go b/internal/quic/packet_writer.go index 1f9e30f6e3..494105eff7 100644 --- a/internal/quic/packet_writer.go +++ b/internal/quic/packet_writer.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/quic.go b/internal/quic/quic.go index f7c1b765d7..aae611a5e9 100644 --- a/internal/quic/quic.go +++ b/internal/quic/quic.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/rangeset.go b/internal/quic/rangeset.go index 9d6b63a74f..ea331ab9e2 100644 --- a/internal/quic/rangeset.go +++ b/internal/quic/rangeset.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic // A rangeset is a set of int64s, stored as an ordered list of non-overlapping, diff --git a/internal/quic/rangeset_test.go b/internal/quic/rangeset_test.go index 292284813b..082f9201c7 100644 --- a/internal/quic/rangeset_test.go +++ b/internal/quic/rangeset_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( diff --git a/internal/quic/sent_packet.go b/internal/quic/sent_packet.go index 03d5e53d17..e5a80be3bb 100644 --- a/internal/quic/sent_packet.go +++ b/internal/quic/sent_packet.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import ( @@ -32,7 +34,7 @@ type sentPacket struct { } var sentPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &sentPacket{} }, } diff --git a/internal/quic/sent_packet_test.go b/internal/quic/sent_packet_test.go index 08a3d8ff03..c01a2fb33b 100644 --- a/internal/quic/sent_packet_test.go +++ b/internal/quic/sent_packet_test.go @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import "testing" func TestSentPacket(t *testing.T) { - frames := []interface{}{ + frames := []any{ byte(frameTypePing), byte(frameTypeStreamBase), uint64(1), diff --git a/internal/quic/sent_val.go b/internal/quic/sent_val.go index f1a9c9fbc9..7ca5b70f36 100644 --- a/internal/quic/sent_val.go +++ b/internal/quic/sent_val.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic // A sentVal tracks sending some piece of information to the peer. diff --git a/internal/quic/sent_val_test.go b/internal/quic/sent_val_test.go index 458b221c2a..7f9d676566 100644 --- a/internal/quic/sent_val_test.go +++ b/internal/quic/sent_val_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import "testing" diff --git a/internal/quic/wire.go b/internal/quic/wire.go index 2494ad0311..f0643c9229 100644 --- a/internal/quic/wire.go +++ b/internal/quic/wire.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import "encoding/binary" diff --git a/internal/quic/wire_test.go b/internal/quic/wire_test.go index a5dd836610..379da0d349 100644 --- a/internal/quic/wire_test.go +++ b/internal/quic/wire_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package quic import (