fix application bug
This commit is contained in:
10
vendor/github.com/lucas-clemente/quic-go/internal/utils/byteorder.go
generated
vendored
10
vendor/github.com/lucas-clemente/quic-go/internal/utils/byteorder.go
generated
vendored
@@ -8,18 +8,10 @@ import (
|
||||
// A ByteOrder specifies how to convert byte sequences into 16-, 32-, or 64-bit unsigned integers.
|
||||
type ByteOrder interface {
|
||||
ReadUintN(b io.ByteReader, length uint8) (uint64, error)
|
||||
ReadUint64(io.ByteReader) (uint64, error)
|
||||
ReadUint32(io.ByteReader) (uint32, error)
|
||||
ReadUint16(io.ByteReader) (uint16, error)
|
||||
|
||||
WriteUint64(*bytes.Buffer, uint64)
|
||||
WriteUint56(*bytes.Buffer, uint64)
|
||||
WriteUint48(*bytes.Buffer, uint64)
|
||||
WriteUint40(*bytes.Buffer, uint64)
|
||||
WriteUintN(b *bytes.Buffer, length uint8, value uint64)
|
||||
WriteUint32(*bytes.Buffer, uint32)
|
||||
WriteUint24(*bytes.Buffer, uint32)
|
||||
WriteUint16(*bytes.Buffer, uint16)
|
||||
|
||||
ReadUfloat16(io.ByteReader) (uint64, error)
|
||||
WriteUfloat16(*bytes.Buffer, uint64)
|
||||
}
|
||||
|
||||
89
vendor/github.com/lucas-clemente/quic-go/internal/utils/byteorder_big_endian.go
generated
vendored
89
vendor/github.com/lucas-clemente/quic-go/internal/utils/byteorder_big_endian.go
generated
vendored
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -26,37 +25,6 @@ func (bigEndian) ReadUintN(b io.ByteReader, length uint8) (uint64, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ReadUint64 reads a uint64
|
||||
func (bigEndian) ReadUint64(b io.ByteReader) (uint64, error) {
|
||||
var b1, b2, b3, b4, b5, b6, b7, b8 uint8
|
||||
var err error
|
||||
if b8, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b7, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b6, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b5, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b4, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b3, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b2, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b1, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(b1) + uint64(b2)<<8 + uint64(b3)<<16 + uint64(b4)<<24 + uint64(b5)<<32 + uint64(b6)<<40 + uint64(b7)<<48 + uint64(b8)<<56, nil
|
||||
}
|
||||
|
||||
// ReadUint32 reads a uint32
|
||||
func (bigEndian) ReadUint32(b io.ByteReader) (uint32, error) {
|
||||
var b1, b2, b3, b4 uint8
|
||||
@@ -89,45 +57,10 @@ func (bigEndian) ReadUint16(b io.ByteReader) (uint16, error) {
|
||||
return uint16(b1) + uint16(b2)<<8, nil
|
||||
}
|
||||
|
||||
// WriteUint64 writes a uint64
|
||||
func (bigEndian) WriteUint64(b *bytes.Buffer, i uint64) {
|
||||
b.Write([]byte{
|
||||
uint8(i >> 56), uint8(i >> 48), uint8(i >> 40), uint8(i >> 32),
|
||||
uint8(i >> 24), uint8(i >> 16), uint8(i >> 8), uint8(i),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint56 writes 56 bit of a uint64
|
||||
func (bigEndian) WriteUint56(b *bytes.Buffer, i uint64) {
|
||||
if i >= (1 << 56) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 56 bits", i))
|
||||
func (bigEndian) WriteUintN(b *bytes.Buffer, length uint8, i uint64) {
|
||||
for j := length; j > 0; j-- {
|
||||
b.WriteByte(uint8(i >> (8 * (j - 1))))
|
||||
}
|
||||
b.Write([]byte{
|
||||
uint8(i >> 48), uint8(i >> 40), uint8(i >> 32),
|
||||
uint8(i >> 24), uint8(i >> 16), uint8(i >> 8), uint8(i),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint48 writes 48 bit of a uint64
|
||||
func (bigEndian) WriteUint48(b *bytes.Buffer, i uint64) {
|
||||
if i >= (1 << 48) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 48 bits", i))
|
||||
}
|
||||
b.Write([]byte{
|
||||
uint8(i >> 40), uint8(i >> 32),
|
||||
uint8(i >> 24), uint8(i >> 16), uint8(i >> 8), uint8(i),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint40 writes 40 bit of a uint64
|
||||
func (bigEndian) WriteUint40(b *bytes.Buffer, i uint64) {
|
||||
if i >= (1 << 40) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 40 bits", i))
|
||||
}
|
||||
b.Write([]byte{
|
||||
uint8(i >> 32),
|
||||
uint8(i >> 24), uint8(i >> 16), uint8(i >> 8), uint8(i),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint32 writes a uint32
|
||||
@@ -135,23 +68,7 @@ func (bigEndian) WriteUint32(b *bytes.Buffer, i uint32) {
|
||||
b.Write([]byte{uint8(i >> 24), uint8(i >> 16), uint8(i >> 8), uint8(i)})
|
||||
}
|
||||
|
||||
// WriteUint24 writes 24 bit of a uint32
|
||||
func (bigEndian) WriteUint24(b *bytes.Buffer, i uint32) {
|
||||
if i >= (1 << 24) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 24 bits", i))
|
||||
}
|
||||
b.Write([]byte{uint8(i >> 16), uint8(i >> 8), uint8(i)})
|
||||
}
|
||||
|
||||
// WriteUint16 writes a uint16
|
||||
func (bigEndian) WriteUint16(b *bytes.Buffer, i uint16) {
|
||||
b.Write([]byte{uint8(i >> 8), uint8(i)})
|
||||
}
|
||||
|
||||
func (l bigEndian) ReadUfloat16(b io.ByteReader) (uint64, error) {
|
||||
return readUfloat16(b, l)
|
||||
}
|
||||
|
||||
func (l bigEndian) WriteUfloat16(b *bytes.Buffer, val uint64) {
|
||||
writeUfloat16(b, l, val)
|
||||
}
|
||||
|
||||
157
vendor/github.com/lucas-clemente/quic-go/internal/utils/byteorder_little_endian.go
generated
vendored
157
vendor/github.com/lucas-clemente/quic-go/internal/utils/byteorder_little_endian.go
generated
vendored
@@ -1,157 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// LittleEndian is the little-endian implementation of ByteOrder.
|
||||
var LittleEndian ByteOrder = littleEndian{}
|
||||
|
||||
type littleEndian struct{}
|
||||
|
||||
var _ ByteOrder = &littleEndian{}
|
||||
|
||||
// ReadUintN reads N bytes
|
||||
func (littleEndian) ReadUintN(b io.ByteReader, length uint8) (uint64, error) {
|
||||
var res uint64
|
||||
for i := uint8(0); i < length; i++ {
|
||||
bt, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
res ^= uint64(bt) << (i * 8)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ReadUint64 reads a uint64
|
||||
func (littleEndian) ReadUint64(b io.ByteReader) (uint64, error) {
|
||||
var b1, b2, b3, b4, b5, b6, b7, b8 uint8
|
||||
var err error
|
||||
if b1, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b2, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b3, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b4, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b5, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b6, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b7, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b8, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(b1) + uint64(b2)<<8 + uint64(b3)<<16 + uint64(b4)<<24 + uint64(b5)<<32 + uint64(b6)<<40 + uint64(b7)<<48 + uint64(b8)<<56, nil
|
||||
}
|
||||
|
||||
// ReadUint32 reads a uint32
|
||||
func (littleEndian) ReadUint32(b io.ByteReader) (uint32, error) {
|
||||
var b1, b2, b3, b4 uint8
|
||||
var err error
|
||||
if b1, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b2, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b3, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b4, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint32(b1) + uint32(b2)<<8 + uint32(b3)<<16 + uint32(b4)<<24, nil
|
||||
}
|
||||
|
||||
// ReadUint16 reads a uint16
|
||||
func (littleEndian) ReadUint16(b io.ByteReader) (uint16, error) {
|
||||
var b1, b2 uint8
|
||||
var err error
|
||||
if b1, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if b2, err = b.ReadByte(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint16(b1) + uint16(b2)<<8, nil
|
||||
}
|
||||
|
||||
// WriteUint64 writes a uint64
|
||||
func (littleEndian) WriteUint64(b *bytes.Buffer, i uint64) {
|
||||
b.Write([]byte{
|
||||
uint8(i), uint8(i >> 8), uint8(i >> 16), uint8(i >> 24),
|
||||
uint8(i >> 32), uint8(i >> 40), uint8(i >> 48), uint8(i >> 56),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint56 writes 56 bit of a uint64
|
||||
func (littleEndian) WriteUint56(b *bytes.Buffer, i uint64) {
|
||||
if i >= (1 << 56) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 56 bits", i))
|
||||
}
|
||||
b.Write([]byte{
|
||||
uint8(i), uint8(i >> 8), uint8(i >> 16), uint8(i >> 24),
|
||||
uint8(i >> 32), uint8(i >> 40), uint8(i >> 48),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint48 writes 48 bit of a uint64
|
||||
func (littleEndian) WriteUint48(b *bytes.Buffer, i uint64) {
|
||||
if i >= (1 << 48) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 48 bits", i))
|
||||
}
|
||||
b.Write([]byte{
|
||||
uint8(i), uint8(i >> 8), uint8(i >> 16), uint8(i >> 24),
|
||||
uint8(i >> 32), uint8(i >> 40),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint40 writes 40 bit of a uint64
|
||||
func (littleEndian) WriteUint40(b *bytes.Buffer, i uint64) {
|
||||
if i >= (1 << 40) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 40 bits", i))
|
||||
}
|
||||
b.Write([]byte{
|
||||
uint8(i), uint8(i >> 8), uint8(i >> 16),
|
||||
uint8(i >> 24), uint8(i >> 32),
|
||||
})
|
||||
}
|
||||
|
||||
// WriteUint32 writes a uint32
|
||||
func (littleEndian) WriteUint32(b *bytes.Buffer, i uint32) {
|
||||
b.Write([]byte{uint8(i), uint8(i >> 8), uint8(i >> 16), uint8(i >> 24)})
|
||||
}
|
||||
|
||||
// WriteUint24 writes 24 bit of a uint32
|
||||
func (littleEndian) WriteUint24(b *bytes.Buffer, i uint32) {
|
||||
if i >= (1 << 24) {
|
||||
panic(fmt.Sprintf("%#x doesn't fit into 24 bits", i))
|
||||
}
|
||||
b.Write([]byte{uint8(i), uint8(i >> 8), uint8(i >> 16)})
|
||||
}
|
||||
|
||||
// WriteUint16 writes a uint16
|
||||
func (littleEndian) WriteUint16(b *bytes.Buffer, i uint16) {
|
||||
b.Write([]byte{uint8(i), uint8(i >> 8)})
|
||||
}
|
||||
|
||||
func (l littleEndian) ReadUfloat16(b io.ByteReader) (uint64, error) {
|
||||
return readUfloat16(b, l)
|
||||
}
|
||||
|
||||
func (l littleEndian) WriteUfloat16(b *bytes.Buffer, val uint64) {
|
||||
writeUfloat16(b, l, val)
|
||||
}
|
||||
86
vendor/github.com/lucas-clemente/quic-go/internal/utils/float16.go
generated
vendored
86
vendor/github.com/lucas-clemente/quic-go/internal/utils/float16.go
generated
vendored
@@ -1,86 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"math"
|
||||
)
|
||||
|
||||
// We define an unsigned 16-bit floating point value, inspired by IEEE floats
|
||||
// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
|
||||
// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
|
||||
// bit) and denormals, but without signs, transfinites or fractions. Wire format
|
||||
// 16 bits (little-endian byte order) are split into exponent (high 5) and
|
||||
// mantissa (low 11) and decoded as:
|
||||
// uint64_t value;
|
||||
// if (exponent == 0) value = mantissa;
|
||||
// else value = (mantissa | 1 << 11) << (exponent - 1)
|
||||
const uFloat16ExponentBits = 5
|
||||
const uFloat16MaxExponent = (1 << uFloat16ExponentBits) - 2 // 30
|
||||
const uFloat16MantissaBits = 16 - uFloat16ExponentBits // 11
|
||||
const uFloat16MantissaEffectiveBits = uFloat16MantissaBits + 1 // 12
|
||||
const uFloat16MaxValue = ((uint64(1) << uFloat16MantissaEffectiveBits) - 1) << uFloat16MaxExponent // 0x3FFC0000000
|
||||
|
||||
// readUfloat16 reads a float in the QUIC-float16 format and returns its uint64 representation
|
||||
func readUfloat16(b io.ByteReader, byteOrder ByteOrder) (uint64, error) {
|
||||
val, err := byteOrder.ReadUint16(b)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
res := uint64(val)
|
||||
|
||||
if res < (1 << uFloat16MantissaEffectiveBits) {
|
||||
// Fast path: either the value is denormalized (no hidden bit), or
|
||||
// normalized (hidden bit set, exponent offset by one) with exponent zero.
|
||||
// Zero exponent offset by one sets the bit exactly where the hidden bit is.
|
||||
// So in both cases the value encodes itself.
|
||||
return res, nil
|
||||
}
|
||||
|
||||
exponent := val >> uFloat16MantissaBits // No sign extend on uint!
|
||||
// After the fast pass, the exponent is at least one (offset by one).
|
||||
// Un-offset the exponent.
|
||||
exponent--
|
||||
// Here we need to clear the exponent and set the hidden bit. We have already
|
||||
// decremented the exponent, so when we subtract it, it leaves behind the
|
||||
// hidden bit.
|
||||
res -= uint64(exponent) << uFloat16MantissaBits
|
||||
res <<= exponent
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// writeUfloat16 writes a float in the QUIC-float16 format from its uint64 representation
|
||||
func writeUfloat16(b *bytes.Buffer, byteOrder ByteOrder, value uint64) {
|
||||
var result uint16
|
||||
if value < (uint64(1) << uFloat16MantissaEffectiveBits) {
|
||||
// Fast path: either the value is denormalized, or has exponent zero.
|
||||
// Both cases are represented by the value itself.
|
||||
result = uint16(value)
|
||||
} else if value >= uFloat16MaxValue {
|
||||
// Value is out of range; clamp it to the maximum representable.
|
||||
result = math.MaxUint16
|
||||
} else {
|
||||
// The highest bit is between position 13 and 42 (zero-based), which
|
||||
// corresponds to exponent 1-30. In the output, mantissa is from 0 to 10,
|
||||
// hidden bit is 11 and exponent is 11 to 15. Shift the highest bit to 11
|
||||
// and count the shifts.
|
||||
exponent := uint16(0)
|
||||
for offset := uint16(16); offset > 0; offset /= 2 {
|
||||
// Right-shift the value until the highest bit is in position 11.
|
||||
// For offset of 16, 8, 4, 2 and 1 (binary search over 1-30),
|
||||
// shift if the bit is at or above 11 + offset.
|
||||
if value >= (uint64(1) << (uFloat16MantissaBits + offset)) {
|
||||
exponent += offset
|
||||
value >>= offset
|
||||
}
|
||||
}
|
||||
|
||||
// Hidden bit (position 11) is set. We should remove it and increment the
|
||||
// exponent. Equivalently, we just add it to the exponent.
|
||||
// This hides the bit.
|
||||
result = (uint16(value) + (exponent << uFloat16MantissaBits))
|
||||
}
|
||||
|
||||
byteOrder.WriteUint16(b, result)
|
||||
}
|
||||
12
vendor/github.com/lucas-clemente/quic-go/internal/utils/minmax.go
generated
vendored
12
vendor/github.com/lucas-clemente/quic-go/internal/utils/minmax.go
generated
vendored
@@ -122,6 +122,18 @@ func MinTime(a, b time.Time) time.Time {
|
||||
return a
|
||||
}
|
||||
|
||||
// MinNonZeroTime returns the earlist time that is not time.Time{}
|
||||
// If both a and b are time.Time{}, it returns time.Time{}
|
||||
func MinNonZeroTime(a, b time.Time) time.Time {
|
||||
if a.IsZero() {
|
||||
return b
|
||||
}
|
||||
if b.IsZero() {
|
||||
return a
|
||||
}
|
||||
return MinTime(a, b)
|
||||
}
|
||||
|
||||
// MaxTime returns the later time
|
||||
func MaxTime(a, b time.Time) time.Time {
|
||||
if a.After(b) {
|
||||
|
||||
50
vendor/github.com/lucas-clemente/quic-go/internal/utils/varint_packetnumber.go
generated
vendored
50
vendor/github.com/lucas-clemente/quic-go/internal/utils/varint_packetnumber.go
generated
vendored
@@ -1,50 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
)
|
||||
|
||||
// ReadVarIntPacketNumber reads a number in the QUIC varint packet number format
|
||||
func ReadVarIntPacketNumber(b *bytes.Reader) (protocol.PacketNumber, protocol.PacketNumberLen, error) {
|
||||
b1, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
if b1&0x80 == 0 {
|
||||
return protocol.PacketNumber(b1), protocol.PacketNumberLen1, nil
|
||||
}
|
||||
b2, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
if b1&0x40 == 0 {
|
||||
return protocol.PacketNumber(uint64(b1&0x3f)<<8 + uint64(b2)), protocol.PacketNumberLen2, nil
|
||||
}
|
||||
b3, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
b4, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return protocol.PacketNumber(uint64(b1&0x3f)<<24 + uint64(b2)<<16 + uint64(b3)<<8 + uint64(b4)), protocol.PacketNumberLen4, nil
|
||||
}
|
||||
|
||||
// WriteVarIntPacketNumber writes a packet number in the QUIC varint packet number format
|
||||
func WriteVarIntPacketNumber(b *bytes.Buffer, i protocol.PacketNumber, len protocol.PacketNumberLen) error {
|
||||
switch len {
|
||||
case protocol.PacketNumberLen1:
|
||||
b.WriteByte(uint8(i & 0x7f))
|
||||
case protocol.PacketNumberLen2:
|
||||
b.Write([]byte{(uint8(i>>8) & 0x3f) | 0x80, uint8(i)})
|
||||
case protocol.PacketNumberLen4:
|
||||
b.Write([]byte{(uint8(i>>24) & 0x3f) | 0xc0, uint8(i >> 16), uint8(i >> 8), uint8(i)})
|
||||
default:
|
||||
return fmt.Errorf("invalid packet number length: %d", len)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user