Skip to content

Commit

Permalink
sync: upstream quic-go v0.38.1
Browse files Browse the repository at this point in the history
This is a merge commit.
  • Loading branch information
gaukas authored Aug 28, 2023
2 parents 3d09353 + 9b03bc2 commit 66db44d
Show file tree
Hide file tree
Showing 137 changed files with 1,504 additions and 524 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/ginkgo_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
# os: [ "ubuntu-latest", "windows-latest", "macos-latest" ]
go: [ "1.20.x", "1.21.0-rc.4" ]
go: [ "1.20.x", "1.21.x" ]
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
Expand All @@ -23,20 +23,36 @@ jobs:
go-version: ${{ matrix.go }}
- run: go version

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

# - name: Run tests (32 bit)
# - name: Run unit tests (32 bit)
# if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
# env:
# TIMESCALE_FACTOR: 10
# GOARCH: 386
# 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

# - name: Run tests with race detector
# - name: Run unit tests with race detector
# if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
# env:
# TIMESCALE_FACTOR: 20
# run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -race -randomize-all -randomize-suites -trace -skip-package integrationtests

- name: Run other tests
run: |
go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace -skip-package self,versionnegotiation integrationtests
go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/versionnegotiation
- name: Run self tests, using QUIC v1
if: success() || failure() # run this step even if the previous one failed
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/self -- -version=1
- name: Run self tests, using QUIC v2
if: success() || failure() # run this step even if the previous one failed
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/self -- -version=2
- name: Run self tests, with GSO disabled
if: ${{ matrix.os == 'ubuntu' && (success() || failure()) }} # run this step even if the previous one failed
env:
QUIC_GO_DISABLE_GSO: true
run: go run github.com/onsi/ginkgo/v2/ginkgo -r -v -randomize-all -randomize-suites -trace integrationtests/self -- -version=1
16 changes: 5 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func DialAddr(ctx context.Context, addr string, tlsConf *tls.Config, conf *Confi
if err != nil {
return nil, err
}
dl, err := setupTransport(udpConn, tlsConf, true)
tr, err := setupTransport(udpConn, tlsConf, true)
if err != nil {
return nil, err
}
return dl.Dial(ctx, udpAddr, tlsConf, conf)
return tr.dial(ctx, udpAddr, addr, tlsConf, conf, false)
}

// DialAddrEarly establishes a new 0-RTT QUIC connection to a server.
Expand All @@ -75,13 +75,13 @@ func DialAddrEarly(ctx context.Context, addr string, tlsConf *tls.Config, conf *
if err != nil {
return nil, err
}
dl, err := setupTransport(udpConn, tlsConf, true)
tr, err := setupTransport(udpConn, tlsConf, true)
if err != nil {
return nil, err
}
conn, err := dl.DialEarly(ctx, udpAddr, tlsConf, conf)
conn, err := tr.dial(ctx, udpAddr, addr, tlsConf, conf, true)
if err != nil {
dl.Close()
tr.Close()
return nil, err
}
return conn, nil
Expand Down Expand Up @@ -166,12 +166,6 @@ func dial(
}

func newClient(sendConn sendConn, connIDGenerator ConnectionIDGenerator, config *Config, tlsConf *tls.Config, onClose func(), use0RTT bool) (*client, error) {
if tlsConf == nil {
tlsConf = &tls.Config{}
} else {
tlsConf = tlsConf.Clone()
}

srcConnID, err := connIDGenerator.GenerateConnectionID()
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"github.com/refraction-networking/uquic/internal/utils"
"github.com/refraction-networking/uquic/logging"

"github.com/golang/mock/gomock"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

type nullMultiplexer struct{}
Expand Down
9 changes: 4 additions & 5 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ var newConnection = func(
handshakeDestConnID: destConnID,
srcConnIDLen: srcConnID.Len(),
tokenGenerator: tokenGenerator,
oneRTTStream: newCryptoStream(),
oneRTTStream: newCryptoStream(true),
perspective: protocol.PerspectiveServer,
tracer: tracer,
logger: logger,
Expand Down Expand Up @@ -394,8 +394,7 @@ var newClientConnection = func(
)

s.mtuDiscoverer = newMTUDiscoverer(s.rttStats, getMaxPacketSize(s.conn.RemoteAddr()), s.sentPacketHandler.SetMaxDatagramSize)
oneRTTStream := newCryptoStream()

oneRTTStream := newCryptoStream(true)
params := &wire.TransportParameters{
InitialMaxStreamDataBidiRemote: protocol.ByteCount(s.config.InitialStreamReceiveWindow),
InitialMaxStreamDataBidiLocal: protocol.ByteCount(s.config.InitialStreamReceiveWindow),
Expand Down Expand Up @@ -453,8 +452,8 @@ var newClientConnection = func(
}

func (s *connection) preSetup() {
s.initialStream = newCryptoStream()
s.handshakeStream = newCryptoStream()
s.initialStream = newCryptoStream(false)
s.handshakeStream = newCryptoStream(false)
s.sendQueue = newSendQueue(s.conn)
s.retransmissionQueue = newRetransmissionQueue()
s.frameParser = wire.NewFrameParser(s.config.EnableDatagrams)
Expand Down
7 changes: 3 additions & 4 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import (
"github.com/refraction-networking/uquic/internal/wire"
"github.com/refraction-networking/uquic/logging"

"github.com/golang/mock/gomock"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

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

It("it closes when no matching version is found", func() {
It("closes when no matching version is found", func() {
errChan := make(chan error, 1)
packer.EXPECT().PackCoalescedPacket(gomock.Any(), gomock.Any(), gomock.Any()).MaxTimes(1)
go func() {
defer GinkgoRecover()
cryptoSetup.EXPECT().StartHandshake().MaxTimes(1)
cryptoSetup.EXPECT().NextEvent().Return(handshake.Event{Kind: handshake.EventNoEvent})
errChan <- conn.run()
}()
connRunner.EXPECT().Remove(srcConnID).MaxTimes(1)
packer.EXPECT().PackCoalescedPacket(gomock.Any(), gomock.Any(), gomock.Any()).MaxTimes(1)
gomock.InOrder(
tracer.EXPECT().ReceivedVersionNegotiationPacket(gomock.Any(), gomock.Any(), gomock.Any()),
tracer.EXPECT().ClosedConnection(gomock.Any()).Do(func(e error) {
Expand Down
25 changes: 23 additions & 2 deletions crypto_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ type cryptoStreamImpl struct {

writeOffset protocol.ByteCount
writeBuf []byte

// Reassemble TLS handshake messages before returning them from GetCryptoData.
// This is only needed because crypto/tls doesn't correctly handle post-handshake messages.
onlyCompleteMsg bool
}

func newCryptoStream() cryptoStream {
return &cryptoStreamImpl{queue: newFrameSorter()}
func newCryptoStream(onlyCompleteMsg bool) cryptoStream {
return &cryptoStreamImpl{
queue: newFrameSorter(),
onlyCompleteMsg: onlyCompleteMsg,
}
}

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

// GetCryptoData retrieves data that was received in CRYPTO frames
func (s *cryptoStreamImpl) GetCryptoData() []byte {
if s.onlyCompleteMsg {
if len(s.msgBuf) < 4 {
return nil
}
msgLen := 4 + int(s.msgBuf[1])<<16 + int(s.msgBuf[2])<<8 + int(s.msgBuf[3])
if len(s.msgBuf) < msgLen {
return nil
}
msg := make([]byte, msgLen)
copy(msg, s.msgBuf[:msgLen])
s.msgBuf = s.msgBuf[msgLen:]
return msg
}

b := s.msgBuf
s.msgBuf = nil
return b
Expand Down
22 changes: 21 additions & 1 deletion crypto_stream_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package quic

import (
"crypto/rand"
"fmt"

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

BeforeEach(func() {
str = newCryptoStream()
str = newCryptoStream(false)
})

Context("handling incoming data", func() {
Expand Down Expand Up @@ -137,4 +138,23 @@ var _ = Describe("Crypto Stream", func() {
Expect(f.Data).To(Equal([]byte("bar")))
})
})

It("reassembles data", func() {
str = newCryptoStream(true)
data := make([]byte, 1337)
l := len(data) - 4
data[1] = uint8(l >> 16)
data[2] = uint8(l >> 8)
data[3] = uint8(l)
rand.Read(data[4:])

for i, b := range data {
Expect(str.GetCryptoData()).To(BeEmpty())
Expect(str.HandleCryptoFrame(&wire.CryptoFrame{
Offset: protocol.ByteCount(i),
Data: []byte{b},
})).To(Succeed())
}
Expect(str.GetCryptoData()).To(Equal(data))
})
})
3 changes: 1 addition & 2 deletions framer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"github.com/refraction-networking/uquic/internal/protocol"
"github.com/refraction-networking/uquic/internal/wire"

"github.com/golang/mock/gomock"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)

var _ = Describe("Framer", func() {
Expand Down
Loading

0 comments on commit 66db44d

Please sign in to comment.