Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare for draft-32 #2831

Merged
merged 3 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Windows Build Status](https://img.shields.io/appveyor/ci/lucas-clemente/quic-go/master.svg?style=flat-square&label=windows+build)](https://ci.appveyor.com/project/lucas-clemente/quic-go/branch/master)
[![Code Coverage](https://img.shields.io/codecov/c/github/lucas-clemente/quic-go/master.svg?style=flat-square)](https://codecov.io/gh/lucas-clemente/quic-go/)

quic-go is an implementation of the [QUIC](https://en.wikipedia.org/wiki/QUIC) protocol in Go. It implements the [IETF QUIC draft-29](https://tools.ietf.org/html/draft-ietf-quic-transport-29).
quic-go is an implementation of the [QUIC](https://en.wikipedia.org/wiki/QUIC) protocol in Go. It implements the [IETF QUIC draft-29](https://tools.ietf.org/html/draft-ietf-quic-transport-29) and [draft-32](https://tools.ietf.org/html/draft-ietf-quic-transport-32).

## Version compatibility

Expand Down
8 changes: 6 additions & 2 deletions conn_id_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type connIDGenerator struct {
retireConnectionID func(protocol.ConnectionID)
replaceWithClosed func(protocol.ConnectionID, packetHandler)
queueControlFrame func(wire.Frame)

version protocol.VersionNumber
}

func newConnIDGenerator(
Expand All @@ -33,6 +35,7 @@ func newConnIDGenerator(
retireConnectionID func(protocol.ConnectionID),
replaceWithClosed func(protocol.ConnectionID, packetHandler),
queueControlFrame func(wire.Frame),
version protocol.VersionNumber,
) *connIDGenerator {
m := &connIDGenerator{
connIDLen: initialConnectionID.Len(),
Expand All @@ -43,6 +46,7 @@ func newConnIDGenerator(
retireConnectionID: retireConnectionID,
replaceWithClosed: replaceWithClosed,
queueControlFrame: queueControlFrame,
version: version,
}
m.activeSrcConnIDs[0] = initialConnectionID
m.initialClientDestConnID = initialClientDestConnID
Expand Down Expand Up @@ -76,7 +80,7 @@ func (m *connIDGenerator) Retire(seq uint64, sentWithDestConnID protocol.Connect
if !ok {
return nil
}
if connID.Equal(sentWithDestConnID) && !RetireBugBackwardsCompatibilityMode {
if connID.Equal(sentWithDestConnID) && !protocol.UseRetireBugBackwardsCompatibilityMode(RetireBugBackwardsCompatibilityMode, m.version) {
return qerr.NewError(qerr.ProtocolViolation, fmt.Sprintf("tried to retire connection ID %d (%s), which was used as the Destination Connection ID on this packet", seq, connID))
}
m.retireConnectionID(connID)
Expand All @@ -89,7 +93,7 @@ func (m *connIDGenerator) Retire(seq uint64, sentWithDestConnID protocol.Connect
}

func (m *connIDGenerator) issueNewConnID() error {
if RetireBugBackwardsCompatibilityMode {
if protocol.UseRetireBugBackwardsCompatibilityMode(RetireBugBackwardsCompatibilityMode, m.version) {
return nil
}
connID, err := protocol.GenerateConnectionID(m.connIDLen)
Expand Down
1 change: 1 addition & 0 deletions conn_id_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var _ = Describe("Connection ID Generator", func() {
func(c protocol.ConnectionID) { retiredConnIDs = append(retiredConnIDs, c) },
func(c protocol.ConnectionID, h packetHandler) { replacedWithClosed[string(c)] = h },
func(f wire.Frame) { queuedFrames = append(queuedFrames, f) },
protocol.VersionDraft29,
)
})

Expand Down
10 changes: 8 additions & 2 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"net"
"time"

"github.com/lucas-clemente/quic-go/logging"

"github.com/lucas-clemente/quic-go/internal/handshake"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/logging"
"github.com/lucas-clemente/quic-go/quictrace"
)

Expand All @@ -29,6 +28,13 @@ type StreamID = protocol.StreamID
// A VersionNumber is a QUIC version number.
type VersionNumber = protocol.VersionNumber

const (
// VersionDraft29 is IETF QUIC draft-29
VersionDraft29 = protocol.VersionDraft29
// VersionDraft32 is IETF QUIC draft-32
VersionDraft32 = protocol.VersionDraft32
)

// A Token can be used to verify the ownership of the client address.
type Token struct {
// IsRetryToken encodes how the client received the token. There are two ways:
Expand Down
12 changes: 12 additions & 0 deletions internal/protocol/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
VersionTLS VersionNumber = 0x51474fff
VersionWhatever VersionNumber = 1 // for when the version doesn't matter
VersionUnknown VersionNumber = math.MaxUint32
VersionDraft29 VersionNumber = 0xff00001d
VersionDraft32 VersionNumber = 0xff000020
)

// SupportedVersions lists the versions that the server supports
Expand All @@ -38,6 +40,10 @@ func (vn VersionNumber) String() string {
return "whatever"
case VersionUnknown:
return "unknown"
case VersionDraft29:
return "draft-29"
case VersionDraft32:
return "draft-32"
case VersionTLS:
return "TLS dev version (WIP)"
default:
Expand All @@ -56,6 +62,12 @@ func (vn VersionNumber) toGQUICVersion() int {
return int(10*(vn-gquicVersion0)/0x100) + int(vn%0x10)
}

// UseRetireBugBackwardsCompatibilityMode says if it is necessary to use the backwards compatilibity mode.
// This is only the case if it 1. is enabled and 2. draft-29 is used.
func UseRetireBugBackwardsCompatibilityMode(enabled bool, v VersionNumber) bool {
return enabled && v == VersionDraft29
}

// IsSupportedVersion returns true if the server supports this version
func IsSupportedVersion(supported []VersionNumber, v VersionNumber) bool {
for _, t := range supported {
Expand Down
11 changes: 11 additions & 0 deletions internal/protocol/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var _ = Describe("Version", func() {
Expect(IsValidVersion(VersionTLS)).To(BeTrue())
Expect(IsValidVersion(VersionWhatever)).To(BeFalse())
Expect(IsValidVersion(VersionUnknown)).To(BeFalse())
Expect(IsValidVersion(VersionDraft29)).To(BeFalse())
Expect(IsValidVersion(VersionDraft32)).To(BeFalse())
Expect(IsValidVersion(1234)).To(BeFalse())
})

Expand All @@ -25,6 +27,8 @@ var _ = Describe("Version", func() {
Expect(VersionTLS.String()).To(ContainSubstring("TLS"))
Expect(VersionWhatever.String()).To(Equal("whatever"))
Expect(VersionUnknown.String()).To(Equal("unknown"))
Expect(VersionDraft29.String()).To(Equal("draft-29"))
Expect(VersionDraft32.String()).To(Equal("draft-32"))
// check with unsupported version numbers from the wiki
Expect(VersionNumber(0x51303039).String()).To(Equal("gQUIC 9"))
Expect(VersionNumber(0x51303133).String()).To(Equal("gQUIC 13"))
Expand All @@ -45,6 +49,13 @@ var _ = Describe("Version", func() {
}
})

It("says if backwards compatibility mode should be used", func() {
Expect(UseRetireBugBackwardsCompatibilityMode(true, VersionDraft29)).To(BeTrue())
Expect(UseRetireBugBackwardsCompatibilityMode(true, VersionDraft32)).To(BeFalse())
Expect(UseRetireBugBackwardsCompatibilityMode(false, VersionDraft29)).To(BeFalse())
Expect(UseRetireBugBackwardsCompatibilityMode(false, VersionDraft32)).To(BeFalse())
})

Context("highest supported version", func() {
It("finds the supported version", func() {
supportedVersions := []VersionNumber{1, 2, 3}
Expand Down
2 changes: 2 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ var newSession = func(
runner.Retire,
runner.ReplaceWithClosed,
s.queueControlFrame,
s.version,
)
s.preSetup()
s.sentPacketHandler, s.receivedPacketHandler = ackhandler.NewAckHandler(
Expand Down Expand Up @@ -390,6 +391,7 @@ var newClientSession = func(
runner.Retire,
runner.ReplaceWithClosed,
s.queueControlFrame,
s.version,
)
s.preSetup()
s.sentPacketHandler, s.receivedPacketHandler = ackhandler.NewAckHandler(
Expand Down