forked from refraction-networking/utls
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): bump github.com/quic-go/quic-go from 0.40.1 to 0.42.0 (r…
…efraction-networking#289) * build(deps): bump github.com/quic-go/quic-go from 0.40.1 to 0.42.0 Bumps [github.com/quic-go/quic-go](https://github.com/quic-go/quic-go) from 0.40.1 to 0.42.0. - [Release notes](https://github.com/quic-go/quic-go/releases) - [Changelog](https://github.com/quic-go/quic-go/blob/master/Changelog.md) - [Commits](quic-go/quic-go@v0.40.1...v0.42.0) --- updated-dependencies: - dependency-name: github.com/quic-go/quic-go dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * update: remove dependency of quic-go We now vendor the quicvarint submodule from quic-go for a minimal dependency tree. This also updates the minimal Go version requirement to Go 1.21, given uTLS promised to support 2 most recent minor versions of Go. Signed-off-by: Gaukas Wang <i@gaukas.wang> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Gaukas Wang <i@gaukas.wang> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gaukas Wang <i@gaukas.wang>
- Loading branch information
1 parent
3d4788c
commit fda1888
Showing
7 changed files
with
307 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright 2024 The quic-go Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file of | ||
// the quic-go repository. | ||
|
||
package protocol | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// The PacketType is the Long Header Type | ||
type PacketType uint8 | ||
|
||
const ( | ||
// PacketTypeInitial is the packet type of an Initial packet | ||
PacketTypeInitial PacketType = 1 + iota | ||
// PacketTypeRetry is the packet type of a Retry packet | ||
PacketTypeRetry | ||
// PacketTypeHandshake is the packet type of a Handshake packet | ||
PacketTypeHandshake | ||
// PacketType0RTT is the packet type of a 0-RTT packet | ||
PacketType0RTT | ||
) | ||
|
||
func (t PacketType) String() string { | ||
switch t { | ||
case PacketTypeInitial: | ||
return "Initial" | ||
case PacketTypeRetry: | ||
return "Retry" | ||
case PacketTypeHandshake: | ||
return "Handshake" | ||
case PacketType0RTT: | ||
return "0-RTT Protected" | ||
default: | ||
return fmt.Sprintf("unknown packet type: %d", t) | ||
} | ||
} | ||
|
||
type ECN uint8 | ||
|
||
const ( | ||
ECNUnsupported ECN = iota | ||
ECNNon // 00 | ||
ECT1 // 01 | ||
ECT0 // 10 | ||
ECNCE // 11 | ||
) | ||
|
||
func ParseECNHeaderBits(bits byte) ECN { | ||
switch bits { | ||
case 0: | ||
return ECNNon | ||
case 0b00000010: | ||
return ECT0 | ||
case 0b00000001: | ||
return ECT1 | ||
case 0b00000011: | ||
return ECNCE | ||
default: | ||
panic("invalid ECN bits") | ||
} | ||
} | ||
|
||
func (e ECN) ToHeaderBits() byte { | ||
//nolint:exhaustive // There are only 4 values. | ||
switch e { | ||
case ECNNon: | ||
return 0 | ||
case ECT0: | ||
return 0b00000010 | ||
case ECT1: | ||
return 0b00000001 | ||
case ECNCE: | ||
return 0b00000011 | ||
default: | ||
panic("ECN unsupported") | ||
} | ||
} | ||
|
||
func (e ECN) String() string { | ||
switch e { | ||
case ECNUnsupported: | ||
return "ECN unsupported" | ||
case ECNNon: | ||
return "Not-ECT" | ||
case ECT1: | ||
return "ECT(1)" | ||
case ECT0: | ||
return "ECT(0)" | ||
case ECNCE: | ||
return "CE" | ||
default: | ||
return fmt.Sprintf("invalid ECN value: %d", e) | ||
} | ||
} | ||
|
||
// A ByteCount in QUIC | ||
type ByteCount int64 | ||
|
||
// MaxByteCount is the maximum value of a ByteCount | ||
const MaxByteCount = ByteCount(1<<62 - 1) | ||
|
||
// InvalidByteCount is an invalid byte count | ||
const InvalidByteCount ByteCount = -1 | ||
|
||
// A StatelessResetToken is a stateless reset token. | ||
type StatelessResetToken [16]byte | ||
|
||
// MaxPacketBufferSize maximum packet size of any QUIC packet, based on | ||
// ethernet's max size, minus the IP and UDP headers. IPv6 has a 40 byte header, | ||
// UDP adds an additional 8 bytes. This is a total overhead of 48 bytes. | ||
// Ethernet's max packet size is 1500 bytes, 1500 - 48 = 1452. | ||
const MaxPacketBufferSize = 1452 | ||
|
||
// MaxLargePacketBufferSize is used when using GSO | ||
const MaxLargePacketBufferSize = 20 * 1024 | ||
|
||
// MinInitialPacketSize is the minimum size an Initial packet is required to have. | ||
const MinInitialPacketSize = 1200 | ||
|
||
// MinUnknownVersionPacketSize is the minimum size a packet with an unknown version | ||
// needs to have in order to trigger a Version Negotiation packet. | ||
const MinUnknownVersionPacketSize = MinInitialPacketSize | ||
|
||
// MinStatelessResetSize is the minimum size of a stateless reset packet that we send | ||
const MinStatelessResetSize = 1 /* first byte */ + 20 /* max. conn ID length */ + 4 /* max. packet number length */ + 1 /* min. payload length */ + 16 /* token */ | ||
|
||
// MinConnectionIDLenInitial is the minimum length of the destination connection ID on an Initial packet. | ||
const MinConnectionIDLenInitial = 8 | ||
|
||
// DefaultAckDelayExponent is the default ack delay exponent | ||
const DefaultAckDelayExponent = 3 | ||
|
||
// DefaultActiveConnectionIDLimit is the default active connection ID limit | ||
const DefaultActiveConnectionIDLimit = 2 | ||
|
||
// MaxAckDelayExponent is the maximum ack delay exponent | ||
const MaxAckDelayExponent = 20 | ||
|
||
// DefaultMaxAckDelay is the default max_ack_delay | ||
const DefaultMaxAckDelay = 25 * time.Millisecond | ||
|
||
// MaxMaxAckDelay is the maximum max_ack_delay | ||
const MaxMaxAckDelay = (1<<14 - 1) * time.Millisecond | ||
|
||
// MaxConnIDLen is the maximum length of the connection ID | ||
const MaxConnIDLen = 20 | ||
|
||
// InvalidPacketLimitAES is the maximum number of packets that we can fail to decrypt when using | ||
// AEAD_AES_128_GCM or AEAD_AES_265_GCM. | ||
const InvalidPacketLimitAES = 1 << 52 | ||
|
||
// InvalidPacketLimitChaCha is the maximum number of packets that we can fail to decrypt when using AEAD_CHACHA20_POLY1305. | ||
const InvalidPacketLimitChaCha = 1 << 36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// Copyright 2024 The quic-go Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file of | ||
// the quic-go repository. | ||
|
||
package quicvarint | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/refraction-networking/utls/internal/quicvarint/protocol" | ||
) | ||
|
||
// taken from the QUIC draft | ||
const ( | ||
// Min is the minimum value allowed for a QUIC varint. | ||
Min = 0 | ||
|
||
// Max is the maximum allowed value for a QUIC varint (2^62-1). | ||
Max = maxVarInt8 | ||
|
||
maxVarInt1 = 63 | ||
maxVarInt2 = 16383 | ||
maxVarInt4 = 1073741823 | ||
maxVarInt8 = 4611686018427387903 | ||
) | ||
|
||
// Read reads a number in the QUIC varint format from r. | ||
func Read(r io.ByteReader) (uint64, error) { | ||
firstByte, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
// the first two bits of the first byte encode the length | ||
len := 1 << ((firstByte & 0xc0) >> 6) | ||
b1 := firstByte & (0xff - 0xc0) | ||
if len == 1 { | ||
return uint64(b1), nil | ||
} | ||
b2, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
if len == 2 { | ||
return uint64(b2) + uint64(b1)<<8, nil | ||
} | ||
b3, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
b4, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
if len == 4 { | ||
return uint64(b4) + uint64(b3)<<8 + uint64(b2)<<16 + uint64(b1)<<24, nil | ||
} | ||
b5, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
b6, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
b7, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
b8, err := r.ReadByte() | ||
if err != nil { | ||
return 0, err | ||
} | ||
return uint64(b8) + uint64(b7)<<8 + uint64(b6)<<16 + uint64(b5)<<24 + uint64(b4)<<32 + uint64(b3)<<40 + uint64(b2)<<48 + uint64(b1)<<56, nil | ||
} | ||
|
||
// Append appends i in the QUIC varint format. | ||
func Append(b []byte, i uint64) []byte { | ||
if i <= maxVarInt1 { | ||
return append(b, uint8(i)) | ||
} | ||
if i <= maxVarInt2 { | ||
return append(b, []byte{uint8(i>>8) | 0x40, uint8(i)}...) | ||
} | ||
if i <= maxVarInt4 { | ||
return append(b, []byte{uint8(i>>24) | 0x80, uint8(i >> 16), uint8(i >> 8), uint8(i)}...) | ||
} | ||
if i <= maxVarInt8 { | ||
return append(b, []byte{ | ||
uint8(i>>56) | 0xc0, uint8(i >> 48), uint8(i >> 40), uint8(i >> 32), | ||
uint8(i >> 24), uint8(i >> 16), uint8(i >> 8), uint8(i), | ||
}...) | ||
} | ||
panic(fmt.Sprintf("%#x doesn't fit into 62 bits", i)) | ||
} | ||
|
||
// AppendWithLen append i in the QUIC varint format with the desired length. | ||
func AppendWithLen(b []byte, i uint64, length protocol.ByteCount) []byte { | ||
if length != 1 && length != 2 && length != 4 && length != 8 { | ||
panic("invalid varint length") | ||
} | ||
l := Len(i) | ||
if l == length { | ||
return Append(b, i) | ||
} | ||
if l > length { | ||
panic(fmt.Sprintf("cannot encode %d in %d bytes", i, length)) | ||
} | ||
if length == 2 { | ||
b = append(b, 0b01000000) | ||
} else if length == 4 { | ||
b = append(b, 0b10000000) | ||
} else if length == 8 { | ||
b = append(b, 0b11000000) | ||
} | ||
for j := protocol.ByteCount(1); j < length-l; j++ { | ||
b = append(b, 0) | ||
} | ||
for j := protocol.ByteCount(0); j < l; j++ { | ||
b = append(b, uint8(i>>(8*(l-1-j)))) | ||
} | ||
return b | ||
} | ||
|
||
// Len determines the number of bytes that will be needed to write the number i. | ||
func Len(i uint64) protocol.ByteCount { | ||
if i <= maxVarInt1 { | ||
return 1 | ||
} | ||
if i <= maxVarInt2 { | ||
return 2 | ||
} | ||
if i <= maxVarInt4 { | ||
return 4 | ||
} | ||
if i <= maxVarInt8 { | ||
return 8 | ||
} | ||
// Don't use a fmt.Sprintf here to format the error message. | ||
// The function would then exceed the inlining budget. | ||
panic(struct { | ||
message string | ||
num uint64 | ||
}{"value doesn't fit into 62 bits: ", i}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters