mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
rename the wire.Header to ExtendedHeader
It's not encrypted yet.
This commit is contained in:
parent
cef26922b4
commit
bf96707f48
17 changed files with 92 additions and 93 deletions
|
@ -331,7 +331,7 @@ func (c *client) handlePacketImpl(p *receivedPacket) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *client) handleVersionNegotiationPacket(hdr *wire.Header) error {
|
||||
func (c *client) handleVersionNegotiationPacket(hdr *wire.ExtendedHeader) error {
|
||||
// ignore delayed / duplicated version negotiation packets
|
||||
if c.receivedVersionNegotiationPacket || c.versionNegotiated {
|
||||
c.logger.Debugf("Received a delayed Version Negotiation Packet.")
|
||||
|
@ -367,7 +367,7 @@ func (c *client) handleVersionNegotiationPacket(hdr *wire.Header) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *client) handleRetryPacket(hdr *wire.Header) {
|
||||
func (c *client) handleRetryPacket(hdr *wire.ExtendedHeader) {
|
||||
c.logger.Debugf("<- Received Retry")
|
||||
hdr.Log(c.logger)
|
||||
if !hdr.OrigDestConnectionID.Equal(c.destConnID) {
|
||||
|
|
|
@ -49,7 +49,7 @@ var _ = Describe("Client", func() {
|
|||
// generate a packet sent by the server that accepts the QUIC version suggested by the client
|
||||
acceptClientVersionPacket := func(connID protocol.ConnectionID) []byte {
|
||||
b := &bytes.Buffer{}
|
||||
Expect((&wire.Header{
|
||||
Expect((&wire.ExtendedHeader{
|
||||
DestConnectionID: connID,
|
||||
PacketNumber: 1,
|
||||
PacketNumberLen: 1,
|
||||
|
@ -60,7 +60,7 @@ var _ = Describe("Client", func() {
|
|||
composeVersionNegotiationPacket := func(connID protocol.ConnectionID, versions []protocol.VersionNumber) *receivedPacket {
|
||||
return &receivedPacket{
|
||||
rcvTime: time.Now(),
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsVersionNegotiation: true,
|
||||
DestConnectionID: connID,
|
||||
SupportedVersions: versions,
|
||||
|
@ -510,7 +510,7 @@ var _ = Describe("Client", func() {
|
|||
manager := NewMockPacketHandlerManager(mockCtrl)
|
||||
manager.EXPECT().Add(gomock.Any(), gomock.Any()).Do(func(id protocol.ConnectionID, handler packetHandler) {
|
||||
go handler.handlePacket(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
Token: []byte("foobar"),
|
||||
|
@ -570,7 +570,7 @@ var _ = Describe("Client", func() {
|
|||
manager := NewMockPacketHandlerManager(mockCtrl)
|
||||
manager.EXPECT().Add(gomock.Any(), gomock.Any()).Do(func(id protocol.ConnectionID, handler packetHandler) {
|
||||
go handler.handlePacket(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
Token: []byte("foobar"),
|
||||
|
@ -678,7 +678,7 @@ var _ = Describe("Client", func() {
|
|||
sess.EXPECT().handlePacket(gomock.Any())
|
||||
cl.session = sess
|
||||
cl.config = &Config{}
|
||||
ph := &wire.Header{
|
||||
ph := &wire.ExtendedHeader{
|
||||
PacketNumber: 1,
|
||||
PacketNumberLen: protocol.PacketNumberLen2,
|
||||
DestConnectionID: connID,
|
||||
|
@ -738,7 +738,7 @@ var _ = Describe("Client", func() {
|
|||
cl.session = NewMockQuicSession(mockCtrl) // don't EXPECT any handlePacket calls
|
||||
connID2 := protocol.ConnectionID{8, 7, 6, 5, 4, 3, 2, 1}
|
||||
Expect(connID).ToNot(Equal(connID2))
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
DestConnectionID: connID2,
|
||||
SrcConnectionID: connID,
|
||||
PacketNumber: 1,
|
||||
|
|
|
@ -22,7 +22,7 @@ type packetData []byte
|
|||
var _ = Describe("QUIC Proxy", func() {
|
||||
makePacket := func(p protocol.PacketNumber, payload []byte) []byte {
|
||||
b := &bytes.Buffer{}
|
||||
hdr := wire.Header{
|
||||
hdr := wire.ExtendedHeader{
|
||||
PacketNumber: p,
|
||||
PacketNumberLen: protocol.PacketNumberLen4,
|
||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0, 0, 0x13, 0x37},
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
)
|
||||
|
||||
// Header is the header of a QUIC packet.
|
||||
type Header struct {
|
||||
// ExtendedHeader is the header of a QUIC packet.
|
||||
type ExtendedHeader struct {
|
||||
Raw []byte
|
||||
|
||||
Version protocol.VersionNumber
|
||||
|
@ -33,7 +33,7 @@ type Header struct {
|
|||
}
|
||||
|
||||
// Write writes the Header.
|
||||
func (h *Header) Write(b *bytes.Buffer, ver protocol.VersionNumber) error {
|
||||
func (h *ExtendedHeader) Write(b *bytes.Buffer, ver protocol.VersionNumber) error {
|
||||
if h.IsLongHeader {
|
||||
return h.writeLongHeader(b, ver)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func (h *Header) Write(b *bytes.Buffer, ver protocol.VersionNumber) error {
|
|||
}
|
||||
|
||||
// TODO: add support for the key phase
|
||||
func (h *Header) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumber) error {
|
||||
func (h *ExtendedHeader) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumber) error {
|
||||
b.WriteByte(byte(0x80 | h.Type))
|
||||
utils.BigEndian.WriteUint32(b, uint32(h.Version))
|
||||
connIDLen, err := encodeConnIDLen(h.DestConnectionID, h.SrcConnectionID)
|
||||
|
@ -76,7 +76,7 @@ func (h *Header) writeLongHeader(b *bytes.Buffer, v protocol.VersionNumber) erro
|
|||
return utils.WriteVarIntPacketNumber(b, h.PacketNumber, h.PacketNumberLen)
|
||||
}
|
||||
|
||||
func (h *Header) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) error {
|
||||
func (h *ExtendedHeader) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) error {
|
||||
typeByte := byte(0x30)
|
||||
typeByte |= byte(h.KeyPhase << 6)
|
||||
|
||||
|
@ -86,7 +86,7 @@ func (h *Header) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) err
|
|||
}
|
||||
|
||||
// GetLength determines the length of the Header.
|
||||
func (h *Header) GetLength(v protocol.VersionNumber) protocol.ByteCount {
|
||||
func (h *ExtendedHeader) GetLength(v protocol.VersionNumber) protocol.ByteCount {
|
||||
if h.IsLongHeader {
|
||||
length := 1 /* type byte */ + 4 /* version */ + 1 /* conn id len byte */ + protocol.ByteCount(h.DestConnectionID.Len()+h.SrcConnectionID.Len()) + protocol.ByteCount(h.PacketNumberLen) + utils.VarIntLen(uint64(h.Length))
|
||||
if h.Type == protocol.PacketTypeInitial {
|
||||
|
@ -101,7 +101,7 @@ func (h *Header) GetLength(v protocol.VersionNumber) protocol.ByteCount {
|
|||
}
|
||||
|
||||
// Log logs the Header
|
||||
func (h *Header) Log(logger utils.Logger) {
|
||||
func (h *ExtendedHeader) Log(logger utils.Logger) {
|
||||
if h.IsLongHeader {
|
||||
if h.Version == 0 {
|
||||
logger.Debugf("\tVersionNegotiationPacket{DestConnectionID: %s, SrcConnectionID: %s, SupportedVersions: %s}", h.DestConnectionID, h.SrcConnectionID, h.SupportedVersions)
|
|
@ -31,7 +31,7 @@ var _ = Describe("Header", func() {
|
|||
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
|
||||
It("writes", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: 0x5,
|
||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe},
|
||||
|
@ -54,7 +54,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("refuses to write a header with a too short connection ID", func() {
|
||||
err := (&Header{
|
||||
err := (&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: 0x5,
|
||||
SrcConnectionID: srcConnID,
|
||||
|
@ -67,7 +67,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("refuses to write a header with a too long connection ID", func() {
|
||||
err := (&Header{
|
||||
err := (&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: 0x5,
|
||||
SrcConnectionID: srcConnID,
|
||||
|
@ -80,7 +80,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("writes a header with an 18 byte connection ID", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: 0x5,
|
||||
SrcConnectionID: srcConnID,
|
||||
|
@ -94,7 +94,7 @@ var _ = Describe("Header", func() {
|
|||
|
||||
It("writes an Initial containing a token", func() {
|
||||
token := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
|
||||
err := (&Header{
|
||||
err := (&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeInitial,
|
||||
Token: token,
|
||||
|
@ -109,7 +109,7 @@ var _ = Describe("Header", func() {
|
|||
|
||||
It("writes a Retry packet", func() {
|
||||
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
||||
err := (&Header{
|
||||
err := (&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
Token: token,
|
||||
|
@ -128,7 +128,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("refuses to write a Retry packet with an invalid Orig Destination Connection ID length", func() {
|
||||
err := (&Header{
|
||||
err := (&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
Token: []byte("foobar"),
|
||||
|
@ -141,7 +141,7 @@ var _ = Describe("Header", func() {
|
|||
|
||||
Context("short header", func() {
|
||||
It("writes a header with connection ID", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
PacketNumber: 0x42,
|
||||
|
@ -154,7 +154,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("writes a header without connection ID", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
PacketNumber: 0x42,
|
||||
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||
|
@ -165,7 +165,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("writes a header with a 2 byte packet number", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
PacketNumberLen: protocol.PacketNumberLen2,
|
||||
PacketNumber: 0x765,
|
||||
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||
|
@ -175,7 +175,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("writes a header with a 4 byte packet number", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
PacketNumberLen: protocol.PacketNumberLen4,
|
||||
PacketNumber: 0x123456,
|
||||
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||
|
@ -185,7 +185,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("errors when given an invalid packet number length", func() {
|
||||
err := (&Header{
|
||||
err := (&ExtendedHeader{
|
||||
PacketNumberLen: 3,
|
||||
PacketNumber: 0xdecafbad,
|
||||
}).Write(buf, versionIETFHeader)
|
||||
|
@ -193,7 +193,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("writes the Key Phase Bit", func() {
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
KeyPhase: 1,
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
PacketNumber: 0x42,
|
||||
|
@ -214,7 +214,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("has the right length for the Long Header, for a short length", func() {
|
||||
h := &Header{
|
||||
h := &ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Length: 1,
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
|
@ -228,7 +228,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("has the right length for the Long Header, for a long length", func() {
|
||||
h := &Header{
|
||||
h := &ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Length: 1500,
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
|
@ -242,7 +242,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("has the right length for an Initial not containing a Token", func() {
|
||||
h := &Header{
|
||||
h := &ExtendedHeader{
|
||||
Type: protocol.PacketTypeInitial,
|
||||
IsLongHeader: true,
|
||||
Length: 1500,
|
||||
|
@ -257,7 +257,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("has the right length for an Initial containing a Token", func() {
|
||||
h := &Header{
|
||||
h := &ExtendedHeader{
|
||||
Type: protocol.PacketTypeInitial,
|
||||
IsLongHeader: true,
|
||||
Length: 1500,
|
||||
|
@ -273,7 +273,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("has the right length for a Short Header containing a connection ID", func() {
|
||||
h := &Header{
|
||||
h := &ExtendedHeader{
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
}
|
||||
|
@ -283,21 +283,21 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("has the right length for a short header without a connection ID", func() {
|
||||
h := &Header{PacketNumberLen: protocol.PacketNumberLen1}
|
||||
h := &ExtendedHeader{PacketNumberLen: protocol.PacketNumberLen1}
|
||||
Expect(h.GetLength(versionIETFHeader)).To(Equal(protocol.ByteCount(1 + 1)))
|
||||
Expect(h.Write(buf, versionIETFHeader)).To(Succeed())
|
||||
Expect(buf.Len()).To(Equal(2))
|
||||
})
|
||||
|
||||
It("has the right length for a short header with a 2 byte packet number", func() {
|
||||
h := &Header{PacketNumberLen: protocol.PacketNumberLen2}
|
||||
h := &ExtendedHeader{PacketNumberLen: protocol.PacketNumberLen2}
|
||||
Expect(h.GetLength(versionIETFHeader)).To(Equal(protocol.ByteCount(1 + 2)))
|
||||
Expect(h.Write(buf, versionIETFHeader)).To(Succeed())
|
||||
Expect(buf.Len()).To(Equal(3))
|
||||
})
|
||||
|
||||
It("has the right length for a short header with a 5 byte packet number", func() {
|
||||
h := &Header{PacketNumberLen: protocol.PacketNumberLen4}
|
||||
h := &ExtendedHeader{PacketNumberLen: protocol.PacketNumberLen4}
|
||||
Expect(h.GetLength(versionIETFHeader)).To(Equal(protocol.ByteCount(1 + 4)))
|
||||
Expect(h.Write(buf, versionIETFHeader)).To(Succeed())
|
||||
Expect(buf.Len()).To(Equal(5))
|
||||
|
@ -337,7 +337,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("logs Long Headers", func() {
|
||||
(&Header{
|
||||
(&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
PacketNumber: 0x1337,
|
||||
|
@ -351,7 +351,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("logs Initial Packets with a Token", func() {
|
||||
(&Header{
|
||||
(&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeInitial,
|
||||
Token: []byte{0xde, 0xad, 0xbe, 0xef},
|
||||
|
@ -366,7 +366,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("logs Initial Packets without a Token", func() {
|
||||
(&Header{
|
||||
(&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeInitial,
|
||||
PacketNumber: 0x42,
|
||||
|
@ -380,7 +380,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("logs Initial Packets with a Token", func() {
|
||||
(&Header{
|
||||
(&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
||||
|
@ -393,7 +393,7 @@ var _ = Describe("Header", func() {
|
|||
})
|
||||
|
||||
It("logs Short Headers containing a connection ID", func() {
|
||||
(&Header{
|
||||
(&ExtendedHeader{
|
||||
KeyPhase: 1,
|
||||
PacketNumber: 0x1337,
|
||||
PacketNumberLen: 4,
|
|
@ -74,7 +74,7 @@ func parseInvariantHeaderImpl(b *bytes.Reader, shortHeaderConnIDLen int) (*Invar
|
|||
|
||||
// Parse parses the version dependent part of the header.
|
||||
// The Reader has to be set such that it points to the first byte of the header.
|
||||
func (iv *InvariantHeader) Parse(b *bytes.Reader, ver protocol.VersionNumber) (*Header, error) {
|
||||
func (iv *InvariantHeader) Parse(b *bytes.Reader, ver protocol.VersionNumber) (*ExtendedHeader, error) {
|
||||
if _, err := b.Seek(int64(iv.len), io.SeekCurrent); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -87,8 +87,8 @@ func (iv *InvariantHeader) Parse(b *bytes.Reader, ver protocol.VersionNumber) (*
|
|||
return iv.parseShortHeader(b, ver)
|
||||
}
|
||||
|
||||
func (iv *InvariantHeader) toHeader() *Header {
|
||||
return &Header{
|
||||
func (iv *InvariantHeader) toExtendedHeader() *ExtendedHeader {
|
||||
return &ExtendedHeader{
|
||||
IsLongHeader: iv.IsLongHeader,
|
||||
DestConnectionID: iv.DestConnectionID,
|
||||
SrcConnectionID: iv.SrcConnectionID,
|
||||
|
@ -96,8 +96,8 @@ func (iv *InvariantHeader) toHeader() *Header {
|
|||
}
|
||||
}
|
||||
|
||||
func (iv *InvariantHeader) parseVersionNegotiationPacket(b *bytes.Reader) (*Header, error) {
|
||||
h := iv.toHeader()
|
||||
func (iv *InvariantHeader) parseVersionNegotiationPacket(b *bytes.Reader) (*ExtendedHeader, error) {
|
||||
h := iv.toExtendedHeader()
|
||||
if b.Len() == 0 {
|
||||
return nil, qerr.Error(qerr.InvalidVersionNegotiationPacket, "empty version list")
|
||||
}
|
||||
|
@ -113,8 +113,8 @@ func (iv *InvariantHeader) parseVersionNegotiationPacket(b *bytes.Reader) (*Head
|
|||
return h, nil
|
||||
}
|
||||
|
||||
func (iv *InvariantHeader) parseLongHeader(b *bytes.Reader, v protocol.VersionNumber) (*Header, error) {
|
||||
h := iv.toHeader()
|
||||
func (iv *InvariantHeader) parseLongHeader(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) {
|
||||
h := iv.toExtendedHeader()
|
||||
h.Type = protocol.PacketType(iv.typeByte & 0x7f)
|
||||
|
||||
if h.Type != protocol.PacketTypeInitial && h.Type != protocol.PacketTypeRetry && h.Type != protocol.PacketType0RTT && h.Type != protocol.PacketTypeHandshake {
|
||||
|
@ -167,8 +167,8 @@ func (iv *InvariantHeader) parseLongHeader(b *bytes.Reader, v protocol.VersionNu
|
|||
return h, nil
|
||||
}
|
||||
|
||||
func (iv *InvariantHeader) parseShortHeader(b *bytes.Reader, v protocol.VersionNumber) (*Header, error) {
|
||||
h := iv.toHeader()
|
||||
func (iv *InvariantHeader) parseShortHeader(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) {
|
||||
h := iv.toExtendedHeader()
|
||||
h.KeyPhase = int(iv.typeByte&0x40) >> 6
|
||||
|
||||
pn, pnLen, err := utils.ReadVarIntPacketNumber(b)
|
||||
|
|
|
@ -180,7 +180,7 @@ var _ = Describe("Header Parsing", func() {
|
|||
It("rejects packets sent with an unknown packet type", func() {
|
||||
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
buf := &bytes.Buffer{}
|
||||
Expect((&Header{
|
||||
Expect((&ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: 42,
|
||||
SrcConnectionID: srcConnID,
|
||||
|
@ -226,7 +226,7 @@ var _ = Describe("Header Parsing", func() {
|
|||
}
|
||||
})
|
||||
|
||||
It("errors on EOF, when parsing the header", func() {
|
||||
It("errors on EOF, when parsing the extended header", func() {
|
||||
data := []byte{
|
||||
0x80 ^ uint8(protocol.PacketTypeInitial),
|
||||
0x1, 0x2, 0x3, 0x4, // version number
|
||||
|
@ -363,7 +363,7 @@ var _ = Describe("Header Parsing", func() {
|
|||
}
|
||||
})
|
||||
|
||||
It("errors on EOF, when parsing the invariant header", func() {
|
||||
It("errors on EOF, when parsing the extended header", func() {
|
||||
data := []byte{
|
||||
0x30 ^ 0x2,
|
||||
0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, // connection ID
|
||||
|
|
|
@ -35,7 +35,7 @@ func (m *MockUnpacker) EXPECT() *MockUnpackerMockRecorder {
|
|||
}
|
||||
|
||||
// Unpack mocks base method
|
||||
func (m *MockUnpacker) Unpack(arg0 []byte, arg1 *wire.Header, arg2 []byte) (*unpackedPacket, error) {
|
||||
func (m *MockUnpacker) Unpack(arg0 []byte, arg1 *wire.ExtendedHeader, arg2 []byte) (*unpackedPacket, error) {
|
||||
ret := m.ctrl.Call(m, "Unpack", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(*unpackedPacket)
|
||||
ret1, _ := ret[1].(error)
|
||||
|
|
|
@ -21,7 +21,7 @@ var _ = Describe("Packet Handler Map", func() {
|
|||
|
||||
getPacket := func(connID protocol.ConnectionID) []byte {
|
||||
buf := &bytes.Buffer{}
|
||||
Expect((&wire.Header{
|
||||
Expect((&wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
DestConnectionID: connID,
|
||||
|
@ -126,7 +126,7 @@ var _ = Describe("Packet Handler Map", func() {
|
|||
packetHandler := NewMockPacketHandler(mockCtrl)
|
||||
packetHandler.EXPECT().GetVersion().Return(protocol.VersionWhatever)
|
||||
handler.Add(connID, packetHandler)
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
Length: 1000,
|
||||
|
@ -147,7 +147,7 @@ var _ = Describe("Packet Handler Map", func() {
|
|||
packetHandler := NewMockPacketHandler(mockCtrl)
|
||||
packetHandler.EXPECT().GetVersion().Return(protocol.VersionWhatever)
|
||||
handler.Add(connID, packetHandler)
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
Length: 3,
|
||||
|
@ -169,7 +169,7 @@ var _ = Describe("Packet Handler Map", func() {
|
|||
Expect(p.data).To(HaveLen(456 - int(p.header.PacketNumberLen)))
|
||||
})
|
||||
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
Length: 456,
|
||||
|
|
|
@ -25,7 +25,7 @@ type packer interface {
|
|||
}
|
||||
|
||||
type packedPacket struct {
|
||||
header *wire.Header
|
||||
header *wire.ExtendedHeader
|
||||
raw []byte
|
||||
frames []wire.Frame
|
||||
encryptionLevel protocol.EncryptionLevel
|
||||
|
@ -397,9 +397,9 @@ func (p *packetPacker) composeNextPacket(
|
|||
return frames, nil
|
||||
}
|
||||
|
||||
func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header {
|
||||
func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.ExtendedHeader {
|
||||
pn, pnLen := p.pnManager.PeekPacketNumber()
|
||||
header := &wire.Header{
|
||||
header := &wire.ExtendedHeader{
|
||||
PacketNumber: pn,
|
||||
PacketNumberLen: pnLen,
|
||||
Version: p.version,
|
||||
|
@ -424,8 +424,7 @@ func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header
|
|||
}
|
||||
|
||||
func (p *packetPacker) writeAndSealPacket(
|
||||
header *wire.Header,
|
||||
frames []wire.Frame,
|
||||
header *wire.ExtendedHeader, frames []wire.Frame,
|
||||
sealer handshake.Sealer,
|
||||
) ([]byte, error) {
|
||||
raw := *getPacketBuffer()
|
||||
|
|
|
@ -35,7 +35,7 @@ func newPacketUnpacker(aead quicAEAD, version protocol.VersionNumber) unpacker {
|
|||
}
|
||||
}
|
||||
|
||||
func (u *packetUnpacker) Unpack(headerBinary []byte, hdr *wire.Header, data []byte) (*unpackedPacket, error) {
|
||||
func (u *packetUnpacker) Unpack(headerBinary []byte, hdr *wire.ExtendedHeader, data []byte) (*unpackedPacket, error) {
|
||||
buf := *getPacketBuffer()
|
||||
buf = buf[:0]
|
||||
defer putPacketBuffer(&buf)
|
||||
|
|
|
@ -15,13 +15,13 @@ import (
|
|||
var _ = Describe("Packet Unpacker", func() {
|
||||
var (
|
||||
unpacker *packetUnpacker
|
||||
hdr *wire.Header
|
||||
hdr *wire.ExtendedHeader
|
||||
aead *MockQuicAEAD
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
aead = NewMockQuicAEAD(mockCtrl)
|
||||
hdr = &wire.Header{
|
||||
hdr = &wire.ExtendedHeader{
|
||||
PacketNumber: 10,
|
||||
PacketNumberLen: 1,
|
||||
Raw: []byte{0x04, 0x4c, 0x01},
|
||||
|
|
|
@ -422,7 +422,7 @@ func (s *server) createNewSession(
|
|||
return sess, nil
|
||||
}
|
||||
|
||||
func (s *server) sendRetry(remoteAddr net.Addr, hdr *wire.Header) error {
|
||||
func (s *server) sendRetry(remoteAddr net.Addr, hdr *wire.ExtendedHeader) error {
|
||||
token, err := s.cookieGenerator.NewToken(remoteAddr, hdr.DestConnectionID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -431,7 +431,7 @@ func (s *server) sendRetry(remoteAddr net.Addr, hdr *wire.Header) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
replyHdr := &wire.Header{
|
||||
replyHdr := &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
Version: hdr.Version,
|
||||
|
|
|
@ -22,7 +22,7 @@ var _ = Describe("Server Session", func() {
|
|||
|
||||
It("handles packets", func() {
|
||||
p := &receivedPacket{
|
||||
header: &wire.Header{DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5}},
|
||||
header: &wire.ExtendedHeader{DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5}},
|
||||
}
|
||||
qsess.EXPECT().handlePacket(p)
|
||||
sess.handlePacket(p)
|
||||
|
@ -32,7 +32,7 @@ var _ = Describe("Server Session", func() {
|
|||
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
|
||||
// don't EXPECT any calls to handlePacket()
|
||||
p := &receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Version: protocol.VersionNumber(123),
|
||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||
|
@ -45,7 +45,7 @@ var _ = Describe("Server Session", func() {
|
|||
It("ignores packets with the wrong Long Header type", func() {
|
||||
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
|
||||
p := &receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeRetry,
|
||||
Version: protocol.VersionNumber(100),
|
||||
|
@ -58,7 +58,7 @@ var _ = Describe("Server Session", func() {
|
|||
|
||||
It("passes on Handshake packets", func() {
|
||||
p := &receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
Version: protocol.VersionNumber(100),
|
||||
|
|
|
@ -98,7 +98,7 @@ var _ = Describe("Server", func() {
|
|||
serv = ln.(*server)
|
||||
})
|
||||
|
||||
parseHeader := func(data []byte) *wire.Header {
|
||||
parseHeader := func(data []byte) *wire.ExtendedHeader {
|
||||
iHdr, err := wire.ParseInvariantHeader(bytes.NewReader(data), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
hdr, err := iHdr.Parse(bytes.NewReader(data), protocol.VersionTLS)
|
||||
|
@ -108,7 +108,7 @@ var _ = Describe("Server", func() {
|
|||
|
||||
It("drops Initial packets with a too short connection ID", func() {
|
||||
serv.handlePacket(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeInitial,
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
||||
|
@ -120,7 +120,7 @@ var _ = Describe("Server", func() {
|
|||
|
||||
It("drops too small Initial", func() {
|
||||
serv.handlePacket(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeInitial,
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
|
@ -132,7 +132,7 @@ var _ = Describe("Server", func() {
|
|||
})
|
||||
|
||||
It("drops packets with a too short connection ID", func() {
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeInitial,
|
||||
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
|
@ -150,7 +150,7 @@ var _ = Describe("Server", func() {
|
|||
It("drops non-Initial packets", func() {
|
||||
serv.logger.SetLogLevel(utils.LogLevelDebug)
|
||||
serv.handlePacket(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
Version: serv.config.Versions[0],
|
||||
},
|
||||
|
@ -174,7 +174,7 @@ var _ = Describe("Server", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
serv.handlePacket(&receivedPacket{
|
||||
remoteAddr: raddr,
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
Type: protocol.PacketTypeInitial,
|
||||
Token: token,
|
||||
Version: serv.config.Versions[0],
|
||||
|
@ -198,7 +198,7 @@ var _ = Describe("Server", func() {
|
|||
}
|
||||
serv.handlePacket(&receivedPacket{
|
||||
remoteAddr: raddr,
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
Type: protocol.PacketTypeInitial,
|
||||
Token: []byte("foobar"),
|
||||
Version: serv.config.Versions[0],
|
||||
|
@ -212,7 +212,7 @@ var _ = Describe("Server", func() {
|
|||
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5}
|
||||
destConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6}
|
||||
serv.handlePacket(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
SrcConnectionID: srcConnID,
|
||||
DestConnectionID: destConnID,
|
||||
|
@ -230,7 +230,7 @@ var _ = Describe("Server", func() {
|
|||
|
||||
It("replies with a Retry packet, if a Cookie is required", func() {
|
||||
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return false }
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
Type: protocol.PacketTypeInitial,
|
||||
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
||||
|
@ -252,7 +252,7 @@ var _ = Describe("Server", func() {
|
|||
|
||||
It("creates a session, if no Cookie is required", func() {
|
||||
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return true }
|
||||
hdr := &wire.Header{
|
||||
hdr := &wire.ExtendedHeader{
|
||||
Type: protocol.PacketTypeInitial,
|
||||
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
|
||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
type unpacker interface {
|
||||
Unpack(headerBinary []byte, hdr *wire.Header, data []byte) (*unpackedPacket, error)
|
||||
Unpack(headerBinary []byte, hdr *wire.ExtendedHeader, data []byte) (*unpackedPacket, error)
|
||||
}
|
||||
|
||||
type streamGetter interface {
|
||||
|
@ -52,7 +52,7 @@ type cryptoStreamHandler interface {
|
|||
|
||||
type receivedPacket struct {
|
||||
remoteAddr net.Addr
|
||||
header *wire.Header
|
||||
header *wire.ExtendedHeader
|
||||
data []byte
|
||||
rcvTime time.Time
|
||||
}
|
||||
|
|
|
@ -444,13 +444,13 @@ var _ = Describe("Session", func() {
|
|||
})
|
||||
|
||||
Context("receiving packets", func() {
|
||||
var hdr *wire.Header
|
||||
var hdr *wire.ExtendedHeader
|
||||
var unpacker *MockUnpacker
|
||||
|
||||
BeforeEach(func() {
|
||||
unpacker = NewMockUnpacker(mockCtrl)
|
||||
sess.unpacker = unpacker
|
||||
hdr = &wire.Header{PacketNumberLen: protocol.PacketNumberLen4}
|
||||
hdr = &wire.ExtendedHeader{PacketNumberLen: protocol.PacketNumberLen4}
|
||||
})
|
||||
|
||||
It("sets the largestRcvdPacketNumber", func() {
|
||||
|
@ -517,7 +517,7 @@ var _ = Describe("Session", func() {
|
|||
// only EXPECT one call to the unpacker
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(&unpackedPacket{}, nil)
|
||||
err := sess.handlePacketImpl(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
DestConnectionID: sess.destConnID,
|
||||
SrcConnectionID: sess.srcConnID,
|
||||
|
@ -526,7 +526,7 @@ var _ = Describe("Session", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
// The next packet has to be ignored, since the source connection ID doesn't match.
|
||||
err = sess.handlePacketImpl(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
DestConnectionID: sess.destConnID,
|
||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||
|
@ -543,7 +543,7 @@ var _ = Describe("Session", func() {
|
|||
Expect(origAddr).ToNot(Equal(remoteIP))
|
||||
p := receivedPacket{
|
||||
remoteAddr: remoteIP,
|
||||
header: &wire.Header{PacketNumber: 1337},
|
||||
header: &wire.ExtendedHeader{PacketNumber: 1337},
|
||||
}
|
||||
err := sess.handlePacketImpl(&p)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -558,7 +558,7 @@ var _ = Describe("Session", func() {
|
|||
data = append(data, []byte("foobar")...)
|
||||
return &packedPacket{
|
||||
raw: data,
|
||||
header: &wire.Header{PacketNumber: pn},
|
||||
header: &wire.ExtendedHeader{PacketNumber: pn},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -929,7 +929,7 @@ var _ = Describe("Session", func() {
|
|||
packer.EXPECT().PackPacket().DoAndReturn(func() (*packedPacket, error) {
|
||||
defer close(done)
|
||||
return &packedPacket{
|
||||
header: &wire.Header{},
|
||||
header: &wire.ExtendedHeader{},
|
||||
raw: *getPacketBuffer(),
|
||||
}, nil
|
||||
}),
|
||||
|
@ -1317,7 +1317,7 @@ var _ = Describe("Client Session", func() {
|
|||
newConnID := protocol.ConnectionID{1, 3, 3, 7, 1, 3, 3, 7}
|
||||
packer.EXPECT().ChangeDestConnectionID(newConnID)
|
||||
err := sess.handlePacketImpl(&receivedPacket{
|
||||
header: &wire.Header{
|
||||
header: &wire.ExtendedHeader{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
SrcConnectionID: newConnID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue