Skip to content

Commit 66db44d

Browse files
authored
sync: upstream quic-go v0.38.1
This is a merge commit.
2 parents 3d09353 + 9b03bc2 commit 66db44d

File tree

137 files changed

+1504
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1504
-524
lines changed

.github/workflows/ginkgo_test.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
# os: [ "ubuntu-latest", "windows-latest", "macos-latest" ]
17-
go: [ "1.20.x", "1.21.0-rc.4" ]
17+
go: [ "1.20.x", "1.21.x" ]
1818
runs-on: "ubuntu-latest"
1919
steps:
2020
- uses: actions/checkout@v3
@@ -23,20 +23,36 @@ jobs:
2323
go-version: ${{ matrix.go }}
2424
- run: go version
2525

26-
- name: Run tests
26+
- name: Run unit tests
2727
env:
2828
TIMESCALE_FACTOR: 10
2929
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -cover -randomize-all -randomize-suites -trace -skip-package integrationtests
3030

31-
# - name: Run tests (32 bit)
31+
# - name: Run unit tests (32 bit)
3232
# if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
3333
# env:
3434
# TIMESCALE_FACTOR: 10
3535
# GOARCH: 386
3636
# run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -cover -coverprofile coverage.txt -output-dir . -randomize-all -randomize-suites -trace -skip-package integrationtests
3737

38-
# - name: Run tests with race detector
38+
# - name: Run unit tests with race detector
3939
# if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
4040
# env:
4141
# TIMESCALE_FACTOR: 20
4242
# run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -race -randomize-all -randomize-suites -trace -skip-package integrationtests
43+
44+
- name: Run other tests
45+
run: |
46+
go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace -skip-package self,versionnegotiation integrationtests
47+
go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/versionnegotiation
48+
- name: Run self tests, using QUIC v1
49+
if: success() || failure() # run this step even if the previous one failed
50+
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/self -- -version=1
51+
- name: Run self tests, using QUIC v2
52+
if: success() || failure() # run this step even if the previous one failed
53+
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/self -- -version=2
54+
- name: Run self tests, with GSO disabled
55+
if: ${{ matrix.os == 'ubuntu' && (success() || failure()) }} # run this step even if the previous one failed
56+
env:
57+
QUIC_GO_DISABLE_GSO: true
58+
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/self -- -version=1

client.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ func DialAddr(ctx context.Context, addr string, tlsConf *tls.Config, conf *Confi
5757
if err != nil {
5858
return nil, err
5959
}
60-
dl, err := setupTransport(udpConn, tlsConf, true)
60+
tr, err := setupTransport(udpConn, tlsConf, true)
6161
if err != nil {
6262
return nil, err
6363
}
64-
return dl.Dial(ctx, udpAddr, tlsConf, conf)
64+
return tr.dial(ctx, udpAddr, addr, tlsConf, conf, false)
6565
}
6666

6767
// DialAddrEarly establishes a new 0-RTT QUIC connection to a server.
@@ -75,13 +75,13 @@ func DialAddrEarly(ctx context.Context, addr string, tlsConf *tls.Config, conf *
7575
if err != nil {
7676
return nil, err
7777
}
78-
dl, err := setupTransport(udpConn, tlsConf, true)
78+
tr, err := setupTransport(udpConn, tlsConf, true)
7979
if err != nil {
8080
return nil, err
8181
}
82-
conn, err := dl.DialEarly(ctx, udpAddr, tlsConf, conf)
82+
conn, err := tr.dial(ctx, udpAddr, addr, tlsConf, conf, true)
8383
if err != nil {
84-
dl.Close()
84+
tr.Close()
8585
return nil, err
8686
}
8787
return conn, nil
@@ -166,12 +166,6 @@ func dial(
166166
}
167167

168168
func newClient(sendConn sendConn, connIDGenerator ConnectionIDGenerator, config *Config, tlsConf *tls.Config, onClose func(), use0RTT bool) (*client, error) {
169-
if tlsConf == nil {
170-
tlsConf = &tls.Config{}
171-
} else {
172-
tlsConf = tlsConf.Clone()
173-
}
174-
175169
srcConnID, err := connIDGenerator.GenerateConnectionID()
176170
if err != nil {
177171
return nil, err

client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import (
1313
"github.com/refraction-networking/uquic/internal/utils"
1414
"github.com/refraction-networking/uquic/logging"
1515

16-
"github.com/golang/mock/gomock"
17-
1816
. "github.com/onsi/ginkgo/v2"
1917
. "github.com/onsi/gomega"
18+
"go.uber.org/mock/gomock"
2019
)
2120

2221
type nullMultiplexer struct{}

connection.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ var newConnection = func(
244244
handshakeDestConnID: destConnID,
245245
srcConnIDLen: srcConnID.Len(),
246246
tokenGenerator: tokenGenerator,
247-
oneRTTStream: newCryptoStream(),
247+
oneRTTStream: newCryptoStream(true),
248248
perspective: protocol.PerspectiveServer,
249249
tracer: tracer,
250250
logger: logger,
@@ -394,8 +394,7 @@ var newClientConnection = func(
394394
)
395395

396396
s.mtuDiscoverer = newMTUDiscoverer(s.rttStats, getMaxPacketSize(s.conn.RemoteAddr()), s.sentPacketHandler.SetMaxDatagramSize)
397-
oneRTTStream := newCryptoStream()
398-
397+
oneRTTStream := newCryptoStream(true)
399398
params := &wire.TransportParameters{
400399
InitialMaxStreamDataBidiRemote: protocol.ByteCount(s.config.InitialStreamReceiveWindow),
401400
InitialMaxStreamDataBidiLocal: protocol.ByteCount(s.config.InitialStreamReceiveWindow),
@@ -453,8 +452,8 @@ var newClientConnection = func(
453452
}
454453

455454
func (s *connection) preSetup() {
456-
s.initialStream = newCryptoStream()
457-
s.handshakeStream = newCryptoStream()
455+
s.initialStream = newCryptoStream(false)
456+
s.handshakeStream = newCryptoStream(false)
458457
s.sendQueue = newSendQueue(s.conn)
459458
s.retransmissionQueue = newRetransmissionQueue()
460459
s.frameParser = wire.NewFrameParser(s.config.EnableDatagrams)

connection_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ import (
2626
"github.com/refraction-networking/uquic/internal/wire"
2727
"github.com/refraction-networking/uquic/logging"
2828

29-
"github.com/golang/mock/gomock"
30-
3129
. "github.com/onsi/ginkgo/v2"
3230
. "github.com/onsi/gomega"
31+
"go.uber.org/mock/gomock"
3332
)
3433

3534
func areConnsRunning() bool {
@@ -2703,16 +2702,16 @@ var _ = Describe("Client Connection", func() {
27032702
Expect(recreateErr.nextPacketNumber).To(Equal(protocol.PacketNumber(128)))
27042703
})
27052704

2706-
It("it closes when no matching version is found", func() {
2705+
It("closes when no matching version is found", func() {
27072706
errChan := make(chan error, 1)
2707+
packer.EXPECT().PackCoalescedPacket(gomock.Any(), gomock.Any(), gomock.Any()).MaxTimes(1)
27082708
go func() {
27092709
defer GinkgoRecover()
27102710
cryptoSetup.EXPECT().StartHandshake().MaxTimes(1)
27112711
cryptoSetup.EXPECT().NextEvent().Return(handshake.Event{Kind: handshake.EventNoEvent})
27122712
errChan <- conn.run()
27132713
}()
27142714
connRunner.EXPECT().Remove(srcConnID).MaxTimes(1)
2715-
packer.EXPECT().PackCoalescedPacket(gomock.Any(), gomock.Any(), gomock.Any()).MaxTimes(1)
27162715
gomock.InOrder(
27172716
tracer.EXPECT().ReceivedVersionNegotiationPacket(gomock.Any(), gomock.Any(), gomock.Any()),
27182717
tracer.EXPECT().ClosedConnection(gomock.Any()).Do(func(e error) {

crypto_stream.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ type cryptoStreamImpl struct {
3030

3131
writeOffset protocol.ByteCount
3232
writeBuf []byte
33+
34+
// Reassemble TLS handshake messages before returning them from GetCryptoData.
35+
// This is only needed because crypto/tls doesn't correctly handle post-handshake messages.
36+
onlyCompleteMsg bool
3337
}
3438

35-
func newCryptoStream() cryptoStream {
36-
return &cryptoStreamImpl{queue: newFrameSorter()}
39+
func newCryptoStream(onlyCompleteMsg bool) cryptoStream {
40+
return &cryptoStreamImpl{
41+
queue: newFrameSorter(),
42+
onlyCompleteMsg: onlyCompleteMsg,
43+
}
3744
}
3845

3946
func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error {
@@ -71,6 +78,20 @@ func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error {
7178

7279
// GetCryptoData retrieves data that was received in CRYPTO frames
7380
func (s *cryptoStreamImpl) GetCryptoData() []byte {
81+
if s.onlyCompleteMsg {
82+
if len(s.msgBuf) < 4 {
83+
return nil
84+
}
85+
msgLen := 4 + int(s.msgBuf[1])<<16 + int(s.msgBuf[2])<<8 + int(s.msgBuf[3])
86+
if len(s.msgBuf) < msgLen {
87+
return nil
88+
}
89+
msg := make([]byte, msgLen)
90+
copy(msg, s.msgBuf[:msgLen])
91+
s.msgBuf = s.msgBuf[msgLen:]
92+
return msg
93+
}
94+
7495
b := s.msgBuf
7596
s.msgBuf = nil
7697
return b

crypto_stream_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package quic
22

33
import (
4+
"crypto/rand"
45
"fmt"
56

67
"github.com/refraction-networking/uquic/internal/protocol"
@@ -15,7 +16,7 @@ var _ = Describe("Crypto Stream", func() {
1516
var str cryptoStream
1617

1718
BeforeEach(func() {
18-
str = newCryptoStream()
19+
str = newCryptoStream(false)
1920
})
2021

2122
Context("handling incoming data", func() {
@@ -137,4 +138,23 @@ var _ = Describe("Crypto Stream", func() {
137138
Expect(f.Data).To(Equal([]byte("bar")))
138139
})
139140
})
141+
142+
It("reassembles data", func() {
143+
str = newCryptoStream(true)
144+
data := make([]byte, 1337)
145+
l := len(data) - 4
146+
data[1] = uint8(l >> 16)
147+
data[2] = uint8(l >> 8)
148+
data[3] = uint8(l)
149+
rand.Read(data[4:])
150+
151+
for i, b := range data {
152+
Expect(str.GetCryptoData()).To(BeEmpty())
153+
Expect(str.HandleCryptoFrame(&wire.CryptoFrame{
154+
Offset: protocol.ByteCount(i),
155+
Data: []byte{b},
156+
})).To(Succeed())
157+
}
158+
Expect(str.GetCryptoData()).To(Equal(data))
159+
})
140160
})

framer_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
"github.com/refraction-networking/uquic/internal/protocol"
99
"github.com/refraction-networking/uquic/internal/wire"
1010

11-
"github.com/golang/mock/gomock"
12-
1311
. "github.com/onsi/ginkgo/v2"
1412
. "github.com/onsi/gomega"
13+
"go.uber.org/mock/gomock"
1514
)
1615

1716
var _ = Describe("Framer", func() {

0 commit comments

Comments
 (0)